Index: remoting/client/gesture_interpreter.cc |
diff --git a/remoting/client/gesture_interpreter.cc b/remoting/client/gesture_interpreter.cc |
index 85dfd340c1436f01e93eda3963b7c2b85729224c..d4389dc9cd41fe163eea13a42de7e184b438c37f 100644 |
--- a/remoting/client/gesture_interpreter.cc |
+++ b/remoting/client/gesture_interpreter.cc |
@@ -3,15 +3,25 @@ |
// found in the LICENSE file. |
#include "remoting/client/gesture_interpreter.h" |
-#include "base/logging.h" |
+ |
+#include "base/bind.h" |
+#include "base/time/time.h" |
#include "remoting/client/direct_input_strategy.h" |
-namespace remoting { |
+namespace { |
+ |
+const float kOneFingerFlingTimeConstant = 325.f; |
+ |
+} // namespace |
+namespace remoting { |
GestureInterpreter::GestureInterpreter( |
const DesktopViewport::TransformationCallback& on_transformation_changed, |
ChromotingSession* input_stub) |
- : input_stub_(input_stub) { |
+ : input_stub_(input_stub), |
+ pan_animation_(kOneFingerFlingTimeConstant, |
+ base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, |
+ base::Unretained(this))) { |
viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, |
true); |
@@ -22,16 +32,17 @@ GestureInterpreter::GestureInterpreter( |
GestureInterpreter::~GestureInterpreter() {} |
void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { |
+ AbortAnimations(); |
input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); |
} |
void GestureInterpreter::Pan(float translation_x, float translation_y) { |
- // TODO(yuweih): Pan deceleration animation. |
- input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, |
- &viewport_); |
+ AbortAnimations(); |
+ PanWithoutAbortAnimations(translation_x, translation_y); |
} |
void GestureInterpreter::Tap(float x, float y) { |
+ AbortAnimations(); |
float cursor_x, cursor_y; |
input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
InjectMouseClick(cursor_x, cursor_y, |
@@ -39,6 +50,7 @@ void GestureInterpreter::Tap(float x, float y) { |
} |
void GestureInterpreter::TwoFingerTap(float x, float y) { |
+ AbortAnimations(); |
float cursor_x, cursor_y; |
input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
InjectMouseClick(cursor_x, cursor_y, |
@@ -46,6 +58,7 @@ void GestureInterpreter::TwoFingerTap(float x, float y) { |
} |
void GestureInterpreter::LongPress(float x, float y, GestureState state) { |
+ AbortAnimations(); |
float cursor_x, cursor_y; |
input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
@@ -55,12 +68,16 @@ void GestureInterpreter::LongPress(float x, float y, GestureState state) { |
is_dragging_mode_); |
} |
-void GestureInterpreter::InjectMouseClick( |
- float x, |
- float y, |
- protocol::MouseEvent_MouseButton button) { |
- input_stub_->SendMouseEvent(x, y, button, true); |
- input_stub_->SendMouseEvent(x, y, button, false); |
+void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { |
+ AbortAnimations(); |
+ pan_animation_.SetVelocity(velocity_x, velocity_y); |
+ pan_animation_.Tick(); |
+} |
+ |
+void GestureInterpreter::ProcessAnimations() { |
+ if (pan_animation_.IsAnimationInProgress()) { |
+ pan_animation_.Tick(); |
+ } |
} |
void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { |
@@ -71,4 +88,22 @@ void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { |
viewport_.SetDesktopSize(width, height); |
} |
+void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, |
+ float translation_y) { |
+ input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, |
+ &viewport_); |
+} |
+ |
+void GestureInterpreter::AbortAnimations() { |
+ pan_animation_.Abort(); |
+} |
+ |
+void GestureInterpreter::InjectMouseClick( |
+ float x, |
+ float y, |
+ protocol::MouseEvent_MouseButton button) { |
+ input_stub_->SendMouseEvent(x, y, button, true); |
+ input_stub_->SendMouseEvent(x, y, button, false); |
+} |
+ |
} // namespace remoting |