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 PointerEvent; | 34 class PointerEvent; |
38 class TouchEvent; | 35 class TouchEvent; |
39 enum class DomCode; | 36 enum class DomCode; |
40 class Event; | |
41 class MouseWheelEvent; | |
42 | |
43 using ScopedEvent = scoped_ptr<Event>; | |
44 | 37 |
45 class EVENTS_EXPORT Event { | 38 class EVENTS_EXPORT Event { |
46 public: | 39 public: |
47 static scoped_ptr<Event> Clone(const Event& event); | 40 static scoped_ptr<Event> Clone(const Event& event); |
48 | 41 |
49 virtual ~Event(); | 42 virtual ~Event(); |
50 | 43 |
51 class DispatcherApi { | 44 class DispatcherApi { |
52 public: | 45 public: |
53 explicit DispatcherApi(Event* event) : event_(event) {} | 46 explicit DispatcherApi(Event* event) : event_(event) {} |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 | 262 |
270 void set_time_stamp(const base::TimeDelta& time_stamp) { | 263 void set_time_stamp(const base::TimeDelta& time_stamp) { |
271 time_stamp_ = time_stamp; | 264 time_stamp_ = time_stamp; |
272 } | 265 } |
273 | 266 |
274 void set_name(const std::string& name) { name_ = name; } | 267 void set_name(const std::string& name) { name_ = name; } |
275 | 268 |
276 private: | 269 private: |
277 friend class EventTestApi; | 270 friend class EventTestApi; |
278 | 271 |
279 // For (de)serialization. | |
280 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
281 | |
282 EventType type_; | 272 EventType type_; |
283 std::string name_; | 273 std::string name_; |
284 base::TimeDelta time_stamp_; | 274 base::TimeDelta time_stamp_; |
285 LatencyInfo latency_; | 275 LatencyInfo latency_; |
286 int flags_; | 276 int flags_; |
287 base::NativeEvent native_event_; | 277 base::NativeEvent native_event_; |
288 bool delete_native_event_; | 278 bool delete_native_event_; |
289 bool cancelable_; | 279 bool cancelable_; |
290 EventTarget* target_; | 280 EventTarget* target_; |
291 EventPhase phase_; | 281 EventPhase phase_; |
292 EventResult result_; | 282 EventResult result_; |
293 | 283 |
294 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information | 284 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information |
295 // is not available. | 285 // is not available. |
296 int source_device_id_; | 286 int source_device_id_; |
297 }; | 287 }; |
298 | 288 |
299 class EVENTS_EXPORT CancelModeEvent : public Event { | 289 class EVENTS_EXPORT CancelModeEvent : public Event { |
300 public: | 290 public: |
301 CancelModeEvent(); | 291 CancelModeEvent(); |
302 ~CancelModeEvent() override; | 292 ~CancelModeEvent() override; |
303 | |
304 private: | |
305 // For (de)serialization. | |
306 CancelModeEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
307 : Event(type, time_stamp, flags) {} | |
308 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
309 friend struct IPC::ParamTraits<ui::CancelModeEvent>; | |
310 }; | 293 }; |
311 | 294 |
312 class EVENTS_EXPORT LocatedEvent : public Event { | 295 class EVENTS_EXPORT LocatedEvent : public Event { |
313 public: | 296 public: |
314 ~LocatedEvent() override; | 297 ~LocatedEvent() override; |
315 | 298 |
316 float x() const { return location_.x(); } | 299 float x() const { return location_.x(); } |
317 float y() const { return location_.y(); } | 300 float y() const { return location_.y(); } |
318 void set_location(const gfx::Point& location) { | 301 void set_location(const gfx::Point& location) { |
319 location_ = gfx::PointF(location); | 302 location_ = gfx::PointF(location); |
(...skipping 23 matching lines...) Expand all Loading... |
343 if (!target || target == source) | 326 if (!target || target == source) |
344 return; | 327 return; |
345 gfx::Point offset = gfx::ToFlooredPoint(location_); | 328 gfx::Point offset = gfx::ToFlooredPoint(location_); |
346 T::ConvertPointToTarget(source, target, &offset); | 329 T::ConvertPointToTarget(source, target, &offset); |
347 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; | 330 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; |
348 location_= location_ - diff; | 331 location_= location_ - diff; |
349 } | 332 } |
350 | 333 |
351 protected: | 334 protected: |
352 friend class LocatedEventTestApi; | 335 friend class LocatedEventTestApi; |
353 | |
354 // For (de)serialization. | |
355 LocatedEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
356 : Event(type, time_stamp, flags) {} | |
357 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
358 friend struct IPC::ParamTraits<ui::LocatedEvent>; | |
359 | |
360 explicit LocatedEvent(const base::NativeEvent& native_event); | 336 explicit LocatedEvent(const base::NativeEvent& native_event); |
361 | 337 |
362 // Create a new LocatedEvent which is identical to the provided model. | 338 // Create a new LocatedEvent which is identical to the provided model. |
363 // If source / target windows are provided, the model location will be | 339 // If source / target windows are provided, the model location will be |
364 // converted from |source| coordinate system to |target| coordinate system. | 340 // converted from |source| coordinate system to |target| coordinate system. |
365 template <class T> | 341 template <class T> |
366 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 342 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
367 : Event(model), | 343 : Event(model), |
368 location_(model.location_), | 344 location_(model.location_), |
369 root_location_(model.root_location_) { | 345 root_location_(model.root_location_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 bool operator==(const PointerDetails& other) const { | 386 bool operator==(const PointerDetails& other) const { |
411 return pointer_type == other.pointer_type && | 387 return pointer_type == other.pointer_type && |
412 radius_x == other.radius_x && | 388 radius_x == other.radius_x && |
413 radius_y == other.radius_y && | 389 radius_y == other.radius_y && |
414 (force == other.force || | 390 (force == other.force || |
415 (std::isnan(force) && std::isnan(other.force))) && | 391 (std::isnan(force) && std::isnan(other.force))) && |
416 tilt_x == other.tilt_x && | 392 tilt_x == other.tilt_x && |
417 tilt_y == other.tilt_y; | 393 tilt_y == other.tilt_y; |
418 } | 394 } |
419 | 395 |
420 // For serialization. | |
421 friend struct IPC::ParamTraits<ui::PointerDetails>; | |
422 | |
423 // The type of pointer device. | 396 // The type of pointer device. |
424 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; | 397 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; |
425 | 398 |
426 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. | 399 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. |
427 float radius_x = 0.0; | 400 float radius_x = 0.0; |
428 | 401 |
429 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 402 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
430 float radius_y = 0.0; | 403 float radius_y = 0.0; |
431 | 404 |
432 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means | 405 // 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... |
532 | 505 |
533 // Updates the button that changed. | 506 // Updates the button that changed. |
534 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } | 507 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } |
535 | 508 |
536 // Event details common to MouseEvent and TouchEvent. | 509 // Event details common to MouseEvent and TouchEvent. |
537 const PointerDetails& pointer_details() const { return pointer_details_; } | 510 const PointerDetails& pointer_details() const { return pointer_details_; } |
538 void set_pointer_details(const PointerDetails& details) { | 511 void set_pointer_details(const PointerDetails& details) { |
539 pointer_details_ = details; | 512 pointer_details_ = details; |
540 } | 513 } |
541 | 514 |
542 protected: | |
543 // For (de)serialization. | |
544 MouseEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
545 : LocatedEvent(type, time_stamp, flags) {} | |
546 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
547 friend struct IPC::ParamTraits<ui::MouseEvent>; | |
548 | |
549 private: | 515 private: |
550 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); | 516 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); |
551 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); | 517 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); |
552 | 518 |
553 // Returns the repeat count based on the previous mouse click, if it is | 519 // Returns the repeat count based on the previous mouse click, if it is |
554 // recent enough and within a small enough distance. | 520 // recent enough and within a small enough distance. |
555 static int GetRepeatCount(const MouseEvent& click_event); | 521 static int GetRepeatCount(const MouseEvent& click_event); |
556 | 522 |
557 // Resets the last_click_event_ for unit tests. | 523 // Resets the last_click_event_ for unit tests. |
558 static void ResetLastClickForTest(); | 524 static void ResetLastClickForTest(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 int flags, | 565 int flags, |
600 int changed_button_flags); | 566 int changed_button_flags); |
601 | 567 |
602 // The amount to scroll. This is in multiples of kWheelDelta. | 568 // The amount to scroll. This is in multiples of kWheelDelta. |
603 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. | 569 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. |
604 int x_offset() const { return offset_.x(); } | 570 int x_offset() const { return offset_.x(); } |
605 int y_offset() const { return offset_.y(); } | 571 int y_offset() const { return offset_.y(); } |
606 const gfx::Vector2d& offset() const { return offset_; } | 572 const gfx::Vector2d& offset() const { return offset_; } |
607 | 573 |
608 private: | 574 private: |
609 // For (de)serialization. | |
610 MouseWheelEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
611 : MouseEvent(type, time_stamp, flags) {} | |
612 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
613 friend struct IPC::ParamTraits<ui::MouseWheelEvent>; | |
614 | |
615 gfx::Vector2d offset_; | 575 gfx::Vector2d offset_; |
616 }; | 576 }; |
617 | 577 |
618 class EVENTS_EXPORT TouchEvent : public LocatedEvent { | 578 class EVENTS_EXPORT TouchEvent : public LocatedEvent { |
619 public: | 579 public: |
620 explicit TouchEvent(const base::NativeEvent& native_event); | 580 explicit TouchEvent(const base::NativeEvent& native_event); |
621 | 581 |
622 // Create a new TouchEvent which is identical to the provided model. | 582 // Create a new TouchEvent which is identical to the provided model. |
623 // If source / target windows are provided, the model location will be | 583 // If source / target windows are provided, the model location will be |
624 // converted from |source| coordinate system to |target| coordinate system. | 584 // converted from |source| coordinate system to |target| coordinate system. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return !!(result() & ER_DISABLE_SYNC_HANDLING); | 637 return !!(result() & ER_DISABLE_SYNC_HANDLING); |
678 } | 638 } |
679 | 639 |
680 // Event details common to MouseEvent and TouchEvent. | 640 // Event details common to MouseEvent and TouchEvent. |
681 const PointerDetails& pointer_details() const { return pointer_details_; } | 641 const PointerDetails& pointer_details() const { return pointer_details_; } |
682 void set_pointer_details(const PointerDetails& pointer_details) { | 642 void set_pointer_details(const PointerDetails& pointer_details) { |
683 pointer_details_ = pointer_details; | 643 pointer_details_ = pointer_details; |
684 } | 644 } |
685 | 645 |
686 private: | 646 private: |
687 // For (de)serialization. | |
688 TouchEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
689 : LocatedEvent(type, time_stamp, flags), | |
690 should_remove_native_touch_id_mapping_(false) {} | |
691 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
692 friend struct IPC::ParamTraits<ui::TouchEvent>; | |
693 | |
694 // Adjusts rotation_angle_ to within the acceptable range. | 647 // Adjusts rotation_angle_ to within the acceptable range. |
695 void FixRotationAngle(); | 648 void FixRotationAngle(); |
696 | 649 |
697 // The identity (typically finger) of the touch starting at 0 and incrementing | 650 // The identity (typically finger) of the touch starting at 0 and incrementing |
698 // for each separable additional touch that the hardware can detect. | 651 // for each separable additional touch that the hardware can detect. |
699 int touch_id_; | 652 const int touch_id_; |
700 | 653 |
701 // A unique identifier for the touch event. | 654 // A unique identifier for the touch event. |
702 uint32_t unique_event_id_; | 655 const uint32_t unique_event_id_; |
703 | 656 |
704 // Clockwise angle (in degrees) of the major axis from the X axis. Must be | 657 // Clockwise angle (in degrees) of the major axis from the X axis. Must be |
705 // less than 180 and non-negative. | 658 // less than 180 and non-negative. |
706 float rotation_angle_; | 659 float rotation_angle_; |
707 | 660 |
708 // Whether the (unhandled) touch event will produce a scroll event (e.g., a | 661 // Whether the (unhandled) touch event will produce a scroll event (e.g., a |
709 // touchmove that exceeds the platform slop region, or a touchend that | 662 // touchmove that exceeds the platform slop region, or a touchend that |
710 // causes a fling). Defaults to false. | 663 // causes a fling). Defaults to false. |
711 bool may_cause_scrolling_; | 664 bool may_cause_scrolling_; |
712 | 665 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 // (Native X11 event flags describe the state before the event.) | 855 // (Native X11 event flags describe the state before the event.) |
903 void NormalizeFlags(); | 856 void NormalizeFlags(); |
904 | 857 |
905 protected: | 858 protected: |
906 friend class KeyEventTestApi; | 859 friend class KeyEventTestApi; |
907 | 860 |
908 // This allows a subclass TranslatedKeyEvent to be a non character event. | 861 // This allows a subclass TranslatedKeyEvent to be a non character event. |
909 void set_is_char(bool is_char) { is_char_ = is_char; } | 862 void set_is_char(bool is_char) { is_char_ = is_char; } |
910 | 863 |
911 private: | 864 private: |
912 // For (de)serialization. | |
913 KeyEvent(EventType type, base::TimeDelta time_stamp, int flags); | |
914 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
915 friend struct IPC::ParamTraits<ui::KeyEvent>; | |
916 | |
917 // Determine key_ on a keystroke event from code_ and flags(). | 865 // Determine key_ on a keystroke event from code_ and flags(). |
918 void ApplyLayout() const; | 866 void ApplyLayout() const; |
919 | 867 |
920 KeyboardCode key_code_; | 868 KeyboardCode key_code_; |
921 | 869 |
922 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). | 870 // DOM KeyboardEvent |code| (e.g. DomCode::US_A, DomCode::SPACE). |
923 // http://www.w3.org/TR/DOM-Level-3-Events-code/ | 871 // http://www.w3.org/TR/DOM-Level-3-Events-code/ |
924 // | 872 // |
925 // This value represents the physical position in the keyboard and can be | 873 // This value represents the physical position in the keyboard and can be |
926 // converted from / to keyboard scan code like XKB. | 874 // converted from / to keyboard scan code like XKB. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 // to provide a consistent user experience. | 933 // to provide a consistent user experience. |
986 void Scale(const float factor); | 934 void Scale(const float factor); |
987 | 935 |
988 float x_offset() const { return x_offset_; } | 936 float x_offset() const { return x_offset_; } |
989 float y_offset() const { return y_offset_; } | 937 float y_offset() const { return y_offset_; } |
990 float x_offset_ordinal() const { return x_offset_ordinal_; } | 938 float x_offset_ordinal() const { return x_offset_ordinal_; } |
991 float y_offset_ordinal() const { return y_offset_ordinal_; } | 939 float y_offset_ordinal() const { return y_offset_ordinal_; } |
992 int finger_count() const { return finger_count_; } | 940 int finger_count() const { return finger_count_; } |
993 | 941 |
994 private: | 942 private: |
995 // For (de)serialization. | |
996 ScrollEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
997 : MouseEvent(type, time_stamp, flags) {} | |
998 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
999 friend struct IPC::ParamTraits<ui::ScrollEvent>; | |
1000 | |
1001 // Potential accelerated offsets. | 943 // Potential accelerated offsets. |
1002 float x_offset_; | 944 float x_offset_; |
1003 float y_offset_; | 945 float y_offset_; |
1004 // Unaccelerated offsets. | 946 // Unaccelerated offsets. |
1005 float x_offset_ordinal_; | 947 float x_offset_ordinal_; |
1006 float y_offset_ordinal_; | 948 float y_offset_ordinal_; |
1007 // Number of fingers on the pad. | 949 // Number of fingers on the pad. |
1008 int finger_count_; | 950 int finger_count_; |
1009 }; | 951 }; |
1010 | 952 |
(...skipping 12 matching lines...) Expand all Loading... |
1023 GestureEvent(const GestureEvent& model, T* source, T* target) | 965 GestureEvent(const GestureEvent& model, T* source, T* target) |
1024 : LocatedEvent(model, source, target), | 966 : LocatedEvent(model, source, target), |
1025 details_(model.details_) { | 967 details_(model.details_) { |
1026 } | 968 } |
1027 | 969 |
1028 ~GestureEvent() override; | 970 ~GestureEvent() override; |
1029 | 971 |
1030 const GestureEventDetails& details() const { return details_; } | 972 const GestureEventDetails& details() const { return details_; } |
1031 | 973 |
1032 private: | 974 private: |
1033 // For (de)serialization. | |
1034 GestureEvent(EventType type, base::TimeDelta time_stamp, int flags) | |
1035 : LocatedEvent(type, time_stamp, flags) {} | |
1036 friend struct IPC::ParamTraits<ui::ScopedEvent>; | |
1037 friend struct IPC::ParamTraits<ui::GestureEvent>; | |
1038 | |
1039 GestureEventDetails details_; | 975 GestureEventDetails details_; |
1040 }; | 976 }; |
1041 | 977 |
1042 } // namespace ui | 978 } // namespace ui |
1043 | 979 |
1044 #endif // UI_EVENTS_EVENT_H_ | 980 #endif // UI_EVENTS_EVENT_H_ |
OLD | NEW |