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

Side by Side Diff: media/base/user_input_monitor_mac.cc

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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/base/user_input_monitor.h"
6
7 #include <ApplicationServices/ApplicationServices.h>
8
9 namespace media {
10 namespace {
11
12 class UserInputMonitorMac : public UserInputMonitor {
13 public:
14 explicit UserInputMonitorMac();
Mark Mentovai 2013/08/23 20:18:11 Doesn’t need to be explicit now, there are no argu
jiayl 2013/08/23 23:47:58 Done.
15 virtual ~UserInputMonitorMac();
16
17 virtual size_t GetKeyPressCount() const OVERRIDE;
18
19 private:
20 virtual void StartMouseMonitoring() OVERRIDE;
21 virtual void StopMouseMonitoring() OVERRIDE;
22 virtual void StartKeyboardMonitoring() OVERRIDE;
23 virtual void StopKeyboardMonitoring() OVERRIDE;
24
25 size_t initial_key_press_count_;
Mark Mentovai 2013/08/23 20:18:11 See previous comment about eliminating this member
jiayl 2013/08/23 23:47:58 Done.
26
27 DISALLOW_COPY_AND_ASSIGN(UserInputMonitorMac);
28 };
29
30 UserInputMonitorMac::UserInputMonitorMac() : initial_key_press_count_(0) {}
31
32 UserInputMonitorMac::~UserInputMonitorMac() {
33 DCHECK(!initial_key_press_count_);
34 }
35
36 size_t UserInputMonitorMac::GetKeyPressCount() const {
37 // Use |kCGEventSourceStateHIDSystemState| since we only want to count
38 // hardware generated events.
39 size_t total_count = CGEventSourceCounterForEventType(
40 kCGEventSourceStateHIDSystemState, kCGEventKeyDown);
41 return total_count - initial_key_press_count_;
42 }
43
44 // TODO(jiayl): add the impl.
45 void UserInputMonitorMac::StartMouseMonitoring() {
46 NOTIMPLEMENTED();
47 }
48
49 // TODO(jiayl): add the impl.
50 void UserInputMonitorMac::StopMouseMonitoring() {
51 NOTIMPLEMENTED();
52 }
53
54 void UserInputMonitorMac::StartKeyboardMonitoring() {
55 DCHECK_EQ(initial_key_press_count_, 0u);
56 initial_key_press_count_ = GetKeyPressCount();
57 }
58
59 void UserInputMonitorMac::StopKeyboardMonitoring() {
60 initial_key_press_count_ = 0;
61 }
62
63 } // namespace
64
65 scoped_ptr<UserInputMonitor> UserInputMonitor::Create(
66 const scoped_refptr<base::SingleThreadTaskRunner>& input_task_runner,
67 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) {
68 return scoped_ptr<UserInputMonitor>(new UserInputMonitorMac());
69 }
70
71 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698