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

Unified Diff: media/base/keyboard_event_counter.h

Issue 22801007: Adds the UserInputMonitor implementation for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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 | « media/audio/audio_input_controller.cc ('k') | media/base/keyboard_event_counter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c82ca597eef11240a9b7a73d665ab9d24a6ba8c8
--- /dev/null
+++ b/media/base/keyboard_event_counter.h
@@ -0,0 +1,48 @@
+// 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"
+#include "ui/base/events/event_constants.h"
+#include "ui/base/keycodes/keyboard_codes.h"
+
+namespace media {
+
+// This class tracks the total number of keypresses based on the OnKeyboardEvent
+// calls it receives from the client.
+// Multiple key down events for the same key are counted as one keypress until
+// the same key is released.
+class KeyboardEventCounter {
+ public:
+ KeyboardEventCounter();
+ ~KeyboardEventCounter();
+
+ // Resets the count to 0. Must be called on the same thread as
+ // OnKeyboardEvent.
+ void Reset();
+
+ // Returns the total number of keypresses since its creation or last Reset()
+ // call. Can be called on any thread.
+ size_t GetKeyPressCount() const;
+
+ // The client should call this method on key down or key up events.
+ // Must be called on a single thread.
+ void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code);
+
+ private:
+ // The set of keys currently held down.
+ std::set<ui::KeyboardCode> pressed_keys_;
+
+ size_t total_key_presses_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/base/keyboard_event_counter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698