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_BASE_EVENTS_EVENT_H_ | 5 #ifndef UI_BASE_EVENTS_EVENT_H_ |
6 #define UI_BASE_EVENTS_EVENT_H_ | 6 #define UI_BASE_EVENTS_EVENT_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/event_types.h" | 10 #include "base/event_types.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 Event* event_; | 46 Event* event_; |
47 | 47 |
48 DISALLOW_COPY_AND_ASSIGN(DispatcherApi); | 48 DISALLOW_COPY_AND_ASSIGN(DispatcherApi); |
49 }; | 49 }; |
50 | 50 |
51 // For testing. | 51 // For testing. |
52 class TestApi { | 52 class TestApi { |
53 public: | 53 public: |
54 explicit TestApi(Event* event) : event_(event) {} | 54 explicit TestApi(Event* event) : event_(event) {} |
55 | 55 |
56 void set_time_stamp(const base::TimeDelta& time_stamp) { | 56 void set_time_stamp(base::TimeDelta time_stamp) { |
57 event_->time_stamp_ = time_stamp; | 57 event_->time_stamp_ = time_stamp; |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 TestApi(); | 61 TestApi(); |
62 Event* event_; | 62 Event* event_; |
63 }; | 63 }; |
64 | 64 |
65 const base::NativeEvent& native_event() const { return native_event_; } | 65 const base::NativeEvent& native_event() const { return native_event_; } |
66 EventType type() const { return type_; } | 66 EventType type() const { return type_; } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 case ET_GESTURE_PINCH_BEGIN: | 134 case ET_GESTURE_PINCH_BEGIN: |
135 case ET_GESTURE_PINCH_END: | 135 case ET_GESTURE_PINCH_END: |
136 case ET_GESTURE_PINCH_UPDATE: | 136 case ET_GESTURE_PINCH_UPDATE: |
137 case ET_GESTURE_LONG_PRESS: | 137 case ET_GESTURE_LONG_PRESS: |
138 case ET_GESTURE_LONG_TAP: | 138 case ET_GESTURE_LONG_TAP: |
139 case ET_GESTURE_MULTIFINGER_SWIPE: | 139 case ET_GESTURE_MULTIFINGER_SWIPE: |
140 return true; | 140 return true; |
141 | 141 |
142 case ET_SCROLL_FLING_CANCEL: | 142 case ET_SCROLL_FLING_CANCEL: |
143 case ET_SCROLL_FLING_START: | 143 case ET_SCROLL_FLING_START: |
144 // These can be ScrollEvents too. But for ScrollEvents have valid native | 144 // These can be ScrollEvents too. EF_FROM_TOUCH determines if they're |
145 // events. No gesture events have native events. | 145 // Gesture or Scroll events. |
146 return !HasNativeEvent(); | 146 return (flags_ & EF_FROM_TOUCH) == EF_FROM_TOUCH; |
147 | 147 |
148 default: | 148 default: |
149 break; | 149 break; |
150 } | 150 } |
151 return false; | 151 return false; |
152 } | 152 } |
153 | 153 |
154 bool IsScrollEvent() const { | 154 bool IsScrollEvent() const { |
| 155 // Flings can be GestureEvents too. EF_FROM_TOUCH determins if they're |
| 156 // Gesture or Scroll events. |
155 return type_ == ET_SCROLL || | 157 return type_ == ET_SCROLL || |
156 ((type_ == ET_SCROLL_FLING_START || | 158 ((type_ == ET_SCROLL_FLING_START || |
157 type_ == ET_SCROLL_FLING_CANCEL) && HasNativeEvent()); | 159 type_ == ET_SCROLL_FLING_CANCEL) && |
| 160 !(flags() & EF_FROM_TOUCH)); |
158 } | 161 } |
159 | 162 |
160 bool IsScrollGestureEvent() const { | 163 bool IsScrollGestureEvent() const { |
161 return type_ == ET_GESTURE_SCROLL_BEGIN || | 164 return type_ == ET_GESTURE_SCROLL_BEGIN || |
162 type_ == ET_GESTURE_SCROLL_UPDATE || | 165 type_ == ET_GESTURE_SCROLL_UPDATE || |
163 type_ == ET_GESTURE_SCROLL_END; | 166 type_ == ET_GESTURE_SCROLL_END; |
164 } | 167 } |
165 | 168 |
166 bool IsFlingScrollEvent() const { | 169 bool IsFlingScrollEvent() const { |
167 return type_ == ET_SCROLL_FLING_CANCEL || | 170 return type_ == ET_SCROLL_FLING_CANCEL || |
(...skipping 24 matching lines...) Expand all Loading... |
192 Event(const Event& copy); | 195 Event(const Event& copy); |
193 void SetType(EventType type); | 196 void SetType(EventType type); |
194 void set_delete_native_event(bool delete_native_event) { | 197 void set_delete_native_event(bool delete_native_event) { |
195 delete_native_event_ = delete_native_event; | 198 delete_native_event_ = delete_native_event; |
196 } | 199 } |
197 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } | 200 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } |
198 void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) { | 201 void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) { |
199 dispatch_to_hidden_targets_ = dispatch_to_hidden_targets; | 202 dispatch_to_hidden_targets_ = dispatch_to_hidden_targets; |
200 } | 203 } |
201 | 204 |
| 205 void set_time_stamp(const base::TimeDelta& time_stamp) { |
| 206 time_stamp_ = time_stamp; |
| 207 } |
| 208 |
202 void set_name(const std::string& name) { name_ = name; } | 209 void set_name(const std::string& name) { name_ = name; } |
203 | 210 |
204 private: | 211 private: |
205 void operator=(const Event&); | 212 void operator=(const Event&); |
206 | 213 |
207 // Safely initializes the native event members of this class. | 214 // Safely initializes the native event members of this class. |
208 void Init(); | 215 void Init(); |
209 void InitWithNativeEvent(const base::NativeEvent& native_event); | 216 void InitWithNativeEvent(const base::NativeEvent& native_event); |
210 | 217 |
211 base::NativeEvent native_event_; | 218 base::NativeEvent native_event_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 virtual void UpdateForRootTransform(const gfx::Transform& root_transform); | 269 virtual void UpdateForRootTransform(const gfx::Transform& root_transform); |
263 | 270 |
264 template <class T> void ConvertLocationToTarget(T* source, T* target) { | 271 template <class T> void ConvertLocationToTarget(T* source, T* target) { |
265 if (target && target != source) | 272 if (target && target != source) |
266 T::ConvertPointToTarget(source, target, &location_); | 273 T::ConvertPointToTarget(source, target, &location_); |
267 } | 274 } |
268 | 275 |
269 protected: | 276 protected: |
270 explicit LocatedEvent(const base::NativeEvent& native_event); | 277 explicit LocatedEvent(const base::NativeEvent& native_event); |
271 | 278 |
| 279 explicit LocatedEvent(const LocatedEvent& model); |
| 280 |
272 // Create a new LocatedEvent which is identical to the provided model. | 281 // Create a new LocatedEvent which is identical to the provided model. |
273 // If source / target windows are provided, the model location will be | 282 // If source / target windows are provided, the model location will be |
274 // converted from |source| coordinate system to |target| coordinate system. | 283 // converted from |source| coordinate system to |target| coordinate system. |
275 template <class T> | 284 template <class T> |
276 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 285 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
277 : Event(model), | 286 : Event(model), |
278 location_(model.location_), | 287 location_(model.location_), |
279 root_location_(model.root_location_), | 288 root_location_(model.root_location_), |
280 valid_system_location_(model.valid_system_location_), | 289 valid_system_location_(model.valid_system_location_), |
281 system_location_(model.system_location_) { | 290 system_location_(model.system_location_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 T* source, | 331 T* source, |
323 T* target, | 332 T* target, |
324 EventType type, | 333 EventType type, |
325 int flags) | 334 int flags) |
326 : LocatedEvent(model, source, target), | 335 : LocatedEvent(model, source, target), |
327 changed_button_flags_(model.changed_button_flags_) { | 336 changed_button_flags_(model.changed_button_flags_) { |
328 SetType(type); | 337 SetType(type); |
329 set_flags(flags); | 338 set_flags(flags); |
330 } | 339 } |
331 | 340 |
| 341 explicit MouseEvent(const MouseEvent& model) |
| 342 : LocatedEvent(model), |
| 343 changed_button_flags_(model.changed_button_flags_) { |
| 344 } |
| 345 |
332 // Used for synthetic events in testing and by the gesture recognizer. | 346 // Used for synthetic events in testing and by the gesture recognizer. |
333 MouseEvent(EventType type, | 347 MouseEvent(EventType type, |
334 const gfx::Point& location, | 348 const gfx::Point& location, |
335 const gfx::Point& root_location, | 349 const gfx::Point& root_location, |
336 int flags); | 350 int flags); |
337 | 351 |
338 // Conveniences to quickly test what button is down | 352 // Conveniences to quickly test what button is down |
339 bool IsOnlyLeftMouseButton() const { | 353 bool IsOnlyLeftMouseButton() const { |
340 return (flags() & EF_LEFT_MOUSE_BUTTON) && | 354 return (flags() & EF_LEFT_MOUSE_BUTTON) && |
341 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON)); | 355 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON)); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 float radius_x_; | 519 float radius_x_; |
506 | 520 |
507 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 521 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
508 float radius_y_; | 522 float radius_y_; |
509 | 523 |
510 // Angle of the major axis away from the X axis. Default 0.0. | 524 // Angle of the major axis away from the X axis. Default 0.0. |
511 float rotation_angle_; | 525 float rotation_angle_; |
512 | 526 |
513 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. | 527 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. |
514 float force_; | 528 float force_; |
515 | |
516 DISALLOW_COPY_AND_ASSIGN(TouchEvent); | |
517 }; | 529 }; |
518 | 530 |
519 class UI_EXPORT KeyEvent : public Event { | 531 class UI_EXPORT KeyEvent : public Event { |
520 public: | 532 public: |
521 KeyEvent(const base::NativeEvent& native_event, bool is_char); | 533 KeyEvent(const base::NativeEvent& native_event, bool is_char); |
522 | 534 |
523 // Used for synthetic events in testing. | 535 // Used for synthetic events in testing. |
524 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); | 536 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); |
525 | 537 |
526 // These setters allow an I18N virtual keyboard to fabricate a keyboard event | 538 // These setters allow an I18N virtual keyboard to fabricate a keyboard event |
(...skipping 30 matching lines...) Expand all Loading... |
557 void NormalizeFlags(); | 569 void NormalizeFlags(); |
558 | 570 |
559 private: | 571 private: |
560 KeyboardCode key_code_; | 572 KeyboardCode key_code_; |
561 // True if this is a translated character event (vs. a raw key down). Both | 573 // True if this is a translated character event (vs. a raw key down). Both |
562 // share the same type: ET_KEY_PRESSED. | 574 // share the same type: ET_KEY_PRESSED. |
563 bool is_char_; | 575 bool is_char_; |
564 | 576 |
565 uint16 character_; | 577 uint16 character_; |
566 uint16 unmodified_character_; | 578 uint16 unmodified_character_; |
567 | |
568 DISALLOW_COPY_AND_ASSIGN(KeyEvent); | |
569 }; | 579 }; |
570 | 580 |
571 // A key event which is translated by an input method (IME). | 581 // A key event which is translated by an input method (IME). |
572 // For example, if an IME receives a KeyEvent(VKEY_SPACE), and it does not | 582 // For example, if an IME receives a KeyEvent(VKEY_SPACE), and it does not |
573 // consume the key, the IME usually generates and dispatches a | 583 // consume the key, the IME usually generates and dispatches a |
574 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and | 584 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and |
575 // it does consume the event, it might dispatch a | 585 // it does consume the event, it might dispatch a |
576 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. | 586 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. |
577 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { | 587 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { |
578 public: | 588 public: |
(...skipping 29 matching lines...) Expand all Loading... |
608 | 618 |
609 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 619 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
610 }; | 620 }; |
611 | 621 |
612 class UI_EXPORT ScrollEvent : public MouseEvent { | 622 class UI_EXPORT ScrollEvent : public MouseEvent { |
613 public: | 623 public: |
614 explicit ScrollEvent(const base::NativeEvent& native_event); | 624 explicit ScrollEvent(const base::NativeEvent& native_event); |
615 template <class T> | 625 template <class T> |
616 ScrollEvent(const ScrollEvent& model, | 626 ScrollEvent(const ScrollEvent& model, |
617 T* source, | 627 T* source, |
618 T* target, | 628 T* target) |
619 EventType type, | 629 : MouseEvent(model, source, target), |
620 int flags) | |
621 : MouseEvent(model, source, target, type, flags), | |
622 x_offset_(model.x_offset_), | 630 x_offset_(model.x_offset_), |
623 y_offset_(model.y_offset_), | 631 y_offset_(model.y_offset_), |
624 finger_count_(model.finger_count_){ | 632 finger_count_(model.finger_count_){ |
625 } | 633 } |
626 | 634 |
627 // Used for tests. | 635 // Used for tests. |
628 ScrollEvent(EventType type, | 636 ScrollEvent(EventType type, |
629 const gfx::Point& location, | 637 const gfx::Point& location, |
| 638 base::TimeDelta time_stamp, |
630 int flags, | 639 int flags, |
631 float x_offset, | 640 float x_offset, |
632 float y_offset); | 641 float y_offset, |
| 642 int finger_count); |
633 | 643 |
634 // Scale the scroll event's offset value. | 644 // Scale the scroll event's offset value. |
635 // This is useful in the multi-monitor setup where it needs to be scaled | 645 // This is useful in the multi-monitor setup where it needs to be scaled |
636 // to provide a consistent user experience. | 646 // to provide a consistent user experience. |
637 void Scale(const float factor); | 647 void Scale(const float factor); |
638 | 648 |
639 float x_offset() const { return x_offset_; } | 649 float x_offset() const { return x_offset_; } |
640 float y_offset() const { return y_offset_; } | 650 float y_offset() const { return y_offset_; } |
641 int finger_count() const { return finger_count_; } | 651 int finger_count() const { return finger_count_; } |
642 | 652 |
643 private: | 653 private: |
644 float x_offset_; | 654 float x_offset_; |
645 float y_offset_; | 655 float y_offset_; |
646 int finger_count_; | 656 int finger_count_; |
647 | |
648 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); | |
649 }; | 657 }; |
650 | 658 |
651 class UI_EXPORT GestureEvent : public LocatedEvent { | 659 class UI_EXPORT GestureEvent : public LocatedEvent { |
652 public: | 660 public: |
653 GestureEvent(EventType type, | 661 GestureEvent(EventType type, |
654 int x, | 662 int x, |
655 int y, | 663 int y, |
656 int flags, | 664 int flags, |
657 base::TimeDelta time_stamp, | 665 base::TimeDelta time_stamp, |
658 const GestureEventDetails& details, | 666 const GestureEventDetails& details, |
(...skipping 25 matching lines...) Expand all Loading... |
684 // This value is stored as a bitfield because the number of touch ids varies, | 692 // This value is stored as a bitfield because the number of touch ids varies, |
685 // but we currently don't need more than 32 touches at a time. | 693 // but we currently don't need more than 32 touches at a time. |
686 const unsigned int touch_ids_bitfield_; | 694 const unsigned int touch_ids_bitfield_; |
687 | 695 |
688 DISALLOW_COPY_AND_ASSIGN(GestureEvent); | 696 DISALLOW_COPY_AND_ASSIGN(GestureEvent); |
689 }; | 697 }; |
690 | 698 |
691 } // namespace ui | 699 } // namespace ui |
692 | 700 |
693 #endif // UI_BASE_EVENTS_EVENT_H_ | 701 #endif // UI_BASE_EVENTS_EVENT_H_ |
OLD | NEW |