Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: chrome/browser/chromeos/accessibility/select_to_speak_event_handler.cc

Issue 2827103003: Revert of Finish implementation of automation API hit testing for the desktop. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
13 #include "ui/accessibility/ax_tree_id_registry.h"
14 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
15 #include "ui/display/display.h" 13 #include "ui/display/display.h"
16 #include "ui/events/event.h" 14 #include "ui/events/event.h"
15 #include "ui/views/focus/view_storage.h"
17 #include "ui/views/view.h" 16 #include "ui/views/view.h"
18 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
19 18
20 namespace chromeos { 19 namespace chromeos {
21 20
22 SelectToSpeakEventHandler::SelectToSpeakEventHandler() { 21 SelectToSpeakEventHandler::SelectToSpeakEventHandler() {
23 if (ash::Shell::HasInstance()) 22 if (ash::Shell::HasInstance())
24 ash::Shell::Get()->GetPrimaryRootWindow()->AddPreTargetHandler(this); 23 ash::Shell::Get()->GetPrimaryRootWindow()->AddPreTargetHandler(this);
25 } 24 }
26 25
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 case ui::ET_MOUSE_ENTERED: 114 case ui::ET_MOUSE_ENTERED:
116 case ui::ET_MOUSE_EXITED: 115 case ui::ET_MOUSE_EXITED:
117 ax_event = ui::AX_EVENT_MOUSE_MOVED; 116 ax_event = ui::AX_EVENT_MOUSE_MOVED;
118 break; 117 break;
119 default: 118 default:
120 return; 119 return;
121 } 120 }
122 121
123 CancelEvent(event); 122 CancelEvent(event);
124 123
125 ui::AXTreeIDRegistry* registry = ui::AXTreeIDRegistry::GetInstance(); 124 // Find the View to post the accessibility event on.
126 ui::AXHostDelegate* delegate = 125 aura::Window* event_target = static_cast<aura::Window*>(event->target());
127 registry->GetHostDelegate(extensions::api::automation::kDesktopTreeID); 126 aura::Window* hit_window = event_target;
128 if (delegate) { 127 if (!hit_window)
129 ui::AXActionData action; 128 return;
130 action.action = ui::AX_ACTION_HIT_TEST; 129
131 action.target_point = event->root_location(); 130 views::Widget* hit_widget = views::Widget::GetWidgetForNativeView(hit_window);
132 action.hit_test_event_to_fire = ax_event; 131 while (!hit_widget) {
133 delegate->PerformAction(action); 132 hit_window = hit_window->parent();
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);
134 } 160 }
135 } 161 }
136 162
137 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { 163 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) {
138 DCHECK(event); 164 DCHECK(event);
139 if (event->cancelable()) { 165 if (event->cancelable()) {
140 event->SetHandled(); 166 event->SetHandled();
141 event->StopPropagation(); 167 event->StopPropagation();
142 } 168 }
143 } 169 }
144 170
145 void SelectToSpeakEventHandler::SendCancelAXEvent() { 171 void SelectToSpeakEventHandler::SendCancelAXEvent() {
146 AutomationManagerAura::GetInstance()->HandleEvent( 172 // If the user releases Search while the button is still down, cancel
147 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); 173 // the Select-to-speak gesture. Try to post it on the same View that
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 }
148 } 186 }
149 187
150 } // namespace chromeos 188 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698