OLD | NEW |
---|---|
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 #include "remoting/protocol/usb_key_codes.h" | |
10 | 9 |
11 namespace remoting { | 10 namespace remoting { |
12 namespace protocol { | 11 namespace protocol { |
13 | 12 |
14 InputEventTracker::InputEventTracker(InputStub* input_stub) | 13 InputEventTracker::InputEventTracker(InputStub* input_stub) |
15 : input_stub_(input_stub), | 14 : input_stub_(input_stub), |
16 mouse_button_state_(0) { | 15 mouse_button_state_(0) { |
17 } | 16 } |
18 | 17 |
19 InputEventTracker::~InputEventTracker() {} | 18 InputEventTracker::~InputEventTracker() {} |
20 | 19 |
21 bool InputEventTracker::IsKeyPressed(uint32 usb_keycode) const { | 20 bool InputEventTracker::IsKeyPressed(ui::DomCode usb_keycode) const { |
22 return pressed_keys_.find(usb_keycode) != pressed_keys_.end(); | 21 return pressed_keys_.find(usb_keycode) != pressed_keys_.end(); |
23 } | 22 } |
24 | 23 |
25 int InputEventTracker::PressedKeyCount() const { | 24 int InputEventTracker::PressedKeyCount() const { |
26 return pressed_keys_.size(); | 25 return pressed_keys_.size(); |
27 } | 26 } |
28 | 27 |
29 void InputEventTracker::ReleaseAll() { | 28 void InputEventTracker::ReleaseAll() { |
30 // Release all pressed keys. | 29 // Release all pressed keys. |
31 for (uint32 keycode : pressed_keys_) { | 30 for (auto keycode : pressed_keys_) { |
32 KeyEvent event; | 31 KeyEvent event; |
33 event.set_pressed(false); | 32 event.set_pressed(false); |
34 event.set_usb_keycode(keycode); | 33 event.set_usb_keycode(static_cast<unsigned int>(keycode)); |
Sergey Ulanov
2015/10/12 21:45:57
use uint32_t instead of unsigned int.
Jamie
2015/10/12 22:26:09
Done.
| |
35 input_stub_->InjectKeyEvent(event); | 34 input_stub_->InjectKeyEvent(event); |
36 } | 35 } |
37 pressed_keys_.clear(); | 36 pressed_keys_.clear(); |
38 | 37 |
39 // Release all mouse buttons. | 38 // Release all mouse buttons. |
40 for (int i = MouseEvent::BUTTON_UNDEFINED + 1; | 39 for (int i = MouseEvent::BUTTON_UNDEFINED + 1; |
41 i < MouseEvent::BUTTON_MAX; ++i) { | 40 i < MouseEvent::BUTTON_MAX; ++i) { |
42 if (mouse_button_state_ & (1 << (i - 1))) { | 41 if (mouse_button_state_ & (1 << (i - 1))) { |
43 MouseEvent mouse; | 42 MouseEvent mouse; |
44 | 43 |
(...skipping 21 matching lines...) Expand all Loading... | |
66 touch_point_ids_.clear(); | 65 touch_point_ids_.clear(); |
67 } | 66 } |
68 DCHECK(touch_point_ids_.empty()); | 67 DCHECK(touch_point_ids_.empty()); |
69 } | 68 } |
70 | 69 |
71 void InputEventTracker::ReleaseAllIfModifiersStuck(bool alt_expected, | 70 void InputEventTracker::ReleaseAllIfModifiersStuck(bool alt_expected, |
72 bool ctrl_expected, | 71 bool ctrl_expected, |
73 bool os_expected, | 72 bool os_expected, |
74 bool shift_expected) { | 73 bool shift_expected) { |
75 bool alt_down = | 74 bool alt_down = |
76 pressed_keys_.find(kUsbLeftAlt) != pressed_keys_.end() || | 75 pressed_keys_.find(ui::DomCode::ALT_LEFT) != pressed_keys_.end() || |
77 pressed_keys_.find(kUsbRightAlt) != pressed_keys_.end(); | 76 pressed_keys_.find(ui::DomCode::ALT_RIGHT) != pressed_keys_.end(); |
78 bool ctrl_down = | 77 bool ctrl_down = |
79 pressed_keys_.find(kUsbLeftControl) != pressed_keys_.end() || | 78 pressed_keys_.find(ui::DomCode::CONTROL_LEFT) != pressed_keys_.end() || |
80 pressed_keys_.find(kUsbRightControl) != pressed_keys_.end(); | 79 pressed_keys_.find(ui::DomCode::CONTROL_RIGHT) != pressed_keys_.end(); |
81 bool os_down = | 80 bool os_down = |
82 pressed_keys_.find(kUsbLeftOs) != pressed_keys_.end() || | 81 pressed_keys_.find(ui::DomCode::OS_LEFT) != pressed_keys_.end() || |
83 pressed_keys_.find(kUsbRightOs) != pressed_keys_.end(); | 82 pressed_keys_.find(ui::DomCode::OS_RIGHT) != pressed_keys_.end(); |
84 bool shift_down = | 83 bool shift_down = |
85 pressed_keys_.find(kUsbLeftShift) != pressed_keys_.end() || | 84 pressed_keys_.find(ui::DomCode::SHIFT_LEFT) != pressed_keys_.end() || |
86 pressed_keys_.find(kUsbRightShift) != pressed_keys_.end(); | 85 pressed_keys_.find(ui::DomCode::SHIFT_RIGHT) != pressed_keys_.end(); |
87 | 86 |
88 if ((alt_down && !alt_expected) || (ctrl_down && !ctrl_expected) || | 87 if ((alt_down && !alt_expected) || (ctrl_down && !ctrl_expected) || |
89 (os_down && !os_expected) || (shift_down && !shift_expected)) { | 88 (os_down && !os_expected) || (shift_down && !shift_expected)) { |
90 ReleaseAll(); | 89 ReleaseAll(); |
91 } | 90 } |
92 } | 91 } |
93 | 92 |
94 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { | 93 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { |
95 // 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. |
96 // Pressed keys will be released with |lock_states| set to 0. | 95 // Pressed keys will be released with |lock_states| set to 0. |
97 // 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 |
98 // we release all the pressed keys at blurring/disconnection time. | 97 // we release all the pressed keys at blurring/disconnection time. |
99 if (event.has_pressed()) { | 98 if (event.has_pressed()) { |
100 if (event.has_usb_keycode()) { | 99 if (event.has_usb_keycode()) { |
101 if (event.pressed()) { | 100 if (event.pressed()) { |
102 pressed_keys_.insert(event.usb_keycode()); | 101 pressed_keys_.insert(static_cast<ui::DomCode>(event.usb_keycode())); |
103 } else { | 102 } else { |
104 pressed_keys_.erase(event.usb_keycode()); | 103 pressed_keys_.erase(static_cast<ui::DomCode>(event.usb_keycode())); |
105 } | 104 } |
106 } | 105 } |
107 } | 106 } |
108 input_stub_->InjectKeyEvent(event); | 107 input_stub_->InjectKeyEvent(event); |
109 } | 108 } |
110 | 109 |
111 void InputEventTracker::InjectTextEvent(const TextEvent& event) { | 110 void InputEventTracker::InjectTextEvent(const TextEvent& event) { |
112 input_stub_->InjectTextEvent(event); | 111 input_stub_->InjectTextEvent(event); |
113 } | 112 } |
114 | 113 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 } | 150 } |
152 break; | 151 break; |
153 default: | 152 default: |
154 break; | 153 break; |
155 } | 154 } |
156 input_stub_->InjectTouchEvent(event); | 155 input_stub_->InjectTouchEvent(event); |
157 } | 156 } |
158 | 157 |
159 } // namespace protocol | 158 } // namespace protocol |
160 } // namespace remoting | 159 } // namespace remoting |
OLD | NEW |