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 WebMouseEvent_h | 5 #ifndef WebMouseEvent_h |
6 #define WebMouseEvent_h | 6 #define WebMouseEvent_h |
7 | 7 |
8 #include "WebInputEvent.h" | 8 #include "WebInputEvent.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 class WebGestureEvent; | 12 class WebGestureEvent; |
13 | 13 |
14 // See WebInputEvent.h for details why this pack is here. | 14 // See WebInputEvent.h for details why this pack is here. |
15 #pragma pack(push, 4) | 15 #pragma pack(push, 4) |
16 | 16 |
17 // WebMouseEvent -------------------------------------------------------------- | 17 // WebMouseEvent -------------------------------------------------------------- |
18 | 18 |
19 // TODO(mustaq): We are truncating |float|s to integers whenever setting | 19 // TODO(mustaq): We are truncating |float|s to integers whenever setting |
20 // coordinate values, to avoid regressions for now. Will be fixed later | 20 // coordinate values, to avoid regressions for now. Will be fixed later |
21 // on. crbug.com/456625 | 21 // on. crbug.com/456625 |
22 class WebMouseEvent : public WebInputEvent, public WebPointerProperties { | 22 class WebMouseEvent : public WebInputEvent, public WebPointerProperties { |
23 public: | 23 public: |
| 24 static constexpr int kDefaultMousePointerId = std::numeric_limits<int>::max(); |
| 25 |
24 int click_count; | 26 int click_count; |
25 | 27 |
26 WebMouseEvent(Type type_param, | 28 WebMouseEvent(Type type_param, |
27 int x_param, | 29 int x_param, |
28 int y_param, | 30 int y_param, |
29 int global_x_param, | 31 int global_x_param, |
30 int global_y_param, | 32 int global_y_param, |
31 int modifiers_param, | 33 int modifiers_param, |
32 double time_stamp_seconds_param) | 34 double time_stamp_seconds_param, |
| 35 int id_param = kDefaultMousePointerId) |
33 : WebInputEvent(sizeof(WebMouseEvent), | 36 : WebInputEvent(sizeof(WebMouseEvent), |
34 type_param, | 37 type_param, |
35 modifiers_param, | 38 modifiers_param, |
36 time_stamp_seconds_param), | 39 time_stamp_seconds_param), |
37 WebPointerProperties(), | 40 WebPointerProperties(id_param), |
38 position_in_widget_(x_param, y_param), | 41 position_in_widget_(x_param, y_param), |
39 position_in_screen_(global_x_param, global_y_param) {} | 42 position_in_screen_(global_x_param, global_y_param) {} |
40 | 43 |
41 WebMouseEvent(Type type_param, | 44 WebMouseEvent(Type type_param, |
42 WebFloatPoint position, | 45 WebFloatPoint position, |
43 WebFloatPoint global_position, | 46 WebFloatPoint global_position, |
44 Button button_param, | 47 Button button_param, |
45 int click_count_param, | 48 int click_count_param, |
46 int modifiers_param, | 49 int modifiers_param, |
47 double time_stamp_seconds_param) | 50 double time_stamp_seconds_param, |
| 51 int id_param = kDefaultMousePointerId) |
48 : WebInputEvent(sizeof(WebMouseEvent), | 52 : WebInputEvent(sizeof(WebMouseEvent), |
49 type_param, | 53 type_param, |
50 modifiers_param, | 54 modifiers_param, |
51 time_stamp_seconds_param), | 55 time_stamp_seconds_param), |
52 WebPointerProperties(button_param, PointerType::kMouse), | 56 WebPointerProperties(id_param, button_param, PointerType::kMouse), |
53 click_count(click_count_param), | 57 click_count(click_count_param), |
54 position_in_widget_(floor(position.x), floor(position.y)), | 58 position_in_widget_(floor(position.x), floor(position.y)), |
55 position_in_screen_(floor(global_position.x), | 59 position_in_screen_(floor(global_position.x), |
56 floor(global_position.y)) {} | 60 floor(global_position.y)) {} |
57 | 61 |
58 WebMouseEvent(Type type_param, | 62 WebMouseEvent(Type type_param, |
59 int modifiers_param, | 63 int modifiers_param, |
60 double time_stamp_seconds_param) | 64 double time_stamp_seconds_param, |
| 65 int id_param = kDefaultMousePointerId) |
61 : WebMouseEvent(sizeof(WebMouseEvent), | 66 : WebMouseEvent(sizeof(WebMouseEvent), |
62 type_param, | 67 type_param, |
63 modifiers_param, | 68 modifiers_param, |
64 time_stamp_seconds_param) {} | 69 time_stamp_seconds_param, |
| 70 id_param) {} |
65 | 71 |
66 WebMouseEvent() : WebMouseEvent(sizeof(WebMouseEvent)) {} | 72 WebMouseEvent() |
| 73 : WebMouseEvent(sizeof(WebMouseEvent), kDefaultMousePointerId) {} |
67 | 74 |
68 bool FromTouch() const { | 75 bool FromTouch() const { |
69 return (GetModifiers() & kIsCompatibilityEventForTouch) != 0; | 76 return (GetModifiers() & kIsCompatibilityEventForTouch) != 0; |
70 } | 77 } |
71 | 78 |
72 #if INSIDE_BLINK | 79 #if INSIDE_BLINK |
73 BLINK_PLATFORM_EXPORT WebMouseEvent(Type type_param, | 80 BLINK_PLATFORM_EXPORT WebMouseEvent(Type type_param, |
74 const WebGestureEvent&, | 81 const WebGestureEvent&, |
75 Button button_param, | 82 Button button_param, |
76 int click_count_param, | 83 int click_count_param, |
77 int modifiers_param, | 84 int modifiers_param, |
78 double time_stamp_seconds_param); | 85 double time_stamp_seconds_param, |
| 86 int id_param = kDefaultMousePointerId); |
79 | 87 |
80 BLINK_PLATFORM_EXPORT WebFloatPoint MovementInRootFrame() const; | 88 BLINK_PLATFORM_EXPORT WebFloatPoint MovementInRootFrame() const; |
81 BLINK_PLATFORM_EXPORT WebFloatPoint PositionInRootFrame() const; | 89 BLINK_PLATFORM_EXPORT WebFloatPoint PositionInRootFrame() const; |
82 | 90 |
83 // Sets any scaled values to be their computed values and sets |frameScale| | 91 // Sets any scaled values to be their computed values and sets |frameScale| |
84 // back to 1 and |translateX|, |translateY| back to 0. | 92 // back to 1 and |translateX|, |translateY| back to 0. |
85 BLINK_PLATFORM_EXPORT WebMouseEvent FlattenTransform() const; | 93 BLINK_PLATFORM_EXPORT WebMouseEvent FlattenTransform() const; |
86 #endif | 94 #endif |
87 | 95 |
88 WebFloatPoint PositionInWidget() const { return position_in_widget_; } | 96 WebFloatPoint PositionInWidget() const { return position_in_widget_; } |
89 void SetPositionInWidget(float x, float y) { | 97 void SetPositionInWidget(float x, float y) { |
90 position_in_widget_ = WebFloatPoint(floor(x), floor(y)); | 98 position_in_widget_ = WebFloatPoint(floor(x), floor(y)); |
91 } | 99 } |
92 | 100 |
93 WebFloatPoint PositionInScreen() const { return position_in_screen_; } | 101 WebFloatPoint PositionInScreen() const { return position_in_screen_; } |
94 void SetPositionInScreen(float x, float y) { | 102 void SetPositionInScreen(float x, float y) { |
95 position_in_screen_ = WebFloatPoint(floor(x), floor(y)); | 103 position_in_screen_ = WebFloatPoint(floor(x), floor(y)); |
96 } | 104 } |
97 | 105 |
98 protected: | 106 protected: |
99 explicit WebMouseEvent(unsigned size_param) | 107 WebMouseEvent(unsigned size_param, int id) |
100 : WebInputEvent(size_param), WebPointerProperties() {} | 108 : WebInputEvent(size_param), WebPointerProperties(id) {} |
101 | 109 |
102 WebMouseEvent(unsigned size_param, | 110 WebMouseEvent(unsigned size_param, |
103 Type type, | 111 Type type, |
104 int modifiers, | 112 int modifiers, |
105 double time_stamp_seconds) | 113 double time_stamp_seconds, |
| 114 int id) |
106 : WebInputEvent(size_param, type, modifiers, time_stamp_seconds), | 115 : WebInputEvent(size_param, type, modifiers, time_stamp_seconds), |
107 WebPointerProperties() {} | 116 WebPointerProperties(id) {} |
108 | 117 |
109 void FlattenTransformSelf(); | 118 void FlattenTransformSelf(); |
110 | 119 |
111 private: | 120 private: |
112 // Widget coordinate, which is relative to the bound of current RenderWidget | 121 // Widget coordinate, which is relative to the bound of current RenderWidget |
113 // (e.g. a plugin or OOPIF inside a RenderView). Similar to viewport | 122 // (e.g. a plugin or OOPIF inside a RenderView). Similar to viewport |
114 // coordinates but without DevTools emulation transform or overscroll applied. | 123 // coordinates but without DevTools emulation transform or overscroll applied. |
115 WebFloatPoint position_in_widget_; | 124 WebFloatPoint position_in_widget_; |
116 | 125 |
117 // Screen coordinate | 126 // Screen coordinate |
118 WebFloatPoint position_in_screen_; | 127 WebFloatPoint position_in_screen_; |
119 }; | 128 }; |
120 | 129 |
121 #pragma pack(pop) | 130 #pragma pack(pop) |
122 | 131 |
123 } // namespace blink | 132 } // namespace blink |
124 | 133 |
125 #endif // WebMouseEvent_h | 134 #endif // WebMouseEvent_h |
OLD | NEW |