blob: bed2b404b95a87456fc715d929bf179bff34bcd6 [file] [log] [blame]
// Copyright 2018 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 "ash/ash_export.h"
#include "ash/public/interfaces/accessibility_controller.mojom.h"
#include "base/macros.h"
#include "ui/events/event_handler.h"
namespace ash {
// SwitchAccessEventHandler sends events to the Switch Access extension
// (via the delegate) when it is enabled.
class ASH_EXPORT SwitchAccessEventHandler : public ui::EventHandler {
explicit SwitchAccessEventHandler(
mojom::SwitchAccessEventHandlerDelegatePtr delegate_ptr);
~SwitchAccessEventHandler() override;
// Sets the keys that are captured by Switch Access.
void set_keys_to_capture(std::vector<int> keys) {
keys_to_capture_ = std::set<int>(keys.begin(), keys.end());
// Sets whether virtual key events should be ignored.
void set_ignore_virtual_key_events(bool should_ignore) {
ignore_virtual_key_events_ = should_ignore;
// For testing usage only.
void FlushMojoForTest();
// ui::EventHandler:
void OnKeyEvent(ui::KeyEvent* event) override;
// The delegate used to send key events to the Switch Access extension.
mojom::SwitchAccessEventHandlerDelegatePtr delegate_ptr_;
std::set<int> keys_to_capture_;
bool ignore_virtual_key_events_;
} // namespace ash