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

Side by Side Diff: remoting/protocol/input_event_tracker.cc

Issue 11781003: Connect to DesktopEnvironment's stubs only when audio/video schedulers are about to be created. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "remoting/protocol/input_event_tracker.h" 5 #include "remoting/protocol/input_event_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "remoting/proto/event.pb.h" 8 #include "remoting/proto/event.pb.h"
9 9
10 namespace remoting { 10 namespace remoting {
(...skipping 10 matching lines...) Expand all
21 21
22 bool InputEventTracker::IsKeyPressed(uint32 usb_keycode) const { 22 bool InputEventTracker::IsKeyPressed(uint32 usb_keycode) const {
23 return pressed_keys_.find(usb_keycode) != pressed_keys_.end(); 23 return pressed_keys_.find(usb_keycode) != pressed_keys_.end();
24 } 24 }
25 25
26 int InputEventTracker::PressedKeyCount() const { 26 int InputEventTracker::PressedKeyCount() const {
27 return pressed_keys_.size(); 27 return pressed_keys_.size();
28 } 28 }
29 29
30 void InputEventTracker::ReleaseAll() { 30 void InputEventTracker::ReleaseAll() {
31 std::set<uint32>::iterator i; 31 if (input_stub_) {
32 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { 32 std::set<uint32>::iterator i;
33 KeyEvent event; 33 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) {
34 event.set_pressed(false); 34 KeyEvent event;
35 event.set_usb_keycode(*i); 35 event.set_pressed(false);
36 input_stub_->InjectKeyEvent(event); 36 event.set_usb_keycode(*i);
37 } 37 input_stub_->InjectKeyEvent(event);
38 pressed_keys_.clear(); 38 }
39 39
40 for (int i = MouseEvent::BUTTON_UNDEFINED + 1; 40 for (int i = MouseEvent::BUTTON_UNDEFINED + 1;
41 i < MouseEvent::BUTTON_MAX; ++i) { 41 i < MouseEvent::BUTTON_MAX; ++i) {
42 if (mouse_button_state_ & (1 << (i - 1))) { 42 if (mouse_button_state_ & (1 << (i - 1))) {
43 MouseEvent mouse; 43 MouseEvent mouse;
44 44
45 // TODO(wez): EventInjectors should cope with positionless events by 45 // TODO(wez): EventInjectors should cope with positionless events by
46 // using the current cursor position, and we wouldn't set position here. 46 // using the current cursor position, and we wouldn't set position here.
47 mouse.set_x(mouse_pos_.x()); 47 mouse.set_x(mouse_pos_.x());
48 mouse.set_y(mouse_pos_.y()); 48 mouse.set_y(mouse_pos_.y());
49 49
50 mouse.set_button((MouseEvent::MouseButton)i); 50 mouse.set_button((MouseEvent::MouseButton)i);
51 mouse.set_button_down(false); 51 mouse.set_button_down(false);
52 input_stub_->InjectMouseEvent(mouse); 52 input_stub_->InjectMouseEvent(mouse);
53 }
53 } 54 }
54 } 55 }
56
57 pressed_keys_.clear();
55 mouse_button_state_ = 0; 58 mouse_button_state_ = 0;
56 } 59 }
57 60
58 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { 61 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) {
59 if (event.has_pressed()) { 62 if (event.has_pressed()) {
60 if (event.has_usb_keycode()) { 63 if (event.has_usb_keycode()) {
61 if (event.pressed()) { 64 if (event.pressed()) {
62 pressed_keys_.insert(event.usb_keycode()); 65 pressed_keys_.insert(event.usb_keycode());
63 } else { 66 } else {
64 pressed_keys_.erase(event.usb_keycode()); 67 pressed_keys_.erase(event.usb_keycode());
65 } 68 }
66 } 69 }
67 } 70 }
68 input_stub_->InjectKeyEvent(event); 71
72 if (input_stub_)
73 input_stub_->InjectKeyEvent(event);
69 } 74 }
70 75
71 void InputEventTracker::InjectMouseEvent(const MouseEvent& event) { 76 void InputEventTracker::InjectMouseEvent(const MouseEvent& event) {
72 if (event.has_x() && event.has_y()) { 77 if (event.has_x() && event.has_y()) {
73 mouse_pos_ = SkIPoint::Make(event.x(), event.y()); 78 mouse_pos_ = SkIPoint::Make(event.x(), event.y());
74 } 79 }
75 if (event.has_button() && event.has_button_down()) { 80 if (event.has_button() && event.has_button_down()) {
76 // Button values are defined in remoting/proto/event.proto. 81 // Button values are defined in remoting/proto/event.proto.
77 if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) { 82 if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) {
78 uint32 button_change = 1 << (event.button() - 1); 83 uint32 button_change = 1 << (event.button() - 1);
79 if (event.button_down()) { 84 if (event.button_down()) {
80 mouse_button_state_ |= button_change; 85 mouse_button_state_ |= button_change;
81 } else { 86 } else {
82 mouse_button_state_ &= ~button_change; 87 mouse_button_state_ &= ~button_change;
83 } 88 }
84 } 89 }
85 } 90 }
86 input_stub_->InjectMouseEvent(event); 91
92 if (input_stub_)
93 input_stub_->InjectMouseEvent(event);
87 } 94 }
88 95
89 } // namespace protocol 96 } // namespace protocol
90 } // namespace remoting 97 } // namespace remoting
OLDNEW
« remoting/protocol/input_event_tracker.h ('K') | « remoting/protocol/input_event_tracker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698