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

Side by Side Diff: media/audio/key_press_monitor.cc

Issue 21183002: Adding key press detection in the browser process. (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 (c) 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/audio/key_press_monitor.h"
6
7 #include "base/message_loop/message_loop_proxy.h"
8
9 namespace media {
10
11 KeyPressMonitor::KeyPressMonitor(
12 const scoped_refptr<base::MessageLoopProxy>& message_loop,
13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
14 const scoped_refptr<base::MessageLoopProxy>& ui_message_loop)
15 : message_loop_(message_loop),
16 io_message_loop_(io_message_loop),
17 ui_message_loop_(ui_message_loop),
18 weak_ptr_factory_(this) {}
Sergey Ulanov 2013/08/08 01:25:48 Move } to the next line.
jiayl 2013/08/09 23:30:14 This is auto formatted by "git-cl format".
19
20 KeyPressMonitor::~KeyPressMonitor() {}
21
22 void KeyPressMonitor::OnMouseMoved(const SkIPoint& position) { NOTREACHED(); }
Sergey Ulanov 2013/08/08 01:25:48 Wrap NOTREACHED();. Putting } for a function on t
jiayl 2013/08/09 23:30:14 This is auto formatted by "git-cl format".
23
24 void KeyPressMonitor::OnKeyboardEvent(ui::EventType event,
25 ui::KeyboardCode key_code) {
26 DCHECK(message_loop_->BelongsToCurrentThread());
27 if (event == ui::ET_KEY_PRESSED) {
28 if (pressed_keys_.find(key_code) != pressed_keys_.end())
29 return;
30 pressed_keys_.insert(key_code);
31 FOR_EACH_OBSERVER(KeyPressListener, listeners_, OnKeyPressed());
32 } else {
33 DCHECK(event == ui::ET_KEY_RELEASED);
Sergey Ulanov 2013/08/08 01:25:48 DCHECK_EQ
jiayl 2013/08/09 23:30:14 Done.
34 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end());
35 pressed_keys_.erase(key_code);
36 }
37 }
38
39 void KeyPressMonitor::AddKeyPressListener(KeyPressListener* listener) {
40 DCHECK(message_loop_->BelongsToCurrentThread());
41 listeners_.AddObserver(listener);
42
43 if (listeners_.size() == 1 && !monitor_.get()) {
44 monitor_.reset(UserInputMonitor::Create(io_message_loop_,
Sergey Ulanov 2013/08/08 01:25:48 monitor_ = UserInputMonitor::Create(....). Don't
jiayl 2013/08/09 23:30:14 Done.
45 ui_message_loop_,
46 message_loop_,
47 UserInputMonitor::KEYBOARD_EVENT,
48 weak_ptr_factory_.GetWeakPtr())
49 .release());
50 }
51 }
52
53 void KeyPressMonitor::RemoveKeyPressListener(KeyPressListener* listener) {
54 DCHECK(message_loop_->BelongsToCurrentThread());
55 listeners_.RemoveObserver(listener);
56
57 if (listeners_.size() == 0) {
58 monitor_.reset(NULL);
59 weak_ptr_factory_.InvalidateWeakPtrs();
60 }
61 }
62
63 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698