| 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 | |
| 7 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "remoting/client/direct_input_strategy.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 | 10 |
| 11 GestureInterpreter::GestureInterpreter( | 11 GestureInterpreter::GestureInterpreter( |
| 12 const DesktopViewport::TransformationCallback& on_transformation_changed) { | 12 const DesktopViewport::TransformationCallback& on_transformation_changed, |
| 13 ChromotingSession* input_stub) |
| 14 : input_stub_(input_stub) { |
| 13 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, | 15 viewport_.RegisterOnTransformationChangedCallback(on_transformation_changed, |
| 14 true); | 16 true); |
| 17 |
| 18 // TODO(yuweih): This should be configurable. |
| 19 input_strategy_.reset(new DirectInputStrategy()); |
| 15 } | 20 } |
| 16 | 21 |
| 17 GestureInterpreter::~GestureInterpreter() {} | 22 GestureInterpreter::~GestureInterpreter() {} |
| 18 | 23 |
| 19 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { | 24 void GestureInterpreter::Pinch(float pivot_x, float pivot_y, float scale) { |
| 20 viewport_.ScaleDesktop(pivot_x, pivot_y, scale); | 25 input_strategy_->HandlePinch(pivot_x, pivot_y, scale, &viewport_); |
| 21 } | 26 } |
| 22 | 27 |
| 23 void GestureInterpreter::Pan(float translation_x, float translation_y) { | 28 void GestureInterpreter::Pan(float translation_x, float translation_y) { |
| 24 // TODO(yuweih): Handle trackpad mode where the viewport always focus on the | 29 // TODO(yuweih): Pan deceleration animation. |
| 25 // cursor. | 30 input_strategy_->HandlePan(translation_x, translation_y, is_dragging_mode_, |
| 26 viewport_.MoveDesktop(translation_x, translation_y); | 31 &viewport_); |
| 27 } | 32 } |
| 28 | 33 |
| 29 void GestureInterpreter::Tap(float x, float y) { | 34 void GestureInterpreter::Tap(float x, float y) { |
| 30 NOTIMPLEMENTED(); | 35 float cursor_x, cursor_y; |
| 36 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 37 InjectMouseClick(cursor_x, cursor_y, |
| 38 protocol::MouseEvent_MouseButton_BUTTON_LEFT); |
| 31 } | 39 } |
| 32 | 40 |
| 33 void GestureInterpreter::LongPress(float x, float y) { | 41 void GestureInterpreter::TwoFingerTap(float x, float y) { |
| 34 NOTIMPLEMENTED(); | 42 float cursor_x, cursor_y; |
| 43 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 44 InjectMouseClick(cursor_x, cursor_y, |
| 45 protocol::MouseEvent_MouseButton_BUTTON_RIGHT); |
| 46 } |
| 47 |
| 48 void GestureInterpreter::LongPress(float x, float y, GestureState state) { |
| 49 float cursor_x, cursor_y; |
| 50 input_strategy_->FindCursorPositions(x, y, viewport_, &cursor_x, &cursor_y); |
| 51 |
| 52 is_dragging_mode_ = state != GESTURE_ENDED; |
| 53 input_stub_->SendMouseEvent(cursor_x, cursor_y, |
| 54 protocol::MouseEvent_MouseButton_BUTTON_LEFT, |
| 55 is_dragging_mode_); |
| 56 } |
| 57 |
| 58 void GestureInterpreter::InjectMouseClick( |
| 59 float x, |
| 60 float y, |
| 61 protocol::MouseEvent_MouseButton button) { |
| 62 input_stub_->SendMouseEvent(x, y, button, true); |
| 63 input_stub_->SendMouseEvent(x, y, button, false); |
| 35 } | 64 } |
| 36 | 65 |
| 37 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { | 66 void GestureInterpreter::OnSurfaceSizeChanged(int width, int height) { |
| 38 viewport_.SetSurfaceSize(width, height); | 67 viewport_.SetSurfaceSize(width, height); |
| 39 } | 68 } |
| 40 | 69 |
| 41 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { | 70 void GestureInterpreter::OnDesktopSizeChanged(int width, int height) { |
| 42 viewport_.SetDesktopSize(width, height); | 71 viewport_.SetDesktopSize(width, height); |
| 43 } | 72 } |
| 44 | 73 |
| 45 } // namespace remoting | 74 } // namespace remoting |
| OLD | NEW |