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