Commit 10870be8 authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

arc-a11y: Add getter of aura::Window* to AXTreeSourceArc

This change adds AXTreeSourceArc#GetWindow so that we will use it later
for calculating scale factors. With the change, AXTreeSourceArc no
longer need to track a device scale factor because it can be extracted
from the window, and this CL deletes related codes as well.

This is a preparation of the next patch.

AX-Relnotes: n/a. (a part of preparation for ARC R)
Bug: b:17251157
Test: unit tests still passes.
Change-Id: I3c3df7801bec70c09a20c86df7b7033b55dafa97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543524
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829046}
parent ac980495
......@@ -25,11 +25,12 @@ void AccessibilityInfoDataWrapper::Serialize(ui::AXNodeData* out_data) const {
void AccessibilityInfoDataWrapper::PopulateBounds(
ui::AXNodeData* out_data) const {
aura::Window* window = tree_source_->GetWindow();
AccessibilityInfoDataWrapper* root = tree_source_->GetRoot();
gfx::Rect info_data_bounds = GetBounds();
gfx::RectF& out_bounds = out_data->relative_bounds.bounds;
if (root && exo::WMHelper::HasInstance()) {
if (window && root && exo::WMHelper::HasInstance()) {
if (tree_source_->is_notification() ||
tree_source_->is_input_method_window() || root->GetId() != GetId()) {
// By default, populate the bounds relative to the tree root.
......@@ -41,8 +42,7 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
} else {
// For the root node of application tree, populate the bounds to be
// relative to its container View.
views::Widget* widget = views::Widget::GetWidgetForNativeView(
exo::WMHelper::GetInstance()->GetActiveWindow());
views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
DCHECK(widget);
DCHECK(widget->widget_delegate());
DCHECK(widget->widget_delegate()->GetContentsView());
......@@ -55,7 +55,8 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
// |out_bounds| is in Chrome DPI here. As ARC is considered the same as web
// in Chrome automation, scale the bounds by device scale factor.
out_bounds.Scale(tree_source_->device_scale_factor());
out_bounds.Scale(
window->GetToplevelWindow()->layer()->device_scale_factor());
} else {
// We cannot compute global bounds, so use the raw bounds.
out_bounds.SetRect(info_data_bounds.x(), info_data_bounds.y(),
......
......@@ -63,7 +63,7 @@ class AccessibilityNodeInfoDataWrapperTest : public testing::Test,
class TestAXTreeSourceArc : public AXTreeSourceArc {
public:
explicit TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate)
: AXTreeSourceArc(delegate, 1.0) {}
: AXTreeSourceArc(delegate) {}
// AXTreeSourceArc overrides.
bool IsRootOfNodeTree(int32_t id) const override {
......
......@@ -424,23 +424,11 @@ void ArcAccessibilityHelperBridge::OnNotificationStateChanged(
auto key = KeyForNotification(notification_key);
switch (state) {
case arc::mojom::AccessibilityNotificationStateType::SURFACE_CREATED: {
aura::Window* window = nullptr;
auto* surface_manager = ArcNotificationSurfaceManager::Get();
if (surface_manager) {
ArcNotificationSurface* surface =
surface_manager->GetArcSurface(notification_key);
if (surface)
window = surface->GetWindow();
}
AXTreeSourceArc* tree_source = GetFromKey(key);
if (tree_source) {
tree_source->set_device_scale_factor(
DeviceScaleFactorFromWindow(window));
if (tree_source)
return;
}
tree_source = CreateFromKey(std::move(key), window);
tree_source = CreateFromKey(std::move(key));
UpdateTreeIdOfNotificationSurface(notification_key,
tree_source->ax_tree_id());
break;
......@@ -546,8 +534,6 @@ void ArcAccessibilityHelperBridge::OnNotificationSurfaceAdded(
return;
surface->SetAXTreeId(tree->ax_tree_id());
tree->set_device_scale_factor(
DeviceScaleFactorFromWindow(surface->GetWindow()));
// Dispatch ax::mojom::Event::kChildrenChanged to force AXNodeData of the
// notification updated. As order of OnNotificationSurfaceAdded call is not
......@@ -804,7 +790,7 @@ void ArcAccessibilityHelperBridge::UpdateWindowProperties(
TreeKey key = KeyForTaskId(task_id);
AXTreeSourceArc* tree = GetFromKey(key);
if (!tree)
tree = CreateFromKey(std::move(key), window);
tree = CreateFromKey(std::move(key));
// Just after the creation of window, widget has not been set yet and this
// is not dispatched to ShellSurfaceBase. Thus, call this every time.
......@@ -876,14 +862,14 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
return;
if (!trees_.count(KeyForInputMethod())) {
auto* tree = CreateFromKey(KeyForInputMethod(),
input_method_surface->host_window());
auto* tree = CreateFromKey(KeyForInputMethod());
input_method_surface->SetChildAxTreeId(tree->ax_tree_id());
}
tree_source = GetFromKey(KeyForInputMethod());
} else {
aura::Window* active_window = GetActiveWindow();
// TODO(b/173658482): Support non-active windows.
if (!active_window)
return;
......@@ -905,7 +891,7 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
tree_source = GetFromKey(key);
if (!tree_source) {
tree_source = CreateFromKey(key, active_window);
tree_source = CreateFromKey(key);
SetChildAxTreeIDForWindow(active_window, tree_source->ax_tree_id());
if (chromeos::AccessibilityManager::Get() &&
chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
......@@ -913,9 +899,6 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
// compare this with TalkBack usage.
base::UmaHistogramBoolean("Arc.AccessibilityWithTalkBack", false);
}
} else {
tree_source->set_device_scale_factor(
DeviceScaleFactorFromWindow(active_window));
}
}
......@@ -1017,11 +1000,8 @@ void ArcAccessibilityHelperBridge::DispatchCustomSpokenFeedbackToggled(
GetEventRouter()->BroadcastEvent(std::move(event));
}
AXTreeSourceArc* ArcAccessibilityHelperBridge::CreateFromKey(
TreeKey key,
aura::Window* window) {
auto tree = std::make_unique<AXTreeSourceArc>(
this, DeviceScaleFactorFromWindow(window));
AXTreeSourceArc* ArcAccessibilityHelperBridge::CreateFromKey(TreeKey key) {
auto tree = std::make_unique<AXTreeSourceArc>(this);
auto* tree_ptr = tree.get();
trees_.insert(std::make_pair(std::move(key), std::move(tree)));
return tree_ptr;
......
......@@ -172,7 +172,7 @@ class ArcAccessibilityHelperBridge
mojom::AccessibilityEventData* event_data) const;
void DispatchCustomSpokenFeedbackToggled(bool enabled) const;
AXTreeSourceArc* CreateFromKey(TreeKey, aura::Window* window);
AXTreeSourceArc* CreateFromKey(TreeKey);
AXTreeSourceArc* GetFromKey(const TreeKey&);
AXTreeSourceArc* GetFromTreeId(ui::AXTreeID tree_id) const;
......
......@@ -8,12 +8,16 @@
#include <string>
#include <utility>
#include "ash/public/cpp/external_arc/message_center/arc_notification_surface.h"
#include "ash/public/cpp/external_arc/message_center/arc_notification_surface_manager.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chromeos/arc/accessibility/accessibility_node_info_data_wrapper.h"
#include "chrome/browser/chromeos/arc/accessibility/accessibility_window_info_data_wrapper.h"
#include "chrome/browser/chromeos/arc/accessibility/arc_accessibility_util.h"
#include "chrome/browser/chromeos/arc/accessibility/geometry_util.h"
#include "components/exo/input_method_surface.h"
#include "components/exo/wm_helper.h"
#include "extensions/browser/api/automation_internal/automation_event_router.h"
#include "extensions/common/extension_messages.h"
#include "ui/accessibility/ax_enums.mojom.h"
......@@ -47,9 +51,8 @@ bool IsDrawerLayout(AXNodeInfoData* node) {
}
} // namespace
AXTreeSourceArc::AXTreeSourceArc(Delegate* delegate, float device_scale_factor)
: device_scale_factor_(device_scale_factor),
current_tree_serializer_(new AXTreeArcSerializer(this)),
AXTreeSourceArc::AXTreeSourceArc(Delegate* delegate)
: current_tree_serializer_(new AXTreeArcSerializer(this)),
is_notification_(false),
is_input_method_window_(false),
delegate_(delegate) {}
......@@ -151,6 +154,35 @@ void AXTreeSourceArc::SerializeNode(AccessibilityInfoDataWrapper* info_data,
info_data->Serialize(out_data);
}
aura::Window* AXTreeSourceArc::GetWindow() const {
if (is_notification_) {
if (!notification_key_.has_value())
return nullptr;
auto* surface_manager = ash::ArcNotificationSurfaceManager::Get();
if (!surface_manager)
return nullptr;
ash::ArcNotificationSurface* surface =
surface_manager->GetArcSurface(notification_key_.value());
if (!surface)
return nullptr;
return surface->GetWindow();
} else if (is_input_method_window_) {
exo::InputMethodSurface* input_method_surface =
exo::InputMethodSurface::GetInputMethodSurface();
if (!input_method_surface)
return nullptr;
return input_method_surface->host_window();
} else if (exo::WMHelper::HasInstance()) {
// TODO(b/173658482): Support non-active windows.
return exo::WMHelper::GetInstance()->GetActiveWindow();
}
return nullptr;
}
void AXTreeSourceArc::NotifyAccessibilityEventInternal(
const AXEventData& event_data) {
if (window_id_ != event_data.window_id) {
......@@ -158,6 +190,8 @@ void AXTreeSourceArc::NotifyAccessibilityEventInternal(
window_id_ = event_data.window_id;
}
is_notification_ = event_data.notification_key.has_value();
if (is_notification_)
notification_key_ = event_data.notification_key;
is_input_method_window_ = event_data.is_input_method_window;
// Prepare the wrapper objects of mojom data from Android.
......
......@@ -45,7 +45,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
virtual bool UseFullFocusMode() const = 0;
};
AXTreeSourceArc(Delegate* delegate, float device_scale_factor);
explicit AXTreeSourceArc(Delegate* delegate);
~AXTreeSourceArc() override;
// Notify automation of an accessibility event.
......@@ -85,8 +85,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
void SerializeNode(AccessibilityInfoDataWrapper* info_data,
ui::AXNodeData* out_data) const override;
float device_scale_factor() const { return device_scale_factor_; }
void set_device_scale_factor(float dsf) { device_scale_factor_ = dsf; }
aura::Window* GetWindow() const;
bool is_notification() { return is_notification_; }
......@@ -162,9 +161,6 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
// Maps an AccessibilityInfoDataWrapper ID to its tree data.
std::map<int32_t, std::unique_ptr<AccessibilityInfoDataWrapper>> tree_map_;
// The device scale factor of the display which the window is on.
float device_scale_factor_;
// Maps an AccessibilityInfoDataWrapper ID to its parent.
std::map<int32_t, int32_t> parent_map_;
......@@ -176,6 +172,8 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
bool is_notification_;
bool is_input_method_window_;
base::Optional<std::string> notification_key_;
std::map<int32_t, std::string> cached_names_;
std::map<int32_t, ax::mojom::Role> cached_roles_;
......
......@@ -137,7 +137,7 @@ class AXTreeSourceArcTest : public testing::Test,
public:
TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate,
MockAutomationEventRouter* router)
: AXTreeSourceArc(delegate, 1.0), router_(router) {}
: AXTreeSourceArc(delegate), router_(router) {}
private:
extensions::AutomationEventRouterInterface* GetAutomationEventRouter()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment