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