OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ | 5 #ifndef CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ |
6 #define CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ | 6 #define CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
10 #include "content/common/input/input_param_traits.h" | 10 #include "content/common/input/input_param_traits.h" |
11 #include "content/common/input/synthetic_gesture_params.h" | 11 #include "content/common/input/synthetic_gesture_params.h" |
12 #include "ui/gfx/geometry/point_f.h" | 12 #include "ui/gfx/geometry/point_f.h" |
13 | 13 |
14 namespace ipc_fuzzer { | 14 namespace ipc_fuzzer { |
15 template <class T> | 15 template <class T> |
16 struct FuzzTraits; | 16 struct FuzzTraits; |
17 } // namespace ipc_fuzzer | 17 } // namespace ipc_fuzzer |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 struct CONTENT_EXPORT SyntheticPointerActionParams | 21 struct CONTENT_EXPORT SyntheticPointerActionParams { |
22 : public SyntheticGestureParams { | |
23 public: | 22 public: |
24 // All the pointer actions that will be dispatched together will be grouped | 23 // All the pointer actions that will be dispatched together will be grouped |
25 // in an array. A FINISH action will be received when we reach the end of the | 24 // in an array. |
26 // action sequence. | |
27 enum class PointerActionType { | 25 enum class PointerActionType { |
28 NOT_INITIALIZED, | 26 NOT_INITIALIZED, |
29 PRESS, | 27 PRESS, |
30 MOVE, | 28 MOVE, |
31 RELEASE, | 29 RELEASE, |
32 IDLE, | 30 IDLE, |
33 FINISH, | 31 POINTER_ACTION_TYPE_MAX = IDLE |
34 POINTER_ACTION_TYPE_MAX = FINISH | |
35 }; | 32 }; |
36 | 33 |
37 SyntheticPointerActionParams(); | 34 SyntheticPointerActionParams(); |
38 SyntheticPointerActionParams(PointerActionType action_type, | 35 SyntheticPointerActionParams(PointerActionType action_type); |
39 GestureSourceType source_type); | 36 ~SyntheticPointerActionParams(); |
40 SyntheticPointerActionParams(const SyntheticPointerActionParams& other); | |
41 ~SyntheticPointerActionParams() override; | |
42 | |
43 GestureType GetGestureType() const override; | |
44 | |
45 static const SyntheticPointerActionParams* Cast( | |
46 const SyntheticGestureParams* gesture_params); | |
47 | 37 |
48 void set_pointer_action_type(PointerActionType pointer_action_type) { | 38 void set_pointer_action_type(PointerActionType pointer_action_type) { |
49 pointer_action_type_ = pointer_action_type; | 39 pointer_action_type_ = pointer_action_type; |
50 } | 40 } |
51 | 41 |
52 void set_index(int index) { | 42 void set_index(int index) { |
53 DCHECK(pointer_action_type_ != PointerActionType::FINISH); | 43 DCHECK_GE(index, 0); |
54 // For mouse pointers, the index should always be 0. | 44 DCHECK_LT(index, blink::WebTouchEvent::kTouchesLengthCap); |
55 DCHECK(gesture_source_type != MOUSE_INPUT || index == 0); | |
56 index_ = index; | 45 index_ = index; |
57 } | 46 } |
58 | 47 |
59 void set_position(const gfx::PointF& position) { | 48 void set_position(const gfx::PointF& position) { |
60 DCHECK(pointer_action_type_ == PointerActionType::PRESS || | 49 DCHECK(pointer_action_type_ == PointerActionType::PRESS || |
61 pointer_action_type_ == PointerActionType::MOVE); | 50 pointer_action_type_ == PointerActionType::MOVE); |
62 position_ = position; | 51 position_ = position; |
63 } | 52 } |
64 | 53 |
65 PointerActionType pointer_action_type() const { return pointer_action_type_; } | 54 PointerActionType pointer_action_type() const { return pointer_action_type_; } |
66 | 55 |
67 int index() const { | 56 int index() const { |
68 DCHECK(pointer_action_type_ != PointerActionType::FINISH); | 57 DCHECK_GE(index_, 0); |
69 // For mouse pointers, the index should always be 0. | 58 DCHECK_LT(index_, blink::WebTouchEvent::kTouchesLengthCap); |
70 DCHECK(gesture_source_type != MOUSE_INPUT || index_ == 0); | |
71 return index_; | 59 return index_; |
72 } | 60 } |
73 | 61 |
74 gfx::PointF position() const { | 62 gfx::PointF position() const { |
75 DCHECK(pointer_action_type_ == PointerActionType::PRESS || | 63 DCHECK(pointer_action_type_ == PointerActionType::PRESS || |
76 pointer_action_type_ == PointerActionType::MOVE); | 64 pointer_action_type_ == PointerActionType::MOVE); |
77 return position_; | 65 return position_; |
78 } | 66 } |
79 | 67 |
80 private: | 68 private: |
81 friend struct IPC::ParamTraits<content::SyntheticPointerActionParams>; | 69 friend struct IPC::ParamTraits<content::SyntheticPointerActionParams>; |
82 friend struct ipc_fuzzer::FuzzTraits<content::SyntheticPointerActionParams>; | 70 friend struct ipc_fuzzer::FuzzTraits<content::SyntheticPointerActionParams>; |
83 | 71 |
84 PointerActionType pointer_action_type_; | 72 PointerActionType pointer_action_type_; |
85 // Pass a position value when sending a press or move action. | 73 // The position of the pointer, where it presses or moves to. |
86 gfx::PointF position_; | 74 gfx::PointF position_; |
87 // Pass an index value except if the pointer_action_type_ is PROCESS. | 75 // The index of the pointer in the pointer action sequence passed from the |
| 76 // user API. |
88 int index_; | 77 int index_; |
89 }; | 78 }; |
90 | 79 |
91 } // namespace content | 80 } // namespace content |
92 | 81 |
93 #endif // CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ | 82 #endif // CONTENT_COMMON_INPUT_SYNTHETIC_POINTER_ACTION_PARAMS_H_ |
OLD | NEW |