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 <memory> |
| 9 |
8 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "ui/events/event_handler.h" | 12 #include "ui/events/event_handler.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 class KeyEvent; | 15 class KeyEvent; |
15 } | 16 } |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 | 19 |
19 // This class is used to implement action when a user press and hold the key. | 20 // This class is used to implement action when a user press and hold the key. |
20 // When a user just pressed and released a key, normal pressed event gets | 21 // When a user just pressed and released a key, normal pressed event gets |
(...skipping 14 matching lines...) Expand all Loading... |
35 // Whether to stop event propagation after processing. | 36 // Whether to stop event propagation after processing. |
36 virtual bool ShouldStopEventPropagation() const = 0; | 37 virtual bool ShouldStopEventPropagation() const = 0; |
37 | 38 |
38 // Called when the key is held. | 39 // Called when the key is held. |
39 virtual void OnKeyHold(const ui::KeyEvent* event) = 0; | 40 virtual void OnKeyHold(const ui::KeyEvent* event) = 0; |
40 | 41 |
41 // Called when the key is release after hold. | 42 // Called when the key is release after hold. |
42 virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0; | 43 virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0; |
43 }; | 44 }; |
44 | 45 |
45 explicit KeyHoldDetector(scoped_ptr<Delegate> delegate); | 46 explicit KeyHoldDetector(std::unique_ptr<Delegate> delegate); |
46 ~KeyHoldDetector() override; | 47 ~KeyHoldDetector() override; |
47 | 48 |
48 // ui::EventHandler overrides: | 49 // ui::EventHandler overrides: |
49 void OnKeyEvent(ui::KeyEvent* key_event) override; | 50 void OnKeyEvent(ui::KeyEvent* key_event) override; |
50 | 51 |
51 private: | 52 private: |
52 // A state to keep track of one click and click and hold operation. | 53 // A state to keep track of one click and click and hold operation. |
53 // | 54 // |
54 // One click: | 55 // One click: |
55 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] | 56 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] |
56 // | 57 // |
57 // Click and hold: | 58 // Click and hold: |
58 // INITIAL --(first press)--> PRESSED --(press)--> | 59 // INITIAL --(first press)--> PRESSED --(press)--> |
59 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)--> | 60 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)--> |
60 // INITIAL[OnKeyUnhold] | 61 // INITIAL[OnKeyUnhold] |
61 enum State { | 62 enum State { |
62 INITIAL, | 63 INITIAL, |
63 PRESSED, | 64 PRESSED, |
64 HOLD | 65 HOLD |
65 }; | 66 }; |
66 | 67 |
67 State state_; | 68 State state_; |
68 scoped_ptr<Delegate> delegate_; | 69 std::unique_ptr<Delegate> delegate_; |
69 | 70 |
70 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector); | 71 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector); |
71 }; | 72 }; |
72 | 73 |
73 } // namespace ash | 74 } // namespace ash |
74 | 75 |
75 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | 76 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ |
OLD | NEW |