Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: ash/accelerators/key_hold_detector.h

Issue 164823005: Long press menu (shift+f6) to toggle spoken feedback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ash/accelerators/key_hold_detector.cc » ('j') | ash/accelerators/key_hold_detector.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/accelerators/key_hold_detector.h
diff --git a/ash/accelerators/key_hold_detector.h b/ash/accelerators/key_hold_detector.h
new file mode 100644
index 0000000000000000000000000000000000000000..81b539924bd5dbe1c8b350ef0b3cbac75e6cf36f
--- /dev/null
+++ b/ash/accelerators/key_hold_detector.h
@@ -0,0 +1,68 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_
+#define ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_
+
+#include "ash/ash_export.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/events/event_handler.h"
+
+namespace ui {
+class KeyEvent;
+}
+
+namespace ash {
+
+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.
+ public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // If this return false, the event handler does not process
+ // the event at all.
+ virtual bool ShouldProcessEvent(const ui::KeyEvent* event) const = 0;
+
+ // This should return true if the event should start the state transition.
+ virtual bool IsStartEvent(const ui::KeyEvent* event) const = 0;
+
+ // Called when the key is held.
+ virtual void OnKeyHold(const ui::KeyEvent* event) = 0;
+
+ // Called when the key is release after hold.
+ virtual void OnKeyUnhold(const ui::KeyEvent* event) = 0;
+ };
+
+ KeyHoldDetector(scoped_ptr<Delegate> delegate);
xiyuan 2014/02/14 01:50:21 nit: explicit
oshima 2014/02/14 18:03:25 Done.
+ virtual ~KeyHoldDetector();
+
+ // ui::EventHandler overrides:
+ virtual void OnKeyEvent(ui::KeyEvent* key_event) OVERRIDE;
+
+ private:
+ // A state to keep track of one click and click and hold operation.
+ //
+ // One click:
+ // INITIAL --(first press)--> PRESSED --(release)--> INITIAL[SEND PRESS]
+ //
+ // Click and hold:
+ // INITIAL --(first press)--> PRESSED --(press)-->
+ // HOLD[OnKeyHold] --(press)--> HOLD[OnKeyHold] --(release)-->
+ // INITIAL[OnKeyUnhold]
+ enum State {
+ INITIAL,
+ PRESSED,
+ HOLD
+ };
+
+ State state_;
+ scoped_ptr<Delegate> delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeyHoldDetector);
+};
+
+} // namespace ash
+
+#endif // ASH_ACCELERATOR_KEY_HOLD_DETECTOR_H_
« no previous file with comments | « no previous file | ash/accelerators/key_hold_detector.cc » ('j') | ash/accelerators/key_hold_detector.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698