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" |
16 #include "ipc/ipc_message_utils.h" | |
17 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
18 #include "ui/events/gesture_event_details.h" | 18 #include "ui/events/gesture_event_details.h" |
19 #include "ui/events/gestures/gesture_types.h" | 19 #include "ui/events/gestures/gesture_types.h" |
20 #include "ui/events/keycodes/dom/dom_key.h" | 20 #include "ui/events/keycodes/dom/dom_key.h" |
21 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
22 #include "ui/events/latency_info.h" | 22 #include "ui/events/latency_info.h" |
23 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
24 #include "ui/gfx/geometry/point_conversions.h" | 24 #include "ui/gfx/geometry/point_conversions.h" |
25 | 25 |
26 namespace gfx { | 26 namespace gfx { |
27 class Transform; | 27 class Transform; |
28 } | 28 } |
29 | 29 |
30 namespace ui { | 30 namespace ui { |
31 class EventTarget; | 31 class EventTarget; |
32 enum class DomCode; | 32 enum class DomCode; |
33 class Event; | |
34 | |
35 typedef scoped_ptr<Event> ScopedEvent; | |
33 | 36 |
34 class EVENTS_EXPORT Event { | 37 class EVENTS_EXPORT Event { |
35 public: | 38 public: |
36 static scoped_ptr<Event> Clone(const Event& event); | 39 static scoped_ptr<Event> Clone(const Event& event); |
37 | 40 |
38 virtual ~Event(); | 41 virtual ~Event(); |
39 | 42 |
40 class DispatcherApi { | 43 class DispatcherApi { |
41 public: | 44 public: |
42 explicit DispatcherApi(Event* event) : event_(event) {} | 45 explicit DispatcherApi(Event* event) : event_(event) {} |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 | 230 |
228 void set_time_stamp(const base::TimeDelta& time_stamp) { | 231 void set_time_stamp(const base::TimeDelta& time_stamp) { |
229 time_stamp_ = time_stamp; | 232 time_stamp_ = time_stamp; |
230 } | 233 } |
231 | 234 |
232 void set_name(const std::string& name) { name_ = name; } | 235 void set_name(const std::string& name) { name_ = name; } |
233 | 236 |
234 private: | 237 private: |
235 friend class EventTestApi; | 238 friend class EventTestApi; |
236 | 239 |
240 // For mojo native implementation of (de)serialization. | |
241 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
Ken Rockot(use gerrit already)
2016/02/17 22:05:21
This is really for Chrome IPC serialization. Here
Mark Dittmer
2016/02/18 14:51:05
Done.
| |
242 | |
237 EventType type_; | 243 EventType type_; |
238 std::string name_; | 244 std::string name_; |
239 base::TimeDelta time_stamp_; | 245 base::TimeDelta time_stamp_; |
240 LatencyInfo latency_; | 246 LatencyInfo latency_; |
241 int flags_; | 247 int flags_; |
242 base::NativeEvent native_event_; | 248 base::NativeEvent native_event_; |
243 bool delete_native_event_; | 249 bool delete_native_event_; |
244 bool cancelable_; | 250 bool cancelable_; |
245 EventTarget* target_; | 251 EventTarget* target_; |
246 EventPhase phase_; | 252 EventPhase phase_; |
247 EventResult result_; | 253 EventResult result_; |
248 | 254 |
249 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 255 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
250 // is not available. | 256 // is not available. |
251 int source_device_id_; | 257 int source_device_id_; |
252 }; | 258 }; |
253 | 259 |
254 class EVENTS_EXPORT CancelModeEvent : public Event { | 260 class EVENTS_EXPORT CancelModeEvent : public Event { |
255 public: | 261 public: |
256 CancelModeEvent(); | 262 CancelModeEvent(); |
257 ~CancelModeEvent() override; | 263 ~CancelModeEvent() override; |
264 | |
265 private: | |
266 // For mojo native implementation of (de)serialization. | |
267 explicit CancelModeEvent(EventType type, | |
268 base::TimeDelta time_stamp, | |
269 int flags) | |
270 : Event(type, time_stamp, flags) {} | |
271 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
272 friend struct IPC::ParamTraits<ui::CancelModeEvent>; | |
258 }; | 273 }; |
259 | 274 |
275 class MouseWheelEvent; | |
276 | |
260 class EVENTS_EXPORT LocatedEvent : public Event { | 277 class EVENTS_EXPORT LocatedEvent : public Event { |
261 public: | 278 public: |
262 ~LocatedEvent() override; | 279 ~LocatedEvent() override; |
263 | 280 |
264 float x() const { return location_.x(); } | 281 float x() const { return location_.x(); } |
265 float y() const { return location_.y(); } | 282 float y() const { return location_.y(); } |
266 void set_location(const gfx::Point& location) { | 283 void set_location(const gfx::Point& location) { |
267 location_ = gfx::PointF(location); | 284 location_ = gfx::PointF(location); |
268 } | 285 } |
269 void set_location_f(const gfx::PointF& location) { location_ = location; } | 286 void set_location_f(const gfx::PointF& location) { location_ = location; } |
(...skipping 21 matching lines...) Expand all Loading... | |
291 if (!target || target == source) | 308 if (!target || target == source) |
292 return; | 309 return; |
293 gfx::Point offset = gfx::ToFlooredPoint(location_); | 310 gfx::Point offset = gfx::ToFlooredPoint(location_); |
294 T::ConvertPointToTarget(source, target, &offset); | 311 T::ConvertPointToTarget(source, target, &offset); |
295 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 312 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
296 location_= location_ - diff; | 313 location_= location_ - diff; |
297 } | 314 } |
298 | 315 |
299 protected: | 316 protected: |
300 friend class LocatedEventTestApi; | 317 friend class LocatedEventTestApi; |
318 | |
319 // For mojo native implementation of (de)serialization. | |
320 explicit LocatedEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
321 : Event(type, time_stamp, flags) {} | |
322 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
323 friend struct IPC::ParamTraits<ui::LocatedEvent>; | |
324 | |
301 explicit LocatedEvent(const base::NativeEvent& native_event); | 325 explicit LocatedEvent(const base::NativeEvent& native_event); |
302 | 326 |
303 // Create a new LocatedEvent which is identical to the provided model. | 327 // Create a new LocatedEvent which is identical to the provided model. |
304 // If source / target windows are provided, the model location will be | 328 // If source / target windows are provided, the model location will be |
305 // converted from |source| coordinate system to |target| coordinate system. | 329 // converted from |source| coordinate system to |target| coordinate system. |
306 template <class T> | 330 template <class T> |
307 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 331 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
308 : Event(model), | 332 : Event(model), |
309 location_(model.location_), | 333 location_(model.location_), |
310 root_location_(model.root_location_) { | 334 root_location_(model.root_location_) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 | 483 |
460 // Updates the button that changed. | 484 // Updates the button that changed. |
461 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 485 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
462 | 486 |
463 // Event details common to MouseEvent and TouchEvent. | 487 // Event details common to MouseEvent and TouchEvent. |
464 const PointerDetails& pointer_details() const { return pointer_details_; } | 488 const PointerDetails& pointer_details() const { return pointer_details_; } |
465 void set_pointer_details(const PointerDetails& details) { | 489 void set_pointer_details(const PointerDetails& details) { |
466 pointer_details_ = details; | 490 pointer_details_ = details; |
467 } | 491 } |
468 | 492 |
493 protected: | |
494 // For mojo native implementation of (de)serialization. | |
495 explicit MouseEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
496 : LocatedEvent(type, time_stamp, flags) {} | |
497 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
498 friend struct IPC::ParamTraits<ui::MouseEvent>; | |
499 | |
469 private: | 500 private: |
470 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 501 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
471 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 502 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
472 | 503 |
473 // Returns the repeat count based on the previous mouse click, if it is | 504 // Returns the repeat count based on the previous mouse click, if it is |
474 // recent enough and within a small enough distance. | 505 // recent enough and within a small enough distance. |
475 static int GetRepeatCount(const MouseEvent& click_event); | 506 static int GetRepeatCount(const MouseEvent& click_event); |
476 | 507 |
477 // Resets the last_click_event_ for unit tests. | 508 // Resets the last_click_event_ for unit tests. |
478 static void ResetLastClickForTest(); | 509 static void ResetLastClickForTest(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 int flags, | 550 int flags, |
520 int changed_button_flags); | 551 int changed_button_flags); |
521 | 552 |
522 // The amount to scroll. This is in multiples of kWheelDelta. | 553 // The amount to scroll. This is in multiples of kWheelDelta. |
523 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 554 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
524 int x_offset() const { return offset_.x(); } | 555 int x_offset() const { return offset_.x(); } |
525 int y_offset() const { return offset_.y(); } | 556 int y_offset() const { return offset_.y(); } |
526 const gfx::Vector2d& offset() const { return offset_; } | 557 const gfx::Vector2d& offset() const { return offset_; } |
527 | 558 |
528 private: | 559 private: |
560 // For mojo native implementation of (de)serialization. | |
561 explicit MouseWheelEvent(EventType type, | |
562 base::TimeDelta time_stamp, | |
563 int flags) | |
564 : MouseEvent(type, time_stamp, flags) {} | |
565 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
566 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; | |
567 | |
529 gfx::Vector2d offset_; | 568 gfx::Vector2d offset_; |
530 }; | 569 }; |
531 | 570 |
532 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 571 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
533 public: | 572 public: |
534 explicit TouchEvent(const base::NativeEvent& native_event); | 573 explicit TouchEvent(const base::NativeEvent& native_event); |
535 | 574 |
536 // Create a new TouchEvent which is identical to the provided model. | 575 // Create a new TouchEvent which is identical to the provided model. |
537 // If source / target windows are provided, the model location will be | 576 // If source / target windows are provided, the model location will be |
538 // converted from |source| coordinate system to |target| coordinate system. | 577 // converted from |source| coordinate system to |target| coordinate system. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 // Marks the event as not participating in synchronous gesture recognition. | 632 // Marks the event as not participating in synchronous gesture recognition. |
594 void DisableSynchronousHandling(); | 633 void DisableSynchronousHandling(); |
595 bool synchronous_handling_disabled() const { | 634 bool synchronous_handling_disabled() const { |
596 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 635 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
597 } | 636 } |
598 | 637 |
599 // Event details common to MouseEvent and TouchEvent. | 638 // Event details common to MouseEvent and TouchEvent. |
600 const PointerDetails& pointer_details() const { return pointer_details_; } | 639 const PointerDetails& pointer_details() const { return pointer_details_; } |
601 | 640 |
602 private: | 641 private: |
642 // For mojo native implementation of (de)serialization. | |
643 explicit TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
644 : LocatedEvent(type, time_stamp, flags), | |
645 should_remove_native_touch_id_mapping_(false) {} | |
646 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
647 friend struct IPC::ParamTraits<ui::TouchEvent>; | |
648 | |
603 // Adjusts rotation_angle_ to within the acceptable range. | 649 // Adjusts rotation_angle_ to within the acceptable range. |
604 void FixRotationAngle(); | 650 void FixRotationAngle(); |
605 | 651 |
606 // The identity (typically finger) of the touch starting at 0 and incrementing | 652 // The identity (typically finger) of the touch starting at 0 and incrementing |
607 // for each separable additional touch that the hardware can detect. | 653 // for each separable additional touch that the hardware can detect. |
608 const int touch_id_; | 654 int touch_id_; |
609 | 655 |
610 // A unique identifier for the touch event. | 656 // A unique identifier for the touch event. |
611 const uint32_t unique_event_id_; | 657 uint32_t unique_event_id_; |
612 | 658 |
613 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 659 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
614 // less than 180 and non-negative. | 660 // less than 180 and non-negative. |
615 float rotation_angle_; | 661 float rotation_angle_; |
616 | 662 |
617 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 663 // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
618 // touchmove that exceeds the platform slop region, or a touchend that | 664 // touchmove that exceeds the platform slop region, or a touchend that |
619 // causes a fling). Defaults to false. | 665 // causes a fling). Defaults to false. |
620 bool may_cause_scrolling_; | 666 bool may_cause_scrolling_; |
621 | 667 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 // (Native X11 event flags describe the state before the event.) | 833 // (Native X11 event flags describe the state before the event.) |
788 void NormalizeFlags(); | 834 void NormalizeFlags(); |
789 | 835 |
790 protected: | 836 protected: |
791 friend class KeyEventTestApi; | 837 friend class KeyEventTestApi; |
792 | 838 |
793 // This allows a subclass TranslatedKeyEvent to be a non character event. | 839 // This allows a subclass TranslatedKeyEvent to be a non character event. |
794 void set_is_char(bool is_char) { is_char_ = is_char; } | 840 void set_is_char(bool is_char) { is_char_ = is_char; } |
795 | 841 |
796 private: | 842 private: |
843 // For mojo native implementation of (de)serialization. | |
844 explicit KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); | |
845 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
846 friend struct IPC::ParamTraits<ui::KeyEvent>; | |
847 | |
797 // Determine key_ on a keystroke event from code_ and flags(). | 848 // Determine key_ on a keystroke event from code_ and flags(). |
798 void ApplyLayout() const; | 849 void ApplyLayout() const; |
799 | 850 |
800 KeyboardCode key_code_; | 851 KeyboardCode key_code_; |
801 | 852 |
802 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 853 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
803 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 854 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
804 // | 855 // |
805 // This value represents the physical position in the keyboard and can be | 856 // This value represents the physical position in the keyboard and can be |
806 // converted from / to keyboard scan code like XKB. | 857 // converted from / to keyboard scan code like XKB. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 // to provide a consistent user experience. | 916 // to provide a consistent user experience. |
866 void Scale(const float factor); | 917 void Scale(const float factor); |
867 | 918 |
868 float x_offset() const { return x_offset_; } | 919 float x_offset() const { return x_offset_; } |
869 float y_offset() const { return y_offset_; } | 920 float y_offset() const { return y_offset_; } |
870 float x_offset_ordinal() const { return x_offset_ordinal_; } | 921 float x_offset_ordinal() const { return x_offset_ordinal_; } |
871 float y_offset_ordinal() const { return y_offset_ordinal_; } | 922 float y_offset_ordinal() const { return y_offset_ordinal_; } |
872 int finger_count() const { return finger_count_; } | 923 int finger_count() const { return finger_count_; } |
873 | 924 |
874 private: | 925 private: |
926 // For mojo native implementation of (de)serialization. | |
927 explicit ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
928 : MouseEvent(type, time_stamp, flags) {} | |
929 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
930 friend struct IPC::ParamTraits<ui::ScrollEvent>; | |
931 | |
875 // Potential accelerated offsets. | 932 // Potential accelerated offsets. |
876 float x_offset_; | 933 float x_offset_; |
877 float y_offset_; | 934 float y_offset_; |
878 // Unaccelerated offsets. | 935 // Unaccelerated offsets. |
879 float x_offset_ordinal_; | 936 float x_offset_ordinal_; |
880 float y_offset_ordinal_; | 937 float y_offset_ordinal_; |
881 // Number of fingers on the pad. | 938 // Number of fingers on the pad. |
882 int finger_count_; | 939 int finger_count_; |
883 }; | 940 }; |
884 | 941 |
(...skipping 12 matching lines...) Expand all Loading... | |
897 GestureEvent(const GestureEvent& model, T* source, T* target) | 954 GestureEvent(const GestureEvent& model, T* source, T* target) |
898 : LocatedEvent(model, source, target), | 955 : LocatedEvent(model, source, target), |
899 details_(model.details_) { | 956 details_(model.details_) { |
900 } | 957 } |
901 | 958 |
902 ~GestureEvent() override; | 959 ~GestureEvent() override; |
903 | 960 |
904 const GestureEventDetails& details() const { return details_; } | 961 const GestureEventDetails& details() const { return details_; } |
905 | 962 |
906 private: | 963 private: |
964 // For mojo native implementation of (de)serialization. | |
965 explicit GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
966 : LocatedEvent(type, time_stamp, flags) {} | |
967 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
968 friend struct IPC::ParamTraits<ui::GestureEvent>; | |
969 | |
907 GestureEventDetails details_; | 970 GestureEventDetails details_; |
908 }; | 971 }; |
909 | 972 |
910 } // namespace ui | 973 } // namespace ui |
911 | 974 |
912 #endif // UI_EVENTS_EVENT_H_ | 975 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |