blob: 8f0f5c24acaf700c048ec43c4982e5eeeee8486d [file] [log] [blame]
yuweihe1bd6ca2017-05-19 01:22:451// Copyright 2017 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
nicholss7666a282017-05-24 15:48:025#include "remoting/client/input/trackpad_input_strategy.h"
yuweihe1bd6ca2017-05-19 01:22:456
7#include "remoting/client/ui/desktop_viewport.h"
8
9namespace remoting {
10
11namespace {
12
13// Trackpad mode does not need tap feedback.
14const float kTapFeedbackRadius = 0.f;
15
16const float kDragFeedbackRadius = 8.f;
17
18} // namespace
19
20TrackpadInputStrategy::TrackpadInputStrategy(const DesktopViewport& viewport)
21 : cursor_position_(viewport.GetViewportCenter()) {}
22
23TrackpadInputStrategy::~TrackpadInputStrategy() {}
24
25void TrackpadInputStrategy::HandleZoom(const ViewMatrix::Point& pivot,
26 float scale,
27 DesktopViewport* viewport) {
28 // The cursor position is the pivot point.
29 ViewMatrix::Point cursor_pivot =
30 viewport->GetTransformation().MapPoint(cursor_position_);
31 viewport->ScaleDesktop(cursor_pivot.x, cursor_pivot.y, scale);
32
33 // Keep the cursor on focus.
34 viewport->SetViewportCenter(cursor_position_.x, cursor_position_.y);
35}
36
37bool TrackpadInputStrategy::HandlePan(const ViewMatrix::Vector2D& translation,
38 Gesture simultaneous_gesture,
39 DesktopViewport* viewport) {
40 if (simultaneous_gesture == ZOOM) {
41 // Don't move the cursor if the user is scaling the viewport.
42 return false;
43 }
44 ViewMatrix::Vector2D translation_on_desktop =
45 viewport->GetTransformation().Invert().MapVector(translation);
46
47 cursor_position_.x += translation_on_desktop.x;
48 cursor_position_.y += translation_on_desktop.y;
49
50 cursor_position_ = viewport->ConstrainPointToDesktop(cursor_position_);
51
52 // Keep the cursor on focus.
53 viewport->SetViewportCenter(cursor_position_.x, cursor_position_.y);
54 return true;
55}
56
yuweihb932f1d2017-05-23 21:18:5257bool TrackpadInputStrategy::TrackTouchInput(
yuweihe1bd6ca2017-05-19 01:22:4558 const ViewMatrix::Point& touch_point,
59 const DesktopViewport& viewport) {
60 // Do nothing. The cursor position is independent of the touch position.
yuweihb932f1d2017-05-23 21:18:5261 // |touch_point| is always valid.
62 return true;
yuweihe1bd6ca2017-05-19 01:22:4563}
64
65ViewMatrix::Point TrackpadInputStrategy::GetCursorPosition() const {
66 return cursor_position_;
67}
68
Yuwei Huangdd311f72017-08-21 18:55:1669void TrackpadInputStrategy::FocusViewportOnCursor(
70 DesktopViewport* viewport) const {
71 viewport->SetViewportCenter(cursor_position_.x, cursor_position_.y);
72}
73
yuweihe1bd6ca2017-05-19 01:22:4574ViewMatrix::Vector2D TrackpadInputStrategy::MapScreenVectorToDesktop(
75 const ViewMatrix::Vector2D& delta,
76 const DesktopViewport& viewport) const {
77 // No conversion is needed for trackpad mode.
78 return delta;
79}
80
nicholssdf09b282017-05-26 20:08:1481float TrackpadInputStrategy::GetFeedbackRadius(TouchFeedbackType type) const {
yuweihe1bd6ca2017-05-19 01:22:4582 switch (type) {
nicholssdf09b282017-05-26 20:08:1483 case TouchFeedbackType::TAP_FEEDBACK:
yuweihe1bd6ca2017-05-19 01:22:4584 return kTapFeedbackRadius;
nicholssdf09b282017-05-26 20:08:1485 case TouchFeedbackType::DRAG_FEEDBACK:
yuweihe1bd6ca2017-05-19 01:22:4586 return kDragFeedbackRadius;
87 }
88 NOTREACHED();
89 return 0.f;
90}
91
92bool TrackpadInputStrategy::IsCursorVisible() const {
93 return true;
94}
nicholss7666a282017-05-24 15:48:0295
yuweihe1bd6ca2017-05-19 01:22:4596} // namespace remoting