Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: remoting/client/plugin/touch_input_scaler.cc

Issue 799233004: Add touch events to the protocol, the stub layer, and to the client plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed TouchInputFilter to TouchInputScaler and moved to client/plugin Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/client/plugin/touch_input_scaler.h"
6
7 #include "base/logging.h"
8 #include "remoting/proto/event.pb.h"
9
10 namespace remoting {
11
12 using protocol::TouchEvent;
13 using protocol::TouchEventPoint;
14
15 namespace {
16
17 // |value| is the number to be scaled and clamped. |output_max| is the output
18 // desktop's max height or width. |input_max| is the input desktop's max height
19 // or width.
20 float ScaleAndClamp(float value, int output_max, int input_max) {
21 value *= output_max;
22 value /= input_max;
Sergey Ulanov 2015/01/29 18:00:46 handle the case when input_max == 0.
Rintaro Kuroiwa 2015/01/30 17:57:01 is_empty() check as line 36 should handle that. I'
23 return std::max(0.0f, std::min(static_cast<float>(output_max), value));
24 }
25
26 } // namespace
27
28 TouchInputScaler::TouchInputScaler(InputStub* input_stub)
29 : InputFilter(input_stub) {
30 }
31
32 TouchInputScaler::~TouchInputScaler() {
33 }
34
35 void TouchInputScaler::InjectTouchEvent(const TouchEvent& event) {
36 if (input_size_.is_empty() || output_size_.is_empty())
37 return;
38
39 // We scale based on the maximum input & output coordinates, rather than the
40 // input and output sizes, so that it's possible to reach the edge of the
41 // output when up-scaling. We also take care to round up or down correctly,
42 // which is important when down-scaling.
43 TouchEvent out_event(event);
44 for (int i = 0; i < out_event.touch_points().size(); ++i) {
45 TouchEventPoint* point = out_event.mutable_touch_points(i);
46 if (point->has_x() || point->has_y()) {
47 DCHECK(point->has_x() && point->has_y());
48 point->set_x(
49 ScaleAndClamp(point->x(), output_size_.width(), input_size_.width()));
50 point->set_y(ScaleAndClamp(point->y(),
51 output_size_.height(),
52 input_size_.height()));
53 }
54 }
55
56 InputFilter::InjectTouchEvent(out_event);
57 }
58
59 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698