OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "remoting/host/capturer.h" | 10 #include "remoting/host/capturer.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 void ClientSession::InjectMouseEvent(const MouseEvent& event) { | 88 void ClientSession::InjectMouseEvent(const MouseEvent& event) { |
89 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { | 89 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { |
90 RecordMouseButtonState(event); | 90 RecordMouseButtonState(event); |
91 MouseEvent event_to_inject = event; | 91 MouseEvent event_to_inject = event; |
92 if (event.has_x() && event.has_y()) { | 92 if (event.has_x() && event.has_y()) { |
93 // In case the client sends events with off-screen coordinates, modify | 93 // In case the client sends events with off-screen coordinates, modify |
94 // the event to lie within the current screen area. This is better than | 94 // the event to lie within the current screen area. This is better than |
95 // simply discarding the event, which might lose a button-up event at the | 95 // simply discarding the event, which might lose a button-up event at the |
96 // end of a drag'n'drop (or cause other related problems). | 96 // end of a drag'n'drop (or cause other related problems). |
97 gfx::Point pos(event.x(), event.y()); | 97 SkIPoint pos(SkIPoint::Make(event.x(), event.y())); |
98 const gfx::Size& screen = capturer_->size_most_recent(); | 98 const SkISize& screen = capturer_->size_most_recent(); |
99 pos.set_x(std::max(0, std::min(screen.width() - 1, pos.x()))); | 99 pos.setX(std::max(0, std::min(screen.width() - 1, pos.x()))); |
100 pos.set_y(std::max(0, std::min(screen.height() - 1, pos.y()))); | 100 pos.setY(std::max(0, std::min(screen.height() - 1, pos.y()))); |
101 event_to_inject.set_x(pos.x()); | 101 event_to_inject.set_x(pos.x()); |
102 event_to_inject.set_y(pos.y()); | 102 event_to_inject.set_y(pos.y()); |
103 | 103 |
104 // Record the mouse position so we can use it if we need to inject | 104 // Record the mouse position so we can use it if we need to inject |
105 // fake mouse button events. Note that we need to do this after we | 105 // fake mouse button events. Note that we need to do this after we |
106 // clamp the values to the screen area. | 106 // clamp the values to the screen area. |
107 remote_mouse_pos_ = pos; | 107 remote_mouse_pos_ = pos; |
108 | 108 |
109 injected_mouse_positions_.push_back(pos); | 109 injected_mouse_positions_.push_back(pos); |
110 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { | 110 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { |
111 VLOG(1) << "Injected mouse positions queue full."; | 111 VLOG(1) << "Injected mouse positions queue full."; |
112 injected_mouse_positions_.pop_front(); | 112 injected_mouse_positions_.pop_front(); |
113 } | 113 } |
114 } | 114 } |
115 input_stub_->InjectMouseEvent(event_to_inject); | 115 input_stub_->InjectMouseEvent(event_to_inject); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 void ClientSession::OnDisconnected() { | 119 void ClientSession::OnDisconnected() { |
120 RestoreEventState(); | 120 RestoreEventState(); |
121 authenticated_ = false; | 121 authenticated_ = false; |
122 } | 122 } |
123 | 123 |
124 void ClientSession::LocalMouseMoved(const gfx::Point& mouse_pos) { | 124 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
125 // If this is a genuine local input event (rather than an echo of a remote | 125 // If this is a genuine local input event (rather than an echo of a remote |
126 // input event that we've just injected), then ignore remote inputs for a | 126 // input event that we've just injected), then ignore remote inputs for a |
127 // short time. | 127 // short time. |
128 std::list<gfx::Point>::iterator found_position = | 128 std::list<SkIPoint>::iterator found_position = |
129 std::find(injected_mouse_positions_.begin(), | 129 std::find(injected_mouse_positions_.begin(), |
130 injected_mouse_positions_.end(), mouse_pos); | 130 injected_mouse_positions_.end(), mouse_pos); |
131 if (found_position != injected_mouse_positions_.end()) { | 131 if (found_position != injected_mouse_positions_.end()) { |
132 // Remove it from the list, and any positions that were added before it, | 132 // Remove it from the list, and any positions that were added before it, |
133 // if any. This is because the local input monitor is assumed to receive | 133 // if any. This is because the local input monitor is assumed to receive |
134 // injected mouse position events in the order in which they were injected | 134 // injected mouse position events in the order in which they were injected |
135 // (if at all). If the position is found somewhere other than the front of | 135 // (if at all). If the position is found somewhere other than the front of |
136 // the queue, this would be because the earlier positions weren't | 136 // the queue, this would be because the earlier positions weren't |
137 // successfully injected (or the local input monitor might have skipped over | 137 // successfully injected (or the local input monitor might have skipped over |
138 // some positions), and not because the events were out-of-sequence. These | 138 // some positions), and not because the events were out-of-sequence. These |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 mouse.set_y(remote_mouse_pos_.y()); | 216 mouse.set_y(remote_mouse_pos_.y()); |
217 mouse.set_button((MouseEvent::MouseButton)i); | 217 mouse.set_button((MouseEvent::MouseButton)i); |
218 mouse.set_button_down(false); | 218 mouse.set_button_down(false); |
219 input_stub_->InjectMouseEvent(mouse); | 219 input_stub_->InjectMouseEvent(mouse); |
220 } | 220 } |
221 } | 221 } |
222 remote_mouse_button_state_ = 0; | 222 remote_mouse_button_state_ = 0; |
223 } | 223 } |
224 | 224 |
225 } // namespace remoting | 225 } // namespace remoting |
OLD | NEW |