Chromium Code Reviews| 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" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 case ui::ET_MOUSE_ENTERED: | 118 case ui::ET_MOUSE_ENTERED: |
| 119 case ui::ET_MOUSE_EXITED: | 119 case ui::ET_MOUSE_EXITED: |
| 120 ax_event = ui::AX_EVENT_MOUSE_MOVED; | 120 ax_event = ui::AX_EVENT_MOUSE_MOVED; |
| 121 break; | 121 break; |
| 122 default: | 122 default: |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 | 125 |
| 126 CancelEvent(event); | 126 CancelEvent(event); |
| 127 | 127 |
| 128 // Find the View to post the accessibility event on. | |
| 129 aura::Window* event_target = static_cast<aura::Window*>(event->target()); | 128 aura::Window* event_target = static_cast<aura::Window*>(event->target()); |
| 130 aura::Window* hit_window = event_target; | 129 views::AXAuraObjCache* cache = views::AXAuraObjCache::GetInstance(); |
| 131 if (!hit_window) | 130 views::AXAuraObjWrapper* ax_obj = cache->GetOrCreate(event_target); |
| 132 return; | 131 ui::AXActionData action; |
| 133 | 132 action.action = ui::AX_ACTION_HIT_TEST; |
| 134 views::Widget* hit_widget = views::Widget::GetWidgetForNativeView(hit_window); | 133 action.target_point = event->location(); |
| 135 while (!hit_widget) { | 134 action.hit_test_event_to_fire = ax_event; |
| 136 hit_window = hit_window->parent(); | 135 ax_obj->HandleAccessibleAction(action); |
|
David Tseng
2017/04/05 23:43:43
I think this should happen inside of the extension
dmazzoni
2017/04/07 23:34:08
I spend all day trying to make this work. It's sli
| |
| 137 if (!hit_window) | |
| 138 break; | |
| 139 | |
| 140 hit_widget = views::Widget::GetWidgetForNativeView(hit_window); | |
| 141 } | |
| 142 | |
| 143 if (!hit_window || !hit_widget) | |
| 144 return; | |
| 145 | |
| 146 gfx::Point window_location = event->location(); | |
| 147 aura::Window::ConvertPointToTarget(event_target, hit_window, | |
| 148 &window_location); | |
| 149 | |
| 150 views::View* root_view = hit_widget->GetRootView(); | |
| 151 views::View* hit_view = root_view->GetEventHandlerForPoint(window_location); | |
| 152 | |
| 153 if (hit_view) { | |
| 154 // Send the accessibility event, then save the view so we can post the | |
| 155 // cancel event on the same view if possible. | |
| 156 hit_view->NotifyAccessibilityEvent(ax_event, true); | |
| 157 if (!last_view_storage_id_) { | |
| 158 last_view_storage_id_ = | |
| 159 views::ViewStorage::GetInstance()->CreateStorageID(); | |
| 160 } | |
| 161 views::ViewStorage::GetInstance()->RemoveView(last_view_storage_id_); | |
| 162 views::ViewStorage::GetInstance()->StoreView(last_view_storage_id_, | |
| 163 hit_view); | |
| 164 } | |
| 165 } | 136 } |
| 166 | 137 |
| 167 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { | 138 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { |
| 168 DCHECK(event); | 139 DCHECK(event); |
| 169 if (event->cancelable()) { | 140 if (event->cancelable()) { |
| 170 event->SetHandled(); | 141 event->SetHandled(); |
| 171 event->StopPropagation(); | 142 event->StopPropagation(); |
| 172 } | 143 } |
| 173 } | 144 } |
| 174 | 145 |
| 175 void SelectToSpeakEventHandler::SendCancelAXEvent() { | 146 void SelectToSpeakEventHandler::SendCancelAXEvent() { |
| 176 // If the user releases Search while the button is still down, cancel | 147 // If the user releases Search while the button is still down, cancel |
| 177 // the Select-to-speak gesture. Try to post it on the same View that | 148 // the Select-to-speak gesture. |
| 178 // was last targeted, but if that's impossible, post it on the desktop. | 149 AutomationManagerAura::GetInstance()->HandleEvent( |
| 179 views::View* last_view = | 150 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); |
|
David Tseng
2017/04/06 16:45:43
Btw, it seems like a hack to do this via ax events
| |
| 180 last_view_storage_id_ | |
| 181 ? views::ViewStorage::GetInstance()->RetrieveView( | |
| 182 last_view_storage_id_) | |
| 183 : nullptr; | |
| 184 if (last_view) { | |
| 185 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true); | |
| 186 } else { | |
| 187 AutomationManagerAura::GetInstance()->HandleEvent( | |
| 188 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); | |
| 189 } | |
| 190 } | 151 } |
| 191 | 152 |
| 192 } // namespace chromeos | 153 } // namespace chromeos |
| OLD | NEW |