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

Side by Side Diff: public/web/WebInputEvent.h

Issue 132183008: Prevent implicit WebInputEvent construction from WebInputEvent::Type (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove unncessary constructor guard Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // properly and don't have paddings/gaps, otherwise memory check tools 51 // properly and don't have paddings/gaps, otherwise memory check tools
52 // like Valgrind will complain about uninitialized memory usage when 52 // like Valgrind will complain about uninitialized memory usage when
53 // transferring these classes over the wire. 53 // transferring these classes over the wire.
54 54
55 #pragma pack(push, 4) 55 #pragma pack(push, 4)
56 56
57 // WebInputEvent -------------------------------------------------------------- 57 // WebInputEvent --------------------------------------------------------------
58 58
59 class WebInputEvent { 59 class WebInputEvent {
60 public: 60 public:
61 WebInputEvent(unsigned sizeParam = sizeof(WebInputEvent))
62 {
63 memset(this, 0, sizeParam);
64 timeStampSeconds = 0.0;
65 size = sizeParam;
66 type = Undefined;
67 modifiers = 0;
68 }
69
70 // When we use an input method (or an input method editor), we receive 61 // When we use an input method (or an input method editor), we receive
71 // two events for a keypress. The former event is a keydown, which 62 // two events for a keypress. The former event is a keydown, which
72 // provides a keycode, and the latter is a textinput, which provides 63 // provides a keycode, and the latter is a textinput, which provides
73 // a character processed by an input method. (The mapping from a 64 // a character processed by an input method. (The mapping from a
74 // keycode to a character code is not trivial for non-English 65 // keycode to a character code is not trivial for non-English
75 // keyboards.) 66 // keyboards.)
76 // To support input methods, Safari sends keydown events to WebKit for 67 // To support input methods, Safari sends keydown events to WebKit for
77 // filtering. WebKit sends filtered keydown events back to Safari, 68 // filtering. WebKit sends filtered keydown events back to Safari,
78 // which sends them to input methods. 69 // which sends them to input methods.
79 // Unfortunately, it is hard to apply this design to Chrome because of 70 // Unfortunately, it is hard to apply this design to Chrome because of
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 || type == MouseUp 208 || type == MouseUp
218 || type == TouchStart 209 || type == TouchStart
219 || type == TouchEnd; 210 || type == TouchEnd;
220 } 211 }
221 212
222 // Returns true if the WebInputEvent is a gesture event. 213 // Returns true if the WebInputEvent is a gesture event.
223 static bool isGestureEventType(int type) 214 static bool isGestureEventType(int type)
224 { 215 {
225 return GestureTypeFirst <= type && type <= GestureTypeLast; 216 return GestureTypeFirst <= type && type <= GestureTypeLast;
226 } 217 }
218
219 protected:
220 explicit WebInputEvent(unsigned sizeParam)
221 {
222 memset(this, 0, sizeParam);
223 timeStampSeconds = 0.0;
224 size = sizeParam;
225 type = Undefined;
226 modifiers = 0;
227 }
227 }; 228 };
228 229
229 // WebKeyboardEvent ----------------------------------------------------------- 230 // WebKeyboardEvent -----------------------------------------------------------
230 231
231 class WebKeyboardEvent : public WebInputEvent { 232 class WebKeyboardEvent : public WebInputEvent {
232 public: 233 public:
233 // Caps on string lengths so we can make them static arrays and keep 234 // Caps on string lengths so we can make them static arrays and keep
234 // them PODs. 235 // them PODs.
235 static const size_t textLengthCap = 4; 236 static const size_t textLengthCap = 4;
236 237
(...skipping 30 matching lines...) Expand all
267 // shift). This is useful for working out shortcut keys. Linux and 268 // shift). This is useful for working out shortcut keys. Linux and
268 // Windows guarantee one character per event. The Mac does not, but in 269 // Windows guarantee one character per event. The Mac does not, but in
269 // reality that's all it ever gives. We're generous, and cap it a bit 270 // reality that's all it ever gives. We're generous, and cap it a bit
270 // longer. 271 // longer.
271 WebUChar text[textLengthCap]; 272 WebUChar text[textLengthCap];
272 WebUChar unmodifiedText[textLengthCap]; 273 WebUChar unmodifiedText[textLengthCap];
273 274
274 // This is a string identifying the key pressed. 275 // This is a string identifying the key pressed.
275 char keyIdentifier[keyIdentifierLengthCap]; 276 char keyIdentifier[keyIdentifierLengthCap];
276 277
277 WebKeyboardEvent(unsigned sizeParam = sizeof(WebKeyboardEvent)) 278 WebKeyboardEvent()
278 : WebInputEvent(sizeParam) 279 : WebInputEvent(sizeof(WebKeyboardEvent))
279 , windowsKeyCode(0) 280 , windowsKeyCode(0)
280 , nativeKeyCode(0) 281 , nativeKeyCode(0)
281 , isSystemKey(false) 282 , isSystemKey(false)
282 { 283 {
283 memset(&text, 0, sizeof(text)); 284 memset(&text, 0, sizeof(text));
284 memset(&unmodifiedText, 0, sizeof(unmodifiedText)); 285 memset(&unmodifiedText, 0, sizeof(unmodifiedText));
285 memset(&keyIdentifier, 0, sizeof(keyIdentifier)); 286 memset(&keyIdentifier, 0, sizeof(keyIdentifier));
286 } 287 }
287 288
288 // Sets keyIdentifier based on the value of windowsKeyCode. This is 289 // Sets keyIdentifier based on the value of windowsKeyCode. This is
(...skipping 19 matching lines...) Expand all
308 int x; 309 int x;
309 int y; 310 int y;
310 int windowX; 311 int windowX;
311 int windowY; 312 int windowY;
312 int globalX; 313 int globalX;
313 int globalY; 314 int globalY;
314 int movementX; 315 int movementX;
315 int movementY; 316 int movementY;
316 int clickCount; 317 int clickCount;
317 318
318 WebMouseEvent(unsigned sizeParam = sizeof(WebMouseEvent)) 319 WebMouseEvent()
320 : WebInputEvent(sizeof(WebMouseEvent))
321 , button(ButtonNone)
322 , x(0)
323 , y(0)
324 , windowX(0)
325 , windowY(0)
326 , globalX(0)
327 , globalY(0)
328 , movementX(0)
329 , movementY(0)
330 , clickCount(0)
331 {
332 }
333
334 protected:
335 explicit WebMouseEvent(unsigned sizeParam)
319 : WebInputEvent(sizeParam) 336 : WebInputEvent(sizeParam)
320 , button(ButtonNone) 337 , button(ButtonNone)
321 , x(0) 338 , x(0)
322 , y(0) 339 , y(0)
323 , windowX(0) 340 , windowX(0)
324 , windowY(0) 341 , windowY(0)
325 , globalX(0) 342 , globalX(0)
326 , globalY(0) 343 , globalY(0)
327 , movementX(0) 344 , movementX(0)
328 , movementY(0) 345 , movementY(0)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // an alternate effect. The common case is that a scroll in the left or 389 // an alternate effect. The common case is that a scroll in the left or
373 // right directions causes a back or forwards navigation, respectively. 390 // right directions causes a back or forwards navigation, respectively.
374 // 391 //
375 // These flags prevent rubber banding from starting in a given direction, 392 // These flags prevent rubber banding from starting in a given direction,
376 // but have no effect on an ongoing rubber banding. A rubber banding that 393 // but have no effect on an ongoing rubber banding. A rubber banding that
377 // started in the vertical direction is allowed to continue in the right 394 // started in the vertical direction is allowed to continue in the right
378 // direction, even if canRubberbandRight is 0. 395 // direction, even if canRubberbandRight is 0.
379 int canRubberbandLeft; 396 int canRubberbandLeft;
380 int canRubberbandRight; 397 int canRubberbandRight;
381 398
382 WebMouseWheelEvent(unsigned sizeParam = sizeof(WebMouseWheelEvent)) 399 WebMouseWheelEvent()
383 : WebMouseEvent(sizeParam) 400 : WebMouseEvent(sizeof(WebMouseWheelEvent))
384 , deltaX(0.0f) 401 , deltaX(0.0f)
385 , deltaY(0.0f) 402 , deltaY(0.0f)
386 , wheelTicksX(0.0f) 403 , wheelTicksX(0.0f)
387 , wheelTicksY(0.0f) 404 , wheelTicksY(0.0f)
388 , accelerationRatioX(1.0f) 405 , accelerationRatioX(1.0f)
389 , accelerationRatioY(1.0f) 406 , accelerationRatioY(1.0f)
390 , scrollByPage(false) 407 , scrollByPage(false)
391 , hasPreciseScrollingDeltas(false) 408 , hasPreciseScrollingDeltas(false)
392 , phase(PhaseNone) 409 , phase(PhaseNone)
393 , momentumPhase(PhaseNone) 410 , momentumPhase(PhaseNone)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 struct { 475 struct {
459 float velocityX; 476 float velocityX;
460 float velocityY; 477 float velocityY;
461 } flingStart; 478 } flingStart;
462 479
463 struct { 480 struct {
464 float scale; 481 float scale;
465 } pinchUpdate; 482 } pinchUpdate;
466 } data; 483 } data;
467 484
468 WebGestureEvent(unsigned sizeParam = sizeof(WebGestureEvent)) 485 WebGestureEvent()
469 : WebInputEvent(sizeParam) 486 : WebInputEvent(sizeof(WebGestureEvent))
470 , x(0) 487 , x(0)
471 , y(0) 488 , y(0)
472 , globalX(0) 489 , globalX(0)
473 , globalY(0) 490 , globalY(0)
474 { 491 {
475 memset(&data, 0, sizeof(data)); 492 memset(&data, 0, sizeof(data));
476 } 493 }
477 }; 494 };
478 495
479 // WebTouchEvent -------------------------------------------------------------- 496 // WebTouchEvent --------------------------------------------------------------
480 497
481 class WebTouchEvent : public WebInputEvent { 498 class WebTouchEvent : public WebInputEvent {
482 public: 499 public:
483 // Maximum number of simultaneous touches supported on 500 // Maximum number of simultaneous touches supported on
484 // Ash/Aura. 501 // Ash/Aura.
485 enum { touchesLengthCap = 12 }; 502 enum { touchesLengthCap = 12 };
486 503
487 unsigned touchesLength; 504 unsigned touchesLength;
488 // List of all touches which are currently down. 505 // List of all touches which are currently down.
489 WebTouchPoint touches[touchesLengthCap]; 506 WebTouchPoint touches[touchesLengthCap];
490 507
491 unsigned changedTouchesLength; 508 unsigned changedTouchesLength;
492 // List of all touches whose state has changed since the last WebTouchEvent 509 // List of all touches whose state has changed since the last WebTouchEvent
493 WebTouchPoint changedTouches[touchesLengthCap]; 510 WebTouchPoint changedTouches[touchesLengthCap];
494 511
495 unsigned targetTouchesLength; 512 unsigned targetTouchesLength;
496 // List of all touches which are currently down and are targeting the event recipient. 513 // List of all touches which are currently down and are targeting the event recipient.
497 WebTouchPoint targetTouches[touchesLengthCap]; 514 WebTouchPoint targetTouches[touchesLengthCap];
498 515
499 WebTouchEvent(unsigned sizeParam = sizeof(WebTouchEvent)) 516 WebTouchEvent()
500 : WebInputEvent(sizeParam) 517 : WebInputEvent(sizeof(WebTouchEvent))
501 , touchesLength(0) 518 , touchesLength(0)
502 , changedTouchesLength(0) 519 , changedTouchesLength(0)
503 , targetTouchesLength(0) 520 , targetTouchesLength(0)
504 { 521 {
505 } 522 }
506 }; 523 };
507 524
508 #pragma pack(pop) 525 #pragma pack(pop)
509 526
510 } // namespace blink 527 } // namespace blink
511 528
512 #endif 529 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698