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 |
| 13 namespace ui { |
| 14 |
| 15 // ---------------------------------------------------------------------- |
| 16 // Wraps an accelerator with the time stamp at which it was recorded. |
| 17 // ---------------------------------------------------------------------- |
| 18 struct UI_BASE_EXPORT AcceleratorEvent { |
| 19 Accelerator accelerator; |
| 20 base::TimeTicks time_stamp; |
| 21 |
| 22 AcceleratorEvent() |
| 23 : accelerator(), |
| 24 time_stamp(base::TimeTicks::Now()) { |
| 25 } |
| 26 |
| 27 explicit AcceleratorEvent(const Accelerator& anAccelerator) |
| 28 : accelerator(anAccelerator), |
| 29 time_stamp(base::TimeTicks::Now()) { |
| 30 } |
| 31 }; |
| 32 |
| 33 // ---------------------------------------------------------------------- |
| 34 // Keeps track of the system-wide current and the most recent previous |
| 35 // key accelerators. |
| 36 // ---------------------------------------------------------------------- |
| 37 class UI_BASE_EXPORT AcceleratorHistory { |
| 38 public: |
| 39 static AcceleratorHistory* GetInstance(); |
| 40 |
| 41 // Builds and records the current accelerator using the given |event|. |
| 42 void BuildCurrentAccelerator(const ui::KeyEvent& event); |
| 43 |
| 44 // Returns the most recent recorded accelerator. |
| 45 const AcceleratorEvent& GetCurrentAccelerator() const; |
| 46 |
| 47 // Returns the most recent previously recorded accelerator that is different |
| 48 // than the current. |
| 49 const AcceleratorEvent& GetPreviousAccelerator() const; |
| 50 |
| 51 private: |
| 52 friend struct DefaultSingletonTraits<AcceleratorHistory>; |
| 53 |
| 54 AcceleratorHistory(); |
| 55 ~AcceleratorHistory(); |
| 56 |
| 57 // We are only interested in the most recent 'different' accelerator. If the |
| 58 // new |event| will result in the same current accelerator then we should |
| 59 // ignore it. |
| 60 bool ShouldBuildCurrentAccelerator(const ui::KeyEvent& event, |
| 61 const int event_modifiers) const; |
| 62 |
| 63 AcceleratorEvent current_accelerator_; |
| 64 AcceleratorEvent previous_accelerator_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(AcceleratorHistory); |
| 67 }; |
| 68 |
| 69 }; // namespace ui |
| 70 |
| 71 #endif // UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ |
OLD | NEW |