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

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: Make private 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 }
228
229 private:
230 WebInputEvent();
tkent 2014/04/02 00:18:52 Is this necessary?
jdduke (slow) 2014/04/02 20:21:00 Nope, removed.
227 }; 231 };
228 232
229 // WebKeyboardEvent ----------------------------------------------------------- 233 // WebKeyboardEvent -----------------------------------------------------------
230 234
231 class WebKeyboardEvent : public WebInputEvent { 235 class WebKeyboardEvent : public WebInputEvent {
232 public: 236 public:
233 // Caps on string lengths so we can make them static arrays and keep 237 // Caps on string lengths so we can make them static arrays and keep
234 // them PODs. 238 // them PODs.
235 static const size_t textLengthCap = 4; 239 static const size_t textLengthCap = 4;
236 240
(...skipping 30 matching lines...) Expand all
267 // shift). This is useful for working out shortcut keys. Linux and 271 // shift). This is useful for working out shortcut keys. Linux and
268 // Windows guarantee one character per event. The Mac does not, but in 272 // 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 273 // reality that's all it ever gives. We're generous, and cap it a bit
270 // longer. 274 // longer.
271 WebUChar text[textLengthCap]; 275 WebUChar text[textLengthCap];
272 WebUChar unmodifiedText[textLengthCap]; 276 WebUChar unmodifiedText[textLengthCap];
273 277
274 // This is a string identifying the key pressed. 278 // This is a string identifying the key pressed.
275 char keyIdentifier[keyIdentifierLengthCap]; 279 char keyIdentifier[keyIdentifierLengthCap];
276 280
277 WebKeyboardEvent(unsigned sizeParam = sizeof(WebKeyboardEvent)) 281 WebKeyboardEvent()
278 : WebInputEvent(sizeParam) 282 : WebInputEvent(sizeof(WebKeyboardEvent))
279 , windowsKeyCode(0) 283 , windowsKeyCode(0)
280 , nativeKeyCode(0) 284 , nativeKeyCode(0)
281 , isSystemKey(false) 285 , isSystemKey(false)
282 { 286 {
283 memset(&text, 0, sizeof(text)); 287 memset(&text, 0, sizeof(text));
284 memset(&unmodifiedText, 0, sizeof(unmodifiedText)); 288 memset(&unmodifiedText, 0, sizeof(unmodifiedText));
285 memset(&keyIdentifier, 0, sizeof(keyIdentifier)); 289 memset(&keyIdentifier, 0, sizeof(keyIdentifier));
286 } 290 }
287 291
288 // Sets keyIdentifier based on the value of windowsKeyCode. This is 292 // Sets keyIdentifier based on the value of windowsKeyCode. This is
(...skipping 19 matching lines...) Expand all
308 int x; 312 int x;
309 int y; 313 int y;
310 int windowX; 314 int windowX;
311 int windowY; 315 int windowY;
312 int globalX; 316 int globalX;
313 int globalY; 317 int globalY;
314 int movementX; 318 int movementX;
315 int movementY; 319 int movementY;
316 int clickCount; 320 int clickCount;
317 321
318 WebMouseEvent(unsigned sizeParam = sizeof(WebMouseEvent)) 322 WebMouseEvent()
323 : WebInputEvent(sizeof(WebMouseEvent))
324 , button(ButtonNone)
325 , x(0)
326 , y(0)
327 , windowX(0)
328 , windowY(0)
329 , globalX(0)
330 , globalY(0)
331 , movementX(0)
332 , movementY(0)
333 , clickCount(0)
334 {
335 }
336
337 protected:
338 explicit WebMouseEvent(unsigned sizeParam)
319 : WebInputEvent(sizeParam) 339 : WebInputEvent(sizeParam)
320 , button(ButtonNone) 340 , button(ButtonNone)
321 , x(0) 341 , x(0)
322 , y(0) 342 , y(0)
323 , windowX(0) 343 , windowX(0)
324 , windowY(0) 344 , windowY(0)
325 , globalX(0) 345 , globalX(0)
326 , globalY(0) 346 , globalY(0)
327 , movementX(0) 347 , movementX(0)
328 , movementY(0) 348 , 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 392 // an alternate effect. The common case is that a scroll in the left or
373 // right directions causes a back or forwards navigation, respectively. 393 // right directions causes a back or forwards navigation, respectively.
374 // 394 //
375 // These flags prevent rubber banding from starting in a given direction, 395 // 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 396 // 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 397 // started in the vertical direction is allowed to continue in the right
378 // direction, even if canRubberbandRight is 0. 398 // direction, even if canRubberbandRight is 0.
379 int canRubberbandLeft; 399 int canRubberbandLeft;
380 int canRubberbandRight; 400 int canRubberbandRight;
381 401
382 WebMouseWheelEvent(unsigned sizeParam = sizeof(WebMouseWheelEvent)) 402 WebMouseWheelEvent()
383 : WebMouseEvent(sizeParam) 403 : WebMouseEvent(sizeof(WebMouseWheelEvent))
384 , deltaX(0.0f) 404 , deltaX(0.0f)
385 , deltaY(0.0f) 405 , deltaY(0.0f)
386 , wheelTicksX(0.0f) 406 , wheelTicksX(0.0f)
387 , wheelTicksY(0.0f) 407 , wheelTicksY(0.0f)
388 , accelerationRatioX(1.0f) 408 , accelerationRatioX(1.0f)
389 , accelerationRatioY(1.0f) 409 , accelerationRatioY(1.0f)
390 , scrollByPage(false) 410 , scrollByPage(false)
391 , hasPreciseScrollingDeltas(false) 411 , hasPreciseScrollingDeltas(false)
392 , phase(PhaseNone) 412 , phase(PhaseNone)
393 , momentumPhase(PhaseNone) 413 , momentumPhase(PhaseNone)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 struct { 478 struct {
459 float velocityX; 479 float velocityX;
460 float velocityY; 480 float velocityY;
461 } flingStart; 481 } flingStart;
462 482
463 struct { 483 struct {
464 float scale; 484 float scale;
465 } pinchUpdate; 485 } pinchUpdate;
466 } data; 486 } data;
467 487
468 WebGestureEvent(unsigned sizeParam = sizeof(WebGestureEvent)) 488 WebGestureEvent()
469 : WebInputEvent(sizeParam) 489 : WebInputEvent(sizeof(WebGestureEvent))
470 , x(0) 490 , x(0)
471 , y(0) 491 , y(0)
472 , globalX(0) 492 , globalX(0)
473 , globalY(0) 493 , globalY(0)
474 { 494 {
475 memset(&data, 0, sizeof(data)); 495 memset(&data, 0, sizeof(data));
476 } 496 }
477 }; 497 };
478 498
479 // WebTouchEvent -------------------------------------------------------------- 499 // WebTouchEvent --------------------------------------------------------------
480 500
481 class WebTouchEvent : public WebInputEvent { 501 class WebTouchEvent : public WebInputEvent {
482 public: 502 public:
483 // Maximum number of simultaneous touches supported on 503 // Maximum number of simultaneous touches supported on
484 // Ash/Aura. 504 // Ash/Aura.
485 enum { touchesLengthCap = 12 }; 505 enum { touchesLengthCap = 12 };
486 506
487 unsigned touchesLength; 507 unsigned touchesLength;
488 // List of all touches which are currently down. 508 // List of all touches which are currently down.
489 WebTouchPoint touches[touchesLengthCap]; 509 WebTouchPoint touches[touchesLengthCap];
490 510
491 unsigned changedTouchesLength; 511 unsigned changedTouchesLength;
492 // List of all touches whose state has changed since the last WebTouchEvent 512 // List of all touches whose state has changed since the last WebTouchEvent
493 WebTouchPoint changedTouches[touchesLengthCap]; 513 WebTouchPoint changedTouches[touchesLengthCap];
494 514
495 unsigned targetTouchesLength; 515 unsigned targetTouchesLength;
496 // List of all touches which are currently down and are targeting the event recipient. 516 // List of all touches which are currently down and are targeting the event recipient.
497 WebTouchPoint targetTouches[touchesLengthCap]; 517 WebTouchPoint targetTouches[touchesLengthCap];
498 518
499 WebTouchEvent(unsigned sizeParam = sizeof(WebTouchEvent)) 519 WebTouchEvent()
500 : WebInputEvent(sizeParam) 520 : WebInputEvent(sizeof(WebTouchEvent))
501 , touchesLength(0) 521 , touchesLength(0)
502 , changedTouchesLength(0) 522 , changedTouchesLength(0)
503 , targetTouchesLength(0) 523 , targetTouchesLength(0)
504 { 524 {
505 } 525 }
506 }; 526 };
507 527
508 #pragma pack(pop) 528 #pragma pack(pop)
509 529
510 } // namespace blink 530 } // namespace blink
511 531
512 #endif 532 #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