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" | |
19 #include "ui/accessibility/ax_action_data.h" | 18 #include "ui/accessibility/ax_action_data.h" |
20 #include "ui/accessibility/ax_enums.h" | 19 #include "ui/accessibility/ax_enums.h" |
21 #include "ui/accessibility/ax_tree_id_registry.h" | 20 #include "ui/accessibility/ax_tree_id_registry.h" |
22 #include "ui/accessibility/platform/aura_window_properties.h" | |
23 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
24 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
25 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | 23 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
26 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
27 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
28 | 26 |
29 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
30 #include "ash/shell.h" // nogncheck | |
31 #include "ash/wm/window_util.h" // nogncheck | 28 #include "ash/wm/window_util.h" // nogncheck |
32 #endif | 29 #endif |
33 | 30 |
34 using content::BrowserContext; | 31 using content::BrowserContext; |
35 using extensions::AutomationEventRouter; | 32 using extensions::AutomationEventRouter; |
36 | 33 |
37 // static | 34 // static |
38 AutomationManagerAura* AutomationManagerAura::GetInstance() { | 35 AutomationManagerAura* AutomationManagerAura::GetInstance() { |
39 return base::Singleton<AutomationManagerAura>::get(); | 36 return base::Singleton<AutomationManagerAura>::get(); |
40 } | 37 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 const std::string& text) { | 74 const std::string& text) { |
78 if (!enabled_) | 75 if (!enabled_) |
79 return; | 76 return; |
80 | 77 |
81 views::AXAuraObjWrapper* obj = | 78 views::AXAuraObjWrapper* obj = |
82 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) | 79 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot()) |
83 ->GetAlertForText(text); | 80 ->GetAlertForText(text); |
84 SendEvent(context, obj, ui::AX_EVENT_ALERT); | 81 SendEvent(context, obj, ui::AX_EVENT_ALERT); |
85 } | 82 } |
86 | 83 |
87 void AutomationManagerAura::PerformAction(const ui::AXActionData& data) { | 84 void AutomationManagerAura::PerformAction( |
| 85 const ui::AXActionData& data) { |
88 CHECK(enabled_); | 86 CHECK(enabled_); |
89 | 87 |
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 | |
97 current_tree_->HandleAccessibleAction(data); | 88 current_tree_->HandleAccessibleAction(data); |
98 } | 89 } |
99 | 90 |
100 void AutomationManagerAura::OnChildWindowRemoved( | 91 void AutomationManagerAura::OnChildWindowRemoved( |
101 views::AXAuraObjWrapper* parent) { | 92 views::AXAuraObjWrapper* parent) { |
102 if (!enabled_) | 93 if (!enabled_) |
103 return; | 94 return; |
104 | 95 |
105 if (!parent) | 96 if (!parent) |
106 parent = current_tree_->GetRoot(); | 97 parent = current_tree_->GetRoot(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 154 |
164 processing_events_ = false; | 155 processing_events_ = false; |
165 auto pending_events_copy = pending_events_; | 156 auto pending_events_copy = pending_events_; |
166 pending_events_.clear(); | 157 pending_events_.clear(); |
167 for (size_t i = 0; i < pending_events_copy.size(); ++i) { | 158 for (size_t i = 0; i < pending_events_copy.size(); ++i) { |
168 SendEvent(context, | 159 SendEvent(context, |
169 pending_events_copy[i].first, | 160 pending_events_copy[i].first, |
170 pending_events_copy[i].second); | 161 pending_events_copy[i].second); |
171 } | 162 } |
172 } | 163 } |
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 |