| OLD | NEW |
| 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/gesture_interpreter.h" | 5 #include "remoting/client/gesture_interpreter.h" |
| 6 #include "base/logging.h" | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/time/time.h" |
| 7 #include "remoting/client/direct_input_strategy.h" | 9 #include "remoting/client/direct_input_strategy.h" |
| 8 | 10 |
| 11 namespace { |
| 12 |
| 13 const float kOneFingerFlingTimeConstant = 325.f; |
| 14 |
| 15 } // namespace |
| 16 |
| 9 namespace remoting { | 17 namespace remoting { |
| 10 | |
| 11 GestureInterpreter::GestureInterpreter( | 18 GestureInterpreter::GestureInterpreter( |
| 12 const DesktopViewport::TransformationCallback& on_transformation_changed, | 19 const DesktopViewport::TransformationCallback& on_transformation_changed, |
| 13 ChromotingSession* input_stub) | 20 ChromotingSession* input_stub) |
| 14 : input_stub_(input_stub) { | 21 : input_stub_(input_stub), |
| 22 pan_animation_(kOneFingerFlingTimeConstant, |
| 23 base::Bind(&GestureInterpreter::PanWithoutAbortAnimations, |
| 24 base::Unretained(this))) { |
| 15 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, | 25 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, |
| 16 true); | 26 true); |
| 17 | 27 |
| 18 // TODO(yuweih): This should be configurable. | 28 // TODO(yuweih): This should be configurable. |
| 19 input_strategy_.reset(new DirectInputStrategy()); | 29 input_strategy_.reset(new DirectInputStrategy()); |
| 20 } | 30 } |
| 21 | 31 |
| 22 GestureInterpreter::~GestureInterpreter() {} | 32 GestureInterpreter::~GestureInterpreter() {} |
| 23 | 33 |
| 24 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { | 34 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { |
| 35 AbortAnimations(); |
| 25 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); | 36 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); |
| 26 } | 37 } |
| 27 | 38 |
| 28 void GestureInterpreter::Pan(float translation_x, float translation_y) { | 39 void GestureInterpreter::Pan(float translation_x, float translation_y) { |
| 29 // TODO(yuweih): Pan deceleration animation. | 40 AbortAnimations(); |
| 30 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, | 41 PanWithoutAbortAnimations(translation_x, translation_y); |
| 31 &viewport_); | |
| 32 } | 42 } |
| 33 | 43 |
| 34 void GestureInterpreter::Tap(float x, float y) { | 44 void GestureInterpreter::Tap(float x, float y) { |
| 45 AbortAnimations(); |
| 35 float cursor_x, cursor_y; | 46 float cursor_x, cursor_y; |
| 36 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 47 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 37 InjectMouseClick(cursor_x, cursor_y, | 48 InjectMouseClick(cursor_x, cursor_y, |
| 38 protocol::MouseEvent_MouseButton_BUTTON_LEFT); | 49 protocol::MouseEvent_MouseButton_BUTTON_LEFT); |
| 39 } | 50 } |
| 40 | 51 |
| 41 void GestureInterpreter::TwoFingerTap(float x, float y) { | 52 void GestureInterpreter::TwoFingerTap(float x, float y) { |
| 53 AbortAnimations(); |
| 42 float cursor_x, cursor_y; | 54 float cursor_x, cursor_y; |
| 43 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 55 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 44 InjectMouseClick(cursor_x, cursor_y, | 56 InjectMouseClick(cursor_x, cursor_y, |
| 45 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); | 57 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); |
| 46 } | 58 } |
| 47 | 59 |
| 48 void GestureInterpreter::LongPress(float x, float y, GestureState state) { | 60 void GestureInterpreter::LongPress(float x, float y, GestureState state) { |
| 61 AbortAnimations(); |
| 49 float cursor_x, cursor_y; | 62 float cursor_x, cursor_y; |
| 50 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); | 63 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 51 | 64 |
| 52 is_dragging_mode_ = state != GESTURE_ENDED; | 65 is_dragging_mode_ = state != GESTURE_ENDED; |
| 53 input_stub_->SendMouseEvent(cursor_x, cursor_y, | 66 input_stub_->SendMouseEvent(cursor_x, cursor_y, |
| 54 protocol::MouseEvent_MouseButton_BUTTON_LEFT, | 67 protocol::MouseEvent_MouseButton_BUTTON_LEFT, |
| 55 is_dragging_mode_); | 68 is_dragging_mode_); |
| 56 } | 69 } |
| 57 | 70 |
| 58 void GestureInterpreter::InjectMouseClick( | 71 void GestureInterpreter::OneFingerFling(float velocity_x, float velocity_y) { |
| 59 float x, | 72 AbortAnimations(); |
| 60 float y, | 73 pan_animation_.SetVelocity(velocity_x, velocity_y); |
| 61 protocol::MouseEvent_MouseButton button) { | 74 pan_animation_.Tick(); |
| 62 input_stub_->SendMouseEvent(x, y, button, true); | 75 } |
| 63 input_stub_->SendMouseEvent(x, y, button, false); | 76 |
| 77 void GestureInterpreter::ProcessAnimations() { |
| 78 if (pan_animation_.IsAnimationInProgress()) { |
| 79 pan_animation_.Tick(); |
| 80 } |
| 64 } | 81 } |
| 65 | 82 |
| 66 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { | 83 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { |
| 67 viewport_.SetSurfaceSize(width, height); | 84 viewport_.SetSurfaceSize(width, height); |
| 68 } | 85 } |
| 69 | 86 |
| 70 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { | 87 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { |
| 71 viewport_.SetDesktopSize(width, height); | 88 viewport_.SetDesktopSize(width, height); |
| 72 } | 89 } |
| 73 | 90 |
| 91 void GestureInterpreter::PanWithoutAbortAnimations(float translation_x, |
| 92 float translation_y) { |
| 93 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, |
| 94 &viewport_); |
| 95 } |
| 96 |
| 97 void GestureInterpreter::AbortAnimations() { |
| 98 pan_animation_.Abort(); |
| 99 } |
| 100 |
| 101 void GestureInterpreter::InjectMouseClick( |
| 102 float x, |
| 103 float y, |
| 104 protocol::MouseEvent_MouseButton button) { |
| 105 input_stub_->SendMouseEvent(x, y, button, true); |
| 106 input_stub_->SendMouseEvent(x, y, button, false); |
| 107 } |
| 108 |
| 74 } // namespace remoting | 109 } // namespace remoting |
| OLD | NEW |