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

Side by Side Diff: third_party/WebKit/public/platform/WebInputEvent.h

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Fix mouse up event sender not modifying modifiers Created 4 years 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 ScrollLockOn = 1 << 18, 188 ScrollLockOn = 1 << 18,
189 189
190 // The set of non-stateful modifiers that specifically change the 190 // The set of non-stateful modifiers that specifically change the
191 // interpretation of the key being pressed. For example; IsLeft, 191 // interpretation of the key being pressed. For example; IsLeft,
192 // IsRight, IsComposing don't change the meaning of the key 192 // IsRight, IsComposing don't change the meaning of the key
193 // being pressed. NumLockOn, ScrollLockOn, CapsLockOn are stateful 193 // being pressed. NumLockOn, ScrollLockOn, CapsLockOn are stateful
194 // and don't indicate explicit depressed state. 194 // and don't indicate explicit depressed state.
195 KeyModifiers = 195 KeyModifiers =
196 SymbolKey | FnKey | AltGrKey | MetaKey | AltKey | ControlKey | ShiftKey, 196 SymbolKey | FnKey | AltGrKey | MetaKey | AltKey | ControlKey | ShiftKey,
197 NoModifiers = 0,
majidvp 2016/12/19 20:09:52 nit: Can we just have None = 0 and put it at the t
dtapuska 2016/12/20 19:49:21 Done.
majidvp 2016/12/21 15:49:44 I prefer these bitset values to be defined as cons
197 }; 198 };
198 199
199 // Indicates whether the browser needs to block on the ACK result for 200 // Indicates whether the browser needs to block on the ACK result for
200 // this event, and if not why note (for metrics/diagnostics purposes). 201 // this event, and if not why note (for metrics/diagnostics purposes).
201 // These values are direct mappings of the values in PlatformEvent 202 // These values are direct mappings of the values in PlatformEvent
202 // so the values can be cast between the enumerations. static_asserts 203 // so the values can be cast between the enumerations. static_asserts
203 // checking this are in web/WebInputEventConversion.cpp. 204 // checking this are in web/WebInputEventConversion.cpp.
204 enum DispatchType { 205 enum DispatchType {
205 // Event can be canceled. 206 // Event can be canceled.
206 Blocking, 207 Blocking,
(...skipping 10 matching lines...) Expand all
217 // expected to stick. If this axis is set to Free, then scrolling is not 218 // expected to stick. If this axis is set to Free, then scrolling is not
218 // stuck to any axis. 219 // stuck to any axis.
219 enum RailsMode { 220 enum RailsMode {
220 RailsModeFree = 0, 221 RailsModeFree = 0,
221 RailsModeHorizontal = 1, 222 RailsModeHorizontal = 1,
222 RailsModeVertical = 2, 223 RailsModeVertical = 2,
223 }; 224 };
224 225
225 static const int InputModifiers = ShiftKey | ControlKey | AltKey | MetaKey; 226 static const int InputModifiers = ShiftKey | ControlKey | AltKey | MetaKey;
226 227
228 static constexpr double TimeStampForTesting = 123.0;
229
majidvp 2016/12/19 20:09:52 Great idea to have a constant for testing.
dtapuska 2016/12/20 19:49:21 Done.
227 double timeStampSeconds; // Seconds since platform start with microsecond 230 double timeStampSeconds; // Seconds since platform start with microsecond
228 // resolution. 231 // resolution.
229 unsigned size; // The size of this structure, for serialization. 232 unsigned size; // The size of this structure, for serialization.
230 Type type; 233 Type type;
231 int modifiers; 234 int modifiers;
232 235
233 // Returns true if the WebInputEvent |type| is a mouse event. 236 // Returns true if the WebInputEvent |type| is a mouse event.
234 static bool isMouseEventType(int type) { 237 static bool isMouseEventType(int type) {
235 return MouseTypeFirst <= type && type <= MouseTypeLast; 238 return MouseTypeFirst <= type && type <= MouseTypeLast;
236 } 239 }
(...skipping 20 matching lines...) Expand all
257 return isGestureEventType(other.type); 260 return isGestureEventType(other.type);
258 if (isTouchEventType(type)) 261 if (isTouchEventType(type))
259 return isTouchEventType(other.type); 262 return isTouchEventType(other.type);
260 if (isKeyboardEventType(type)) 263 if (isKeyboardEventType(type))
261 return isKeyboardEventType(other.type); 264 return isKeyboardEventType(other.type);
262 return type == other.type; 265 return type == other.type;
263 } 266 }
264 267
265 BLINK_COMMON_EXPORT static const char* GetName(WebInputEvent::Type); 268 BLINK_COMMON_EXPORT static const char* GetName(WebInputEvent::Type);
266 269
270 void setType(Type typeParam) { type = typeParam; }
271
272 void setModifiers(int modifiersParam) { modifiers = modifiersParam; }
273
274 void setTimeStampSeconds(double seconds) { timeStampSeconds = seconds; }
275
267 protected: 276 protected:
277 WebInputEvent(unsigned sizeParam,
278 Type typeParam,
279 int modifiersParam,
280 double timeStampSecondsParam) {
281 memset(this, 0, sizeParam);
282 timeStampSeconds = timeStampSecondsParam;
283 size = sizeParam;
284 type = typeParam;
285 modifiers = modifiersParam;
286 }
287
268 explicit WebInputEvent(unsigned sizeParam) { 288 explicit WebInputEvent(unsigned sizeParam) {
269 memset(this, 0, sizeParam); 289 memset(this, 0, sizeParam);
270 timeStampSeconds = 0.0; 290 timeStampSeconds = 0.0;
271 size = sizeParam; 291 size = sizeParam;
272 type = Undefined; 292 type = Undefined;
273 modifiers = 0;
majidvp 2016/12/19 20:09:53 why do you no longer not need to initialize modifi
dtapuska 2016/12/20 19:49:21 yes it is an int and zeroed in the memset. I left
274 } 293 }
275 }; 294 };
276 295
277 // WebKeyboardEvent ----------------------------------------------------------- 296 // WebKeyboardEvent -----------------------------------------------------------
278 297
279 class WebKeyboardEvent : public WebInputEvent { 298 class WebKeyboardEvent : public WebInputEvent {
280 public: 299 public:
281 // Caps on string lengths so we can make them static arrays and keep 300 // Caps on string lengths so we can make them static arrays and keep
282 // them PODs. 301 // them PODs.
283 static const size_t textLengthCap = 4; 302 static const size_t textLengthCap = 4;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 338
320 // |text| is the text generated by this keystroke. |unmodifiedText| is 339 // |text| is the text generated by this keystroke. |unmodifiedText| is
321 // |text|, but unmodified by an concurrently-held modifiers (except 340 // |text|, but unmodified by an concurrently-held modifiers (except
322 // shift). This is useful for working out shortcut keys. Linux and 341 // shift). This is useful for working out shortcut keys. Linux and
323 // Windows guarantee one character per event. The Mac does not, but in 342 // Windows guarantee one character per event. The Mac does not, but in
324 // reality that's all it ever gives. We're generous, and cap it a bit 343 // reality that's all it ever gives. We're generous, and cap it a bit
325 // longer. 344 // longer.
326 WebUChar text[textLengthCap]; 345 WebUChar text[textLengthCap];
327 WebUChar unmodifiedText[textLengthCap]; 346 WebUChar unmodifiedText[textLengthCap];
328 347
329 WebKeyboardEvent() 348 WebKeyboardEvent(Type type, int modifiers, double timeStampSeconds)
330 : WebInputEvent(sizeof(WebKeyboardEvent)), 349 : WebInputEvent(sizeof(WebKeyboardEvent),
331 windowsKeyCode(0), 350 type,
332 nativeKeyCode(0), 351 modifiers,
333 isSystemKey(false), 352 timeStampSeconds) {}
334 isBrowserShortcut(false) { 353
335 } 354 WebKeyboardEvent() : WebInputEvent(sizeof(WebKeyboardEvent)) {}
336 355
337 // Please refer to bug http://b/issue?id=961192, which talks about Webkit 356 // Please refer to bug http://b/issue?id=961192, which talks about Webkit
338 // keyboard event handling changes. It also mentions the list of keys 357 // keyboard event handling changes. It also mentions the list of keys
339 // which don't have associated character events. 358 // which don't have associated character events.
340 bool isCharacterKey() const { 359 bool isCharacterKey() const {
341 // TODO(dtapuska): Determine if we can remove this method and just 360 // TODO(dtapuska): Determine if we can remove this method and just
342 // not actually generate events for these instead of filtering them out. 361 // not actually generate events for these instead of filtering them out.
343 switch (windowsKeyCode) { 362 switch (windowsKeyCode) {
344 case 0x08: // VK_BACK 363 case 0x08: // VK_BACK
345 case 0x1b: // VK_ESCAPE 364 case 0x1b: // VK_ESCAPE
(...skipping 18 matching lines...) Expand all
364 int windowY; 383 int windowY;
365 384
366 // Screen coordinate 385 // Screen coordinate
367 int globalX; 386 int globalX;
368 int globalY; 387 int globalY;
369 388
370 int movementX; 389 int movementX;
371 int movementY; 390 int movementY;
372 int clickCount; 391 int clickCount;
373 392
393 WebMouseEvent(Type type, int modifiers, double timeStampSeconds)
394 : WebInputEvent(sizeof(WebMouseEvent), type, modifiers, timeStampSeconds),
395 WebPointerProperties() {}
396
374 WebMouseEvent() 397 WebMouseEvent()
375 : WebInputEvent(sizeof(WebMouseEvent)), 398 : WebInputEvent(sizeof(WebMouseEvent)), WebPointerProperties() {}
376 WebPointerProperties(),
377 x(0),
378 y(0),
379 windowX(0),
380 windowY(0),
381 globalX(0),
382 globalY(0),
383 movementX(0),
384 movementY(0),
385 clickCount(0) {}
386 399
387 protected: 400 protected:
388 explicit WebMouseEvent(unsigned sizeParam) 401 explicit WebMouseEvent(unsigned sizeParam)
389 : WebInputEvent(sizeParam), 402 : WebInputEvent(sizeParam), WebPointerProperties() {}
390 WebPointerProperties(), 403
391 x(0), 404 WebMouseEvent(unsigned sizeParam,
392 y(0), 405 Type type,
393 windowX(0), 406 int modifiers,
394 windowY(0), 407 double timeStampSeconds)
395 globalX(0), 408 : WebInputEvent(sizeParam, type, modifiers, timeStampSeconds),
396 globalY(0), 409 WebPointerProperties() {}
397 movementX(0),
398 movementY(0),
399 clickCount(0) {}
400 }; 410 };
401 411
402 // WebMouseWheelEvent --------------------------------------------------------- 412 // WebMouseWheelEvent ---------------------------------------------------------
403 413
404 class WebMouseWheelEvent : public WebMouseEvent { 414 class WebMouseWheelEvent : public WebMouseEvent {
405 public: 415 public:
406 enum Phase { 416 enum Phase {
407 PhaseNone = 0, 417 PhaseNone = 0,
408 PhaseBegan = 1 << 0, 418 PhaseBegan = 1 << 0,
409 PhaseStationary = 1 << 1, 419 PhaseStationary = 1 << 1,
(...skipping 23 matching lines...) Expand all
433 443
434 bool scrollByPage; 444 bool scrollByPage;
435 bool hasPreciseScrollingDeltas; 445 bool hasPreciseScrollingDeltas;
436 446
437 RailsMode railsMode; 447 RailsMode railsMode;
438 448
439 // Whether the event is blocking, non-blocking, all event 449 // Whether the event is blocking, non-blocking, all event
440 // listeners were passive or was forced to be non-blocking. 450 // listeners were passive or was forced to be non-blocking.
441 DispatchType dispatchType; 451 DispatchType dispatchType;
442 452
453 WebMouseWheelEvent(Type type, int modifiers, double timeStampSeconds)
454 : WebMouseEvent(sizeof(WebMouseWheelEvent),
455 type,
456 modifiers,
457 timeStampSeconds),
458 deltaX(0.0f),
459 deltaY(0.0f),
460 wheelTicksX(0.0f),
461 wheelTicksY(0.0f),
462 accelerationRatioX(1.0f),
463 accelerationRatioY(1.0f),
464 resendingPluginId(-1),
465 phase(PhaseNone),
466 momentumPhase(PhaseNone),
467 railsMode(RailsModeFree),
468 dispatchType(Blocking) {}
469
443 WebMouseWheelEvent() 470 WebMouseWheelEvent()
444 : WebMouseEvent(sizeof(WebMouseWheelEvent)), 471 : WebMouseEvent(sizeof(WebMouseWheelEvent)),
445 deltaX(0.0f), 472 deltaX(0.0f),
446 deltaY(0.0f), 473 deltaY(0.0f),
447 wheelTicksX(0.0f), 474 wheelTicksX(0.0f),
448 wheelTicksY(0.0f), 475 wheelTicksY(0.0f),
449 accelerationRatioX(1.0f), 476 accelerationRatioX(1.0f),
450 accelerationRatioY(1.0f), 477 accelerationRatioY(1.0f),
451 resendingPluginId(-1), 478 resendingPluginId(-1),
452 phase(PhaseNone), 479 phase(PhaseNone),
453 momentumPhase(PhaseNone), 480 momentumPhase(PhaseNone),
454 scrollByPage(false),
455 hasPreciseScrollingDeltas(false),
456 railsMode(RailsModeFree), 481 railsMode(RailsModeFree),
457 dispatchType(Blocking) {} 482 dispatchType(Blocking) {}
458 }; 483 };
459 484
460 485
461 // WebTouchEvent -------------------------------------------------------------- 486 // WebTouchEvent --------------------------------------------------------------
462 487
463 // TODO(e_hakkinen): Replace with WebPointerEvent. crbug.com/508283 488 // TODO(e_hakkinen): Replace with WebPointerEvent. crbug.com/508283
464 class WebTouchEvent : public WebInputEvent { 489 class WebTouchEvent : public WebInputEvent {
465 public: 490 public:
(...skipping 16 matching lines...) Expand all
482 507
483 // Whether this touch event is a touchstart or a first touchmove event per 508 // Whether this touch event is a touchstart or a first touchmove event per
484 // scroll. 509 // scroll.
485 bool touchStartOrFirstTouchMove; 510 bool touchStartOrFirstTouchMove;
486 511
487 // A unique identifier for the touch event. Valid ids start at one and 512 // A unique identifier for the touch event. Valid ids start at one and
488 // increase monotonically. Zero means an unknown id. 513 // increase monotonically. Zero means an unknown id.
489 uint32_t uniqueTouchEventId; 514 uint32_t uniqueTouchEventId;
490 515
491 WebTouchEvent() 516 WebTouchEvent()
492 : WebInputEvent(sizeof(WebTouchEvent)), 517 : WebInputEvent(sizeof(WebTouchEvent)), dispatchType(Blocking) {}
493 touchesLength(0), 518
494 dispatchType(Blocking), 519 WebTouchEvent(Type type, int modifiers, double timeStampSeconds)
495 movedBeyondSlopRegion(false), 520 : WebInputEvent(sizeof(WebTouchEvent), type, modifiers, timeStampSeconds),
496 touchStartOrFirstTouchMove(false), 521 dispatchType(Blocking) {}
497 uniqueTouchEventId(0) {}
498 }; 522 };
499 523
500 #pragma pack(pop) 524 #pragma pack(pop)
501 525
502 } // namespace blink 526 } // namespace blink
503 527
504 #endif 528 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698