OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" | 5 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou
ter.h" | 12 #include "chrome/browser/extensions/api/automation_internal/automation_event_rou
ter.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/common/extensions/api/automation_api_constants.h" | 14 #include "chrome/common/extensions/api/automation_api_constants.h" |
15 #include "chrome/common/extensions/chrome_extension_messages.h" | 15 #include "chrome/common/extensions/chrome_extension_messages.h" |
16 #include "content/public/browser/ax_event_notification_details.h" | 16 #include "content/public/browser/ax_event_notification_details.h" |
17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/render_frame_host.h" |
18 #include "ui/accessibility/ax_action_data.h" | 19 #include "ui/accessibility/ax_action_data.h" |
19 #include "ui/accessibility/ax_enums.h" | 20 #include "ui/accessibility/ax_enums.h" |
20 #include "ui/accessibility/ax_tree_id_registry.h" | 21 #include "ui/accessibility/ax_tree_id_registry.h" |
| 22 #include "ui/accessibility/platform/aura_window_properties.h" |
21 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
22 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
23 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 25 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
24 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
26 | 28 |
27 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 30 #include "ash/shell.h" // nogncheck |
28 #include "ash/wm/window_util.h" // nogncheck | 31 #include "ash/wm/window_util.h" // nogncheck |
29 #endif | 32 #endif |
30 | 33 |
31 using content::BrowserContext; | 34 using content::BrowserContext; |
32 using extensions::AutomationEventRouter; | 35 using extensions::AutomationEventRouter; |
33 | 36 |
34 // static | 37 // static |
35 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 38 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
36 return base::Singleton<AutomationManagerAura>::get(); | 39 return base::Singleton<AutomationManagerAura>::get(); |
37 } | 40 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const std::string& text) { | 77 const std::string& text) { |
75 if (!enabled_) | 78 if (!enabled_) |
76 return; | 79 return; |
77 | 80 |
78 views::AXAuraObjWrapper* obj = | 81 views::AXAuraObjWrapper* obj = |
79 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 82 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
80 ->GetAlertForText(text); | 83 ->GetAlertForText(text); |
81 SendEvent(context, obj, ui::AX_EVENT_ALERT); | 84 SendEvent(context, obj, ui::AX_EVENT_ALERT); |
82 } | 85 } |
83 | 86 |
84 void AutomationManagerAura::PerformAction( | 87 void AutomationManagerAura::PerformAction(const ui::AXActionData& data) { |
85 const ui::AXActionData& data) { | |
86 CHECK(enabled_); | 88 CHECK(enabled_); |
87 | 89 |
| 90 // Unlike all of the other actions, a hit test requires determining the |
| 91 // node to perform the action on first. |
| 92 if (data.action == ui::AX_ACTION_HIT_TEST) { |
| 93 PerformHitTest(data); |
| 94 return; |
| 95 } |
| 96 |
88 current_tree_->HandleAccessibleAction(data); | 97 current_tree_->HandleAccessibleAction(data); |
89 } | 98 } |
90 | 99 |
91 void AutomationManagerAura::OnChildWindowRemoved( | 100 void AutomationManagerAura::OnChildWindowRemoved( |
92 views::AXAuraObjWrapper* parent) { | 101 views::AXAuraObjWrapper* parent) { |
93 if (!enabled_) | 102 if (!enabled_) |
94 return; | 103 return; |
95 | 104 |
96 if (!parent) | 105 if (!parent) |
97 parent = current_tree_->GetRoot(); | 106 parent = current_tree_->GetRoot(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 163 |
155 processing_events_ = false; | 164 processing_events_ = false; |
156 auto pending_events_copy = pending_events_; | 165 auto pending_events_copy = pending_events_; |
157 pending_events_.clear(); | 166 pending_events_.clear(); |
158 for (size_t i = 0; i < pending_events_copy.size(); ++i) { | 167 for (size_t i = 0; i < pending_events_copy.size(); ++i) { |
159 SendEvent(context, | 168 SendEvent(context, |
160 pending_events_copy[i].first, | 169 pending_events_copy[i].first, |
161 pending_events_copy[i].second); | 170 pending_events_copy[i].second); |
162 } | 171 } |
163 } | 172 } |
| 173 |
| 174 void AutomationManagerAura::PerformHitTest( |
| 175 const ui::AXActionData& original_action) { |
| 176 #if defined(OS_CHROMEOS) |
| 177 ui::AXActionData action = original_action; |
| 178 aura::Window* root_window = ash::Shell::Get()->GetPrimaryRootWindow(); |
| 179 if (!root_window) |
| 180 return; |
| 181 |
| 182 // Determine which aura Window is associated with the target point. |
| 183 aura::Window* window = |
| 184 root_window->GetEventHandlerForPoint(action.target_point); |
| 185 if (!window) |
| 186 return; |
| 187 |
| 188 // Convert point to local coordinates of the hit window. |
| 189 aura::Window::ConvertPointToTarget(root_window, window, &action.target_point); |
| 190 |
| 191 // If the window has a child AX tree ID, forward the action to the |
| 192 // associated AXHostDelegate or RenderFrameHost. |
| 193 ui::AXTreeIDRegistry::AXTreeID child_ax_tree_id = |
| 194 window->GetProperty(ui::kChildAXTreeID); |
| 195 if (child_ax_tree_id != ui::AXTreeIDRegistry::kNoAXTreeID) { |
| 196 ui::AXTreeIDRegistry* registry = ui::AXTreeIDRegistry::GetInstance(); |
| 197 ui::AXHostDelegate* delegate = registry->GetHostDelegate(child_ax_tree_id); |
| 198 if (delegate) { |
| 199 delegate->PerformAction(action); |
| 200 return; |
| 201 } |
| 202 |
| 203 content::RenderFrameHost* rfh = |
| 204 content::RenderFrameHost::FromAXTreeID(child_ax_tree_id); |
| 205 if (rfh) |
| 206 rfh->AccessibilityPerformAction(action); |
| 207 return; |
| 208 } |
| 209 |
| 210 // If the window doesn't have a child tree ID, try to fire the event |
| 211 // on a View. |
| 212 views::Widget* widget = views::Widget::GetWidgetForNativeView(window); |
| 213 if (widget) { |
| 214 views::View* root_view = widget->GetRootView(); |
| 215 views::View* hit_view = |
| 216 root_view->GetEventHandlerForPoint(action.target_point); |
| 217 if (hit_view) { |
| 218 hit_view->NotifyAccessibilityEvent(action.hit_test_event_to_fire, true); |
| 219 return; |
| 220 } |
| 221 } |
| 222 |
| 223 // Otherwise, fire the event directly on the Window. |
| 224 views::AXAuraObjWrapper* window_wrapper = |
| 225 views::AXAuraObjCache::GetInstance()->GetOrCreate(window); |
| 226 if (window_wrapper) |
| 227 SendEvent(nullptr, window_wrapper, action.hit_test_event_to_fire); |
| 228 #endif |
| 229 } |
OLD | NEW |