Chromium Code Reviews| 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/host/client_session.h" | 5 #include "remoting/host/client_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "remoting/host/capturer.h" | 10 #include "remoting/host/capturer.h" |
| 11 #include "remoting/proto/event.pb.h" | 11 #include "remoting/proto/event.pb.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 | 14 |
| 15 ClientSession::ClientSession( | 15 ClientSession::ClientSession( |
| 16 EventHandler* event_handler, | 16 EventHandler* event_handler, |
| 17 scoped_ptr<protocol::ConnectionToClient> connection, | 17 scoped_ptr<protocol::ConnectionToClient> connection, |
| 18 protocol::HostEventStub* host_event_stub, | 18 protocol::HostEventStub* host_event_stub, |
| 19 Capturer* capturer) | 19 Capturer* capturer) |
| 20 : event_handler_(event_handler), | 20 : event_handler_(event_handler), |
| 21 connection_(connection.Pass()), | 21 connection_(connection.Pass()), |
| 22 client_jid_(connection_->session()->jid()), | 22 client_jid_(connection_->session()->jid()), |
| 23 host_event_stub_(host_event_stub), | 23 host_event_stub_(host_event_stub), |
| 24 input_tracker_(host_event_stub), | 24 input_tracker_(host_event_stub_), |
| 25 remote_input_filter_(&input_tracker_), | 25 remote_input_filter_(&input_tracker_), |
| 26 mouse_input_filter_(&remote_input_filter_), | |
| 26 capturer_(capturer) { | 27 capturer_(capturer) { |
| 27 connection_->SetEventHandler(this); | 28 connection_->SetEventHandler(this); |
| 28 | 29 |
| 29 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be | 30 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
| 30 // set before channels are connected. Make it possible to set stubs | 31 // set before channels are connected. Make it possible to set stubs |
| 31 // later and set them only when connection is authenticated. | 32 // later and set them only when connection is authenticated. |
| 32 connection_->set_clipboard_stub(this); | 33 connection_->set_clipboard_stub(this); |
| 33 connection_->set_host_stub(this); | 34 connection_->set_host_stub(this); |
| 34 connection_->set_input_stub(this); | 35 connection_->set_input_stub(this); |
| 35 } | 36 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 52 } | 53 } |
| 53 | 54 |
| 54 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { | 55 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { |
| 55 DCHECK(CalledOnValidThread()); | 56 DCHECK(CalledOnValidThread()); |
| 56 auth_input_filter_.InjectKeyEvent(event); | 57 auth_input_filter_.InjectKeyEvent(event); |
| 57 } | 58 } |
| 58 | 59 |
| 59 void ClientSession::InjectMouseEvent(const protocol::MouseEvent& event) { | 60 void ClientSession::InjectMouseEvent(const protocol::MouseEvent& event) { |
| 60 DCHECK(CalledOnValidThread()); | 61 DCHECK(CalledOnValidThread()); |
| 61 | 62 |
| 62 protocol::MouseEvent event_to_inject = event; | 63 // Ensure that the MouseInputFilter is clamping to the current dimensions. |
| 63 if (event.has_x() && event.has_y()) { | 64 mouse_input_filter_.set_output_size(capturer_->size_most_recent()); |
| 64 // In case the client sends events with off-screen coordinates, modify | 65 mouse_input_filter_.set_input_size(capturer_->size_most_recent()); |
|
Wez
2012/04/27 17:39:51
I'd like to get rid of the InputStub overrides on
| |
| 65 // the event to lie within the current screen area. This is better than | 66 |
| 66 // simply discarding the event, which might lose a button-up event at the | 67 auth_input_filter_.InjectMouseEvent(event); |
| 67 // end of a drag'n'drop (or cause other related problems). | |
| 68 SkIPoint pos(SkIPoint::Make(event.x(), event.y())); | |
| 69 const SkISize& screen = capturer_->size_most_recent(); | |
| 70 pos.setX(std::max(0, std::min(screen.width() - 1, pos.x()))); | |
| 71 pos.setY(std::max(0, std::min(screen.height() - 1, pos.y()))); | |
| 72 event_to_inject.set_x(pos.x()); | |
| 73 event_to_inject.set_y(pos.y()); | |
| 74 } | |
| 75 auth_input_filter_.InjectMouseEvent(event_to_inject); | |
| 76 } | 68 } |
| 77 | 69 |
| 78 void ClientSession::NotifyClientDimensions( | 70 void ClientSession::NotifyClientDimensions( |
| 79 const protocol::ClientDimensions& dimensions) { | 71 const protocol::ClientDimensions& dimensions) { |
| 80 // TODO(wez): Use the dimensions, e.g. to resize the host desktop to match. | 72 // TODO(wez): Use the dimensions, e.g. to resize the host desktop to match. |
| 81 } | 73 } |
| 82 | 74 |
| 83 void ClientSession::OnConnectionAuthenticated( | 75 void ClientSession::OnConnectionAuthenticated( |
| 84 protocol::ConnectionToClient* connection) { | 76 protocol::ConnectionToClient* connection) { |
| 85 DCHECK(CalledOnValidThread()); | 77 DCHECK(CalledOnValidThread()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 remote_input_filter_.LocalMouseMoved(mouse_pos); | 134 remote_input_filter_.LocalMouseMoved(mouse_pos); |
| 143 } | 135 } |
| 144 | 136 |
| 145 void ClientSession::SetDisableInputs(bool disable_inputs) { | 137 void ClientSession::SetDisableInputs(bool disable_inputs) { |
| 146 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
| 147 | 139 |
| 148 if (disable_inputs) { | 140 if (disable_inputs) { |
| 149 disable_input_filter_.set_input_stub(NULL); | 141 disable_input_filter_.set_input_stub(NULL); |
| 150 input_tracker_.ReleaseAll(); | 142 input_tracker_.ReleaseAll(); |
| 151 } else { | 143 } else { |
| 152 disable_input_filter_.set_input_stub(&remote_input_filter_); | 144 disable_input_filter_.set_input_stub(&mouse_input_filter_); |
| 153 } | 145 } |
| 154 } | 146 } |
| 155 | 147 |
| 156 } // namespace remoting | 148 } // namespace remoting |
| OLD | NEW |