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

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

Issue 2882653004: [CRD iOS] Injecting scroll events w/ fling animation (Closed)
Patch Set: Rebase 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/chromoting_session.h"
10 #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" 11 #include "remoting/client/ui/renderer_proxy.h"
12 12
13 namespace { 13 namespace {
14 14
15 const float kOneFingerFlingTimeConstant = 325.f; 15 const float kOneFingerFlingTimeConstant = 325.f;
16 const float kScrollFlingTimeConstant = 120.f;
16 17
17 } // namespace 18 } // namespace
18 19
19 namespace remoting { 20 namespace remoting {
20 GestureInterpreter::GestureInterpreter(RendererProxy* renderer, 21 GestureInterpreter::GestureInterpreter(RendererProxy* renderer,
21 ChromotingSession* input_stub) 22 ChromotingSession* input_stub)
22 : renderer_(renderer), 23 : renderer_(renderer),
23 input_stub_(input_stub), 24 input_stub_(input_stub),
24 pan_animation_(kOneFingerFlingTimeConstant, 25 pan_animation_(kOneFingerFlingTimeConstant,
25 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, 26 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations,
26 base::Unretained(this))) { 27 base::Unretained(this))),
28 scroll_animation_(
29 kScrollFlingTimeConstant,
30 base::Bind(&GestureInterpreter::ScrollWithoutAbortAnimations,
31 base::Unretained(this))) {
27 viewport_.RegisterOnTransformationChangedCallback( 32 viewport_.RegisterOnTransformationChangedCallback(
28 base::Bind(&RendererProxy::SetTransformation, 33 base::Bind(&RendererProxy::SetTransformation,
29 base::Unretained(renderer_)), 34 base::Unretained(renderer_)),
30 true); 35 true);
31 36
32 // TODO(yuweih): This should be configurable. 37 // TODO(yuweih): This should be configurable.
33 input_strategy_.reset(new DirectInputStrategy()); 38 input_strategy_.reset(new DirectInputStrategy());
34 renderer_->SetCursorVisibility(input_strategy_->IsCursorVisible()); 39 renderer_->SetCursorVisibility(input_strategy_->IsCursorVisible());
35 SetCursorPositionOnRenderer(); 40 SetCursorPositionOnRenderer();
36 } 41 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 protocol::MouseEvent_MouseButton_BUTTON_LEFT, 85 protocol::MouseEvent_MouseButton_BUTTON_LEFT,
81 is_dragging_mode_); 86 is_dragging_mode_);
82 } 87 }
83 88
84 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { 89 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) {
85 AbortAnimations(); 90 AbortAnimations();
86 pan_animation_.SetVelocity(velocity_x, velocity_y); 91 pan_animation_.SetVelocity(velocity_x, velocity_y);
87 pan_animation_.Tick(); 92 pan_animation_.Tick();
88 } 93 }
89 94
95 void GestureInterpreter::Scroll(float x, float y, float dx, float dy) {
96 AbortAnimations();
97
98 ViewMatrix::Point cursor_position = TrackAndGetPosition(x, y);
99
100 // Inject the cursor position to the host so that scrolling can happen on the
101 // right place.
102 input_stub_->SendMouseEvent(cursor_position.x, cursor_position.y,
103 protocol::MouseEvent_MouseButton_BUTTON_UNDEFINED,
104 false);
105
106 ScrollWithoutAbortAnimations(dx, dy);
107 }
108
109 void GestureInterpreter::ScrollWithVelocity(float velocity_x,
110 float velocity_y) {
111 AbortAnimations();
112
113 scroll_animation_.SetVelocity(velocity_x, velocity_y);
114 scroll_animation_.Tick();
115 }
116
90 void GestureInterpreter::ProcessAnimations() { 117 void GestureInterpreter::ProcessAnimations() {
91 if (pan_animation_.IsAnimationInProgress()) { 118 pan_animation_.Tick();
92 pan_animation_.Tick(); 119 scroll_animation_.Tick();
93 }
94 } 120 }
95 121
96 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { 122 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) {
97 viewport_.SetSurfaceSize(width, height); 123 viewport_.SetSurfaceSize(width, height);
98 } 124 }
99 125
100 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { 126 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) {
101 viewport_.SetDesktopSize(width, height); 127 viewport_.SetDesktopSize(width, height);
102 } 128 }
103 129
104 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, 130 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x,
105 float translation_y) { 131 float translation_y) {
106 input_strategy_->HandlePan({translation_x, translation_y}, is_dragging_mode_, 132 input_strategy_->HandlePan({translation_x, translation_y}, is_dragging_mode_,
107 &viewport_); 133 &viewport_);
108 SetCursorPositionOnRenderer(); 134 SetCursorPositionOnRenderer();
109 } 135 }
110 136
137 void GestureInterpreter::ScrollWithoutAbortAnimations(float dx, float dy) {
138 ViewMatrix::Point desktopDelta =
139 input_strategy_->MapScreenVectorToDesktop({dx, dy}, viewport_);
140 input_stub_->SendMouseWheelEvent(desktopDelta.x, desktopDelta.y);
141 }
142
111 void GestureInterpreter::AbortAnimations() { 143 void GestureInterpreter::AbortAnimations() {
112 pan_animation_.Abort(); 144 pan_animation_.Abort();
113 } 145 }
114 146
115 void GestureInterpreter::InjectMouseClick( 147 void GestureInterpreter::InjectMouseClick(
116 float x, 148 float x,
117 float y, 149 float y,
118 protocol::MouseEvent_MouseButton button) { 150 protocol::MouseEvent_MouseButton button) {
119 input_stub_->SendMouseEvent(x, y, button, true); 151 input_stub_->SendMouseEvent(x, y, button, true);
120 input_stub_->SendMouseEvent(x, y, button, false); 152 input_stub_->SendMouseEvent(x, y, button, false);
(...skipping 22 matching lines...) Expand all
143 if (feedback_radius > 0) { 175 if (feedback_radius > 0) {
144 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving 176 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving
145 // the *2 logic inside the renderer. 177 // the *2 logic inside the renderer.
146 float diameter_on_desktop = 178 float diameter_on_desktop =
147 2.f * feedback_radius / viewport_.GetTransformation().GetScale(); 179 2.f * feedback_radius / viewport_.GetTransformation().GetScale();
148 renderer_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop); 180 renderer_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop);
149 } 181 }
150 } 182 }
151 183
152 } // namespace remoting 184 } // 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