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 ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | |
| 6 #define ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | |
| 7 | |
| 8 #include "ash/ash_export.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "ui/events/event_handler.h" | |
| 11 | |
| 12 namespace ui { | |
| 13 class KeyEvent; | |
| 14 } | |
| 15 | |
| 16 namespace ash { | |
| 17 | |
| 18 class ASH_EXPORT KeyHoldDetector : public ui::EventHandler { | |
|
xiyuan
2014/02/14 01:50:21
nit: Document the class?
oshima
2014/02/14 18:03:25
Done.
| |
| 19 public: | |
| 20 class Delegate { | |
| 21 public: | |
| 22 virtual ~Delegate() {} | |
| 23 | |
| 24 // If this return false, the event handler does not process | |
| 25 // the event at all. | |
| 26 virtual bool ShouldProcessEvent(const ui::KeyEvent* event) const = 0; | |
| 27 | |
| 28 // This should return true if the event should start the state transition. | |
| 29 virtual bool IsStartEvent(const ui::KeyEvent* event) const = 0; | |
| 30 | |
| 31 // Called when the key is held. | |
| 32 virtual void OnKeyHold(const ui::KeyEvent* event) = 0; | |
| 33 | |
| 34 // Called when the key is release after hold. | |
| 35 virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0; | |
| 36 }; | |
| 37 | |
| 38 KeyHoldDetector(scoped_ptr<Delegate> delegate); | |
|
xiyuan
2014/02/14 01:50:21
nit: explicit
oshima
2014/02/14 18:03:25
Done.
| |
| 39 virtual ~KeyHoldDetector(); | |
| 40 | |
| 41 // ui::EventHandler overrides: | |
| 42 virtual void OnKeyEvent(ui::KeyEvent* key_event) OVERRIDE; | |
| 43 | |
| 44 private: | |
| 45 // A state to keep track of one click and click and hold operation. | |
| 46 // | |
| 47 // One click: | |
| 48 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS] | |
| 49 // | |
| 50 // Click and hold: | |
| 51 // INITIAL --(first press)--> PRESSED --(press)--> | |
| 52 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)--> | |
| 53 // INITIAL[OnKeyUnhold] | |
| 54 enum State { | |
| 55 INITIAL, | |
| 56 PRESSED, | |
| 57 HOLD | |
| 58 }; | |
| 59 | |
| 60 State state_; | |
| 61 scoped_ptr<Delegate> delegate_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector); | |
| 64 }; | |
| 65 | |
| 66 } // namespace ash | |
| 67 | |
| 68 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_ | |
| OLD | NEW |