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