Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [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 | |
Aman Verma | 8378f3f | 2023-11-29 18:08:46 | [diff] [blame] | 5 | #ifndef CONTENT_COMMON_INPUT_SYNTHETIC_TOUCH_DRIVER_H_ |
| 6 | #define CONTENT_COMMON_INPUT_SYNTHETIC_TOUCH_DRIVER_H_ |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 7 | |
David Bertoni | e79d522 | 2023-11-07 20:23:43 | [diff] [blame] | 8 | #include <map> |
| 9 | |
| 10 | #include "base/memory/weak_ptr.h" |
Aman Verma | 8378f3f | 2023-11-29 18:08:46 | [diff] [blame] | 11 | #include "content/common/input/synthetic_pointer_driver.h" |
Dave Tapuska | 6db16e3 | 2020-06-09 13:58:06 | [diff] [blame] | 12 | #include "third_party/blink/public/common/input/synthetic_web_input_event_builders.h" |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 13 | |
| 14 | namespace content { |
| 15 | |
David Bertoni | e79d522 | 2023-11-07 20:23:43 | [diff] [blame] | 16 | class SyntheticTouchDriver final : public SyntheticPointerDriver { |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 17 | public: |
| 18 | SyntheticTouchDriver(); |
Dave Tapuska | 6db16e3 | 2020-06-09 13:58:06 | [diff] [blame] | 19 | explicit SyntheticTouchDriver(blink::SyntheticWebTouchEvent touch_event); |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 20 | |
| 21 | SyntheticTouchDriver(const SyntheticTouchDriver&) = delete; |
| 22 | SyntheticTouchDriver& operator=(const SyntheticTouchDriver&) = delete; |
| 23 | |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 24 | ~SyntheticTouchDriver() override; |
| 25 | |
| 26 | void DispatchEvent(SyntheticGestureTarget* target, |
| 27 | const base::TimeTicks& timestamp) override; |
| 28 | |
Lan Wei | 34e7e98 | 2019-02-11 21:18:18 | [diff] [blame] | 29 | void Press( |
| 30 | float x, |
| 31 | float y, |
| 32 | int index, |
| 33 | SyntheticPointerActionParams::Button button = |
| 34 | SyntheticPointerActionParams::Button::LEFT, |
| 35 | int key_modifiers = 0, |
| 36 | float width = 40.f, |
| 37 | float height = 40.f, |
| 38 | float rotation_angle = 0.f, |
Lan Wei | 34bf2c4 | 2021-04-14 17:42:58 | [diff] [blame] | 39 | float force = 0.5, |
| 40 | float tangential_pressure = 0.f, |
| 41 | int tilt_x = 0, |
| 42 | int tilt_y = 0, |
Lan Wei | 34e7e98 | 2019-02-11 21:18:18 | [diff] [blame] | 43 | const base::TimeTicks& timestamp = base::TimeTicks::Now()) override; |
Lan Wei | 3b538d7 | 2019-02-01 15:33:31 | [diff] [blame] | 44 | void Move(float x, |
| 45 | float y, |
| 46 | int index, |
| 47 | int key_modifiers = 0, |
| 48 | float width = 40.f, |
| 49 | float height = 40.f, |
| 50 | float rotation_angle = 0.f, |
Lan Wei | 34bf2c4 | 2021-04-14 17:42:58 | [diff] [blame] | 51 | float force = 0.5, |
| 52 | float tangential_pressure = 0.f, |
| 53 | int tilt_x = 0, |
Steve Kobes | 1fc813d | 2021-07-21 15:02:41 | [diff] [blame] | 54 | int tilt_y = 0, |
| 55 | SyntheticPointerActionParams::Button button = |
| 56 | SyntheticPointerActionParams::Button::NO_BUTTON) override; |
lanwei | 988a2345 | 2017-01-18 21:42:14 | [diff] [blame] | 57 | void Release(int index, |
| 58 | SyntheticPointerActionParams::Button button = |
Lan Wei | 5323996 | 2019-01-29 17:38:13 | [diff] [blame] | 59 | SyntheticPointerActionParams::Button::LEFT, |
| 60 | int key_modifiers = 0) override; |
Lan Wei | 9c6f124 | 2019-02-11 23:01:30 | [diff] [blame] | 61 | void Cancel(int index = 0, |
| 62 | SyntheticPointerActionParams::Button button = |
| 63 | SyntheticPointerActionParams::Button::LEFT, |
| 64 | int key_modifiers = 0) override; |
Lan Wei | 095958dc | 2019-01-30 18:11:13 | [diff] [blame] | 65 | void Leave(int index = 0) override; |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 66 | |
| 67 | bool UserInputCheck( |
| 68 | const SyntheticPointerActionParams& params) const override; |
| 69 | |
David Bertoni | e79d522 | 2023-11-07 20:23:43 | [diff] [blame] | 70 | base::WeakPtr<SyntheticPointerDriver> AsWeakPtr() override; |
| 71 | |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 72 | private: |
Lan Wei | ae5352b9 | 2018-09-17 18:18:59 | [diff] [blame] | 73 | using PointerIdIndexMap = std::map<int, int>; |
lanwei | 3df2fbb | 2016-12-21 22:10:02 | [diff] [blame] | 74 | |
Lan Wei | ae5352b9 | 2018-09-17 18:18:59 | [diff] [blame] | 75 | void ResetPointerIdIndexMap(); |
Lan Wei | 09742f44 | 2018-07-31 17:45:42 | [diff] [blame] | 76 | int GetIndexFromMap(int value) const; |
| 77 | |
Dave Tapuska | 6db16e3 | 2020-06-09 13:58:06 | [diff] [blame] | 78 | blink::SyntheticWebTouchEvent touch_event_; |
Lan Wei | ae5352b9 | 2018-09-17 18:18:59 | [diff] [blame] | 79 | PointerIdIndexMap pointer_id_map_; |
David Bertoni | e79d522 | 2023-11-07 20:23:43 | [diff] [blame] | 80 | base::WeakPtrFactory<SyntheticTouchDriver> weak_ptr_factory_{this}; |
lanwei | 1060f1f | 2016-11-28 23:00:31 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace content |
| 84 | |
Aman Verma | 8378f3f | 2023-11-29 18:08:46 | [diff] [blame] | 85 | #endif // CONTENT_COMMON_INPUT_SYNTHETIC_TOUCH_DRIVER_H_ |