Chromium Code Reviews| 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" |
| 11 #include "chrome/common/extensions/extension_constants.h" | 11 #include "chrome/common/extensions/extension_constants.h" |
| 12 #include "extensions/browser/extension_host.h" | 12 #include "extensions/browser/extension_host.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 SwitchAccessEventHandler::SwitchAccessEventHandler() { | 17 SwitchAccessEventHandler::SwitchAccessEventHandler() { |
| 18 if (ash::Shell::HasInstance()) | 18 if (ash::Shell::HasInstance()) |
| 19 ash::Shell::Get()->AddPreTargetHandler(this); | 19 ash::Shell::Get()->AddPreTargetHandler(this); |
| 20 } | 20 } |
| 21 | 21 |
| 22 SwitchAccessEventHandler::~SwitchAccessEventHandler() { | 22 SwitchAccessEventHandler::~SwitchAccessEventHandler() { |
| 23 if (ash::Shell::HasInstance()) | 23 if (ash::Shell::HasInstance()) |
| 24 ash::Shell::Get()->RemovePreTargetHandler(this); | 24 ash::Shell::Get()->RemovePreTargetHandler(this); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void SwitchAccessEventHandler::SetKeysToCapture( | |
| 28 const std::vector<int>& key_codes) { | |
| 29 captured_keys_ = key_codes; | |
| 30 } | |
| 31 | |
| 27 void SwitchAccessEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 32 void SwitchAccessEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 28 DCHECK(event); | 33 DCHECK(event); |
| 29 | 34 |
| 30 ui::KeyboardCode key_code = event->key_code(); | 35 ui::KeyboardCode key_code = event->key_code(); |
| 31 if (key_code == ui::VKEY_1 || key_code == ui::VKEY_2 || | 36 if (std::find(captured_keys_.begin(), captured_keys_.end(), key_code) != |
|
David Tseng
2017/05/26 22:10:31
Do you care that this will capture as an example,
elichtenberg
2017/05/27 00:13:04
I'm fine with that. I don't see any reason to make
| |
| 32 key_code == ui::VKEY_3 || key_code == ui::VKEY_4 || | 37 captured_keys_.end()) { |
| 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) { | |
| 36 CancelEvent(event); | 38 CancelEvent(event); |
| 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 |