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

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: changes from review 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 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. |output_max| is the output desktop's max
18 // height or width. |input_max| is the input desktop's max height or width.
19 float Scale(float value, int output_max, int input_max) {
20 DCHECK_GT(output_max, 0);
21 DCHECK_GT(input_max, 0);
22 value *= output_max;
23 value /= input_max;
24 return value;
25 }
26
27 // Same as Scale() but |value| will be scaled and clamped using |output_max| and
28 // |input_max|.
29 float ScaleAndClamp(float value, int output_max, int input_max) {
30 value = Scale(value, output_max, input_max);
31 return std::max(0.0f, std::min(static_cast<float>(output_max), value));
32 }
33
34 } // namespace
35
36 TouchInputScaler::TouchInputScaler(InputStub* input_stub)
37 : InputFilter(input_stub) {}
38
39 TouchInputScaler::~TouchInputScaler() {}
40
41 void TouchInputScaler::InjectTouchEvent(const TouchEvent& event) {
42 if (input_size_.is_empty() || output_size_.is_empty())
43 return;
44
45 // We scale based on the maximum input & output coordinates, rather than the
46 // input and output sizes, so that it's possible to reach the edge of the
47 // output when up-scaling. We also take care to round up or down correctly,
48 // which is important when down-scaling.
49 TouchEvent out_event(event);
50 for (int i = 0; i < out_event.touch_points().size(); ++i) {
51 TouchEventPoint* point = out_event.mutable_touch_points(i);
52 if (point->has_x() || point->has_y()) {
53 DCHECK(point->has_x() && point->has_y());
54 point->set_x(
55 ScaleAndClamp(point->x(), output_size_.width(), input_size_.width()));
56 point->set_y(ScaleAndClamp(point->y(), output_size_.height(),
57 input_size_.height()));
58 }
59
60 // Also scale the touch size. When the output desktop and the input desktop
61 // sizes do not match, the touch size should be scaled for more predicatable
Wez 2015/02/23 23:24:07 typo: predictable. It's not clear what it means f
Rintaro Kuroiwa 2015/02/24 23:43:10 Changed description and an example where scaling i
62 // hit testing.
63 // TODO(rkuroiwa): Also clamp. Note that point->angle() affects the maximum
64 // size.
65 if (point->has_radius_x() || point->has_radius_y()) {
66 DCHECK(point->has_radius_x() && point->has_radius_y());
67 point->set_radius_x(
68 Scale(point->radius_x(), output_size_.width(), input_size_.width()));
69 point->set_radius_y(Scale(point->radius_y(), output_size_.height(),
70 input_size_.height()));
71 }
72 }
73
74 InputFilter::InjectTouchEvent(out_event);
75 }
76
77 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/plugin/touch_input_scaler.h ('k') | remoting/client/plugin/touch_input_scaler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698