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 "base/stl_util.h" |
8 #include "remoting/proto/event.pb.h" | 9 #include "remoting/proto/event.pb.h" |
9 | 10 |
10 namespace remoting { | 11 namespace remoting { |
11 namespace protocol { | 12 namespace protocol { |
12 | 13 |
13 InputEventTracker::InputEventTracker(InputStub* input_stub) | 14 InputEventTracker::InputEventTracker(InputStub* input_stub) |
14 : input_stub_(input_stub), | 15 : input_stub_(input_stub), |
15 mouse_button_state_(0) { | 16 mouse_button_state_(0) { |
16 } | 17 } |
17 | 18 |
(...skipping 26 matching lines...) Expand all Loading... |
44 // using the current cursor position, and we wouldn't set position here. | 45 // using the current cursor position, and we wouldn't set position here. |
45 mouse.set_x(mouse_pos_.x()); | 46 mouse.set_x(mouse_pos_.x()); |
46 mouse.set_y(mouse_pos_.y()); | 47 mouse.set_y(mouse_pos_.y()); |
47 | 48 |
48 mouse.set_button((MouseEvent::MouseButton)i); | 49 mouse.set_button((MouseEvent::MouseButton)i); |
49 mouse.set_button_down(false); | 50 mouse.set_button_down(false); |
50 input_stub_->InjectMouseEvent(mouse); | 51 input_stub_->InjectMouseEvent(mouse); |
51 } | 52 } |
52 } | 53 } |
53 mouse_button_state_ = 0; | 54 mouse_button_state_ = 0; |
| 55 |
| 56 if (!touch_point_ids_.empty()) { |
| 57 TouchEvent cancel_all_touch_event; |
| 58 cancel_all_touch_event.set_event_type(TouchEvent::TOUCH_POINT_CANCEL); |
| 59 for (uint32 touch_point_id : touch_point_ids_) { |
| 60 TouchEventPoint* point = cancel_all_touch_event.add_touch_points(); |
| 61 point->set_id(touch_point_id); |
| 62 } |
| 63 input_stub_->InjectTouchEvent(cancel_all_touch_event); |
| 64 touch_point_ids_.clear(); |
| 65 } |
| 66 DCHECK(touch_point_ids_.empty()); |
54 } | 67 } |
55 | 68 |
56 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { | 69 void InputEventTracker::InjectKeyEvent(const KeyEvent& event) { |
57 // We don't need to track the keyboard lock states of key down events. | 70 // We don't need to track the keyboard lock states of key down events. |
58 // Pressed keys will be released with |lock_states| set to 0. | 71 // Pressed keys will be released with |lock_states| set to 0. |
59 // The lock states of auto generated key up events don't matter as long as | 72 // The lock states of auto generated key up events don't matter as long as |
60 // we release all the pressed keys at blurring/disconnection time. | 73 // we release all the pressed keys at blurring/disconnection time. |
61 if (event.has_pressed()) { | 74 if (event.has_pressed()) { |
62 if (event.has_usb_keycode()) { | 75 if (event.has_usb_keycode()) { |
63 if (event.pressed()) { | 76 if (event.pressed()) { |
(...skipping 21 matching lines...) Expand all Loading... |
85 if (event.button_down()) { | 98 if (event.button_down()) { |
86 mouse_button_state_ |= button_change; | 99 mouse_button_state_ |= button_change; |
87 } else { | 100 } else { |
88 mouse_button_state_ &= ~button_change; | 101 mouse_button_state_ &= ~button_change; |
89 } | 102 } |
90 } | 103 } |
91 } | 104 } |
92 input_stub_->InjectMouseEvent(event); | 105 input_stub_->InjectMouseEvent(event); |
93 } | 106 } |
94 | 107 |
| 108 void InputEventTracker::InjectTouchEvent(const TouchEvent& event) { |
| 109 switch (event.event_type()) { |
| 110 case TouchEvent::TOUCH_POINT_START: |
| 111 for (const TouchEventPoint& touch_point : event.touch_points()) { |
| 112 DCHECK(touch_point_ids_.find(touch_point.id()) == |
| 113 touch_point_ids_.end()); |
| 114 touch_point_ids_.insert(touch_point.id()); |
| 115 } |
| 116 break; |
| 117 case TouchEvent::TOUCH_POINT_END: |
| 118 case TouchEvent::TOUCH_POINT_CANCEL: |
| 119 for (const TouchEventPoint& touch_point : event.touch_points()) { |
| 120 DCHECK(touch_point_ids_.find(touch_point.id()) != |
| 121 touch_point_ids_.end()); |
| 122 touch_point_ids_.erase(touch_point.id()); |
| 123 } |
| 124 break; |
| 125 default: |
| 126 break; |
| 127 } |
| 128 input_stub_->InjectTouchEvent(event); |
| 129 } |
| 130 |
95 } // namespace protocol | 131 } // namespace protocol |
96 } // namespace remoting | 132 } // namespace remoting |
OLD | NEW |