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 // Starts the given feedback at (cursor_x, cursor_y) if the feedback radius | |
95 // is non-zero. | |
96 void StartInputFeedback(float cursor_x, | |
97 float cursor_y, | |
98 InputStrategy::InputFeedbackType feedback_type); | |
99 | |
100 InputMode input_mode_ = UNDEFINED_INPUT_MODE; | |
101 std::unique_ptr<InputStrategy> input_strategy_; | |
102 DesktopViewport viewport_; | |
103 RendererProxy* renderer_; | |
104 ChromotingSession* input_stub_; | |
105 InputStrategy::Gesture gesture_in_progress_; | |
106 | |
107 FlingAnimation pan_animation_; | |
108 FlingAnimation scroll_animation_; | |
109 | |
110 // GestureInterpreter is neither copyable nor movable. | |
111 GestureInterpreter(const GestureInterpreter&) = delete; | |
112 GestureInterpreter& operator=(const GestureInterpreter&) = delete; | |
113 }; | |
114 | |
115 } // namespace remoting | |
116 #endif // REMOTING_CLIENT_UI_GESTURE_INTERPRETER_H_ | |
OLD | NEW |