OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | 5 #ifndef ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ |
6 #define ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | 6 #define ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/events/event_handler.h" | 10 #include "ui/events/event_handler.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 virtual void OnKeyHold(const ui::KeyEvent* event) = 0; | 35 virtual void OnKeyHold(const ui::KeyEvent* event) = 0; |
36 | 36 |
37 // Called when the key is release after hold. | 37 // Called when the key is release after hold. |
38 virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0; | 38 virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0; |
39 }; | 39 }; |
40 | 40 |
41 explicit KeyHoldDetector(scoped_ptr<Delegate> delegate); | 41 explicit KeyHoldDetector(scoped_ptr<Delegate> delegate); |
42 virtual ~KeyHoldDetector(); | 42 virtual ~KeyHoldDetector(); |
43 | 43 |
44 // ui::EventHandler overrides: | 44 // ui::EventHandler overrides: |
45 virtual void OnKeyEvent(ui::KeyEvent* key_event) OVERRIDE; | 45 virtual void OnKeyEvent(ui::KeyEvent* key_event) override; |
46 | 46 |
47 private: | 47 private: |
48 // A state to keep track of one click and click and hold operation. | 48 // A state to keep track of one click and click and hold operation. |
49 // | 49 // |
50 // One click: | 50 // One click: |
51 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] | 51 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] |
52 // | 52 // |
53 // Click and hold: | 53 // Click and hold: |
54 // INITIAL --(first press)--> PRESSED --(press)--> | 54 // INITIAL --(first press)--> PRESSED --(press)--> |
55 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)--> | 55 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)--> |
56 // INITIAL[OnKeyUnhold] | 56 // INITIAL[OnKeyUnhold] |
57 enum State { | 57 enum State { |
58 INITIAL, | 58 INITIAL, |
59 PRESSED, | 59 PRESSED, |
60 HOLD | 60 HOLD |
61 }; | 61 }; |
62 | 62 |
63 State state_; | 63 State state_; |
64 scoped_ptr<Delegate> delegate_; | 64 scoped_ptr<Delegate> delegate_; |
65 | 65 |
66 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector); | 66 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector); |
67 }; | 67 }; |
68 | 68 |
69 } // namespace ash | 69 } // namespace ash |
70 | 70 |
71 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | 71 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ |
OLD | NEW |