Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 ASH_COMMON_KEY_EVENT_WATCHER_H_ | |
| 6 #define ASH_COMMON_KEY_EVENT_WATCHER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "ui/base/accelerators/accelerator.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 class KeyEvent; | |
| 17 } | |
| 18 | |
| 19 namespace ash { | |
| 20 | |
| 21 // This class watches the key event given in the form of accelerator | |
| 22 // and calls the registered callback. | |
| 23 class ASH_EXPORT KeyEventWatcher { | |
|
James Cook
2016/09/22 21:17:16
I like how this only listens for the keys it cares
| |
| 24 public: | |
| 25 using KeyEventCallback = base::Callback<void(const ui::KeyEvent&)>; | |
| 26 | |
| 27 KeyEventWatcher(); | |
| 28 virtual ~KeyEventWatcher(); | |
| 29 | |
| 30 // Add a callback that is called when the accelerator |accel| is | |
| 31 // pressed. | |
|
James Cook
2016/09/22 21:17:16
Document that the key event will be consumed if a
oshima
2016/09/23 09:37:19
Done.
| |
| 32 void AddKeyEventCallback(const ui::Accelerator& accel, | |
| 33 const KeyEventCallback& callback); | |
| 34 | |
| 35 protected: | |
| 36 // Finds and calls the registered callback whose accelerator matches | |
| 37 // the |event|. Returns false if no accelerator is matched. | |
| 38 bool HandleKeyEvent(const ui::KeyEvent& event); | |
| 39 | |
| 40 private: | |
| 41 std::map<ui::Accelerator, KeyEventCallback> callback_map_; | |
| 42 | |
| 43 DISALLOW_COPY_AND_ASSIGN(KeyEventWatcher); | |
| 44 }; | |
| 45 | |
| 46 } // namespace ash | |
| 47 | |
| 48 #endif // ASH_COMMON_KEY_EVENT_WATCHER_H_ | |
| OLD | NEW |