Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ | |
| 6 #define UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ | |
| 7 | |
| 8 #include "base/memory/singleton.h" | |
| 9 #include "ui/base/accelerators/accelerator.h" | |
| 10 #include "ui/base/ui_base_export.h" | |
| 11 #include "ui/events/event.h" | |
| 12 #include "ui/events/event_handler.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 | |
| 16 // ---------------------------------------------------------------------- | |
| 17 // Keeps track of the system-wide current and the most recent previous | |
| 18 // key accelerators. | |
| 19 // ---------------------------------------------------------------------- | |
| 20 class UI_BASE_EXPORT AcceleratorHistory : public EventHandler { | |
| 21 public: | |
| 22 static AcceleratorHistory* GetInstance(); | |
| 23 | |
| 24 // Returns the most recent recorded accelerator. | |
| 25 const Accelerator& GetCurrentAccelerator() const; | |
| 26 | |
| 27 // Returns the most recent previously recorded accelerator that is different | |
| 28 // than the current. | |
| 29 const Accelerator& GetPreviousAccelerator() const; | |
| 30 | |
| 31 // Stores the given |accelerator| only if it's different than the currently | |
| 32 // stored one. | |
| 33 void StoreCurrentAccelerator(const Accelerator& accelerator); | |
| 34 | |
| 35 private: | |
| 36 friend struct DefaultSingletonTraits<AcceleratorHistory>; | |
| 37 | |
| 38 AcceleratorHistory(); | |
| 39 ~AcceleratorHistory(); | |
| 40 | |
| 41 // ui::EventHandler | |
|
Jun Mukai
2014/11/17 17:39:20
colon at the end of the line
| |
| 42 void OnKeyEvent(KeyEvent* event) override; | |
| 43 | |
| 44 // Builds and records the current accelerator using the given |event|. | |
| 45 void BuildCurrentAccelerator(const ui::KeyEvent& event); | |
| 46 | |
| 47 // We are only interested in the most recent 'different' accelerator. If the | |
| 48 // new |event| will result in the same current accelerator then we should | |
| 49 // ignore it. | |
| 50 bool ShouldBuildCurrentAccelerator(const ui::KeyEvent& event, | |
| 51 const int event_modifiers) const; | |
| 52 | |
| 53 Accelerator current_accelerator_; | |
| 54 Accelerator previous_accelerator_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(AcceleratorHistory); | |
| 57 }; | |
| 58 | |
| 59 }; // namespace ui | |
| 60 | |
| 61 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ | |
| OLD | NEW |