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.
5 #ifndef ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_
6 #define ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_
8 #include "ash/ash_export.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/events/event_handler.h"
18 // This class is used to implement action when a user press and hold the key.
19 // When a user just pressed and released a key, normal pressed event gets
20 // generated upon release.
21 class ASH_EXPORT KeyHoldDetector
: public ui::EventHandler
{
25 virtual ~Delegate() {}
27 // If this return false, the event handler does not process
29 virtual bool ShouldProcessEvent(const ui::KeyEvent
* event
) const = 0;
31 // This should return true if the event should start the state transition.
32 virtual bool IsStartEvent(const ui::KeyEvent
* event
) const = 0;
34 // Whether to stop event propagation after processing.
35 virtual bool ShouldStopEventPropagation() const = 0;
37 // Called when the key is held.
38 virtual void OnKeyHold(const ui::KeyEvent
* event
) = 0;
40 // Called when the key is release after hold.
41 virtual void OnKeyUnhold(const ui::KeyEvent
* event
) = 0;
44 explicit KeyHoldDetector(scoped_ptr
<Delegate
> delegate
);
45 ~KeyHoldDetector() override
;
47 // ui::EventHandler overrides:
48 void OnKeyEvent(ui::KeyEvent
* key_event
) override
;
51 // A state to keep track of one click and click and hold operation.
54 // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS]
57 // INITIAL --(first press)--> PRESSED --(press)-->
58 // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)-->
59 // INITIAL[OnKeyUnhold]
67 scoped_ptr
<Delegate
> delegate_
;
69 DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector
);
74 #endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_