Avi Drissman | d6cdf9b | 2022-09-15 19:52:53 | [diff] [blame^] | 1 | // Copyright 2017 The Chromium Authors |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Lei Zhang | 8232b34 | 2021-04-21 20:15:36 | [diff] [blame] | 5 | #ifndef REMOTING_CLIENT_INPUT_TOUCH_INPUT_STRATEGY_H_ |
| 6 | #define REMOTING_CLIENT_INPUT_TOUCH_INPUT_STRATEGY_H_ |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 7 | |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 8 | #include "remoting/client/ui/view_matrix.h" |
| 9 | |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 10 | namespace remoting { |
| 11 | |
| 12 | class DesktopViewport; |
| 13 | |
| 14 | // This is an interface used by GestureInterpreter to customize the way gestures |
| 15 | // are handled. |
nicholss | df09b28 | 2017-05-26 20:08:14 | [diff] [blame] | 16 | class TouchInputStrategy { |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 17 | public: |
nicholss | df09b28 | 2017-05-26 20:08:14 | [diff] [blame] | 18 | enum TouchFeedbackType { |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 19 | TAP_FEEDBACK, |
yuweih | e1bd6ca | 2017-05-19 01:22:45 | [diff] [blame] | 20 | DRAG_FEEDBACK, |
| 21 | }; |
| 22 | |
| 23 | enum Gesture { |
| 24 | NONE, |
| 25 | ZOOM, |
| 26 | DRAG, |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 27 | }; |
| 28 | |
nicholss | df09b28 | 2017-05-26 20:08:14 | [diff] [blame] | 29 | virtual ~TouchInputStrategy() {} |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 30 | |
yuweih | e1bd6ca | 2017-05-19 01:22:45 | [diff] [blame] | 31 | // Called when the GestureInterpreter receives a zoom gesture. The |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 32 | // implementation is responsible for modifying the viewport and observing the |
| 33 | // change. |
yuweih | e1bd6ca | 2017-05-19 01:22:45 | [diff] [blame] | 34 | virtual void HandleZoom(const ViewMatrix::Point& pivot, |
| 35 | float scale, |
| 36 | DesktopViewport* viewport) = 0; |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 37 | |
| 38 | // Called when the GestureInterpreter receives a pan gesture. The |
| 39 | // implementation is responsible for modifying the viewport and observing the |
| 40 | // change. |
yuweih | e1bd6ca | 2017-05-19 01:22:45 | [diff] [blame] | 41 | // simultaneous_gesture: Gesture that is simultaneously in progress. |
| 42 | // Returns true if this changes the cursor position. |
| 43 | virtual bool HandlePan(const ViewMatrix::Vector2D& translation, |
| 44 | Gesture simultaneous_gesture, |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 45 | DesktopViewport* viewport) = 0; |
| 46 | |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 47 | // Called when a touch input (which will end up injecting a mouse event at |
| 48 | // certain position in the host) is done at |touch_point|. |
| 49 | // The implementation should move the cursor to proper position. |
yuweih | b932f1d | 2017-05-23 21:18:52 | [diff] [blame] | 50 | // |
| 51 | // Returns true if |touch_point| is a valid input, false otherwise. If the |
| 52 | // input is not valid, the implementation should not change its cursor |
| 53 | // position. |
| 54 | virtual bool TrackTouchInput(const ViewMatrix::Point& touch_point, |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 55 | const DesktopViewport& viewport) = 0; |
| 56 | |
| 57 | // Returns the current cursor position. |
| 58 | virtual ViewMatrix::Point GetCursorPosition() const = 0; |
| 59 | |
Yuwei Huang | dd311f7 | 2017-08-21 18:55:16 | [diff] [blame] | 60 | // Focuses the viewport on the cursor position if necessary. |
| 61 | virtual void FocusViewportOnCursor(DesktopViewport* viewport) const = 0; |
| 62 | |
yuweih | f6db64d1 | 2017-05-17 06:34:33 | [diff] [blame] | 63 | // Maps a vector (or movement) in the surface coordinate to the vector to be |
| 64 | // used on the desktop. For example it can be used to map a scroll gesture |
| 65 | // on the screen to change in mouse wheel position. |
| 66 | virtual ViewMatrix::Vector2D MapScreenVectorToDesktop( |
| 67 | const ViewMatrix::Vector2D& delta, |
| 68 | const DesktopViewport& viewport) const = 0; |
| 69 | |
yuweih | 7fbc805 | 2017-05-17 05:23:49 | [diff] [blame] | 70 | // Returns the maximum radius of the feedback animation on the surface's |
| 71 | // coordinate for the given input type. The feedback will then be shown on the |
| 72 | // cursor positions returned by GetCursorPosition(). Return 0 if no feedback |
| 73 | // should be shown. |
nicholss | df09b28 | 2017-05-26 20:08:14 | [diff] [blame] | 74 | virtual float GetFeedbackRadius(TouchFeedbackType type) const = 0; |
yuweih | d980e96 | 2017-05-09 03:53:05 | [diff] [blame] | 75 | |
| 76 | // Returns true if the input strategy maintains a visible cursor on the |
| 77 | // desktop. |
| 78 | virtual bool IsCursorVisible() const = 0; |
| 79 | }; |
| 80 | |
| 81 | } // namespace remoting |
Lei Zhang | 8232b34 | 2021-04-21 20:15:36 | [diff] [blame] | 82 | #endif // REMOTING_CLIENT_INPUT_TOUCH_INPUT_STRATEGY_H_ |