OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/mouse_input_filter.h" |
| 6 |
| 7 #include "remoting/proto/event.pb.h" |
| 8 |
| 9 namespace remoting { |
| 10 |
| 11 MouseInputFilter::MouseInputFilter(protocol::InputStub* input_stub) |
| 12 : input_stub_(input_stub) { |
| 13 input_size_.setEmpty(); |
| 14 output_size_.setEmpty(); |
| 15 } |
| 16 |
| 17 MouseInputFilter::~MouseInputFilter() { |
| 18 } |
| 19 |
| 20 void MouseInputFilter::InjectKeyEvent(const protocol::KeyEvent& event) { |
| 21 input_stub_->InjectKeyEvent(event); |
| 22 } |
| 23 |
| 24 void MouseInputFilter::InjectMouseEvent(const protocol::MouseEvent& event) { |
| 25 if (input_size_.isZero() || output_size_.isZero()) |
| 26 return; |
| 27 |
| 28 protocol::MouseEvent out_event(event); |
| 29 if (out_event.has_x()) { |
| 30 int x = (out_event.x() * output_size_.width()) / input_size_.width(); |
| 31 out_event.set_x(std::max(0, std::min(output_size_.width() - 1, x))); |
| 32 } |
| 33 if (out_event.has_y()) { |
| 34 int y = (out_event.y() * output_size_.height()) / input_size_.height(); |
| 35 out_event.set_y(std::max(0, std::min(output_size_.height() - 1, y))); |
| 36 } |
| 37 |
| 38 input_stub_->InjectMouseEvent(out_event); |
| 39 } |
| 40 |
| 41 void MouseInputFilter::set_input_size(const SkISize& size) { |
| 42 input_size_ = size; |
| 43 } |
| 44 |
| 45 void MouseInputFilter::set_output_size(const SkISize& size) { |
| 46 output_size_ = size; |
| 47 } |
| 48 |
| 49 } // namespace remoting |
OLD | NEW |