Chromium Code Reviews| Index: media/base/user_input_monitor_mac.cc |
| diff --git a/media/base/user_input_monitor_mac.cc b/media/base/user_input_monitor_mac.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1ddfa3d001bc0059cd9b2b6b416146a3fe10ddf |
| --- /dev/null |
| +++ b/media/base/user_input_monitor_mac.cc |
| @@ -0,0 +1,67 @@ |
| +// 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. |
| + |
| +#include "media/base/user_input_monitor.h" |
| + |
| +#include <ApplicationServices/ApplicationServices.h> |
| + |
| +namespace media { |
| +namespace { |
| + |
| +class UserInputMonitorMac : public UserInputMonitor { |
|
Mark Mentovai
2013/08/23 18:09:03
This is a total mess.
You’ve got UserInputMonitor
|
| + public: |
| + explicit UserInputMonitorMac(); |
| + virtual ~UserInputMonitorMac(); |
| + |
| + virtual size_t GetKeyPressCount() const OVERRIDE; |
| + |
| + private: |
| + virtual void StartMouseMonitoring() OVERRIDE; |
| + virtual void StopMouseMonitoring() OVERRIDE; |
| + virtual void StartKeyboardMonitoring() OVERRIDE; |
| + virtual void StopKeyboardMonitoring() OVERRIDE; |
| + |
| + size_t initial_key_press_count_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UserInputMonitorMac); |
| +}; |
| + |
| +UserInputMonitorMac::UserInputMonitorMac() : initial_key_press_count_(0) {} |
| + |
| +UserInputMonitorMac::~UserInputMonitorMac() { |
| + DCHECK(!initial_key_press_count_); |
| +} |
| + |
| +size_t UserInputMonitorMac::GetKeyPressCount() const { |
| + size_t total_count = CGEventSourceCounterForEventType( |
| + kCGEventSourceStateHIDSystemState, kCGEventKeyDown); |
|
Mark Mentovai
2013/08/23 18:09:03
I believe I understand why you used this given the
|
| + return total_count - initial_key_press_count_; |
| +} |
| + |
| +void UserInputMonitorMac::StartMouseMonitoring() { |
| + NOTREACHED(); |
| +} |
| + |
| +void UserInputMonitorMac::StopMouseMonitoring() { |
| + NOTREACHED(); |
| +} |
| + |
| +void UserInputMonitorMac::StartKeyboardMonitoring() { |
| + initial_key_press_count_ = CGEventSourceCounterForEventType( |
|
Mark Mentovai
2013/08/23 18:09:03
Since you shouldn’t reach this code without initia
|
| + kCGEventSourceStateHIDSystemState, kCGEventKeyDown); |
| +} |
| + |
| +void UserInputMonitorMac::StopKeyboardMonitoring() { |
| + initial_key_press_count_ = 0; |
| +} |
| + |
| +} // namespace |
| + |
| +scoped_ptr<UserInputMonitor> UserInputMonitor::Create( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& input_task_runner, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
| + return scoped_ptr<UserInputMonitor>(new UserInputMonitorMac()); |
| +} |
| + |
| +} // namespace media |