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

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: add linux impl 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,
DaleCurtis 2013/08/07 17:50:39 Not really necessary to pass all this in, you coul
DaleCurtis 2013/08/07 18:58:02 I forgot this is in media/ so you can't do this af
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) {}
19
20 KeyPressMonitor::~KeyPressMonitor() {}
21
22 void KeyPressMonitor::OnMouseMoved(const SkIPoint& position) {
23 NOTREACHED();
24 }
25
26 void KeyPressMonitor::OnKeyboardEvent(ui::EventType event,
27 ui::KeyboardCode key_code) {
28 DCHECK(message_loop_->BelongsToCurrentThread());
29 if (event == ui::ET_KEY_PRESSED) {
30 if (pressed_keys_.find(key_code) != pressed_keys_.end())
31 return;
32 pressed_keys_.insert(key_code);
33 FOR_EACH_OBSERVER(KeyPressListener, listeners_, OnKeyPressed());
tommi (sloooow) - chröme 2013/08/06 10:57:47 Would it make sense to have two events, OnKeyPress
jiayl 2013/08/06 17:24:11 It doesn't seem necessary if my understanding of t
34 } else {
35 DCHECK(event == ui::ET_KEY_RELEASED);
36 DCHECK(pressed_keys_.find(key_code) != pressed_keys_.end());
37 pressed_keys_.erase(key_code);
38 }
39 }
40
41 void KeyPressMonitor::AddKeyPressListener(KeyPressListener* listener) {
42 DCHECK(message_loop_->BelongsToCurrentThread());
43 listeners_.AddObserver(listener);
44
45 if (listeners_.size() == 1 && !monitor_.get()) {
46 monitor_.reset(UserInputMonitor::Create(io_message_loop_,
47 ui_message_loop_,
48 message_loop_,
49 UserInputMonitor::KEYBOARD_EVENT,
50 weak_ptr_factory_.GetWeakPtr())
51 .release());
52 }
53 }
54
55 void KeyPressMonitor::RemoveKeyPressListener(KeyPressListener* listener) {
56 DCHECK(message_loop_->BelongsToCurrentThread());
57 listeners_.RemoveObserver(listener);
58
59 if (listeners_.size() == 0) {
60 monitor_.reset(NULL);
61 weak_ptr_factory_.InvalidateWeakPtrs();
62 }
63 }
64
65 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698