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

Unified Diff: chrome/browser/chromeos/accessibility/switch_access_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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/accessibility/switch_access_event_handler.cc
diff --git a/chrome/browser/chromeos/accessibility/switch_access_event_handler.cc b/chrome/browser/chromeos/accessibility/switch_access_event_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..25421569e22ca2ec03d544aefddb90cbe1372e81
--- /dev/null
+++ b/chrome/browser/chromeos/accessibility/switch_access_event_handler.cc
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/accessibility/switch_access_event_handler.h"
+
+#include "ash/shell.h"
+#include "base/logging.h"
+#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
+#include "chrome/browser/chromeos/accessibility/event_handler_common.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "extensions/browser/extension_host.h"
+#include "ui/events/event.h"
+
+namespace chromeos {
+
+SwitchAccessEventHandler::SwitchAccessEventHandler() {
+ if (ash::Shell::HasInstance())
+ ash::Shell::GetInstance()->AddPreTargetHandler(this);
+}
+
+SwitchAccessEventHandler::~SwitchAccessEventHandler() {
+ if (ash::Shell::HasInstance())
+ ash::Shell::GetInstance()->RemovePreTargetHandler(this);
+}
+
+void SwitchAccessEventHandler::OnKeyEvent(ui::KeyEvent* event) {
+ DCHECK(event);
+
+ ui::KeyboardCode key_code = event->key_code();
+ if (key_code == ui::VKEY_1 || key_code == ui::VKEY_2 ||
+ key_code == ui::VKEY_3 || key_code == ui::VKEY_4 ||
+ key_code == ui::VKEY_5) {
+ CancelEvent(event);
+ LOG(ERROR) << "Dispatching key " << key_code - ui::VKEY_0
+ << " to switch access";
+ DispatchKeyEventToSwitchAccess(*event);
+ }
+}
+
+void SwitchAccessEventHandler::CancelEvent(ui::Event* event) {
+ DCHECK(event);
+ if (event->cancelable()) {
+ event->SetHandled();
+ event->StopPropagation();
+ }
+}
+
+void SwitchAccessEventHandler::DispatchKeyEventToSwitchAccess(
+ const ui::KeyEvent& event) {
+ extensions::ExtensionHost* host =
+ GetAccessibilityExtensionHost(extension_misc::kSwitchAccessExtensionId);
+ ForwardKeyToExtension(event, host);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698