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

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

Issue 2711343005: Set keys to traverse accessibility tree. Using focus ring to highlight selected node. (Closed)
Patch Set: Fixing closure compilation error Created 3 years, 9 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 "chrome/browser/speech/tts_controller.h" 9 #include "chrome/browser/speech/tts_controller.h"
9 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" 10 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
12 #include "ui/display/display.h" 13 #include "ui/display/display.h"
13 #include "ui/events/event.h" 14 #include "ui/events/event.h"
14 #include "ui/views/focus/view_storage.h" 15 #include "ui/views/focus/view_storage.h"
15 #include "ui/views/view.h" 16 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
20 SelectToSpeakEventHandler::SelectToSpeakEventHandler() { 21 SelectToSpeakEventHandler::SelectToSpeakEventHandler() {
21 if (ash::Shell::HasInstance()) 22 if (ash::Shell::HasInstance())
22 ash::Shell::GetInstance()->AddPreTargetHandler(this); 23 ash::Shell::GetInstance()->AddPreTargetHandler(this);
23 } 24 }
24 25
25 SelectToSpeakEventHandler::~SelectToSpeakEventHandler() { 26 SelectToSpeakEventHandler::~SelectToSpeakEventHandler() {
26 if (ash::Shell::HasInstance()) 27 if (ash::Shell::HasInstance())
27 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 28 ash::Shell::GetInstance()->RemovePreTargetHandler(this);
28 } 29 }
29 30
30 void SelectToSpeakEventHandler::OnKeyEvent(ui::KeyEvent* event) { 31 void SelectToSpeakEventHandler::OnKeyEvent(ui::KeyEvent* event) {
32 DCHECK(event);
33
31 // We can only call TtsController on the UI thread, make sure we 34 // We can only call TtsController on the UI thread, make sure we
32 // don't ever try to run this code on some other thread. 35 // don't ever try to run this code on some other thread.
33 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 36 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
34 37
35 ui::KeyboardCode key_code = event->key_code(); 38 ui::KeyboardCode key_code = event->key_code();
36 39
37 // Stop speech when the user taps and releases Control or Search 40 // Stop speech when the user taps and releases Control or Search
38 // without pressing any other keys along the way. 41 // without pressing any other keys along the way.
39 if (state_ != MOUSE_RELEASED && event->type() == ui::ET_KEY_RELEASED && 42 if (state_ != MOUSE_RELEASED && event->type() == ui::ET_KEY_RELEASED &&
40 (key_code == ui::VKEY_CONTROL || key_code == ui::VKEY_LWIN) && 43 (key_code == ui::VKEY_CONTROL || key_code == ui::VKEY_LWIN) &&
(...skipping 25 matching lines...) Expand all
66 CancelEvent(event); 69 CancelEvent(event);
67 state_ = INACTIVE; 70 state_ = INACTIVE;
68 } 71 }
69 } 72 }
70 } else if (state_ == SEARCH_DOWN) { 73 } else if (state_ == SEARCH_DOWN) {
71 state_ = INACTIVE; 74 state_ = INACTIVE;
72 } 75 }
73 } 76 }
74 77
75 void SelectToSpeakEventHandler::OnMouseEvent(ui::MouseEvent* event) { 78 void SelectToSpeakEventHandler::OnMouseEvent(ui::MouseEvent* event) {
79 DCHECK(event);
76 if (state_ == INACTIVE) 80 if (state_ == INACTIVE)
77 return; 81 return;
78 82
79 if ((state_ == SEARCH_DOWN || state_ == MOUSE_RELEASED) && 83 if ((state_ == SEARCH_DOWN || state_ == MOUSE_RELEASED) &&
80 event->type() == ui::ET_MOUSE_PRESSED) { 84 event->type() == ui::ET_MOUSE_PRESSED) {
81 state_ = CAPTURING; 85 state_ = CAPTURING;
82 } 86 }
83 87
84 if (state_ == WAIT_FOR_MOUSE_RELEASE && 88 if (state_ == WAIT_FOR_MOUSE_RELEASE &&
85 event->type() == ui::ET_MOUSE_RELEASED) { 89 event->type() == ui::ET_MOUSE_RELEASED) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 last_view_storage_id_ = 154 last_view_storage_id_ =
151 views::ViewStorage::GetInstance()->CreateStorageID(); 155 views::ViewStorage::GetInstance()->CreateStorageID();
152 } 156 }
153 views::ViewStorage::GetInstance()->RemoveView(last_view_storage_id_); 157 views::ViewStorage::GetInstance()->RemoveView(last_view_storage_id_);
154 views::ViewStorage::GetInstance()->StoreView(last_view_storage_id_, 158 views::ViewStorage::GetInstance()->StoreView(last_view_storage_id_,
155 hit_view); 159 hit_view);
156 } 160 }
157 } 161 }
158 162
159 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) { 163 void SelectToSpeakEventHandler::CancelEvent(ui::Event* event) {
164 DCHECK(event);
160 if (event->cancelable()) { 165 if (event->cancelable()) {
161 event->SetHandled(); 166 event->SetHandled();
162 event->StopPropagation(); 167 event->StopPropagation();
163 } 168 }
164 } 169 }
165 170
166 void SelectToSpeakEventHandler::SendCancelAXEvent() { 171 void SelectToSpeakEventHandler::SendCancelAXEvent() {
167 // If the user releases Search while the button is still down, cancel 172 // If the user releases Search while the button is still down, cancel
168 // the Select-to-speak gesture. Try to post it on the same View that 173 // the Select-to-speak gesture. Try to post it on the same View that
169 // was last targeted, but if that's impossible, post it on the desktop. 174 // was last targeted, but if that's impossible, post it on the desktop.
170 views::View* last_view = 175 views::View* last_view =
171 last_view_storage_id_ 176 last_view_storage_id_
172 ? views::ViewStorage::GetInstance()->RetrieveView( 177 ? views::ViewStorage::GetInstance()->RetrieveView(
173 last_view_storage_id_) 178 last_view_storage_id_)
174 : nullptr; 179 : nullptr;
175 if (last_view) { 180 if (last_view) {
176 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true); 181 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true);
177 } else { 182 } else {
178 AutomationManagerAura::GetInstance()->HandleEvent( 183 AutomationManagerAura::GetInstance()->HandleEvent(
179 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); 184 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED);
180 } 185 }
181 } 186 }
182 187
183 } // namespace chromeos 188 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698