| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ | 5 #ifndef MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |
| 6 #define MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ | 6 #define MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
| 15 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
| 16 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 // This class tracks the total number of keypresses based on the OnKeyboardEvent | 20 // This class tracks the total number of keypresses based on the OnKeyboardEvent |
| 21 // calls it receives from the client. | 21 // calls it receives from the client. |
| 22 // Multiple key down events for the same key are counted as one keypress until | 22 // Multiple key down events for the same key are counted as one keypress until |
| 23 // the same key is released. | 23 // the same key is released. |
| 24 class MEDIA_EXPORT KeyboardEventCounter { | 24 class MEDIA_EXPORT KeyboardEventCounter { |
| 25 public: | 25 public: |
| 26 KeyboardEventCounter(); | 26 KeyboardEventCounter(); |
| 27 ~KeyboardEventCounter(); | 27 ~KeyboardEventCounter(); |
| 28 | 28 |
| 29 // Resets the count to 0. Must be called on the same thread as | |
| 30 // OnKeyboardEvent. | |
| 31 void Reset(); | |
| 32 | |
| 33 // Returns the total number of keypresses since its creation or last Reset() | 29 // Returns the total number of keypresses since its creation or last Reset() |
| 34 // call. Can be called on any thread. | 30 // call. Can be called on any thread. |
| 35 size_t GetKeyPressCount() const; | 31 size_t GetKeyPressCount() const; |
| 36 | 32 |
| 37 // The client should call this method on key down or key up events. | 33 // The client should call this method on key down or key up events. |
| 38 // Must be called on a single thread. | 34 // Must be called on a single thread. |
| 39 void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code); | 35 void OnKeyboardEvent(ui::EventType event, ui::KeyboardCode key_code); |
| 40 | 36 |
| 41 private: | 37 private: |
| 42 // The set of keys currently held down. | 38 // The set of keys currently held down. |
| 43 std::set<ui::KeyboardCode> pressed_keys_; | 39 std::set<ui::KeyboardCode> pressed_keys_; |
| 44 | 40 |
| 45 size_t total_key_presses_; | 41 size_t total_key_presses_; |
| 46 | 42 |
| 47 DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter); | 43 DISALLOW_COPY_AND_ASSIGN(KeyboardEventCounter); |
| 48 }; | 44 }; |
| 49 | 45 |
| 50 } // namespace media | 46 } // namespace media |
| 51 | 47 |
| 52 #endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ | 48 #endif // MEDIA_BASE_KEYBOARD_EVENT_COUNTER_H_ |
| OLD | NEW |