Index: media/base/keyboard_event_counter.h |
diff --git a/media/base/keyboard_event_counter.h b/media/base/keyboard_event_counter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d0a1bb84178d2068f50b1d55d5e1b107109ba69f |
--- /dev/null |
+++ b/media/base/keyboard_event_counter.h |
@@ -0,0 +1,45 @@ |
+// Copyright 2013 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 MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |
+#define MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |
+ |
+#include <set> |
+#include "base/synchronization/lock.h" |
Mark Mentovai
2013/08/23 20:18:11
Blank line before this.
jiayl
2013/08/23 23:47:58
Done.
|
+#include "ui/base/events/event_constants.h" |
+#include "ui/base/keycodes/keyboard_codes.h" |
+ |
+namespace media { |
+ |
+// This class tracks the total number key presses based on the OnKeyboardEvent |
Mark Mentovai
2013/08/23 20:18:11
total number of keypresses
jiayl
2013/08/23 23:47:58
Done.
|
+// calls it receives from the client. |
+// Multiple key down events for the same key is counted as one keypress until |
Mark Mentovai
2013/08/23 20:18:11
is → are
jiayl
2013/08/23 23:47:58
Done.
|
+// the same key is released. |
+// Thread safe. |
+class KeyboardEventCounter { |
+ public: |
+ KeyboardEventCounter(); |
+ ~KeyboardEventCounter(); |
+ |
+ // Resets the count to 0. |
+ void Reset(); |
+ // Returns the total number of keypresses since its creation or last Reset() |
Mark Mentovai
2013/08/23 20:18:11
Put blank lines before the comments that introduce
jiayl
2013/08/23 23:47:58
Done.
|
+ // call. |
+ size_t GetKeyPressCount() const; |
+ // The client should call this method on key down or key up events. |
+ void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code); |
+ |
+ private: |
+ // "mutable" for GetKeyPressCount(). |
+ mutable base::Lock lock_; |
+ // The set of keys currently held down. |
+ std::set<int> pressed_keys_; |
Mark Mentovai
2013/08/23 20:18:11
ui::KeyboardCode, not int?
jiayl
2013/08/23 23:47:58
Done.
|
+ size_t total_key_presses_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |