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 enum class DomCode; | 35 enum class DomCode; |
| 36 class Event; |
| 37 class MouseWheelEvent; |
| 38 |
| 39 using ScopedEvent = scoped_ptr<Event>; |
33 | 40 |
34 class EVENTS_EXPORT Event { | 41 class EVENTS_EXPORT Event { |
35 public: | 42 public: |
36 static scoped_ptr<Event> Clone(const Event& event); | 43 static scoped_ptr<Event> Clone(const Event& event); |
37 | 44 |
38 virtual ~Event(); | 45 virtual ~Event(); |
39 | 46 |
40 class DispatcherApi { | 47 class DispatcherApi { |
41 public: | 48 public: |
42 explicit DispatcherApi(Event* event) : event_(event) {} | 49 explicit DispatcherApi(Event* event) : event_(event) {} |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 240 |
234 void set_time_stamp(const base::TimeDelta& time_stamp) { | 241 void set_time_stamp(const base::TimeDelta& time_stamp) { |
235 time_stamp_ = time_stamp; | 242 time_stamp_ = time_stamp; |
236 } | 243 } |
237 | 244 |
238 void set_name(const std::string& name) { name_ = name; } | 245 void set_name(const std::string& name) { name_ = name; } |
239 | 246 |
240 private: | 247 private: |
241 friend class EventTestApi; | 248 friend class EventTestApi; |
242 | 249 |
| 250 // For (de)serialization. |
| 251 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 252 |
243 EventType type_; | 253 EventType type_; |
244 std::string name_; | 254 std::string name_; |
245 base::TimeDelta time_stamp_; | 255 base::TimeDelta time_stamp_; |
246 LatencyInfo latency_; | 256 LatencyInfo latency_; |
247 int flags_; | 257 int flags_; |
248 base::NativeEvent native_event_; | 258 base::NativeEvent native_event_; |
249 bool delete_native_event_; | 259 bool delete_native_event_; |
250 bool cancelable_; | 260 bool cancelable_; |
251 EventTarget* target_; | 261 EventTarget* target_; |
252 EventPhase phase_; | 262 EventPhase phase_; |
253 EventResult result_; | 263 EventResult result_; |
254 | 264 |
255 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 265 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
256 // is not available. | 266 // is not available. |
257 int source_device_id_; | 267 int source_device_id_; |
258 }; | 268 }; |
259 | 269 |
260 class EVENTS_EXPORT CancelModeEvent : public Event { | 270 class EVENTS_EXPORT CancelModeEvent : public Event { |
261 public: | 271 public: |
262 CancelModeEvent(); | 272 CancelModeEvent(); |
263 ~CancelModeEvent() override; | 273 ~CancelModeEvent() override; |
| 274 |
| 275 private: |
| 276 // For (de)serialization. |
| 277 CancelModeEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 278 : Event(type, time_stamp, flags) {} |
| 279 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 280 friend struct IPC::ParamTraits<ui::CancelModeEvent>; |
264 }; | 281 }; |
265 | 282 |
266 class EVENTS_EXPORT LocatedEvent : public Event { | 283 class EVENTS_EXPORT LocatedEvent : public Event { |
267 public: | 284 public: |
268 ~LocatedEvent() override; | 285 ~LocatedEvent() override; |
269 | 286 |
270 float x() const { return location_.x(); } | 287 float x() const { return location_.x(); } |
271 float y() const { return location_.y(); } | 288 float y() const { return location_.y(); } |
272 void set_location(const gfx::Point& location) { | 289 void set_location(const gfx::Point& location) { |
273 location_ = gfx::PointF(location); | 290 location_ = gfx::PointF(location); |
(...skipping 23 matching lines...) Expand all Loading... |
297 if (!target || target == source) | 314 if (!target || target == source) |
298 return; | 315 return; |
299 gfx::Point offset = gfx::ToFlooredPoint(location_); | 316 gfx::Point offset = gfx::ToFlooredPoint(location_); |
300 T::ConvertPointToTarget(source, target, &offset); | 317 T::ConvertPointToTarget(source, target, &offset); |
301 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 318 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
302 location_= location_ - diff; | 319 location_= location_ - diff; |
303 } | 320 } |
304 | 321 |
305 protected: | 322 protected: |
306 friend class LocatedEventTestApi; | 323 friend class LocatedEventTestApi; |
| 324 |
| 325 // For (de)serialization. |
| 326 LocatedEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 327 : Event(type, time_stamp, flags) {} |
| 328 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 329 friend struct IPC::ParamTraits<ui::LocatedEvent>; |
| 330 |
307 explicit LocatedEvent(const base::NativeEvent& native_event); | 331 explicit LocatedEvent(const base::NativeEvent& native_event); |
308 | 332 |
309 // Create a new LocatedEvent which is identical to the provided model. | 333 // Create a new LocatedEvent which is identical to the provided model. |
310 // If source / target windows are provided, the model location will be | 334 // If source / target windows are provided, the model location will be |
311 // converted from |source| coordinate system to |target| coordinate system. | 335 // converted from |source| coordinate system to |target| coordinate system. |
312 template <class T> | 336 template <class T> |
313 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 337 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
314 : Event(model), | 338 : Event(model), |
315 location_(model.location_), | 339 location_(model.location_), |
316 root_location_(model.root_location_) { | 340 root_location_(model.root_location_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 bool operator==(const PointerDetails& other) const { | 381 bool operator==(const PointerDetails& other) const { |
358 return pointer_type == other.pointer_type && | 382 return pointer_type == other.pointer_type && |
359 radius_x == other.radius_x && | 383 radius_x == other.radius_x && |
360 radius_y == other.radius_y && | 384 radius_y == other.radius_y && |
361 (force == other.force || | 385 (force == other.force || |
362 (std::isnan(force) && std::isnan(other.force))) && | 386 (std::isnan(force) && std::isnan(other.force))) && |
363 tilt_x == other.tilt_x && | 387 tilt_x == other.tilt_x && |
364 tilt_y == other.tilt_y; | 388 tilt_y == other.tilt_y; |
365 } | 389 } |
366 | 390 |
| 391 // For serialization. |
| 392 friend struct IPC::ParamTraits<ui::PointerDetails>; |
| 393 |
367 // The type of pointer device. | 394 // The type of pointer device. |
368 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 395 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
369 | 396 |
370 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 397 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
371 float radius_x = 0.0; | 398 float radius_x = 0.0; |
372 | 399 |
373 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 400 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
374 float radius_y = 0.0; | 401 float radius_y = 0.0; |
375 | 402 |
376 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means | 403 // 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... |
476 | 503 |
477 // Updates the button that changed. | 504 // Updates the button that changed. |
478 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 505 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
479 | 506 |
480 // Event details common to MouseEvent and TouchEvent. | 507 // Event details common to MouseEvent and TouchEvent. |
481 const PointerDetails& pointer_details() const { return pointer_details_; } | 508 const PointerDetails& pointer_details() const { return pointer_details_; } |
482 void set_pointer_details(const PointerDetails& details) { | 509 void set_pointer_details(const PointerDetails& details) { |
483 pointer_details_ = details; | 510 pointer_details_ = details; |
484 } | 511 } |
485 | 512 |
| 513 protected: |
| 514 // For (de)serialization. |
| 515 MouseEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 516 : LocatedEvent(type, time_stamp, flags) {} |
| 517 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 518 friend struct IPC::ParamTraits<ui::MouseEvent>; |
| 519 |
486 private: | 520 private: |
487 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 521 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
488 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 522 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
489 | 523 |
490 // Returns the repeat count based on the previous mouse click, if it is | 524 // Returns the repeat count based on the previous mouse click, if it is |
491 // recent enough and within a small enough distance. | 525 // recent enough and within a small enough distance. |
492 static int GetRepeatCount(const MouseEvent& click_event); | 526 static int GetRepeatCount(const MouseEvent& click_event); |
493 | 527 |
494 // Resets the last_click_event_ for unit tests. | 528 // Resets the last_click_event_ for unit tests. |
495 static void ResetLastClickForTest(); | 529 static void ResetLastClickForTest(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 int flags, | 570 int flags, |
537 int changed_button_flags); | 571 int changed_button_flags); |
538 | 572 |
539 // The amount to scroll. This is in multiples of kWheelDelta. | 573 // The amount to scroll. This is in multiples of kWheelDelta. |
540 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 574 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
541 int x_offset() const { return offset_.x(); } | 575 int x_offset() const { return offset_.x(); } |
542 int y_offset() const { return offset_.y(); } | 576 int y_offset() const { return offset_.y(); } |
543 const gfx::Vector2d& offset() const { return offset_; } | 577 const gfx::Vector2d& offset() const { return offset_; } |
544 | 578 |
545 private: | 579 private: |
| 580 // For (de)serialization. |
| 581 MouseWheelEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 582 : MouseEvent(type, time_stamp, flags) {} |
| 583 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 584 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; |
| 585 |
546 gfx::Vector2d offset_; | 586 gfx::Vector2d offset_; |
547 }; | 587 }; |
548 | 588 |
549 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 589 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
550 public: | 590 public: |
551 explicit TouchEvent(const base::NativeEvent& native_event); | 591 explicit TouchEvent(const base::NativeEvent& native_event); |
552 | 592 |
553 // Create a new TouchEvent which is identical to the provided model. | 593 // Create a new TouchEvent which is identical to the provided model. |
554 // If source / target windows are provided, the model location will be | 594 // If source / target windows are provided, the model location will be |
555 // converted from |source| coordinate system to |target| coordinate system. | 595 // converted from |source| coordinate system to |target| coordinate system. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 648 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
609 } | 649 } |
610 | 650 |
611 // Event details common to MouseEvent and TouchEvent. | 651 // Event details common to MouseEvent and TouchEvent. |
612 const PointerDetails& pointer_details() const { return pointer_details_; } | 652 const PointerDetails& pointer_details() const { return pointer_details_; } |
613 void set_pointer_details(const PointerDetails& pointer_details) { | 653 void set_pointer_details(const PointerDetails& pointer_details) { |
614 pointer_details_ = pointer_details; | 654 pointer_details_ = pointer_details; |
615 } | 655 } |
616 | 656 |
617 private: | 657 private: |
| 658 // For (de)serialization. |
| 659 TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 660 : LocatedEvent(type, time_stamp, flags), |
| 661 should_remove_native_touch_id_mapping_(false) {} |
| 662 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 663 friend struct IPC::ParamTraits<ui::TouchEvent>; |
| 664 |
618 // Adjusts rotation_angle_ to within the acceptable range. | 665 // Adjusts rotation_angle_ to within the acceptable range. |
619 void FixRotationAngle(); | 666 void FixRotationAngle(); |
620 | 667 |
621 // The identity (typically finger) of the touch starting at 0 and incrementing | 668 // The identity (typically finger) of the touch starting at 0 and incrementing |
622 // for each separable additional touch that the hardware can detect. | 669 // for each separable additional touch that the hardware can detect. |
623 const int touch_id_; | 670 int touch_id_; |
624 | 671 |
625 // A unique identifier for the touch event. | 672 // A unique identifier for the touch event. |
626 const uint32_t unique_event_id_; | 673 uint32_t unique_event_id_; |
627 | 674 |
628 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 675 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
629 // less than 180 and non-negative. | 676 // less than 180 and non-negative. |
630 float rotation_angle_; | 677 float rotation_angle_; |
631 | 678 |
632 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 679 // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
633 // touchmove that exceeds the platform slop region, or a touchend that | 680 // touchmove that exceeds the platform slop region, or a touchend that |
634 // causes a fling). Defaults to false. | 681 // causes a fling). Defaults to false. |
635 bool may_cause_scrolling_; | 682 bool may_cause_scrolling_; |
636 | 683 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // (Native X11 event flags describe the state before the event.) | 864 // (Native X11 event flags describe the state before the event.) |
818 void NormalizeFlags(); | 865 void NormalizeFlags(); |
819 | 866 |
820 protected: | 867 protected: |
821 friend class KeyEventTestApi; | 868 friend class KeyEventTestApi; |
822 | 869 |
823 // This allows a subclass TranslatedKeyEvent to be a non character event. | 870 // This allows a subclass TranslatedKeyEvent to be a non character event. |
824 void set_is_char(bool is_char) { is_char_ = is_char; } | 871 void set_is_char(bool is_char) { is_char_ = is_char; } |
825 | 872 |
826 private: | 873 private: |
| 874 // For (de)serialization. |
| 875 KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); |
| 876 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 877 friend struct IPC::ParamTraits<ui::KeyEvent>; |
| 878 |
827 // Determine key_ on a keystroke event from code_ and flags(). | 879 // Determine key_ on a keystroke event from code_ and flags(). |
828 void ApplyLayout() const; | 880 void ApplyLayout() const; |
829 | 881 |
830 KeyboardCode key_code_; | 882 KeyboardCode key_code_; |
831 | 883 |
832 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 884 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
833 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 885 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
834 // | 886 // |
835 // This value represents the physical position in the keyboard and can be | 887 // This value represents the physical position in the keyboard and can be |
836 // converted from / to keyboard scan code like XKB. | 888 // converted from / to keyboard scan code like XKB. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 // to provide a consistent user experience. | 947 // to provide a consistent user experience. |
896 void Scale(const float factor); | 948 void Scale(const float factor); |
897 | 949 |
898 float x_offset() const { return x_offset_; } | 950 float x_offset() const { return x_offset_; } |
899 float y_offset() const { return y_offset_; } | 951 float y_offset() const { return y_offset_; } |
900 float x_offset_ordinal() const { return x_offset_ordinal_; } | 952 float x_offset_ordinal() const { return x_offset_ordinal_; } |
901 float y_offset_ordinal() const { return y_offset_ordinal_; } | 953 float y_offset_ordinal() const { return y_offset_ordinal_; } |
902 int finger_count() const { return finger_count_; } | 954 int finger_count() const { return finger_count_; } |
903 | 955 |
904 private: | 956 private: |
| 957 // For (de)serialization. |
| 958 ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 959 : MouseEvent(type, time_stamp, flags) {} |
| 960 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 961 friend struct IPC::ParamTraits<ui::ScrollEvent>; |
| 962 |
905 // Potential accelerated offsets. | 963 // Potential accelerated offsets. |
906 float x_offset_; | 964 float x_offset_; |
907 float y_offset_; | 965 float y_offset_; |
908 // Unaccelerated offsets. | 966 // Unaccelerated offsets. |
909 float x_offset_ordinal_; | 967 float x_offset_ordinal_; |
910 float y_offset_ordinal_; | 968 float y_offset_ordinal_; |
911 // Number of fingers on the pad. | 969 // Number of fingers on the pad. |
912 int finger_count_; | 970 int finger_count_; |
913 }; | 971 }; |
914 | 972 |
(...skipping 12 matching lines...) Expand all Loading... |
927 GestureEvent(const GestureEvent& model, T* source, T* target) | 985 GestureEvent(const GestureEvent& model, T* source, T* target) |
928 : LocatedEvent(model, source, target), | 986 : LocatedEvent(model, source, target), |
929 details_(model.details_) { | 987 details_(model.details_) { |
930 } | 988 } |
931 | 989 |
932 ~GestureEvent() override; | 990 ~GestureEvent() override; |
933 | 991 |
934 const GestureEventDetails& details() const { return details_; } | 992 const GestureEventDetails& details() const { return details_; } |
935 | 993 |
936 private: | 994 private: |
| 995 // For (de)serialization. |
| 996 GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) |
| 997 : LocatedEvent(type, time_stamp, flags) {} |
| 998 friend struct IPC::ParamTraits<ui::ScopedEvent>; |
| 999 friend struct IPC::ParamTraits<ui::GestureEvent>; |
| 1000 |
937 GestureEventDetails details_; | 1001 GestureEventDetails details_; |
938 }; | 1002 }; |
939 | 1003 |
940 } // namespace ui | 1004 } // namespace ui |
941 | 1005 |
942 #endif // UI_EVENTS_EVENT_H_ | 1006 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |