| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | |
| 10 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 11 #include "base/event_types.h" | 10 #include "base/event_types.h" |
| 12 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 17 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 18 #include "ui/events/gesture_event_details.h" | 17 #include "ui/events/gesture_event_details.h" |
| 19 #include "ui/events/gestures/gesture_types.h" | 18 #include "ui/events/gestures/gesture_types.h" |
| 20 #include "ui/events/keycodes/dom/dom_key.h" | 19 #include "ui/events/keycodes/dom/dom_key.h" |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 #include "ui/events/latency_info.h" | 21 #include "ui/events/latency_info.h" |
| 23 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 24 #include "ui/gfx/geometry/point_conversions.h" | 23 #include "ui/gfx/geometry/point_conversions.h" |
| 25 | 24 |
| 26 namespace gfx { | 25 namespace gfx { |
| 27 class Transform; | 26 class Transform; |
| 28 } | 27 } |
| 29 | 28 |
| 29 namespace IPC { |
| 30 template <class P> struct ParamTraits; |
| 31 } |
| 32 |
| 30 namespace ui { | 33 namespace ui { |
| 31 class EventTarget; | 34 class EventTarget; |
| 32 class KeyEvent; | 35 class KeyEvent; |
| 33 class MouseEvent; | 36 class MouseEvent; |
| 34 class MouseWheelEvent; | 37 class MouseWheelEvent; |
| 35 class PointerEvent; | 38 class PointerEvent; |
| 36 class ScrollEvent; | 39 class ScrollEvent; |
| 37 class TouchEvent; | 40 class TouchEvent; |
| 38 enum class DomCode; | 41 enum class DomCode; |
| 42 class Event; |
| 43 class MouseWheelEvent; |
| 44 |
| 45 using ScopedEvent = scoped_ptr<Event>; |
| 39 | 46 |
| 40 class EVENTS_EXPORT Event { | 47 class EVENTS_EXPORT Event { |
| 41 public: | 48 public: |
| 42 static scoped_ptr<Event> Clone(const Event& event); | 49 static scoped_ptr<Event> Clone(const Event& event); |
| 43 | 50 |
| 44 virtual ~Event(); | 51 virtual ~Event(); |
| 45 | 52 |
| 46 class DispatcherApi { | 53 class DispatcherApi { |
| 47 public: | 54 public: |
| 48 explicit DispatcherApi(Event* event) : event_(event) {} | 55 explicit DispatcherApi(Event* event) : event_(event) {} |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 282 |
| 276 void set_time_stamp(const base::TimeDelta& time_stamp) { | 283 void set_time_stamp(const base::TimeDelta& time_stamp) { |
| 277 time_stamp_ = time_stamp; | 284 time_stamp_ = time_stamp; |
| 278 } | 285 } |
| 279 | 286 |
| 280 void set_name(const std::string& name) { name_ = name; } | 287 void set_name(const std::string& name) { name_ = name; } |
| 281 | 288 |
| 282 private: | 289 private: |
| 283 friend class EventTestApi; | 290 friend class EventTestApi; |
| 284 | 291 |
| 292 // For (de)serialization. |
| 293 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 294 |
| 285 EventType type_; | 295 EventType type_; |
| 286 std::string name_; | 296 std::string name_; |
| 287 base::TimeDelta time_stamp_; | 297 base::TimeDelta time_stamp_; |
| 288 LatencyInfo latency_; | 298 LatencyInfo latency_; |
| 289 int flags_; | 299 int flags_; |
| 290 base::NativeEvent native_event_; | 300 base::NativeEvent native_event_; |
| 291 bool delete_native_event_; | 301 bool delete_native_event_; |
| 292 bool cancelable_; | 302 bool cancelable_; |
| 293 EventTarget* target_; | 303 EventTarget* target_; |
| 294 EventPhase phase_; | 304 EventPhase phase_; |
| 295 EventResult result_; | 305 EventResult result_; |
| 296 | 306 |
| 297 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 307 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
| 298 // is not available. | 308 // is not available. |
| 299 int source_device_id_; | 309 int source_device_id_; |
| 300 }; | 310 }; |
| 301 | 311 |
| 302 class EVENTS_EXPORT CancelModeEvent : public Event { | 312 class EVENTS_EXPORT CancelModeEvent : public Event { |
| 303 public: | 313 public: |
| 304 CancelModeEvent(); | 314 CancelModeEvent(); |
| 305 ~CancelModeEvent() override; | 315 ~CancelModeEvent() override; |
| 316 |
| 317 private: |
| 318 // For (de)serialization. |
| 319 CancelModeEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 320 : Event(type, time_stamp, flags) {} |
| 321 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 322 friend struct IPC::ParamTraits<ui::CancelModeEvent>; |
| 306 }; | 323 }; |
| 307 | 324 |
| 308 class EVENTS_EXPORT LocatedEvent : public Event { | 325 class EVENTS_EXPORT LocatedEvent : public Event { |
| 309 public: | 326 public: |
| 310 ~LocatedEvent() override; | 327 ~LocatedEvent() override; |
| 311 | 328 |
| 312 float x() const { return location_.x(); } | 329 float x() const { return location_.x(); } |
| 313 float y() const { return location_.y(); } | 330 float y() const { return location_.y(); } |
| 314 void set_location(const gfx::Point& location) { | 331 void set_location(const gfx::Point& location) { |
| 315 location_ = gfx::PointF(location); | 332 location_ = gfx::PointF(location); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 339 if (!target || target == source) | 356 if (!target || target == source) |
| 340 return; | 357 return; |
| 341 gfx::Point offset = gfx::ToFlooredPoint(location_); | 358 gfx::Point offset = gfx::ToFlooredPoint(location_); |
| 342 T::ConvertPointToTarget(source, target, &offset); | 359 T::ConvertPointToTarget(source, target, &offset); |
| 343 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 360 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
| 344 location_= location_ - diff; | 361 location_= location_ - diff; |
| 345 } | 362 } |
| 346 | 363 |
| 347 protected: | 364 protected: |
| 348 friend class LocatedEventTestApi; | 365 friend class LocatedEventTestApi; |
| 366 |
| 367 // For (de)serialization. |
| 368 LocatedEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 369 : Event(type, time_stamp, flags) {} |
| 370 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 371 friend struct IPC::ParamTraits<ui::LocatedEvent>; |
| 372 |
| 349 explicit LocatedEvent(const base::NativeEvent& native_event); | 373 explicit LocatedEvent(const base::NativeEvent& native_event); |
| 350 | 374 |
| 351 // Create a new LocatedEvent which is identical to the provided model. | 375 // Create a new LocatedEvent which is identical to the provided model. |
| 352 // If source / target windows are provided, the model location will be | 376 // If source / target windows are provided, the model location will be |
| 353 // converted from |source| coordinate system to |target| coordinate system. | 377 // converted from |source| coordinate system to |target| coordinate system. |
| 354 template <class T> | 378 template <class T> |
| 355 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 379 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
| 356 : Event(model), | 380 : Event(model), |
| 357 location_(model.location_), | 381 location_(model.location_), |
| 358 root_location_(model.root_location_) { | 382 root_location_(model.root_location_) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 bool operator==(const PointerDetails& other) const { | 423 bool operator==(const PointerDetails& other) const { |
| 400 return pointer_type == other.pointer_type && | 424 return pointer_type == other.pointer_type && |
| 401 radius_x == other.radius_x && | 425 radius_x == other.radius_x && |
| 402 radius_y == other.radius_y && | 426 radius_y == other.radius_y && |
| 403 (force == other.force || | 427 (force == other.force || |
| 404 (std::isnan(force) && std::isnan(other.force))) && | 428 (std::isnan(force) && std::isnan(other.force))) && |
| 405 tilt_x == other.tilt_x && | 429 tilt_x == other.tilt_x && |
| 406 tilt_y == other.tilt_y; | 430 tilt_y == other.tilt_y; |
| 407 } | 431 } |
| 408 | 432 |
| 433 // For serialization. |
| 434 friend struct IPC::ParamTraits<ui::PointerDetails>; |
| 435 |
| 409 // The type of pointer device. | 436 // The type of pointer device. |
| 410 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 437 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
| 411 | 438 |
| 412 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 439 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
| 413 float radius_x = 0.0; | 440 float radius_x = 0.0; |
| 414 | 441 |
| 415 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 442 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| 416 float radius_y = 0.0; | 443 float radius_y = 0.0; |
| 417 | 444 |
| 418 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means | 445 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 545 |
| 519 // Updates the button that changed. | 546 // Updates the button that changed. |
| 520 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 547 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
| 521 | 548 |
| 522 // Event details common to MouseEvent and TouchEvent. | 549 // Event details common to MouseEvent and TouchEvent. |
| 523 const PointerDetails& pointer_details() const { return pointer_details_; } | 550 const PointerDetails& pointer_details() const { return pointer_details_; } |
| 524 void set_pointer_details(const PointerDetails& details) { | 551 void set_pointer_details(const PointerDetails& details) { |
| 525 pointer_details_ = details; | 552 pointer_details_ = details; |
| 526 } | 553 } |
| 527 | 554 |
| 555 protected: |
| 556 // For (de)serialization. |
| 557 MouseEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 558 : LocatedEvent(type, time_stamp, flags) {} |
| 559 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 560 friend struct IPC::ParamTraits<ui::MouseEvent>; |
| 561 |
| 528 private: | 562 private: |
| 529 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 563 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
| 530 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 564 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
| 531 | 565 |
| 532 // Returns the repeat count based on the previous mouse click, if it is | 566 // Returns the repeat count based on the previous mouse click, if it is |
| 533 // recent enough and within a small enough distance. | 567 // recent enough and within a small enough distance. |
| 534 static int GetRepeatCount(const MouseEvent& click_event); | 568 static int GetRepeatCount(const MouseEvent& click_event); |
| 535 | 569 |
| 536 // Resets the last_click_event_ for unit tests. | 570 // Resets the last_click_event_ for unit tests. |
| 537 static void ResetLastClickForTest(); | 571 static void ResetLastClickForTest(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 int flags, | 612 int flags, |
| 579 int changed_button_flags); | 613 int changed_button_flags); |
| 580 | 614 |
| 581 // The amount to scroll. This is in multiples of kWheelDelta. | 615 // The amount to scroll. This is in multiples of kWheelDelta. |
| 582 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 616 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
| 583 int x_offset() const { return offset_.x(); } | 617 int x_offset() const { return offset_.x(); } |
| 584 int y_offset() const { return offset_.y(); } | 618 int y_offset() const { return offset_.y(); } |
| 585 const gfx::Vector2d& offset() const { return offset_; } | 619 const gfx::Vector2d& offset() const { return offset_; } |
| 586 | 620 |
| 587 private: | 621 private: |
| 622 // For (de)serialization. |
| 623 MouseWheelEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 624 : MouseEvent(type, time_stamp, flags) {} |
| 625 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 626 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; |
| 627 |
| 588 gfx::Vector2d offset_; | 628 gfx::Vector2d offset_; |
| 589 }; | 629 }; |
| 590 | 630 |
| 591 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 631 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
| 592 public: | 632 public: |
| 593 explicit TouchEvent(const base::NativeEvent& native_event); | 633 explicit TouchEvent(const base::NativeEvent& native_event); |
| 594 | 634 |
| 595 // Create a new TouchEvent which is identical to the provided model. | 635 // Create a new TouchEvent which is identical to the provided model. |
| 596 // If source / target windows are provided, the model location will be | 636 // If source / target windows are provided, the model location will be |
| 597 // converted from |source| coordinate system to |target| coordinate system. | 637 // converted from |source| coordinate system to |target| coordinate system. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 690 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
| 651 } | 691 } |
| 652 | 692 |
| 653 // Event details common to MouseEvent and TouchEvent. | 693 // Event details common to MouseEvent and TouchEvent. |
| 654 const PointerDetails& pointer_details() const { return pointer_details_; } | 694 const PointerDetails& pointer_details() const { return pointer_details_; } |
| 655 void set_pointer_details(const PointerDetails& pointer_details) { | 695 void set_pointer_details(const PointerDetails& pointer_details) { |
| 656 pointer_details_ = pointer_details; | 696 pointer_details_ = pointer_details; |
| 657 } | 697 } |
| 658 | 698 |
| 659 private: | 699 private: |
| 700 // For (de)serialization. |
| 701 TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 702 : LocatedEvent(type, time_stamp, flags), |
| 703 should_remove_native_touch_id_mapping_(false) {} |
| 704 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 705 friend struct IPC::ParamTraits<ui::TouchEvent>; |
| 706 |
| 660 // Adjusts rotation_angle_ to within the acceptable range. | 707 // Adjusts rotation_angle_ to within the acceptable range. |
| 661 void FixRotationAngle(); | 708 void FixRotationAngle(); |
| 662 | 709 |
| 663 // The identity (typically finger) of the touch starting at 0 and incrementing | 710 // The identity (typically finger) of the touch starting at 0 and incrementing |
| 664 // for each separable additional touch that the hardware can detect. | 711 // for each separable additional touch that the hardware can detect. |
| 665 const int touch_id_; | 712 int touch_id_; |
| 666 | 713 |
| 667 // A unique identifier for the touch event. | 714 // A unique identifier for the touch event. |
| 668 const uint32_t unique_event_id_; | 715 uint32_t unique_event_id_; |
| 669 | 716 |
| 670 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 717 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
| 671 // less than 180 and non-negative. | 718 // less than 180 and non-negative. |
| 672 float rotation_angle_; | 719 float rotation_angle_; |
| 673 | 720 |
| 674 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 721 // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
| 675 // touchmove that exceeds the platform slop region, or a touchend that | 722 // touchmove that exceeds the platform slop region, or a touchend that |
| 676 // causes a fling). Defaults to false. | 723 // causes a fling). Defaults to false. |
| 677 bool may_cause_scrolling_; | 724 bool may_cause_scrolling_; |
| 678 | 725 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 // (Native X11 event flags describe the state before the event.) | 915 // (Native X11 event flags describe the state before the event.) |
| 869 void NormalizeFlags(); | 916 void NormalizeFlags(); |
| 870 | 917 |
| 871 protected: | 918 protected: |
| 872 friend class KeyEventTestApi; | 919 friend class KeyEventTestApi; |
| 873 | 920 |
| 874 // This allows a subclass TranslatedKeyEvent to be a non character event. | 921 // This allows a subclass TranslatedKeyEvent to be a non character event. |
| 875 void set_is_char(bool is_char) { is_char_ = is_char; } | 922 void set_is_char(bool is_char) { is_char_ = is_char; } |
| 876 | 923 |
| 877 private: | 924 private: |
| 925 // For (de)serialization. |
| 926 KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); |
| 927 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 928 friend struct IPC::ParamTraits<ui::KeyEvent>; |
| 929 |
| 878 // Determine key_ on a keystroke event from code_ and flags(). | 930 // Determine key_ on a keystroke event from code_ and flags(). |
| 879 void ApplyLayout() const; | 931 void ApplyLayout() const; |
| 880 | 932 |
| 881 KeyboardCode key_code_; | 933 KeyboardCode key_code_; |
| 882 | 934 |
| 883 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 935 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
| 884 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 936 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
| 885 // | 937 // |
| 886 // This value represents the physical position in the keyboard and can be | 938 // This value represents the physical position in the keyboard and can be |
| 887 // converted from / to keyboard scan code like XKB. | 939 // converted from / to keyboard scan code like XKB. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 // to provide a consistent user experience. | 998 // to provide a consistent user experience. |
| 947 void Scale(const float factor); | 999 void Scale(const float factor); |
| 948 | 1000 |
| 949 float x_offset() const { return x_offset_; } | 1001 float x_offset() const { return x_offset_; } |
| 950 float y_offset() const { return y_offset_; } | 1002 float y_offset() const { return y_offset_; } |
| 951 float x_offset_ordinal() const { return x_offset_ordinal_; } | 1003 float x_offset_ordinal() const { return x_offset_ordinal_; } |
| 952 float y_offset_ordinal() const { return y_offset_ordinal_; } | 1004 float y_offset_ordinal() const { return y_offset_ordinal_; } |
| 953 int finger_count() const { return finger_count_; } | 1005 int finger_count() const { return finger_count_; } |
| 954 | 1006 |
| 955 private: | 1007 private: |
| 1008 // For (de)serialization. |
| 1009 ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 1010 : MouseEvent(type, time_stamp, flags) {} |
| 1011 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 1012 friend struct IPC::ParamTraits<ui::ScrollEvent>; |
| 1013 |
| 956 // Potential accelerated offsets. | 1014 // Potential accelerated offsets. |
| 957 float x_offset_; | 1015 float x_offset_; |
| 958 float y_offset_; | 1016 float y_offset_; |
| 959 // Unaccelerated offsets. | 1017 // Unaccelerated offsets. |
| 960 float x_offset_ordinal_; | 1018 float x_offset_ordinal_; |
| 961 float y_offset_ordinal_; | 1019 float y_offset_ordinal_; |
| 962 // Number of fingers on the pad. | 1020 // Number of fingers on the pad. |
| 963 int finger_count_; | 1021 int finger_count_; |
| 964 }; | 1022 }; |
| 965 | 1023 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 978 GestureEvent(const GestureEvent& model, T* source, T* target) | 1036 GestureEvent(const GestureEvent& model, T* source, T* target) |
| 979 : LocatedEvent(model, source, target), | 1037 : LocatedEvent(model, source, target), |
| 980 details_(model.details_) { | 1038 details_(model.details_) { |
| 981 } | 1039 } |
| 982 | 1040 |
| 983 ~GestureEvent() override; | 1041 ~GestureEvent() override; |
| 984 | 1042 |
| 985 const GestureEventDetails& details() const { return details_; } | 1043 const GestureEventDetails& details() const { return details_; } |
| 986 | 1044 |
| 987 private: | 1045 private: |
| 1046 // For (de)serialization. |
| 1047 GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 1048 : LocatedEvent(type, time_stamp, flags) {} |
| 1049 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 1050 friend struct IPC::ParamTraits<ui::GestureEvent>; |
| 1051 |
| 988 GestureEventDetails details_; | 1052 GestureEventDetails details_; |
| 989 }; | 1053 }; |
| 990 | 1054 |
| 991 } // namespace ui | 1055 } // namespace ui |
| 992 | 1056 |
| 993 #endif // UI_EVENTS_EVENT_H_ | 1057 #endif // UI_EVENTS_EVENT_H_ |
| OLD | NEW |