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

Side by Side Diff: ui/events/event.h

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow manipulation of pointer details after construction Created 5 years, 4 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 | ui/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_EVENTS_EVENT_H_ 5 #ifndef UI_EVENTS_EVENT_H_
6 #define UI_EVENTS_EVENT_H_ 6 #define UI_EVENTS_EVENT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/event_types.h" 10 #include "base/event_types.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::TimeDelta time_stamp, 315 base::TimeDelta time_stamp,
316 int flags); 316 int flags);
317 317
318 gfx::PointF location_; 318 gfx::PointF location_;
319 319
320 // |location_| multiplied by an optional transformation matrix for 320 // |location_| multiplied by an optional transformation matrix for
321 // rotations, animations and skews. 321 // rotations, animations and skews.
322 gfx::PointF root_location_; 322 gfx::PointF root_location_;
323 }; 323 };
324 324
325 // Structure for handling common fields between touch and mouse to support
326 // PointerEvents API.
327 class EVENTS_EXPORT PointerDetails {
328 public:
329 PointerDetails() {}
330 explicit PointerDetails(EventPointerType pointer_type)
331 : pointer_type_(pointer_type) {}
332 PointerDetails(EventPointerType pointer_type,
333 float radius_x,
334 float radius_y,
335 float force,
336 float tilt_x,
337 float tilt_y)
338 : pointer_type_(pointer_type),
339 radius_x_(radius_x),
340 radius_y_(radius_y),
341 force_(force),
342 tilt_x_(tilt_x),
343 tilt_y_(tilt_y) {}
344
345 EventPointerType pointer_type() const { return pointer_type_; };
346
347 // If we aren't provided with a radius on one axis, use the
348 // information from the other axis.
349 float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; }
350 float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; }
351 float force() const { return force_; }
352 float tilt_x() const { return tilt_x_; }
353 float tilt_y() const { return tilt_y_; }
354
355 void set_pointer_type(EventPointerType type) { pointer_type_ = type; }
356 void set_radius_x(float r) { radius_x_ = r; }
357 void set_radius_y(float r) { radius_y_ = r; }
358 void set_force(float f) { force_ = f; }
359 void set_tilt_x(float t) { tilt_x_ = t; }
360 void set_tilt_y(float t) { tilt_y_ = t; }
361
362 private:
363 // The type of pointer device.
364 EventPointerType pointer_type_ = EventPointerType::POINTER_TYPE_UNKNOWN;
365
366 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
367 float radius_x_ = 0.0;
368
369 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
370 float radius_y_ = 0.0;
371
372 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
373 float force_ = 0.0;
374
375 // Angle of tilt of the X (major) axis. 0.0 if unknown.
376 float tilt_x_ = 0.0;
377
378 // Angle of tilt of the Y (minor) axis. 0.0 if unknown.
379 float tilt_y_ = 0.0;
380 };
381
325 class EVENTS_EXPORT MouseEvent : public LocatedEvent { 382 class EVENTS_EXPORT MouseEvent : public LocatedEvent {
326 public: 383 public:
327 explicit MouseEvent(const base::NativeEvent& native_event); 384 explicit MouseEvent(const base::NativeEvent& native_event);
328 385
329 // Create a new MouseEvent based on the provided model. 386 // Create a new MouseEvent based on the provided model.
330 // Uses the provided |type| and |flags| for the new event. 387 // Uses the provided |type| and |flags| for the new event.
331 // If source / target windows are provided, the model location will be 388 // If source / target windows are provided, the model location will be
332 // converted from |source| coordinate system to |target| coordinate system. 389 // converted from |source| coordinate system to |target| coordinate system.
333 template <class T> 390 template <class T>
334 MouseEvent(const MouseEvent& model, T* source, T* target) 391 MouseEvent(const MouseEvent& model, T* source, T* target)
335 : LocatedEvent(model, source, target), 392 : LocatedEvent(model, source, target),
336 changed_button_flags_(model.changed_button_flags_) { 393 changed_button_flags_(model.changed_button_flags_),
337 } 394 pointer_details_(model.pointer_details_) {}
338 395
339 template <class T> 396 template <class T>
340 MouseEvent(const MouseEvent& model, 397 MouseEvent(const MouseEvent& model,
341 T* source, 398 T* source,
342 T* target, 399 T* target,
343 EventType type, 400 EventType type,
344 int flags) 401 int flags)
345 : LocatedEvent(model, source, target), 402 : LocatedEvent(model, source, target),
346 changed_button_flags_(model.changed_button_flags_) { 403 changed_button_flags_(model.changed_button_flags_),
404 pointer_details_(model.pointer_details_) {
347 SetType(type); 405 SetType(type);
348 set_flags(flags); 406 set_flags(flags);
349 } 407 }
350 408
351 // Used for synthetic events in testing, gesture recognizer and Ozone 409 // Used for synthetic events in testing, gesture recognizer and Ozone
352 MouseEvent(EventType type, 410 MouseEvent(EventType type,
353 const gfx::PointF& location, 411 const gfx::PointF& location,
354 const gfx::PointF& root_location, 412 const gfx::PointF& root_location,
355 base::TimeDelta time_stamp, 413 base::TimeDelta time_stamp,
356 int flags, 414 int flags,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // Identifies the button that changed. During a press this corresponds to the 458 // Identifies the button that changed. During a press this corresponds to the
401 // button that was pressed and during a release this corresponds to the button 459 // button that was pressed and during a release this corresponds to the button
402 // that was released. 460 // that was released.
403 // NOTE: during a press and release flags() contains the complete set of 461 // NOTE: during a press and release flags() contains the complete set of
404 // flags. Use this to determine the button that was pressed or released. 462 // flags. Use this to determine the button that was pressed or released.
405 int changed_button_flags() const { return changed_button_flags_; } 463 int changed_button_flags() const { return changed_button_flags_; }
406 464
407 // Updates the button that changed. 465 // Updates the button that changed.
408 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } 466 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; }
409 467
468 // Event details common to MouseEvent and TouchEvent.
469 PointerDetails* pointer_details() { return &pointer_details_; }
470
410 private: 471 private:
411 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); 472 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease);
412 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); 473 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft);
413 474
414 // Returns the flags for the mouse buttons. 475 // Returns the flags for the mouse buttons.
415 int button_flags() const { 476 int button_flags() const {
416 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | 477 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON |
417 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | 478 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON |
418 EF_FORWARD_MOUSE_BUTTON); 479 EF_FORWARD_MOUSE_BUTTON);
419 } 480 }
420 481
421 // Returns the repeat count based on the previous mouse click, if it is 482 // Returns the repeat count based on the previous mouse click, if it is
422 // recent enough and within a small enough distance. 483 // recent enough and within a small enough distance.
423 static int GetRepeatCount(const MouseEvent& click_event); 484 static int GetRepeatCount(const MouseEvent& click_event);
424 485
425 // Resets the last_click_event_ for unit tests. 486 // Resets the last_click_event_ for unit tests.
426 static void ResetLastClickForTest(); 487 static void ResetLastClickForTest();
427 488
428 // See description above getter for details. 489 // See description above getter for details.
429 int changed_button_flags_; 490 int changed_button_flags_;
430 491
431 static MouseEvent* last_click_event_; 492 static MouseEvent* last_click_event_;
432 493
433 // We can create a MouseEvent for a native event more than once. We set this 494 // We can create a MouseEvent for a native event more than once. We set this
434 // to true when the next event either has a different timestamp or we see a 495 // to true when the next event either has a different timestamp or we see a
435 // release signalling that the press (click) event was completed. 496 // release signalling that the press (click) event was completed.
436 static bool last_click_complete_; 497 static bool last_click_complete_;
498
499 // Structure for holding pointer details for implementing PointerEvents API.
500 PointerDetails pointer_details_;
437 }; 501 };
438 502
439 class ScrollEvent; 503 class ScrollEvent;
440 504
441 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { 505 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent {
442 public: 506 public:
443 // See |offset| for details. 507 // See |offset| for details.
444 static const int kWheelDelta; 508 static const int kWheelDelta;
445 509
446 explicit MouseWheelEvent(const base::NativeEvent& native_event); 510 explicit MouseWheelEvent(const base::NativeEvent& native_event);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 explicit TouchEvent(const base::NativeEvent& native_event); 543 explicit TouchEvent(const base::NativeEvent& native_event);
480 544
481 // Create a new TouchEvent which is identical to the provided model. 545 // Create a new TouchEvent which is identical to the provided model.
482 // If source / target windows are provided, the model location will be 546 // If source / target windows are provided, the model location will be
483 // converted from |source| coordinate system to |target| coordinate system. 547 // converted from |source| coordinate system to |target| coordinate system.
484 template <class T> 548 template <class T>
485 TouchEvent(const TouchEvent& model, T* source, T* target) 549 TouchEvent(const TouchEvent& model, T* source, T* target)
486 : LocatedEvent(model, source, target), 550 : LocatedEvent(model, source, target),
487 touch_id_(model.touch_id_), 551 touch_id_(model.touch_id_),
488 unique_event_id_(model.unique_event_id_), 552 unique_event_id_(model.unique_event_id_),
489 radius_x_(model.radius_x_),
490 radius_y_(model.radius_y_),
491 rotation_angle_(model.rotation_angle_), 553 rotation_angle_(model.rotation_angle_),
492 force_(model.force_),
493 may_cause_scrolling_(model.may_cause_scrolling_), 554 may_cause_scrolling_(model.may_cause_scrolling_),
494 should_remove_native_touch_id_mapping_(false) {} 555 should_remove_native_touch_id_mapping_(false),
556 pointer_details_(model.pointer_details_) {}
495 557
496 TouchEvent(EventType type, 558 TouchEvent(EventType type,
497 const gfx::PointF& location, 559 const gfx::PointF& location,
498 int touch_id, 560 int touch_id,
499 base::TimeDelta time_stamp); 561 base::TimeDelta time_stamp);
500 562
501 TouchEvent(EventType type, 563 TouchEvent(EventType type,
502 const gfx::PointF& location, 564 const gfx::PointF& location,
503 int flags, 565 int flags,
504 int touch_id, 566 int touch_id,
505 base::TimeDelta timestamp, 567 base::TimeDelta timestamp,
506 float radius_x, 568 float radius_x,
507 float radius_y, 569 float radius_y,
508 float angle, 570 float angle,
509 float force); 571 float force);
510 572
511 TouchEvent(const TouchEvent& copy); 573 TouchEvent(const TouchEvent& copy);
512 574
513 ~TouchEvent() override; 575 ~TouchEvent() override;
514 576
515 // The id of the pointer this event modifies. 577 // The id of the pointer this event modifies.
516 int touch_id() const { return touch_id_; } 578 int touch_id() const { return touch_id_; }
517 // A unique identifier for this event. 579 // A unique identifier for this event.
518 uint32 unique_event_id() const { return unique_event_id_; } 580 uint32 unique_event_id() const { return unique_event_id_; }
519 // If we aren't provided with a radius on one axis, use the 581
520 // information from the other axis. 582 // TODO(robert.bradford): Drop these shims.
521 float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; } 583 float radius_x() const { return pointer_details_.radius_x(); }
522 float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; } 584 float radius_y() const { return pointer_details_.radius_y(); }
585 float force() const { return pointer_details_.force(); }
586
523 float rotation_angle() const { return rotation_angle_; } 587 float rotation_angle() const { return rotation_angle_; }
524 float force() const { return force_; }
525 588
526 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } 589 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; }
527 bool may_cause_scrolling() const { return may_cause_scrolling_; } 590 bool may_cause_scrolling() const { return may_cause_scrolling_; }
528 591
529 // Used for unit tests. 592 // TODO(robert.bradford): ozone_platform_egltest.cc could use
530 void set_radius_x(const float r) { radius_x_ = r; } 593 // UpdateForRootTransform() instead: crbug.com/519337
531 void set_radius_y(const float r) { radius_y_ = r; } 594 void set_radius_x(const float r) { pointer_details()->set_radius_x(r); }
595 void set_radius_y(const float r) { pointer_details()->set_radius_y(r); }
532 596
533 void set_should_remove_native_touch_id_mapping( 597 void set_should_remove_native_touch_id_mapping(
534 bool should_remove_native_touch_id_mapping) { 598 bool should_remove_native_touch_id_mapping) {
535 should_remove_native_touch_id_mapping_ = 599 should_remove_native_touch_id_mapping_ =
536 should_remove_native_touch_id_mapping; 600 should_remove_native_touch_id_mapping;
537 } 601 }
538 602
539 // Overridden from LocatedEvent. 603 // Overridden from LocatedEvent.
540 void UpdateForRootTransform( 604 void UpdateForRootTransform(
541 const gfx::Transform& inverted_root_transform) override; 605 const gfx::Transform& inverted_root_transform) override;
542 606
543 // Marks the event as not participating in synchronous gesture recognition. 607 // Marks the event as not participating in synchronous gesture recognition.
544 void DisableSynchronousHandling(); 608 void DisableSynchronousHandling();
545 bool synchronous_handling_disabled() const { 609 bool synchronous_handling_disabled() const {
546 return !!(result() & ER_DISABLE_SYNC_HANDLING); 610 return !!(result() & ER_DISABLE_SYNC_HANDLING);
547 } 611 }
548 612
613 // Event details common to MouseEvent and TouchEvent.
614 PointerDetails* pointer_details() { return &pointer_details_; }
sadrul 2015/08/17 14:44:43 Can this return a const& instead? The callers sho
615
549 private: 616 private:
550 // Adjusts rotation_angle_ to within the acceptable range. 617 // Adjusts rotation_angle_ to within the acceptable range.
551 void FixRotationAngle(); 618 void FixRotationAngle();
552 619
553 // The identity (typically finger) of the touch starting at 0 and incrementing 620 // The identity (typically finger) of the touch starting at 0 and incrementing
554 // for each separable additional touch that the hardware can detect. 621 // for each separable additional touch that the hardware can detect.
555 const int touch_id_; 622 const int touch_id_;
556 623
557 // A unique identifier for the touch event. 624 // A unique identifier for the touch event.
558 const uint32 unique_event_id_; 625 const uint32 unique_event_id_;
559 626
560 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
561 float radius_x_;
562
563 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
564 float radius_y_;
565
566 // Clockwise angle (in degrees) of the major axis from the X axis. Must be 627 // Clockwise angle (in degrees) of the major axis from the X axis. Must be
567 // less than 180 and non-negative. 628 // less than 180 and non-negative.
568 float rotation_angle_; 629 float rotation_angle_;
569 630
570 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
571 float force_;
572
573 // Whether the (unhandled) touch event will produce a scroll event (e.g., a 631 // Whether the (unhandled) touch event will produce a scroll event (e.g., a
574 // touchmove that exceeds the platform slop region, or a touchend that 632 // touchmove that exceeds the platform slop region, or a touchend that
575 // causes a fling). Defaults to false. 633 // causes a fling). Defaults to false.
576 bool may_cause_scrolling_; 634 bool may_cause_scrolling_;
577 635
578 // True if this event should remove the mapping between the native 636 // True if this event should remove the mapping between the native
579 // event id and the touch_id_. This should only be the case for 637 // event id and the touch_id_. This should only be the case for
580 // release and cancel events where the associated touch press event 638 // release and cancel events where the associated touch press event
581 // created a mapping between the native id and the touch_id_. 639 // created a mapping between the native id and the touch_id_.
582 bool should_remove_native_touch_id_mapping_; 640 bool should_remove_native_touch_id_mapping_;
641
642 // Structure for holding pointer details for implementing PointerEvents API.
643 PointerDetails pointer_details_;
583 }; 644 };
584 645
585 // An interface that individual platforms can use to store additional data on 646 // An interface that individual platforms can use to store additional data on
586 // KeyEvent. 647 // KeyEvent.
587 // 648 //
588 // Currently only used in mojo. 649 // Currently only used in mojo.
589 class EVENTS_EXPORT ExtendedKeyEventData { 650 class EVENTS_EXPORT ExtendedKeyEventData {
590 public: 651 public:
591 virtual ~ExtendedKeyEventData() {} 652 virtual ~ExtendedKeyEventData() {}
592 653
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 932
872 const GestureEventDetails& details() const { return details_; } 933 const GestureEventDetails& details() const { return details_; }
873 934
874 private: 935 private:
875 GestureEventDetails details_; 936 GestureEventDetails details_;
876 }; 937 };
877 938
878 } // namespace ui 939 } // namespace ui
879 940
880 #endif // UI_EVENTS_EVENT_H_ 941 #endif // UI_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698