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 | |
36 << " to switch access"; | |
37 DispatchKeyEventToSwitchAccess(*event); | 37 DispatchKeyEventToSwitchAccess(*event); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 void SwitchAccessEventHandler::CancelEvent(ui::Event* event) { | 41 void SwitchAccessEventHandler::CancelEvent(ui::Event* event) { |
42 DCHECK(event); | 42 DCHECK(event); |
43 if (event->cancelable()) { | 43 if (event->cancelable()) { |
44 event->SetHandled(); | 44 event->SetHandled(); |
45 event->StopPropagation(); | 45 event->StopPropagation(); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void SwitchAccessEventHandler::DispatchKeyEventToSwitchAccess( | 49 void SwitchAccessEventHandler::DispatchKeyEventToSwitchAccess( |
50 const ui::KeyEvent& event) { | 50 const ui::KeyEvent& event) { |
51 extensions::ExtensionHost* host = | 51 extensions::ExtensionHost* host = |
52 GetAccessibilityExtensionHost(extension_misc::kSwitchAccessExtensionId); | 52 GetAccessibilityExtensionHost(extension_misc::kSwitchAccessExtensionId); |
53 ForwardKeyToExtension(event, host); | 53 ForwardKeyToExtension(event, host); |
54 } | 54 } |
55 | 55 |
56 } // namespace chromeos | 56 } // namespace chromeos |
OLD | NEW |