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

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
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::ScrollFling(float velocity_x, float velocity_y) {
110 AbortAnimations();
111
112 scroll_animation_.SetVelocity(velocity_x, velocity_y);
113 scroll_animation_.Tick();
114 }
115
90 void GestureInterpreter::ProcessAnimations() { 116 void GestureInterpreter::ProcessAnimations() {
91 if (pan_animation_.IsAnimationInProgress()) { 117 if (pan_animation_.IsAnimationInProgress()) {
92 pan_animation_.Tick(); 118 pan_animation_.Tick();
93 } 119 }
120 if (scroll_animation_.IsAnimationInProgress()) {
nicholss 2017/05/16 18:13:10 Does it hurt to call Tick without checking IsAnima
Yuwei 2017/05/17 05:42:20 Done. TBH nope. Just the negligible overhead of o
121 scroll_animation_.Tick();
122 }
94 } 123 }
95 124
96 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { 125 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) {
97 viewport_.SetSurfaceSize(width, height); 126 viewport_.SetSurfaceSize(width, height);
98 } 127 }
99 128
100 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { 129 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) {
101 viewport_.SetDesktopSize(width, height); 130 viewport_.SetDesktopSize(width, height);
102 } 131 }
103 132
104 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, 133 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x,
105 float translation_y) { 134 float translation_y) {
106 input_strategy_->HandlePan({translation_x, translation_y}, is_dragging_mode_, 135 input_strategy_->HandlePan({translation_x, translation_y}, is_dragging_mode_,
107 &viewport_); 136 &viewport_);
108 SetCursorPositionOnRenderer(); 137 SetCursorPositionOnRenderer();
109 } 138 }
110 139
140 void GestureInterpreter::ScrollWithoutAbortAnimations(float dx, float dy) {
141 ViewMatrix::Point desktopDelta =
142 input_strategy_->MapScrollVector({dx, dy}, viewport_);
143 input_stub_->SendMouseWheelEvent(desktopDelta.x, desktopDelta.y);
144 }
145
111 void GestureInterpreter::AbortAnimations() { 146 void GestureInterpreter::AbortAnimations() {
112 pan_animation_.Abort(); 147 pan_animation_.Abort();
113 } 148 }
114 149
115 void GestureInterpreter::InjectMouseClick( 150 void GestureInterpreter::InjectMouseClick(
116 float x, 151 float x,
117 float y, 152 float y,
118 protocol::MouseEvent_MouseButton button) { 153 protocol::MouseEvent_MouseButton button) {
119 input_stub_->SendMouseEvent(x, y, button, true); 154 input_stub_->SendMouseEvent(x, y, button, true);
120 input_stub_->SendMouseEvent(x, y, button, false); 155 input_stub_->SendMouseEvent(x, y, button, false);
(...skipping 22 matching lines...) Expand all
143 if (feedback_radius > 0) { 178 if (feedback_radius > 0) {
144 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving 179 // TODO(yuweih): The renderer takes diameter as parameter. Consider moving
145 // the *2 logic inside the renderer. 180 // the *2 logic inside the renderer.
146 float diameter_on_desktop = 181 float diameter_on_desktop =
147 2.f * feedback_radius / viewport_.GetTransformation().GetScale(); 182 2.f * feedback_radius / viewport_.GetTransformation().GetScale();
148 renderer_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop); 183 renderer_->StartInputFeedback(cursor_x, cursor_y, diameter_on_desktop);
149 } 184 }
150 } 185 }
151 186
152 } // namespace remoting 187 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698