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