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

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

Issue 2698273002: Select-to-speak: Stop speech when tapping Search or Control (Closed)
Patch Set: Trigger on tap and release of Search or Control Created 3 years, 10 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 "chrome/browser/speech/tts_controller.h"
8 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h" 9 #include "chrome/browser/ui/aura/accessibility/automation_manager_aura.h"
10 #include "content/public/browser/browser_thread.h"
9 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
10 #include "ui/display/display.h" 12 #include "ui/display/display.h"
11 #include "ui/events/event.h" 13 #include "ui/events/event.h"
12 #include "ui/views/focus/view_storage.h" 14 #include "ui/views/focus/view_storage.h"
13 #include "ui/views/view.h" 15 #include "ui/views/view.h"
14 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
15 17
16 namespace chromeos { 18 namespace chromeos {
17 19
18 SelectToSpeakEventHandler::SelectToSpeakEventHandler() { 20 SelectToSpeakEventHandler::SelectToSpeakEventHandler() {
19 if (ash::Shell::HasInstance()) 21 if (ash::Shell::HasInstance())
20 ash::Shell::GetInstance()->AddPreTargetHandler(this); 22 ash::Shell::GetInstance()->AddPreTargetHandler(this);
21 } 23 }
22 24
23 SelectToSpeakEventHandler::~SelectToSpeakEventHandler() { 25 SelectToSpeakEventHandler::~SelectToSpeakEventHandler() {
24 if (ash::Shell::HasInstance()) 26 if (ash::Shell::HasInstance())
25 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 27 ash::Shell::GetInstance()->RemovePreTargetHandler(this);
26 } 28 }
27 29
28 void SelectToSpeakEventHandler::OnKeyEvent(ui::KeyEvent* event) { 30 void SelectToSpeakEventHandler::OnKeyEvent(ui::KeyEvent* event) {
29 if (event->key_code() == ui::VKEY_LWIN) { 31 // 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.
33 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
34
35 ui::KeyboardCode key_code = event->key_code();
36
37 // Stop speech when the user taps and releases Control or Search
38 // without pressing any other keys along the way.
39 if (state_ != MOUSE_RELEASED && event->type() == ui::ET_KEY_RELEASED &&
40 (key_code == ui::VKEY_CONTROL || key_code == ui::VKEY_LWIN) &&
41 keys_pressed_together_.find(key_code) != keys_pressed_together_.end() &&
42 keys_pressed_together_.size() == 1) {
43 TtsController::GetInstance()->Stop();
44 }
45
46 // Update keys_currently_down_ and keys_pressed_together_.
47 if (event->type() == ui::ET_KEY_PRESSED) {
48 keys_currently_down_.insert(key_code);
49 keys_pressed_together_.insert(key_code);
50 } else if (event->type() == ui::ET_KEY_RELEASED) {
51 keys_currently_down_.erase(key_code);
52 if (keys_currently_down_.empty())
53 keys_pressed_together_.clear();
54 }
55
56 // Update the state when pressing and releasing the Search key (VKEY_LWIN).
57 if (key_code == ui::VKEY_LWIN) {
30 if (event->type() == ui::ET_KEY_PRESSED && state_ == INACTIVE) { 58 if (event->type() == ui::ET_KEY_PRESSED && state_ == INACTIVE) {
31 state_ = SEARCH_DOWN; 59 state_ = SEARCH_DOWN;
32 } else if (event->type() == ui::ET_KEY_RELEASED) { 60 } else if (event->type() == ui::ET_KEY_RELEASED) {
33 if (state_ == CAPTURING) { 61 if (state_ == CAPTURING) {
34 SendCancelAXEvent(); 62 SendCancelAXEvent();
35 CancelEvent(event); 63 CancelEvent(event);
36 state_ = WAIT_FOR_MOUSE_RELEASE; 64 state_ = WAIT_FOR_MOUSE_RELEASE;
37 } else if (state_ == MOUSE_RELEASED) { 65 } else if (state_ == MOUSE_RELEASED) {
38 CancelEvent(event); 66 CancelEvent(event);
39 state_ = INACTIVE; 67 state_ = INACTIVE;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 : nullptr; 174 : nullptr;
147 if (last_view) { 175 if (last_view) {
148 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true); 176 last_view->NotifyAccessibilityEvent(ui::AX_EVENT_MOUSE_CANCELED, true);
149 } else { 177 } else {
150 AutomationManagerAura::GetInstance()->HandleEvent( 178 AutomationManagerAura::GetInstance()->HandleEvent(
151 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED); 179 nullptr, nullptr, ui::AX_EVENT_MOUSE_CANCELED);
152 } 180 }
153 } 181 }
154 182
155 } // namespace chromeos 183 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698