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 { ...@@ -25,11 +25,12 @@ void AccessibilityInfoDataWrapper::Serialize(ui::AXNodeData* out_data) const {
void AccessibilityInfoDataWrapper::PopulateBounds( void AccessibilityInfoDataWrapper::PopulateBounds(
ui::AXNodeData* out_data) const { ui::AXNodeData* out_data) const {
aura::Window* window = tree_source_->GetWindow();
AccessibilityInfoDataWrapper* root = tree_source_->GetRoot(); AccessibilityInfoDataWrapper* root = tree_source_->GetRoot();
gfx::Rect info_data_bounds = GetBounds(); gfx::Rect info_data_bounds = GetBounds();
gfx::RectF& out_bounds = out_data->relative_bounds.bounds; 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() || if (tree_source_->is_notification() ||
tree_source_->is_input_method_window() || root->GetId() != GetId()) { tree_source_->is_input_method_window() || root->GetId() != GetId()) {
// By default, populate the bounds relative to the tree root. // By default, populate the bounds relative to the tree root.
...@@ -41,8 +42,7 @@ void AccessibilityInfoDataWrapper::PopulateBounds( ...@@ -41,8 +42,7 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
} else { } else {
// For the root node of application tree, populate the bounds to be // For the root node of application tree, populate the bounds to be
// relative to its container View. // relative to its container View.
views::Widget* widget = views::Widget::GetWidgetForNativeView( views::Widget* widget = views::Widget::GetWidgetForNativeView(window);
exo::WMHelper::GetInstance()->GetActiveWindow());
DCHECK(widget); DCHECK(widget);
DCHECK(widget->widget_delegate()); DCHECK(widget->widget_delegate());
DCHECK(widget->widget_delegate()->GetContentsView()); DCHECK(widget->widget_delegate()->GetContentsView());
...@@ -55,7 +55,8 @@ void AccessibilityInfoDataWrapper::PopulateBounds( ...@@ -55,7 +55,8 @@ void AccessibilityInfoDataWrapper::PopulateBounds(
// |out_bounds| is in Chrome DPI here. As ARC is considered the same as web // |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. // 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 { } else {
// We cannot compute global bounds, so use the raw bounds. // We cannot compute global bounds, so use the raw bounds.
out_bounds.SetRect(info_data_bounds.x(), info_data_bounds.y(), out_bounds.SetRect(info_data_bounds.x(), info_data_bounds.y(),
......
...@@ -63,7 +63,7 @@ class AccessibilityNodeInfoDataWrapperTest : public testing::Test, ...@@ -63,7 +63,7 @@ class AccessibilityNodeInfoDataWrapperTest : public testing::Test,
class TestAXTreeSourceArc : public AXTreeSourceArc { class TestAXTreeSourceArc : public AXTreeSourceArc {
public: public:
explicit TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate) explicit TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate)
: AXTreeSourceArc(delegate, 1.0) {} : AXTreeSourceArc(delegate) {}
// AXTreeSourceArc overrides. // AXTreeSourceArc overrides.
bool IsRootOfNodeTree(int32_t id) const override { bool IsRootOfNodeTree(int32_t id) const override {
......
...@@ -424,23 +424,11 @@ void ArcAccessibilityHelperBridge::OnNotificationStateChanged( ...@@ -424,23 +424,11 @@ void ArcAccessibilityHelperBridge::OnNotificationStateChanged(
auto key = KeyForNotification(notification_key); auto key = KeyForNotification(notification_key);
switch (state) { switch (state) {
case arc::mojom::AccessibilityNotificationStateType::SURFACE_CREATED: { 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); AXTreeSourceArc* tree_source = GetFromKey(key);
if (tree_source) { if (tree_source)
tree_source->set_device_scale_factor(
DeviceScaleFactorFromWindow(window));
return; return;
}
tree_source = CreateFromKey(std::move(key), window); tree_source = CreateFromKey(std::move(key));
UpdateTreeIdOfNotificationSurface(notification_key, UpdateTreeIdOfNotificationSurface(notification_key,
tree_source->ax_tree_id()); tree_source->ax_tree_id());
break; break;
...@@ -546,8 +534,6 @@ void ArcAccessibilityHelperBridge::OnNotificationSurfaceAdded( ...@@ -546,8 +534,6 @@ void ArcAccessibilityHelperBridge::OnNotificationSurfaceAdded(
return; return;
surface->SetAXTreeId(tree->ax_tree_id()); surface->SetAXTreeId(tree->ax_tree_id());
tree->set_device_scale_factor(
DeviceScaleFactorFromWindow(surface->GetWindow()));
// Dispatch ax::mojom::Event::kChildrenChanged to force AXNodeData of the // Dispatch ax::mojom::Event::kChildrenChanged to force AXNodeData of the
// notification updated. As order of OnNotificationSurfaceAdded call is not // notification updated. As order of OnNotificationSurfaceAdded call is not
...@@ -804,7 +790,7 @@ void ArcAccessibilityHelperBridge::UpdateWindowProperties( ...@@ -804,7 +790,7 @@ void ArcAccessibilityHelperBridge::UpdateWindowProperties(
TreeKey key = KeyForTaskId(task_id); TreeKey key = KeyForTaskId(task_id);
AXTreeSourceArc* tree = GetFromKey(key); AXTreeSourceArc* tree = GetFromKey(key);
if (!tree) 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 // Just after the creation of window, widget has not been set yet and this
// is not dispatched to ShellSurfaceBase. Thus, call this every time. // is not dispatched to ShellSurfaceBase. Thus, call this every time.
...@@ -876,14 +862,14 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent( ...@@ -876,14 +862,14 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
return; return;
if (!trees_.count(KeyForInputMethod())) { if (!trees_.count(KeyForInputMethod())) {
auto* tree = CreateFromKey(KeyForInputMethod(), auto* tree = CreateFromKey(KeyForInputMethod());
input_method_surface->host_window());
input_method_surface->SetChildAxTreeId(tree->ax_tree_id()); input_method_surface->SetChildAxTreeId(tree->ax_tree_id());
} }
tree_source = GetFromKey(KeyForInputMethod()); tree_source = GetFromKey(KeyForInputMethod());
} else { } else {
aura::Window* active_window = GetActiveWindow(); aura::Window* active_window = GetActiveWindow();
// TODO(b/173658482): Support non-active windows.
if (!active_window) if (!active_window)
return; return;
...@@ -905,7 +891,7 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent( ...@@ -905,7 +891,7 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
tree_source = GetFromKey(key); tree_source = GetFromKey(key);
if (!tree_source) { if (!tree_source) {
tree_source = CreateFromKey(key, active_window); tree_source = CreateFromKey(key);
SetChildAxTreeIDForWindow(active_window, tree_source->ax_tree_id()); SetChildAxTreeIDForWindow(active_window, tree_source->ax_tree_id());
if (chromeos::AccessibilityManager::Get() && if (chromeos::AccessibilityManager::Get() &&
chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) { chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled()) {
...@@ -913,9 +899,6 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent( ...@@ -913,9 +899,6 @@ void ArcAccessibilityHelperBridge::HandleFilterTypeAllEvent(
// compare this with TalkBack usage. // compare this with TalkBack usage.
base::UmaHistogramBoolean("Arc.AccessibilityWithTalkBack", false); base::UmaHistogramBoolean("Arc.AccessibilityWithTalkBack", false);
} }
} else {
tree_source->set_device_scale_factor(
DeviceScaleFactorFromWindow(active_window));
} }
} }
...@@ -1017,11 +1000,8 @@ void ArcAccessibilityHelperBridge::DispatchCustomSpokenFeedbackToggled( ...@@ -1017,11 +1000,8 @@ void ArcAccessibilityHelperBridge::DispatchCustomSpokenFeedbackToggled(
GetEventRouter()->BroadcastEvent(std::move(event)); GetEventRouter()->BroadcastEvent(std::move(event));
} }
AXTreeSourceArc* ArcAccessibilityHelperBridge::CreateFromKey( AXTreeSourceArc* ArcAccessibilityHelperBridge::CreateFromKey(TreeKey key) {
TreeKey key, auto tree = std::make_unique<AXTreeSourceArc>(this);
aura::Window* window) {
auto tree = std::make_unique<AXTreeSourceArc>(
this, DeviceScaleFactorFromWindow(window));
auto* tree_ptr = tree.get(); auto* tree_ptr = tree.get();
trees_.insert(std::make_pair(std::move(key), std::move(tree))); trees_.insert(std::make_pair(std::move(key), std::move(tree)));
return tree_ptr; return tree_ptr;
......
...@@ -172,7 +172,7 @@ class ArcAccessibilityHelperBridge ...@@ -172,7 +172,7 @@ class ArcAccessibilityHelperBridge
mojom::AccessibilityEventData* event_data) const; mojom::AccessibilityEventData* event_data) const;
void DispatchCustomSpokenFeedbackToggled(bool enabled) const; void DispatchCustomSpokenFeedbackToggled(bool enabled) const;
AXTreeSourceArc* CreateFromKey(TreeKey, aura::Window* window); AXTreeSourceArc* CreateFromKey(TreeKey);
AXTreeSourceArc* GetFromKey(const TreeKey&); AXTreeSourceArc* GetFromKey(const TreeKey&);
AXTreeSourceArc* GetFromTreeId(ui::AXTreeID tree_id) const; AXTreeSourceArc* GetFromTreeId(ui::AXTreeID tree_id) const;
......
...@@ -8,12 +8,16 @@ ...@@ -8,12 +8,16 @@
#include <string> #include <string>
#include <utility> #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/string_util.h"
#include "base/strings/stringprintf.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_node_info_data_wrapper.h"
#include "chrome/browser/chromeos/arc/accessibility/accessibility_window_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/arc_accessibility_util.h"
#include "chrome/browser/chromeos/arc/accessibility/geometry_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/browser/api/automation_internal/automation_event_router.h"
#include "extensions/common/extension_messages.h" #include "extensions/common/extension_messages.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
...@@ -47,9 +51,8 @@ bool IsDrawerLayout(AXNodeInfoData* node) { ...@@ -47,9 +51,8 @@ bool IsDrawerLayout(AXNodeInfoData* node) {
} }
} // namespace } // namespace
AXTreeSourceArc::AXTreeSourceArc(Delegate* delegate, float device_scale_factor) AXTreeSourceArc::AXTreeSourceArc(Delegate* delegate)
: device_scale_factor_(device_scale_factor), : current_tree_serializer_(new AXTreeArcSerializer(this)),
current_tree_serializer_(new AXTreeArcSerializer(this)),
is_notification_(false), is_notification_(false),
is_input_method_window_(false), is_input_method_window_(false),
delegate_(delegate) {} delegate_(delegate) {}
...@@ -151,6 +154,35 @@ void AXTreeSourceArc::SerializeNode(AccessibilityInfoDataWrapper* info_data, ...@@ -151,6 +154,35 @@ void AXTreeSourceArc::SerializeNode(AccessibilityInfoDataWrapper* info_data,
info_data->Serialize(out_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( void AXTreeSourceArc::NotifyAccessibilityEventInternal(
const AXEventData& event_data) { const AXEventData& event_data) {
if (window_id_ != event_data.window_id) { if (window_id_ != event_data.window_id) {
...@@ -158,6 +190,8 @@ void AXTreeSourceArc::NotifyAccessibilityEventInternal( ...@@ -158,6 +190,8 @@ void AXTreeSourceArc::NotifyAccessibilityEventInternal(
window_id_ = event_data.window_id; window_id_ = event_data.window_id;
} }
is_notification_ = event_data.notification_key.has_value(); 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; is_input_method_window_ = event_data.is_input_method_window;
// Prepare the wrapper objects of mojom data from Android. // Prepare the wrapper objects of mojom data from Android.
......
...@@ -45,7 +45,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*, ...@@ -45,7 +45,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
virtual bool UseFullFocusMode() const = 0; virtual bool UseFullFocusMode() const = 0;
}; };
AXTreeSourceArc(Delegate* delegate, float device_scale_factor); explicit AXTreeSourceArc(Delegate* delegate);
~AXTreeSourceArc() override; ~AXTreeSourceArc() override;
// Notify automation of an accessibility event. // Notify automation of an accessibility event.
...@@ -85,8 +85,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*, ...@@ -85,8 +85,7 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
void SerializeNode(AccessibilityInfoDataWrapper* info_data, void SerializeNode(AccessibilityInfoDataWrapper* info_data,
ui::AXNodeData* out_data) const override; ui::AXNodeData* out_data) const override;
float device_scale_factor() const { return device_scale_factor_; } aura::Window* GetWindow() const;
void set_device_scale_factor(float dsf) { device_scale_factor_ = dsf; }
bool is_notification() { return is_notification_; } bool is_notification() { return is_notification_; }
...@@ -162,9 +161,6 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*, ...@@ -162,9 +161,6 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
// Maps an AccessibilityInfoDataWrapper ID to its tree data. // Maps an AccessibilityInfoDataWrapper ID to its tree data.
std::map<int32_t, std::unique_ptr<AccessibilityInfoDataWrapper>> tree_map_; 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. // Maps an AccessibilityInfoDataWrapper ID to its parent.
std::map<int32_t, int32_t> parent_map_; std::map<int32_t, int32_t> parent_map_;
...@@ -176,6 +172,8 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*, ...@@ -176,6 +172,8 @@ class AXTreeSourceArc : public ui::AXTreeSource<AccessibilityInfoDataWrapper*,
bool is_notification_; bool is_notification_;
bool is_input_method_window_; bool is_input_method_window_;
base::Optional<std::string> notification_key_;
std::map<int32_t, std::string> cached_names_; std::map<int32_t, std::string> cached_names_;
std::map<int32_t, ax::mojom::Role> cached_roles_; std::map<int32_t, ax::mojom::Role> cached_roles_;
......
...@@ -137,7 +137,7 @@ class AXTreeSourceArcTest : public testing::Test, ...@@ -137,7 +137,7 @@ class AXTreeSourceArcTest : public testing::Test,
public: public:
TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate, TestAXTreeSourceArc(AXTreeSourceArc::Delegate* delegate,
MockAutomationEventRouter* router) MockAutomationEventRouter* router)
: AXTreeSourceArc(delegate, 1.0), router_(router) {} : AXTreeSourceArc(delegate), router_(router) {}
private: private:
extensions::AutomationEventRouterInterface* GetAutomationEventRouter() 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