| OLD | NEW |
| 1 // Copyright (c) 2011 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/client/mouse_input_filter.h" | 5 #include "remoting/protocol/mouse_input_filter.h" |
| 6 | 6 |
| 7 #include "remoting/proto/event.pb.h" | 7 #include "remoting/proto/event.pb.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 namespace protocol { |
| 10 | 11 |
| 11 MouseInputFilter::MouseInputFilter(protocol::InputStub* input_stub) | 12 MouseInputFilter::MouseInputFilter(InputStub* input_stub) |
| 12 : input_stub_(input_stub) { | 13 : InputFilter(input_stub) { |
| 13 input_max_.setEmpty(); | 14 input_max_.setEmpty(); |
| 14 output_max_.setEmpty(); | 15 output_max_.setEmpty(); |
| 15 } | 16 } |
| 16 | 17 |
| 17 MouseInputFilter::~MouseInputFilter() { | 18 MouseInputFilter::~MouseInputFilter() { |
| 18 } | 19 } |
| 19 | 20 |
| 20 void MouseInputFilter::InjectKeyEvent(const protocol::KeyEvent& event) { | 21 void MouseInputFilter::InjectMouseEvent(const MouseEvent& event) { |
| 21 input_stub_->InjectKeyEvent(event); | |
| 22 } | |
| 23 | |
| 24 void MouseInputFilter::InjectMouseEvent(const protocol::MouseEvent& event) { | |
| 25 if (input_max_.isEmpty() || output_max_.isEmpty()) | 22 if (input_max_.isEmpty() || output_max_.isEmpty()) |
| 26 return; | 23 return; |
| 27 | 24 |
| 28 // We scale based on the maximum input & output coordinates, rather than the | 25 // We scale based on the maximum input & output coordinates, rather than the |
| 29 // input and output sizes, so that it's possible to reach the edge of the | 26 // input and output sizes, so that it's possible to reach the edge of the |
| 30 // output when up-scaling. We also take care to round up or down correctly, | 27 // output when up-scaling. We also take care to round up or down correctly, |
| 31 // which is important when down-scaling. | 28 // which is important when down-scaling. |
| 32 protocol::MouseEvent out_event(event); | 29 MouseEvent out_event(event); |
| 33 if (out_event.has_x()) { | 30 if (out_event.has_x()) { |
| 34 int x = out_event.x() * output_max_.width(); | 31 int x = out_event.x() * output_max_.width(); |
| 35 x = (x + input_max_.width() / 2) / input_max_.width(); | 32 x = (x + input_max_.width() / 2) / input_max_.width(); |
| 36 out_event.set_x(std::max(0, std::min(output_max_.width(), x))); | 33 out_event.set_x(std::max(0, std::min(output_max_.width(), x))); |
| 37 } | 34 } |
| 38 if (out_event.has_y()) { | 35 if (out_event.has_y()) { |
| 39 int y = out_event.y() * output_max_.height(); | 36 int y = out_event.y() * output_max_.height(); |
| 40 y = (y + input_max_.height() / 2) / input_max_.height(); | 37 y = (y + input_max_.height() / 2) / input_max_.height(); |
| 41 out_event.set_y(std::max(0, std::min(output_max_.height(), y))); | 38 out_event.set_y(std::max(0, std::min(output_max_.height(), y))); |
| 42 } | 39 } |
| 43 | 40 |
| 44 input_stub_->InjectMouseEvent(out_event); | 41 InputFilter::InjectMouseEvent(out_event); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void MouseInputFilter::set_input_size(const SkISize& size) { | 44 void MouseInputFilter::set_input_size(const SkISize& size) { |
| 48 input_max_ = SkISize::Make(size.width() - 1, size.height() - 1); | 45 input_max_ = SkISize::Make(size.width() - 1, size.height() - 1); |
| 49 } | 46 } |
| 50 | 47 |
| 51 void MouseInputFilter::set_output_size(const SkISize& size) { | 48 void MouseInputFilter::set_output_size(const SkISize& size) { |
| 52 output_max_ = SkISize::Make(size.width() - 1, size.height() - 1); | 49 output_max_ = SkISize::Make(size.width() - 1, size.height() - 1); |
| 53 } | 50 } |
| 54 | 51 |
| 52 } // namespace protocol |
| 55 } // namespace remoting | 53 } // namespace remoting |
| OLD | NEW |