| 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 #ifndef REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ | 5 #ifndef REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ |
| 6 #define REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ | 6 #define REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "remoting/client/ui/desktop_viewport.h" | 10 #include "remoting/client/ui/desktop_viewport.h" |
| 11 #include "remoting/client/ui/fling_animation.h" | 11 #include "remoting/client/ui/fling_animation.h" |
| 12 #include "remoting/client/ui/input_strategy.h" | 12 #include "remoting/client/ui/input_strategy.h" |
| 13 #include "remoting/proto/event.pb.h" | 13 #include "remoting/proto/event.pb.h" |
| 14 | 14 |
| 15 namespace remoting { | 15 namespace remoting { |
| 16 | 16 |
| 17 class ChromotingSession; | 17 class ChromotingSession; |
| 18 class RendererProxy; | 18 class RendererProxy; |
| 19 | 19 |
| 20 // This is a class for interpreting a raw touch input into actions like moving | 20 // This is a class for interpreting a raw touch input into actions like moving |
| 21 // the viewport and injecting mouse clicks. | 21 // the viewport and injecting mouse clicks. |
| 22 class GestureInterpreter { | 22 class GestureInterpreter { |
| 23 public: | 23 public: |
| 24 enum GestureState { GESTURE_BEGAN, GESTURE_CHANGED, GESTURE_ENDED }; | 24 enum GestureState { GESTURE_BEGAN, GESTURE_CHANGED, GESTURE_ENDED }; |
| 25 | 25 |
| 26 enum InputMode { |
| 27 UNDEFINED_INPUT_MODE, |
| 28 DIRECT_INPUT_MODE, |
| 29 TRACKPAD_INPUT_MODE |
| 30 }; |
| 31 |
| 26 GestureInterpreter(RendererProxy* renderer, ChromotingSession* input_stub); | 32 GestureInterpreter(RendererProxy* renderer, ChromotingSession* input_stub); |
| 27 ~GestureInterpreter(); | 33 ~GestureInterpreter(); |
| 28 | 34 |
| 35 // Must be called right after the renderer is ready. |
| 36 void SetInputMode(InputMode mode); |
| 37 |
| 38 // Returns the current input mode. |
| 39 InputMode GetInputMode() const; |
| 40 |
| 29 // Coordinates of the OpenGL view surface will be used. | 41 // Coordinates of the OpenGL view surface will be used. |
| 30 | 42 |
| 31 // This can happen in conjunction with Pan(). | 43 // Called during a two-finger pinching gesture. This can happen in conjunction |
| 32 void Pinch(float pivot_x, float pivot_y, float scale); | 44 // with Pan(). |
| 45 void Zoom(float pivot_x, float pivot_y, float scale, GestureState state); |
| 33 | 46 |
| 34 // Called whenever the user did a pan gesture. It can be one-finger pan, no | 47 // Called whenever the user did a pan gesture. It can be one-finger pan, no |
| 35 // matter long-press in on or not, or two-finger pan in conjunction with pinch | 48 // matter dragging in on or not, or two-finger pan in conjunction with zoom. |
| 36 // and long-press. Two-finger pan without pinch is consider a scroll gesture. | 49 // Two-finger pan without zoom is consider a scroll gesture. |
| 37 void Pan(float translation_x, float translation_y); | 50 void Pan(float translation_x, float translation_y); |
| 38 | 51 |
| 39 // Called when the user did a one-finger tap. | 52 // Called when the user did a one-finger tap. |
| 40 void Tap(float x, float y); | 53 void Tap(float x, float y); |
| 41 | 54 |
| 42 void TwoFingerTap(float x, float y); | 55 void TwoFingerTap(float x, float y); |
| 43 | 56 |
| 44 // Caller is expected to call both Pan() and LongPress() when long-press is in | 57 // Caller is expected to call both Pan() and Drag() when dragging is in |
| 45 // progress. | 58 // progress. |
| 46 void LongPress(float x, float y, GestureState state); | 59 void Drag(float x, float y, GestureState state); |
| 47 | 60 |
| 48 // Called when the user has just done a one-finger pan (no long-press or | 61 // Called when the user has just done a one-finger pan (no dragging or |
| 49 // pinching) and the pan gesture still has some final velocity. | 62 // zooming) and the pan gesture still has some final velocity. |
| 50 void OneFingerFling(float velocity_x, float velocity_y); | 63 void OneFingerFling(float velocity_x, float velocity_y); |
| 51 | 64 |
| 52 // Called during a two-finger scroll (panning without pinching) gesture. | 65 // Called during a two-finger scroll (panning without zooming) gesture. |
| 53 void Scroll(float x, float y, float dx, float dy); | 66 void Scroll(float x, float y, float dx, float dy); |
| 54 | 67 |
| 55 // Called when the user has just done a scroll gesture and the scroll gesture | 68 // Called when the user has just done a scroll gesture and the scroll gesture |
| 56 // still has some final velocity. | 69 // still has some final velocity. |
| 57 void ScrollWithVelocity(float velocity_x, float velocity_y); | 70 void ScrollWithVelocity(float velocity_x, float velocity_y); |
| 58 | 71 |
| 59 // Called to process one animation frame. | 72 // Called to process one animation frame. |
| 60 void ProcessAnimations(); | 73 void ProcessAnimations(); |
| 61 | 74 |
| 62 void OnSurfaceSizeChanged(int width, int height); | 75 void OnSurfaceSizeChanged(int width, int height); |
| 63 void OnDesktopSizeChanged(int width, int height); | 76 void OnDesktopSizeChanged(int width, int height); |
| 64 | 77 |
| 65 private: | 78 private: |
| 66 void PanWithoutAbortAnimations(float translation_x, float translation_y); | 79 void PanWithoutAbortAnimations(float translation_x, float translation_y); |
| 67 | 80 |
| 68 void ScrollWithoutAbortAnimations(float dx, float dy); | 81 void ScrollWithoutAbortAnimations(float dx, float dy); |
| 69 | 82 |
| 70 void AbortAnimations(); | 83 void AbortAnimations(); |
| 71 | 84 |
| 72 void InjectMouseClick(float x, | 85 void InjectMouseClick(float x, |
| 73 float y, | 86 float y, |
| 74 protocol::MouseEvent_MouseButton button); | 87 protocol::MouseEvent_MouseButton button); |
| 75 | 88 |
| 89 void InjectCursorPosition(float x, float y); |
| 90 |
| 91 void SetGestureInProgress(InputStrategy::Gesture gesture, |
| 92 bool is_in_progress); |
| 93 |
| 76 // Tracks the touch point and gets back the cursor position from the input | 94 // Tracks the touch point and gets back the cursor position from the input |
| 77 // strategy. | 95 // strategy. |
| 78 ViewMatrix::Point TrackAndGetPosition(float touch_x, float touch_y); | 96 ViewMatrix::Point TrackAndGetPosition(float touch_x, float touch_y); |
| 79 | 97 |
| 80 // If the cursor is visible, send the cursor position from the input strategy | |
| 81 // to the renderer. | |
| 82 void SetCursorPositionOnRenderer(); | |
| 83 | |
| 84 // Starts the given feedback at (cursor_x, cursor_y) if the feedback radius | 98 // Starts the given feedback at (cursor_x, cursor_y) if the feedback radius |
| 85 // is non-zero. | 99 // is non-zero. |
| 86 void StartInputFeedback(float cursor_x, | 100 void StartInputFeedback(float cursor_x, |
| 87 float cursor_y, | 101 float cursor_y, |
| 88 InputStrategy::InputFeedbackType feedback_type); | 102 InputStrategy::InputFeedbackType feedback_type); |
| 89 | 103 |
| 104 InputMode input_mode_ = UNDEFINED_INPUT_MODE; |
| 90 std::unique_ptr<InputStrategy> input_strategy_; | 105 std::unique_ptr<InputStrategy> input_strategy_; |
| 91 DesktopViewport viewport_; | 106 DesktopViewport viewport_; |
| 92 RendererProxy* renderer_; | 107 RendererProxy* renderer_; |
| 93 ChromotingSession* input_stub_; | 108 ChromotingSession* input_stub_; |
| 94 bool is_dragging_mode_ = false; | 109 InputStrategy::Gesture gesture_in_progress_; |
| 95 | 110 |
| 96 FlingAnimation pan_animation_; | 111 FlingAnimation pan_animation_; |
| 97 FlingAnimation scroll_animation_; | 112 FlingAnimation scroll_animation_; |
| 98 | 113 |
| 99 // GestureInterpreter is neither copyable nor movable. | 114 // GestureInterpreter is neither copyable nor movable. |
| 100 GestureInterpreter(const GestureInterpreter&) = delete; | 115 GestureInterpreter(const GestureInterpreter&) = delete; |
| 101 GestureInterpreter& operator=(const GestureInterpreter&) = delete; | 116 GestureInterpreter& operator=(const GestureInterpreter&) = delete; |
| 102 }; | 117 }; |
| 103 | 118 |
| 104 } // namespace remoting | 119 } // namespace remoting |
| 105 #endif // REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ | 120 #endif // REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ |
| OLD | NEW |