OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chromeos/accessibility/select_to_speak_event_handler.h" | 5 #include "chrome/browser/chromeos/accessibility/select_to_speak_event_handler.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/speech/tts_controller.h" | 9 #include "chrome/browser/speech/tts_controller.h" |
10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" | 10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" |
| 11 #include "chrome/common/extensions/api/automation_api_constants.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "ui/accessibility/ax_tree_id_registry.h" |
12 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
13 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
14 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
15 #include "ui/views/focus/view_storage.h" | |
16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 SelectToSpeakEventHandler::SelectToSpeakEventHandler() { | 22 SelectToSpeakEventHandler::SelectToSpeakEventHandler() { |
22 if (ash::Shell::HasInstance()) | 23 if (ash::Shell::HasInstance()) |
23 ash::Shell::Get()->GetPrimaryRootWindow()->AddPreTargetHandler(this); | 24 ash::Shell::Get()->GetPrimaryRootWindow()->AddPreTargetHandler(this); |
24 } | 25 } |
25 | 26 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 case ui::ET_MOUSE_ENTERED: | 115 case ui::ET_MOUSE_ENTERED: |
115 case ui::ET_MOUSE_EXITED: | 116 case ui::ET_MOUSE_EXITED: |
116 ax_event = ui::AX_EVENT_MOUSE_MOVED; | 117 ax_event = ui::AX_EVENT_MOUSE_MOVED; |
117 break; | 118 break; |
118 default: | 119 default: |
119 return; | 120 return; |
120 } | 121 } |
121 | 122 |
122 CancelEvent(event); | 123 CancelEvent(event); |
123 | 124 |
124 // Find the View to post the accessibility event on. | 125 ui::AXTreeIDRegistry* registry = ui::AXTreeIDRegistry::GetInstance(); |
125 aura::Window* event_target = static_cast<aura::Window*>(event->target()); | 126 ui::AXHostDelegate* delegate = |
126 aura::Window* hit_window = event_target; | 127 registry->GetHostDelegate(extensions::api::automation::kDesktopTreeID); |
127 if (!hit_window) | 128 if (delegate) { |
128 return; | 129 ui::AXActionData action; |
129 | 130 action.action = ui::AX_ACTION_HIT_TEST; |
130 views::Widget* hit_widget = views::Widget::GetWidgetForNativeView(hit_window); | 131 action.target_point = event->root_location(); |
131 while (!hit_widget) { | 132 action.hit_test_event_to_fire = ax_event; |
132 hit_window = hit_window->parent(); | 133 delegate->PerformAction(action); |
133 if (!hit_window) | |
134 break; | |
135 | |
136 hit_widget = views::Widget::GetWidgetForNativeView(hit_window); | |
137 } | |
138 | |
139 if (!hit_window || !hit_widget) | |
140 return; | |
141 | |
142 gfx::Point window_location = event->location(); | |
143 aura::Window::ConvertPointToTarget(event_target, hit_window, | |
144 &window_location); | |
145 | |
146 views::View* root_view = hit_widget->GetRootView(); | |
147 views::View* hit_view = root_view->GetEventHandlerForPoint(window_location); | |
148 | |
149 if (hit_view) { | |
150 // Send the accessibility event, then save the view so we can post the | |
151 // cancel event on the same view if possible. | |
152 hit_view->NotifyAccessibilityEvent(ax_event, true); | |
153 if (!last_view_storage_id_) { | |
154 last_view_storage_id_ = | |
155 views::ViewStorage::GetInstance()->CreateStorageID(); | |
156 } | |
157 views::ViewStorage::GetInstance()->RemoveView(last_view_storage_id_); | |
158 views::ViewStorage::GetInstance()->StoreView(last_view_storage_id_, | |
159 hit_view); | |
160 } | 134 } |
161 } | 135 } |
162 | 136 |
163 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { | 137 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { |
164 DCHECK(event); | 138 DCHECK(event); |
165 if (event->cancelable()) { | 139 if (event->cancelable()) { |
166 event->SetHandled(); | 140 event->SetHandled(); |
167 event->StopPropagation(); | 141 event->StopPropagation(); |
168 } | 142 } |
169 } | 143 } |
170 | 144 |
171 void SelectToSpeakEventHandler::SendCancelAXEvent() { | 145 void SelectToSpeakEventHandler::SendCancelAXEvent() { |
172 // If the user releases Search while the button is still down, cancel | 146 AutomationManagerAura::GetInstance()->HandleEvent( |
173 // the Select-to-speak gesture. Try to post it on the same View that | 147 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); |
174 // was last targeted, but if that's impossible, post it on the desktop. | |
175 views::View* last_view = | |
176 last_view_storage_id_ | |
177 ? views::ViewStorage::GetInstance()->RetrieveView( | |
178 last_view_storage_id_) | |
179 : nullptr; | |
180 if (last_view) { | |
181 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true); | |
182 } else { | |
183 AutomationManagerAura::GetInstance()->HandleEvent( | |
184 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); | |
185 } | |
186 } | 148 } |
187 | 149 |
188 } // namespace chromeos | 150 } // namespace chromeos |
OLD | NEW |