OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_STATE_KEEPER_H_ |
| 6 #define COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_STATE_KEEPER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "components/keyboard_lock/key_event_filter.h" |
| 12 #include "components/keyboard_lock/key_hook_activator.h" |
| 13 |
| 14 namespace keyboard_lock { |
| 15 |
| 16 // An implementation of both KeyHookActivator and KeyEventFilter by maintaining |
| 17 // the internal states and filtering out unregistered key codes. |
| 18 class KeyHookStateKeeper final |
| 19 : public KeyEventFilter, |
| 20 public KeyHookActivator { |
| 21 public: |
| 22 KeyHookStateKeeper(std::unique_ptr<KeyEventFilter> filter, |
| 23 std::unique_ptr<KeyHook> key_hook); |
| 24 ~KeyHookStateKeeper() override; |
| 25 |
| 26 // KeyEventFilter implementations. |
| 27 bool OnKeyDown(ui::KeyboardCode code, int flags) override; |
| 28 bool OnKeyUp(ui::KeyboardCode code, int flags) override; |
| 29 |
| 30 // KeyHookActivator implementations. |
| 31 void RegisterKey(const std::vector<ui::KeyboardCode>& codes, |
| 32 base::Callback<void(bool)> on_result) override; |
| 33 void UnregisterKey(const std::vector<ui::KeyboardCode>& codes, |
| 34 base::Callback<void(bool)> on_result) override; |
| 35 void Activate(base::Callback<void(bool)> on_result) override; |
| 36 void Deactivate(base::Callback<void(bool)> on_result) override; |
| 37 |
| 38 private: |
| 39 const std::unique_ptr<KeyEventFilter> filter_; |
| 40 const std::unique_ptr<KeyHook> key_hook_; |
| 41 std::vector<bool> states_; |
| 42 bool active_; |
| 43 }; |
| 44 |
| 45 } // namespace keyboard_lock |
| 46 |
| 47 #endif // COMPONENTS_KEYBOARD_LOCK_KEY_HOOK_STATE_KEEPER_H_ |
OLD | NEW |