OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/switch_access_event_handler.h" | 5 #include "chrome/browser/chromeos/accessibility/switch_access_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/chromeos/accessibility/accessibility_manager.h" | 9 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
10 #include "chrome/browser/chromeos/accessibility/event_handler_common.h" | 10 #include "chrome/browser/chromeos/accessibility/event_handler_common.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 if (ash::Shell::HasInstance()) | 23 if (ash::Shell::HasInstance()) |
24 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 24 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
25 } | 25 } |
26 | 26 |
27 void SwitchAccessEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 27 void SwitchAccessEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
28 DCHECK(event); | 28 DCHECK(event); |
29 | 29 |
30 ui::KeyboardCode key_code = event->key_code(); | 30 ui::KeyboardCode key_code = event->key_code(); |
31 if (key_code == ui::VKEY_1 || key_code == ui::VKEY_2 || | 31 if (key_code == ui::VKEY_1 || key_code == ui::VKEY_2 || |
32 key_code == ui::VKEY_3 || key_code == ui::VKEY_4 || | 32 key_code == ui::VKEY_3 || key_code == ui::VKEY_4 || |
33 key_code == ui::VKEY_5) { | 33 key_code == ui::VKEY_5 || key_code == ui::VKEY_6 || |
| 34 key_code == ui::VKEY_7 || key_code == ui::VKEY_8 || |
| 35 key_code == ui::VKEY_9) { |
34 CancelEvent(event); | 36 CancelEvent(event); |
35 LOG(ERROR) << "Dispatching key " << key_code - ui::VKEY_0 | 37 LOG(ERROR) << "Dispatching key " << key_code - ui::VKEY_0 |
36 << " to switch access"; | 38 << " to switch access"; |
37 DispatchKeyEventToSwitchAccess(*event); | 39 DispatchKeyEventToSwitchAccess(*event); |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 void SwitchAccessEventHandler::CancelEvent(ui::Event* event) { | 43 void SwitchAccessEventHandler::CancelEvent(ui::Event* event) { |
42 DCHECK(event); | 44 DCHECK(event); |
43 if (event->cancelable()) { | 45 if (event->cancelable()) { |
44 event->SetHandled(); | 46 event->SetHandled(); |
45 event->StopPropagation(); | 47 event->StopPropagation(); |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 void SwitchAccessEventHandler::DispatchKeyEventToSwitchAccess( | 51 void SwitchAccessEventHandler::DispatchKeyEventToSwitchAccess( |
50 const ui::KeyEvent& event) { | 52 const ui::KeyEvent& event) { |
51 extensions::ExtensionHost* host = | 53 extensions::ExtensionHost* host = |
52 GetAccessibilityExtensionHost(extension_misc::kSwitchAccessExtensionId); | 54 GetAccessibilityExtensionHost(extension_misc::kSwitchAccessExtensionId); |
53 ForwardKeyToExtension(event, host); | 55 ForwardKeyToExtension(event, host); |
54 } | 56 } |
55 | 57 |
56 } // namespace chromeos | 58 } // namespace chromeos |
OLD | NEW |