Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 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/protocol/touch_input_filter.h" | |
| 6 | |
| 7 #include "remoting/proto/event.pb.h" | |
| 8 | |
| 9 namespace remoting { | |
| 10 namespace protocol { | |
| 11 | |
| 12 namespace { | |
| 13 // |value| is the number to be scaled. |output_max| is the output desktop's max | |
| 14 // height or width. |input_max| is the input desktop's max height or width. | |
| 15 float ScaleAndClamp(float value, int output_max, int input_max) { | |
| 16 float scale = static_cast<float>(output_max) / input_max; | |
| 17 float new_value = value * scale; | |
| 18 return std::max(0.0f, std::min(static_cast<float>(output_max), new_value)); | |
|
Wez
2015/01/21 03:08:38
This seems a convoluted way to get the effect you
Rintaro Kuroiwa
2015/01/28 01:12:30
Done.
| |
| 19 } | |
| 20 } // namespace | |
| 21 | |
| 22 TouchInputFilter::TouchInputFilter() { | |
|
Wez
2015/01/21 03:08:37
You can use c++11 default constructor here (i.e. =
Rintaro Kuroiwa
2015/01/28 01:12:30
wow, C++11 :)
Done
| |
| 23 } | |
| 24 | |
| 25 TouchInputFilter::TouchInputFilter(InputStub* input_stub) | |
| 26 : InputFilter(input_stub) { | |
| 27 } | |
| 28 | |
| 29 TouchInputFilter::~TouchInputFilter() { | |
| 30 } | |
| 31 | |
| 32 void TouchInputFilter::InjectTouchEvent(const TouchEvent& event) { | |
| 33 if (input_max_.is_empty() || output_max_.is_empty()) | |
| 34 return; | |
| 35 | |
| 36 // We scale based on the maximum input & output coordinates, rather than the | |
| 37 // input and output sizes, so that it's possible to reach the edge of the | |
| 38 // output when up-scaling. We also take care to round up or down correctly, | |
| 39 // which is important when down-scaling. | |
|
Wez
2015/01/21 03:08:38
Thinking Out Loud: It does seem a shame to be cons
Rintaro Kuroiwa
2015/01/28 01:12:30
Since I'm implementing the client side atm, WDYT a
| |
| 40 TouchEvent out_event(event); | |
| 41 for (int i = 0; i < out_event.touch_points().size(); ++i) { | |
| 42 TouchEvent::Point* point = out_event.mutable_touch_points(i); | |
| 43 if (point->has_x()) { | |
|
Wez
2015/01/21 03:08:38
Is it possible for events to have an X coordinate
Rintaro Kuroiwa
2015/01/28 01:12:30
No, there is X iff Y. Making this || and DCHECKing
| |
| 44 point->set_x( | |
| 45 ScaleAndClamp(point->x(), output_max_.width(), input_max_.width())); | |
| 46 } | |
| 47 if (point->has_y()) { | |
| 48 point->set_y( | |
| 49 ScaleAndClamp(point->y(), output_max_.height(), input_max_.height())); | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 InputFilter::InjectTouchEvent(out_event); | |
| 54 } | |
| 55 | |
| 56 void TouchInputFilter::set_input_size(const webrtc::DesktopSize& size) { | |
| 57 input_max_.set(size.width() - 1, size.height() - 1); | |
| 58 } | |
| 59 | |
| 60 void TouchInputFilter::set_output_size(const webrtc::DesktopSize& size) { | |
| 61 output_max_.set(size.width() - 1, size.height() - 1); | |
| 62 } | |
| 63 | |
| 64 } // namespace protocol | |
| 65 } // namespace remoting | |
| OLD | NEW |