Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1391)

Side by Side Diff: content/common/input/synthetic_web_input_event_builders.cc

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/common/input/synthetic_web_input_event_builders.h" 5 #include "content/common/input/synthetic_web_input_event_builders.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/input/web_touch_event_traits.h" 8 #include "content/common/input/web_touch_event_traits.h"
9 #include "ui/events/base_event_utils.h" 9 #include "ui/events/base_event_utils.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 using blink::WebInputEvent; 14 using blink::WebInputEvent;
15 using blink::WebKeyboardEvent; 15 using blink::WebKeyboardEvent;
16 using blink::WebGestureEvent; 16 using blink::WebGestureEvent;
17 using blink::WebMouseEvent; 17 using blink::WebMouseEvent;
18 using blink::WebMouseWheelEvent; 18 using blink::WebMouseWheelEvent;
19 using blink::WebTouchEvent; 19 using blink::WebTouchEvent;
20 using blink::WebTouchPoint; 20 using blink::WebTouchPoint;
21 21
22 WebMouseEvent SyntheticWebMouseEventBuilder::Build( 22 WebMouseEvent SyntheticWebMouseEventBuilder::Build(
23 blink::WebInputEvent::Type type) { 23 blink::WebInputEvent::Type type) {
24 WebMouseEvent result; 24 return WebMouseEvent(type, WebInputEvent::NoModifiers,
25 result.type = type; 25 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
26 return result;
27 } 26 }
28 27
29 WebMouseEvent SyntheticWebMouseEventBuilder::Build( 28 WebMouseEvent SyntheticWebMouseEventBuilder::Build(
30 blink::WebInputEvent::Type type, 29 blink::WebInputEvent::Type type,
31 int window_x, 30 int window_x,
32 int window_y, 31 int window_y,
33 int modifiers) { 32 int modifiers) {
34 DCHECK(WebInputEvent::isMouseEventType(type)); 33 DCHECK(WebInputEvent::isMouseEventType(type));
35 WebMouseEvent result = Build(type); 34 WebMouseEvent result(type, modifiers,
35 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
36 result.x = window_x; 36 result.x = window_x;
37 result.y = window_y; 37 result.y = window_y;
38 result.windowX = window_x; 38 result.windowX = window_x;
39 result.windowY = window_y; 39 result.windowY = window_y;
40 result.modifiers = modifiers;
41 40
42 if (type == WebInputEvent::MouseDown || type == WebInputEvent::MouseUp) 41 if (type == WebInputEvent::MouseDown || type == WebInputEvent::MouseUp)
43 result.button = WebMouseEvent::Button::Left; 42 result.button = WebMouseEvent::Button::Left;
44 else 43 else
45 result.button = WebMouseEvent::Button::NoButton; 44 result.button = WebMouseEvent::Button::NoButton;
46 45
47 return result; 46 return result;
48 } 47 }
49 48
50 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build( 49 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(
51 WebMouseWheelEvent::Phase phase) { 50 WebMouseWheelEvent::Phase phase) {
52 WebMouseWheelEvent result; 51 WebMouseWheelEvent result(WebInputEvent::MouseWheel,
53 result.type = WebInputEvent::MouseWheel; 52 WebInputEvent::NoModifiers,
53 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
54 result.phase = phase; 54 result.phase = phase;
55 return result; 55 return result;
56 } 56 }
57 57
58 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, 58 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x,
59 float y, 59 float y,
60 float dx, 60 float dx,
61 float dy, 61 float dy,
62 int modifiers, 62 int modifiers,
63 bool precise) { 63 bool precise) {
64 return Build(x, y, 0, 0, dx, dy, modifiers, precise); 64 return Build(x, y, 0, 0, dx, dy, modifiers, precise);
65 } 65 }
66 66
67 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x, 67 WebMouseWheelEvent SyntheticWebMouseWheelEventBuilder::Build(float x,
68 float y, 68 float y,
69 float global_x, 69 float global_x,
70 float global_y, 70 float global_y,
71 float dx, 71 float dx,
72 float dy, 72 float dy,
73 int modifiers, 73 int modifiers,
74 bool precise) { 74 bool precise) {
75 WebMouseWheelEvent result; 75 WebMouseWheelEvent result(WebInputEvent::MouseWheel, modifiers,
76 result.type = WebInputEvent::MouseWheel; 76 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
77 result.globalX = global_x; 77 result.globalX = global_x;
78 result.globalY = global_y; 78 result.globalY = global_y;
79 result.x = x; 79 result.x = x;
80 result.y = y; 80 result.y = y;
81 result.deltaX = dx; 81 result.deltaX = dx;
82 result.deltaY = dy; 82 result.deltaY = dy;
83 if (dx) 83 if (dx)
84 result.wheelTicksX = dx > 0.0f ? 1.0f : -1.0f; 84 result.wheelTicksX = dx > 0.0f ? 1.0f : -1.0f;
85 if (dy) 85 if (dy)
86 result.wheelTicksY = dy > 0.0f ? 1.0f : -1.0f; 86 result.wheelTicksY = dy > 0.0f ? 1.0f : -1.0f;
87 result.modifiers = modifiers;
88 result.hasPreciseScrollingDeltas = precise; 87 result.hasPreciseScrollingDeltas = precise;
89 return result; 88 return result;
90 } 89 }
91 90
92 WebKeyboardEvent SyntheticWebKeyboardEventBuilder::Build( 91 WebKeyboardEvent SyntheticWebKeyboardEventBuilder::Build(
93 WebInputEvent::Type type) { 92 WebInputEvent::Type type) {
94 DCHECK(WebInputEvent::isKeyboardEventType(type)); 93 DCHECK(WebInputEvent::isKeyboardEventType(type));
95 WebKeyboardEvent result; 94 WebKeyboardEvent result(type, WebInputEvent::NoModifiers,
96 result.type = type; 95 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
97 result.windowsKeyCode = ui::VKEY_L; // non-null made up value. 96 result.windowsKeyCode = ui::VKEY_L; // non-null made up value.
98 return result; 97 return result;
99 } 98 }
100 99
101 WebGestureEvent SyntheticWebGestureEventBuilder::Build( 100 WebGestureEvent SyntheticWebGestureEventBuilder::Build(
102 WebInputEvent::Type type, 101 WebInputEvent::Type type,
103 blink::WebGestureDevice source_device) { 102 blink::WebGestureDevice source_device,
103 int modifiers) {
104 DCHECK(WebInputEvent::isGestureEventType(type)); 104 DCHECK(WebInputEvent::isGestureEventType(type));
105 WebGestureEvent result; 105 WebGestureEvent result(type, modifiers,
106 result.type = type; 106 ui::EventTimeStampToSeconds(ui::EventTimeForNow()));
107 result.sourceDevice = source_device; 107 result.sourceDevice = source_device;
108 if (type == WebInputEvent::GestureTap || 108 if (type == WebInputEvent::GestureTap ||
109 type == WebInputEvent::GestureTapUnconfirmed || 109 type == WebInputEvent::GestureTapUnconfirmed ||
110 type == WebInputEvent::GestureDoubleTap) { 110 type == WebInputEvent::GestureDoubleTap) {
111 result.data.tap.tapCount = 1; 111 result.data.tap.tapCount = 1;
112 result.data.tap.width = 10; 112 result.data.tap.width = 10;
113 result.data.tap.height = 10; 113 result.data.tap.height = 10;
114 } 114 }
115 return result; 115 return result;
116 } 116 }
117 117
118 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollBegin( 118 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollBegin(
119 float dx_hint, 119 float dx_hint,
120 float dy_hint, 120 float dy_hint,
121 blink::WebGestureDevice source_device) { 121 blink::WebGestureDevice source_device) {
122 WebGestureEvent result = 122 WebGestureEvent result =
123 Build(WebInputEvent::GestureScrollBegin, source_device); 123 Build(WebInputEvent::GestureScrollBegin, source_device);
124 result.data.scrollBegin.deltaXHint = dx_hint; 124 result.data.scrollBegin.deltaXHint = dx_hint;
125 result.data.scrollBegin.deltaYHint = dy_hint; 125 result.data.scrollBegin.deltaYHint = dy_hint;
126 return result; 126 return result;
127 } 127 }
128 128
129 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollUpdate( 129 WebGestureEvent SyntheticWebGestureEventBuilder::BuildScrollUpdate(
130 float dx, 130 float dx,
131 float dy, 131 float dy,
132 int modifiers, 132 int modifiers,
133 blink::WebGestureDevice source_device) { 133 blink::WebGestureDevice source_device) {
134 WebGestureEvent result = 134 WebGestureEvent result =
135 Build(WebInputEvent::GestureScrollUpdate, source_device); 135 Build(WebInputEvent::GestureScrollUpdate, source_device, modifiers);
136 result.data.scrollUpdate.deltaX = dx; 136 result.data.scrollUpdate.deltaX = dx;
137 result.data.scrollUpdate.deltaY = dy; 137 result.data.scrollUpdate.deltaY = dy;
138 result.modifiers = modifiers;
139 return result; 138 return result;
140 } 139 }
141 140
142 WebGestureEvent SyntheticWebGestureEventBuilder::BuildPinchUpdate( 141 WebGestureEvent SyntheticWebGestureEventBuilder::BuildPinchUpdate(
143 float scale, 142 float scale,
144 float anchor_x, 143 float anchor_x,
145 float anchor_y, 144 float anchor_y,
146 int modifiers, 145 int modifiers,
147 blink::WebGestureDevice source_device) { 146 blink::WebGestureDevice source_device) {
148 WebGestureEvent result = 147 WebGestureEvent result =
149 Build(WebInputEvent::GesturePinchUpdate, source_device); 148 Build(WebInputEvent::GesturePinchUpdate, source_device, modifiers);
150 result.data.pinchUpdate.scale = scale; 149 result.data.pinchUpdate.scale = scale;
151 result.x = anchor_x; 150 result.x = anchor_x;
152 result.y = anchor_y; 151 result.y = anchor_y;
153 result.globalX = anchor_x; 152 result.globalX = anchor_x;
154 result.globalY = anchor_y; 153 result.globalY = anchor_y;
155 result.modifiers = modifiers;
156 return result; 154 return result;
157 } 155 }
158 156
159 WebGestureEvent SyntheticWebGestureEventBuilder::BuildFling( 157 WebGestureEvent SyntheticWebGestureEventBuilder::BuildFling(
160 float velocity_x, 158 float velocity_x,
161 float velocity_y, 159 float velocity_y,
162 blink::WebGestureDevice source_device) { 160 blink::WebGestureDevice source_device) {
163 WebGestureEvent result = Build(WebInputEvent::GestureFlingStart, 161 WebGestureEvent result = Build(WebInputEvent::GestureFlingStart,
164 source_device); 162 source_device);
165 result.data.flingStart.velocityX = velocity_x; 163 result.data.flingStart.velocityX = velocity_x;
166 result.data.flingStart.velocityY = velocity_y; 164 result.data.flingStart.velocityY = velocity_y;
167 return result; 165 return result;
168 } 166 }
169 167
170 SyntheticWebTouchEvent::SyntheticWebTouchEvent() : WebTouchEvent() { 168 SyntheticWebTouchEvent::SyntheticWebTouchEvent() : WebTouchEvent() {
171 uniqueTouchEventId = ui::GetNextTouchEventId(); 169 uniqueTouchEventId = ui::GetNextTouchEventId();
172 SetTimestamp(base::TimeTicks::Now()); 170 SetTimestamp(ui::EventTimeForNow());
173 } 171 }
174 172
175 void SyntheticWebTouchEvent::ResetPoints() { 173 void SyntheticWebTouchEvent::ResetPoints() {
176 int activePointCount = 0; 174 int activePointCount = 0;
177 for (unsigned int i = 0; i < touchesLength; ++i) { 175 for (unsigned int i = 0; i < touchesLength; ++i) {
178 switch (touches[i].state) { 176 switch (touches[i].state) {
179 case WebTouchPoint::StatePressed: 177 case WebTouchPoint::StatePressed:
180 case WebTouchPoint::StateMoved: 178 case WebTouchPoint::StateMoved:
181 case WebTouchPoint::StateStationary: 179 case WebTouchPoint::StateStationary:
182 touches[i].state = WebTouchPoint::StateStationary; 180 touches[i].state = WebTouchPoint::StateStationary;
(...skipping 20 matching lines...) Expand all
203 WebTouchPoint& point = touches[index]; 201 WebTouchPoint& point = touches[index];
204 point.id = index; 202 point.id = index;
205 point.position.x = point.screenPosition.x = x; 203 point.position.x = point.screenPosition.x = x;
206 point.position.y = point.screenPosition.y = y; 204 point.position.y = point.screenPosition.y = y;
207 point.state = WebTouchPoint::StatePressed; 205 point.state = WebTouchPoint::StatePressed;
208 point.radiusX = point.radiusY = 1.f; 206 point.radiusX = point.radiusY = 1.f;
209 point.rotationAngle = 1.f; 207 point.rotationAngle = 1.f;
210 point.force = 1.f; 208 point.force = 1.f;
211 point.tiltX = point.tiltY = 0; 209 point.tiltX = point.tiltY = 0;
212 ++touchesLength; 210 ++touchesLength;
213 WebTouchEventTraits::ResetType( 211 WebTouchEventTraits::ResetType(WebInputEvent::TouchStart, timeStampSeconds,
214 WebInputEvent::TouchStart, timeStampSeconds, this); 212 this);
215 return point.id; 213 return point.id;
216 } 214 }
217 215
218 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { 216 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) {
219 CHECK_GE(index, 0); 217 CHECK_GE(index, 0);
220 CHECK_LT(index, kTouchesLengthCap); 218 CHECK_LT(index, kTouchesLengthCap);
221 // Always set this bit to avoid otherwise unexpected touchmove suppression. 219 // Always set this bit to avoid otherwise unexpected touchmove suppression.
222 // The caller can opt-out explicitly, if necessary. 220 // The caller can opt-out explicitly, if necessary.
223 movedBeyondSlopRegion = true; 221 movedBeyondSlopRegion = true;
224 WebTouchPoint& point = touches[index]; 222 WebTouchPoint& point = touches[index];
225 point.position.x = point.screenPosition.x = x; 223 point.position.x = point.screenPosition.x = x;
226 point.position.y = point.screenPosition.y = y; 224 point.position.y = point.screenPosition.y = y;
227 touches[index].state = WebTouchPoint::StateMoved; 225 touches[index].state = WebTouchPoint::StateMoved;
228 WebTouchEventTraits::ResetType( 226 WebTouchEventTraits::ResetType(WebInputEvent::TouchMove, timeStampSeconds,
229 WebInputEvent::TouchMove, timeStampSeconds, this); 227 this);
230 } 228 }
231 229
232 void SyntheticWebTouchEvent::ReleasePoint(int index) { 230 void SyntheticWebTouchEvent::ReleasePoint(int index) {
233 CHECK_GE(index, 0); 231 CHECK_GE(index, 0);
234 CHECK_LT(index, kTouchesLengthCap); 232 CHECK_LT(index, kTouchesLengthCap);
235 touches[index].state = WebTouchPoint::StateReleased; 233 touches[index].state = WebTouchPoint::StateReleased;
236 WebTouchEventTraits::ResetType( 234 WebTouchEventTraits::ResetType(WebInputEvent::TouchEnd, timeStampSeconds,
237 WebInputEvent::TouchEnd, timeStampSeconds, this); 235 this);
238 } 236 }
239 237
240 void SyntheticWebTouchEvent::CancelPoint(int index) { 238 void SyntheticWebTouchEvent::CancelPoint(int index) {
241 CHECK_GE(index, 0); 239 CHECK_GE(index, 0);
242 CHECK_LT(index, kTouchesLengthCap); 240 CHECK_LT(index, kTouchesLengthCap);
243 touches[index].state = WebTouchPoint::StateCancelled; 241 touches[index].state = WebTouchPoint::StateCancelled;
244 WebTouchEventTraits::ResetType( 242 WebTouchEventTraits::ResetType(WebInputEvent::TouchCancel, timeStampSeconds,
245 WebInputEvent::TouchCancel, timeStampSeconds, this); 243 this);
246 } 244 }
247 245
248 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) { 246 void SyntheticWebTouchEvent::SetTimestamp(base::TimeTicks timestamp) {
249 timeStampSeconds = ui::EventTimeStampToSeconds(timestamp); 247 setTimeStampSeconds(ui::EventTimeStampToSeconds(timestamp));
250 } 248 }
251 249
252 int SyntheticWebTouchEvent::FirstFreeIndex() { 250 int SyntheticWebTouchEvent::FirstFreeIndex() {
253 for (size_t i = 0; i < kTouchesLengthCap; ++i) { 251 for (size_t i = 0; i < kTouchesLengthCap; ++i) {
254 if (touches[i].state == WebTouchPoint::StateUndefined) 252 if (touches[i].state == WebTouchPoint::StateUndefined)
255 return i; 253 return i;
256 } 254 }
257 return -1; 255 return -1;
258 } 256 }
259 257
260 } // namespace content 258 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698