Chromium Code Reviews| Index: remoting/protocol/touch_input_filter.cc |
| diff --git a/remoting/protocol/touch_input_filter.cc b/remoting/protocol/touch_input_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..39f9708788f4fedaadf10fd64dae20860a28e12c |
| --- /dev/null |
| +++ b/remoting/protocol/touch_input_filter.cc |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/protocol/touch_input_filter.h" |
| + |
| +#include "remoting/proto/event.pb.h" |
| + |
| +namespace remoting { |
| +namespace protocol { |
| + |
| +namespace { |
| +// |value| is the number to be scaled. |output_max| is the output desktop's max |
| +// height or width. |input_max| is the input desktop's max height or width. |
| +float ScaleAndClamp(float value, int output_max, int input_max) { |
| + float scale = static_cast<float>(output_max) / input_max; |
| + float new_value = value * scale; |
| + 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.
|
| +} |
| +} // namespace |
| + |
| +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
|
| +} |
| + |
| +TouchInputFilter::TouchInputFilter(InputStub* input_stub) |
| + : InputFilter(input_stub) { |
| +} |
| + |
| +TouchInputFilter::~TouchInputFilter() { |
| +} |
| + |
| +void TouchInputFilter::InjectTouchEvent(const TouchEvent& event) { |
| + if (input_max_.is_empty() || output_max_.is_empty()) |
| + return; |
| + |
| + // We scale based on the maximum input & output coordinates, rather than the |
| + // input and output sizes, so that it's possible to reach the edge of the |
| + // output when up-scaling. We also take care to round up or down correctly, |
| + // 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
|
| + TouchEvent out_event(event); |
| + for (int i = 0; i < out_event.touch_points().size(); ++i) { |
| + TouchEvent::Point* point = out_event.mutable_touch_points(i); |
| + 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
|
| + point->set_x( |
| + ScaleAndClamp(point->x(), output_max_.width(), input_max_.width())); |
| + } |
| + if (point->has_y()) { |
| + point->set_y( |
| + ScaleAndClamp(point->y(), output_max_.height(), input_max_.height())); |
| + } |
| + } |
| + |
| + InputFilter::InjectTouchEvent(out_event); |
| +} |
| + |
| +void TouchInputFilter::set_input_size(const webrtc::DesktopSize& size) { |
| + input_max_.set(size.width() - 1, size.height() - 1); |
| +} |
| + |
| +void TouchInputFilter::set_output_size(const webrtc::DesktopSize& size) { |
| + output_max_.set(size.width() - 1, size.height() - 1); |
| +} |
| + |
| +} // namespace protocol |
| +} // namespace remoting |