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

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

Issue 1760633003: Notify normalizing input filters on blur. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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 {
11 namespace protocol { 11 namespace protocol {
12 12
13 InputEventTracker::InputEventTracker(InputStub* input_stub) 13 InputEventTracker::InputEventTracker() {}
14 : input_stub_(input_stub),
15 mouse_button_state_(0) {
16 }
17
18 InputEventTracker::~InputEventTracker() {} 14 InputEventTracker::~InputEventTracker() {}
19 15
20 bool InputEventTracker::IsKeyPressed(ui::DomCode usb_keycode) const { 16 bool InputEventTracker::IsKeyPressed(ui::DomCode usb_keycode) const {
21 return pressed_keys_.find(usb_keycode) != pressed_keys_.end(); 17 return pressed_keys_.find(usb_keycode) != pressed_keys_.end();
22 } 18 }
23 19
24 int InputEventTracker::PressedKeyCount() const { 20 int InputEventTracker::PressedKeyCount() const {
25 return pressed_keys_.size(); 21 return pressed_keys_.size();
26 } 22 }
27 23
28 void InputEventTracker::ReleaseAll() { 24 void InputEventTracker::ReleaseAll() {
25 DCHECK(input_stub_);
Jamie 2016/03/03 00:18:54 Note that this is different from the previous impl
26
29 // Release all pressed keys. 27 // Release all pressed keys.
30 for (auto keycode : pressed_keys_) { 28 for (auto keycode : pressed_keys_) {
31 KeyEvent event; 29 KeyEvent event;
32 event.set_pressed(false); 30 event.set_pressed(false);
33 event.set_usb_keycode(static_cast<uint32_t>(keycode)); 31 event.set_usb_keycode(static_cast<uint32_t>(keycode));
34 input_stub_->InjectKeyEvent(event); 32 input_stub_->InjectKeyEvent(event);
35 } 33 }
36 pressed_keys_.clear(); 34 pressed_keys_.clear();
37 35
38 // Release all mouse buttons. 36 // Release all mouse buttons.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 pressed_keys_.find(ui::DomCode::SHIFT_LEFT) != pressed_keys_.end() || 82 pressed_keys_.find(ui::DomCode::SHIFT_LEFT) != pressed_keys_.end() ||
85 pressed_keys_.find(ui::DomCode::SHIFT_RIGHT) != pressed_keys_.end(); 83 pressed_keys_.find(ui::DomCode::SHIFT_RIGHT) != pressed_keys_.end();
86 84
87 if ((alt_down && !alt_expected) || (ctrl_down && !ctrl_expected) || 85 if ((alt_down && !alt_expected) || (ctrl_down && !ctrl_expected) ||
88 (os_down && !os_expected) || (shift_down && !shift_expected)) { 86 (os_down && !os_expected) || (shift_down && !shift_expected)) {
89 ReleaseAll(); 87 ReleaseAll();
90 } 88 }
91 } 89 }
92 90
93 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { 91 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) {
92 DCHECK(input_stub_);
93
94 // We don't need to track the keyboard lock states of key down events. 94 // We don't need to track the keyboard lock states of key down events.
95 // Pressed keys will be released with |lock_states| set to 0. 95 // Pressed keys will be released with |lock_states| set to 0.
96 // The lock states of auto generated key up events don't matter as long as 96 // The lock states of auto generated key up events don't matter as long as
97 // we release all the pressed keys at blurring/disconnection time. 97 // we release all the pressed keys at blurring/disconnection time.
98 if (event.has_pressed()) { 98 if (event.has_pressed()) {
99 if (event.has_usb_keycode()) { 99 if (event.has_usb_keycode()) {
100 if (event.pressed()) { 100 if (event.pressed()) {
101 pressed_keys_.insert(static_cast<ui::DomCode>(event.usb_keycode())); 101 pressed_keys_.insert(static_cast<ui::DomCode>(event.usb_keycode()));
102 } else { 102 } else {
103 pressed_keys_.erase(static_cast<ui::DomCode>(event.usb_keycode())); 103 pressed_keys_.erase(static_cast<ui::DomCode>(event.usb_keycode()));
104 } 104 }
105 } 105 }
106 } 106 }
107 input_stub_->InjectKeyEvent(event); 107 input_stub_->InjectKeyEvent(event);
108 } 108 }
109 109
110 void InputEventTracker::InjectTextEvent(const TextEvent& event) { 110 void InputEventTracker::InjectTextEvent(const TextEvent& event) {
111 DCHECK(input_stub_);
111 input_stub_->InjectTextEvent(event); 112 input_stub_->InjectTextEvent(event);
112 } 113 }
113 114
114 void InputEventTracker::InjectMouseEvent(const MouseEvent& event) { 115 void InputEventTracker::InjectMouseEvent(const MouseEvent& event) {
116 DCHECK(input_stub_);
117
115 if (event.has_x() && event.has_y()) { 118 if (event.has_x() && event.has_y()) {
116 mouse_pos_ = webrtc::DesktopVector(event.x(), event.y()); 119 mouse_pos_ = webrtc::DesktopVector(event.x(), event.y());
117 } 120 }
118 if (event.has_button() && event.has_button_down()) { 121 if (event.has_button() && event.has_button_down()) {
119 // Button values are defined in remoting/proto/event.proto. 122 // Button values are defined in remoting/proto/event.proto.
120 if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) { 123 if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) {
121 uint32_t button_change = 1 << (event.button() - 1); 124 uint32_t button_change = 1 << (event.button() - 1);
122 if (event.button_down()) { 125 if (event.button_down()) {
123 mouse_button_state_ |= button_change; 126 mouse_button_state_ |= button_change;
124 } else { 127 } else {
125 mouse_button_state_ &= ~button_change; 128 mouse_button_state_ &= ~button_change;
126 } 129 }
127 } 130 }
128 } 131 }
129 input_stub_->InjectMouseEvent(event); 132 input_stub_->InjectMouseEvent(event);
130 } 133 }
131 134
132 void InputEventTracker::InjectTouchEvent(const TouchEvent& event) { 135 void InputEventTracker::InjectTouchEvent(const TouchEvent& event) {
136 DCHECK(input_stub_);
133 // We only need the IDs to cancel all touch points in ReleaseAll(). Other 137 // We only need the IDs to cancel all touch points in ReleaseAll(). Other
134 // fields do not have to be tracked here as long as the host keeps track of 138 // fields do not have to be tracked here as long as the host keeps track of
135 // them. 139 // them.
136 switch (event.event_type()) { 140 switch (event.event_type()) {
137 case TouchEvent::TOUCH_POINT_START: 141 case TouchEvent::TOUCH_POINT_START:
138 for (const TouchEventPoint& touch_point : event.touch_points()) { 142 for (const TouchEventPoint& touch_point : event.touch_points()) {
139 DCHECK(touch_point_ids_.find(touch_point.id()) == 143 DCHECK(touch_point_ids_.find(touch_point.id()) ==
140 touch_point_ids_.end()); 144 touch_point_ids_.end());
141 touch_point_ids_.insert(touch_point.id()); 145 touch_point_ids_.insert(touch_point.id());
142 } 146 }
143 break; 147 break;
144 case TouchEvent::TOUCH_POINT_END: 148 case TouchEvent::TOUCH_POINT_END:
145 case TouchEvent::TOUCH_POINT_CANCEL: 149 case TouchEvent::TOUCH_POINT_CANCEL:
146 for (const TouchEventPoint& touch_point : event.touch_points()) { 150 for (const TouchEventPoint& touch_point : event.touch_points()) {
147 DCHECK(touch_point_ids_.find(touch_point.id()) != 151 DCHECK(touch_point_ids_.find(touch_point.id()) !=
148 touch_point_ids_.end()); 152 touch_point_ids_.end());
149 touch_point_ids_.erase(touch_point.id()); 153 touch_point_ids_.erase(touch_point.id());
150 } 154 }
151 break; 155 break;
152 default: 156 default:
153 break; 157 break;
154 } 158 }
155 input_stub_->InjectTouchEvent(event); 159 input_stub_->InjectTouchEvent(event);
156 } 160 }
157 161
158 } // namespace protocol 162 } // namespace protocol
159 } // namespace remoting 163 } // 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