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 |
Tom Sepez
2016/02/18 18:46:10
nit: using ScopedEvent = scoped_ptr<Event>;
Mark Dittmer
2016/02/18 19:12:56
Done.
| |
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) {} |
43 | 46 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 | 236 |
234 void set_time_stamp(const base::TimeDelta& time_stamp) { | 237 void set_time_stamp(const base::TimeDelta& time_stamp) { |
235 time_stamp_ = time_stamp; | 238 time_stamp_ = time_stamp; |
236 } | 239 } |
237 | 240 |
238 void set_name(const std::string& name) { name_ = name; } | 241 void set_name(const std::string& name) { name_ = name; } |
239 | 242 |
240 private: | 243 private: |
241 friend class EventTestApi; | 244 friend class EventTestApi; |
242 | 245 |
246 // For (de)serialization. | |
247 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
Tom Sepez
2016/02/18 18:46:10
jam@ and I have argued about this in the past -- i
Mark Dittmer
2016/02/18 19:12:56
What is the proposed implementation alternative? R
jam
2016/02/18 21:01:26
I care less about this now.
My main question is
| |
248 | |
243 EventType type_; | 249 EventType type_; |
244 std::string name_; | 250 std::string name_; |
245 base::TimeDelta time_stamp_; | 251 base::TimeDelta time_stamp_; |
246 LatencyInfo latency_; | 252 LatencyInfo latency_; |
247 int flags_; | 253 int flags_; |
248 base::NativeEvent native_event_; | 254 base::NativeEvent native_event_; |
249 bool delete_native_event_; | 255 bool delete_native_event_; |
250 bool cancelable_; | 256 bool cancelable_; |
251 EventTarget* target_; | 257 EventTarget* target_; |
252 EventPhase phase_; | 258 EventPhase phase_; |
253 EventResult result_; | 259 EventResult result_; |
254 | 260 |
255 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 261 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
256 // is not available. | 262 // is not available. |
257 int source_device_id_; | 263 int source_device_id_; |
258 }; | 264 }; |
259 | 265 |
260 class EVENTS_EXPORT CancelModeEvent : public Event { | 266 class EVENTS_EXPORT CancelModeEvent : public Event { |
261 public: | 267 public: |
262 CancelModeEvent(); | 268 CancelModeEvent(); |
263 ~CancelModeEvent() override; | 269 ~CancelModeEvent() override; |
270 | |
271 private: | |
272 // For (de)serialization. | |
273 explicit CancelModeEvent(EventType type, | |
Tom Sepez
2016/02/18 18:46:10
Nit: no |explicit| as it's not a single-arg ctor.
Mark Dittmer
2016/02/18 19:12:56
Done.
| |
274 base::TimeDelta time_stamp, | |
275 int flags) | |
276 : Event(type, time_stamp, flags) {} | |
277 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
278 friend struct IPC::ParamTraits<ui::CancelModeEvent>; | |
264 }; | 279 }; |
265 | 280 |
281 class MouseWheelEvent; | |
Tom Sepez
2016/02/18 18:46:10
nit: move to top
Mark Dittmer
2016/02/18 19:12:56
Done.
| |
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); |
274 } | 291 } |
275 void set_location_f(const gfx::PointF& location) { location_ = location; } | 292 void set_location_f(const gfx::PointF& location) { location_ = location; } |
(...skipping 21 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 explicit 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 explicit 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 explicit MouseWheelEvent(EventType type, | |
582 base::TimeDelta time_stamp, | |
583 int flags) | |
584 : MouseEvent(type, time_stamp, flags) {} | |
585 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
586 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; | |
587 | |
546 gfx::Vector2d offset_; | 588 gfx::Vector2d offset_; |
547 }; | 589 }; |
548 | 590 |
549 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 591 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
550 public: | 592 public: |
551 explicit TouchEvent(const base::NativeEvent& native_event); | 593 explicit TouchEvent(const base::NativeEvent& native_event); |
552 | 594 |
553 // Create a new TouchEvent which is identical to the provided model. | 595 // Create a new TouchEvent which is identical to the provided model. |
554 // If source / target windows are provided, the model location will be | 596 // If source / target windows are provided, the model location will be |
555 // 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... | |
608 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 650 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
609 } | 651 } |
610 | 652 |
611 // Event details common to MouseEvent and TouchEvent. | 653 // Event details common to MouseEvent and TouchEvent. |
612 const PointerDetails& pointer_details() const { return pointer_details_; } | 654 const PointerDetails& pointer_details() const { return pointer_details_; } |
613 void set_pointer_details(const PointerDetails& pointer_details) { | 655 void set_pointer_details(const PointerDetails& pointer_details) { |
614 pointer_details_ = pointer_details; | 656 pointer_details_ = pointer_details; |
615 } | 657 } |
616 | 658 |
617 private: | 659 private: |
660 // For (de)serialization. | |
661 explicit TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
662 : LocatedEvent(type, time_stamp, flags), | |
663 should_remove_native_touch_id_mapping_(false) {} | |
664 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
665 friend struct IPC::ParamTraits<ui::TouchEvent>; | |
666 | |
618 // Adjusts rotation_angle_ to within the acceptable range. | 667 // Adjusts rotation_angle_ to within the acceptable range. |
619 void FixRotationAngle(); | 668 void FixRotationAngle(); |
620 | 669 |
621 // The identity (typically finger) of the touch starting at 0 and incrementing | 670 // The identity (typically finger) of the touch starting at 0 and incrementing |
622 // for each separable additional touch that the hardware can detect. | 671 // for each separable additional touch that the hardware can detect. |
623 const int touch_id_; | 672 int touch_id_; |
624 | 673 |
625 // A unique identifier for the touch event. | 674 // A unique identifier for the touch event. |
626 const uint32_t unique_event_id_; | 675 uint32_t unique_event_id_; |
627 | 676 |
628 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 677 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
629 // less than 180 and non-negative. | 678 // less than 180 and non-negative. |
630 float rotation_angle_; | 679 float rotation_angle_; |
631 | 680 |
632 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 681 // 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 | 682 // touchmove that exceeds the platform slop region, or a touchend that |
634 // causes a fling). Defaults to false. | 683 // causes a fling). Defaults to false. |
635 bool may_cause_scrolling_; | 684 bool may_cause_scrolling_; |
636 | 685 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 // (Native X11 event flags describe the state before the event.) | 866 // (Native X11 event flags describe the state before the event.) |
818 void NormalizeFlags(); | 867 void NormalizeFlags(); |
819 | 868 |
820 protected: | 869 protected: |
821 friend class KeyEventTestApi; | 870 friend class KeyEventTestApi; |
822 | 871 |
823 // This allows a subclass TranslatedKeyEvent to be a non character event. | 872 // This allows a subclass TranslatedKeyEvent to be a non character event. |
824 void set_is_char(bool is_char) { is_char_ = is_char; } | 873 void set_is_char(bool is_char) { is_char_ = is_char; } |
825 | 874 |
826 private: | 875 private: |
876 // For (de)serialization. | |
877 explicit KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); | |
878 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
879 friend struct IPC::ParamTraits<ui::KeyEvent>; | |
880 | |
827 // Determine key_ on a keystroke event from code_ and flags(). | 881 // Determine key_ on a keystroke event from code_ and flags(). |
828 void ApplyLayout() const; | 882 void ApplyLayout() const; |
829 | 883 |
830 KeyboardCode key_code_; | 884 KeyboardCode key_code_; |
831 | 885 |
832 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 886 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
833 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 887 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
834 // | 888 // |
835 // This value represents the physical position in the keyboard and can be | 889 // This value represents the physical position in the keyboard and can be |
836 // converted from / to keyboard scan code like XKB. | 890 // 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. | 949 // to provide a consistent user experience. |
896 void Scale(const float factor); | 950 void Scale(const float factor); |
897 | 951 |
898 float x_offset() const { return x_offset_; } | 952 float x_offset() const { return x_offset_; } |
899 float y_offset() const { return y_offset_; } | 953 float y_offset() const { return y_offset_; } |
900 float x_offset_ordinal() const { return x_offset_ordinal_; } | 954 float x_offset_ordinal() const { return x_offset_ordinal_; } |
901 float y_offset_ordinal() const { return y_offset_ordinal_; } | 955 float y_offset_ordinal() const { return y_offset_ordinal_; } |
902 int finger_count() const { return finger_count_; } | 956 int finger_count() const { return finger_count_; } |
903 | 957 |
904 private: | 958 private: |
959 // For (de)serialization. | |
960 explicit ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
961 : MouseEvent(type, time_stamp, flags) {} | |
962 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
963 friend struct IPC::ParamTraits<ui::ScrollEvent>; | |
964 | |
905 // Potential accelerated offsets. | 965 // Potential accelerated offsets. |
906 float x_offset_; | 966 float x_offset_; |
907 float y_offset_; | 967 float y_offset_; |
908 // Unaccelerated offsets. | 968 // Unaccelerated offsets. |
909 float x_offset_ordinal_; | 969 float x_offset_ordinal_; |
910 float y_offset_ordinal_; | 970 float y_offset_ordinal_; |
911 // Number of fingers on the pad. | 971 // Number of fingers on the pad. |
912 int finger_count_; | 972 int finger_count_; |
913 }; | 973 }; |
914 | 974 |
(...skipping 12 matching lines...) Expand all Loading... | |
927 GestureEvent(const GestureEvent& model, T* source, T* target) | 987 GestureEvent(const GestureEvent& model, T* source, T* target) |
928 : LocatedEvent(model, source, target), | 988 : LocatedEvent(model, source, target), |
929 details_(model.details_) { | 989 details_(model.details_) { |
930 } | 990 } |
931 | 991 |
932 ~GestureEvent() override; | 992 ~GestureEvent() override; |
933 | 993 |
934 const GestureEventDetails& details() const { return details_; } | 994 const GestureEventDetails& details() const { return details_; } |
935 | 995 |
936 private: | 996 private: |
997 // For (de)serialization. | |
998 explicit GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
999 : LocatedEvent(type, time_stamp, flags) {} | |
1000 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
1001 friend struct IPC::ParamTraits<ui::GestureEvent>; | |
1002 | |
937 GestureEventDetails details_; | 1003 GestureEventDetails details_; |
938 }; | 1004 }; |
939 | 1005 |
940 } // namespace ui | 1006 } // namespace ui |
941 | 1007 |
942 #endif // UI_EVENTS_EVENT_H_ | 1008 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |