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

Side by Side Diff: remoting/client/ui/gesture_interpreter.cc

Issue 2879743002: [CRD iOS] Hook the touch input feedback (Closed)
Patch Set: Fix dependency and race condition Created 3 years, 7 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
« no previous file with comments | « remoting/client/ui/gesture_interpreter.h ('k') | remoting/client/ui/input_strategy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/client/ui/gesture_interpreter.h" 5 #include "remoting/client/ui/gesture_interpreter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "remoting/client/chromoting_session.h"
9 #include "remoting/client/ui/direct_input_strategy.h" 10 #include "remoting/client/ui/direct_input_strategy.h"
11 #include "remoting/client/ui/renderer_proxy.h"
10 12
11 namespace { 13 namespace {
12 14
13 const float kOneFingerFlingTimeConstant = 325.f; 15 const float kOneFingerFlingTimeConstant = 325.f;
14 16
15 } // namespace 17 } // namespace
16 18
17 namespace remoting { 19 namespace remoting {
18 GestureInterpreter::GestureInterpreter( 20 GestureInterpreter::GestureInterpreter(RendererProxy* renderer,
19 const DesktopViewport::TransformationCallback& on_transformation_changed, 21 ChromotingSession* input_stub)
20 ChromotingSession* input_stub) 22 : renderer_(renderer),
21 : input_stub_(input_stub), 23 input_stub_(input_stub),
22 pan_animation_(kOneFingerFlingTimeConstant, 24 pan_animation_(kOneFingerFlingTimeConstant,
23 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, 25 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations,
24 base::Unretained(this))) { 26 base::Unretained(this))) {
25 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, 27 viewport_.RegisterOnTransformationChangedCallback(
26 true); 28 base::Bind(&RendererProxy::SetTransformation,
29 base::Unretained(renderer_)),
30 true);
27 31
28 // TODO(yuweih): This should be configurable. 32 // TODO(yuweih): This should be configurable.
29 input_strategy_.reset(new DirectInputStrategy()); 33 input_strategy_.reset(new DirectInputStrategy());
34 renderer_->SetCursorVisibility(input_strategy_->IsCursorVisible());
35 SetCursorPositionOnRenderer();
30 } 36 }
31 37
32 GestureInterpreter::~GestureInterpreter() {} 38 GestureInterpreter::~GestureInterpreter() {}
33 39
34 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { 40 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) {
35 AbortAnimations(); 41 AbortAnimations();
36 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); 42 input_strategy_->HandlePinch({pivot_x, pivot_y}, scale, &viewport_);
37 } 43 }
38 44
39 void GestureInterpreter::Pan(float translation_x, float translation_y) { 45 void GestureInterpreter::Pan(float translation_x, float translation_y) {
40 AbortAnimations(); 46 AbortAnimations();
41 PanWithoutAbortAnimations(translation_x, translation_y); 47 PanWithoutAbortAnimations(translation_x, translation_y);
42 } 48 }
43 49
44 void GestureInterpreter::Tap(float x, float y) { 50 void GestureInterpreter::Tap(float x, float y) {
45 AbortAnimations(); 51 AbortAnimations();
46 float cursor_x, cursor_y; 52
47 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); 53 ViewMatrix::Point cursor_position = TrackAndGetPosition(x, y);
48 InjectMouseClick(cursor_x, cursor_y, 54 StartInputFeedback(cursor_position.x, cursor_position.y,
55 InputStrategy::TAP_FEEDBACK);
56 InjectMouseClick(cursor_position.x, cursor_position.y,
49 protocol::MouseEvent_MouseButton_BUTTON_LEFT); 57 protocol::MouseEvent_MouseButton_BUTTON_LEFT);
50 } 58 }
51 59
52 void GestureInterpreter::TwoFingerTap(float x, float y) { 60 void GestureInterpreter::TwoFingerTap(float x, float y) {
53 AbortAnimations(); 61 AbortAnimations();
54 float cursor_x, cursor_y; 62
55 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); 63 ViewMatrix::Point cursor_position = TrackAndGetPosition(x, y);
56 InjectMouseClick(cursor_x, cursor_y, 64 InjectMouseClick(cursor_position.x, cursor_position.y,
57 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); 65 protocol::MouseEvent_MouseButton_BUTTON_RIGHT);
58 } 66 }
59 67
60 void GestureInterpreter::LongPress(float x, float y, GestureState state) { 68 void GestureInterpreter::LongPress(float x, float y, GestureState state) {
61 AbortAnimations(); 69 AbortAnimations();
62 float cursor_x, cursor_y; 70
63 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); 71 ViewMatrix::Point cursor_position = TrackAndGetPosition(x, y);
72
73 if (state == GESTURE_BEGAN) {
74 StartInputFeedback(cursor_position.x, cursor_position.y,
75 InputStrategy::LONG_PRESS_FEEDBACK);
76 }
64 77
65 is_dragging_mode_ = state != GESTURE_ENDED; 78 is_dragging_mode_ = state != GESTURE_ENDED;
66 input_stub_->SendMouseEvent(cursor_x, cursor_y, 79 input_stub_->SendMouseEvent(cursor_position.x, cursor_position.y,
67 protocol::MouseEvent_MouseButton_BUTTON_LEFT, 80 protocol::MouseEvent_MouseButton_BUTTON_LEFT,
68 is_dragging_mode_); 81 is_dragging_mode_);
69 } 82 }
70 83
71 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { 84 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) {
72 AbortAnimations(); 85 AbortAnimations();
73 pan_animation_.SetVelocity(velocity_x, velocity_y); 86 pan_animation_.SetVelocity(velocity_x, velocity_y);
74 pan_animation_.Tick(); 87 pan_animation_.Tick();
75 } 88 }
76 89
77 void GestureInterpreter::ProcessAnimations() { 90 void GestureInterpreter::ProcessAnimations() {
78 if (pan_animation_.IsAnimationInProgress()) { 91 if (pan_animation_.IsAnimationInProgress()) {
79 pan_animation_.Tick(); 92 pan_animation_.Tick();
80 } 93 }
81 } 94 }
82 95
83 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { 96 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) {
84 viewport_.SetSurfaceSize(width, height); 97 viewport_.SetSurfaceSize(width, height);
85 } 98 }
86 99
87 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { 100 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) {
88 viewport_.SetDesktopSize(width, height); 101 viewport_.SetDesktopSize(width, height);
89 } 102 }
90 103
91 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, 104 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x,
92 float translation_y) { 105 float translation_y) {
93 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, 106 input_strategy_->HandlePan({translation_x, translation_y}, is_dragging_mode_,
94 &viewport_); 107 &viewport_);
108 SetCursorPositionOnRenderer();
95 } 109 }
96 110
97 void GestureInterpreter::AbortAnimations() { 111 void GestureInterpreter::AbortAnimations() {
98 pan_animation_.Abort(); 112 pan_animation_.Abort();
99 } 113 }
100 114
101 void GestureInterpreter::InjectMouseClick( 115 void GestureInterpreter::InjectMouseClick(
102 float x, 116 float x,
103 float y, 117 float y,
104 protocol::MouseEvent_MouseButton button) { 118 protocol::MouseEvent_MouseButton button) {
105 input_stub_->SendMouseEvent(x, y, button, true); 119 input_stub_->SendMouseEvent(x, y, button, true);
106 input_stub_->SendMouseEvent(x, y, button, false); 120 input_stub_->SendMouseEvent(x, y, button, false);
107 } 121 }
108 122
123 ViewMatrix::Point GestureInterpreter::TrackAndGetPosition(float touch_x,
124 float touch_y) {
125 input_strategy_->TrackTouchInput({touch_x, touch_y}, viewport_);
126 return input_strategy_->GetCursorPosition();
127 }
128
129 void GestureInterpreter::SetCursorPositionOnRenderer() {
130 if (input_strategy_->IsCursorVisible()) {
131 ViewMatrix::Point cursor_position = input_strategy_->GetCursorPosition();
132 renderer_->SetCursorPosition(cursor_position.x, cursor_position.y);
133 }
134 }
135
136 void GestureInterpreter::StartInputFeedback(
137 float cursor_x,
138 float cursor_y,
139 InputStrategy::InputFeedbackType feedback_type) {
140 // This radius is on the view's coordinates. Need to be converted to desktop
141 // coordinate.
142 float feedback_radius = input_strategy_->GetFeedbackRadius(feedback_type);
143 if (feedback_radius > 0) {
144 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving
145 // the *2 logic inside the renderer.
146 float diameter_on_desktop =
147 2.f * feedback_radius / viewport_.GetTransformation().GetScale();
148 renderer_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop);
149 }
150 }
151
109 } // namespace remoting 152 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/ui/gesture_interpreter.h ('k') | remoting/client/ui/input_strategy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698