Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. But for ScrollEvents have valid native |
| 145 // events. No gesture events have native events. | 145 // events. No gesture events have native events. |
|
sadrul
2013/01/22 20:07:24
Update the comment.
DaveMoore
2013/01/27 21:21:54
Done.
| |
| 146 return !HasNativeEvent(); | 146 return flags_ & 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 return type_ == ET_SCROLL || | 155 return type_ == ET_SCROLL || |
| 156 ((type_ == ET_SCROLL_FLING_START || | 156 ((type_ == ET_SCROLL_FLING_START || |
| 157 type_ == ET_SCROLL_FLING_CANCEL) && HasNativeEvent()); | 157 type_ == ET_SCROLL_FLING_CANCEL) && |
| 158 !(flags() & EF_FROM_TOUCH)); | |
| 158 } | 159 } |
| 159 | 160 |
| 160 bool IsScrollGestureEvent() const { | 161 bool IsScrollGestureEvent() const { |
| 161 return type_ == ET_GESTURE_SCROLL_BEGIN || | 162 return type_ == ET_GESTURE_SCROLL_BEGIN || |
| 162 type_ == ET_GESTURE_SCROLL_UPDATE || | 163 type_ == ET_GESTURE_SCROLL_UPDATE || |
| 163 type_ == ET_GESTURE_SCROLL_END; | 164 type_ == ET_GESTURE_SCROLL_END; |
| 164 } | 165 } |
| 165 | 166 |
| 166 bool IsFlingScrollEvent() const { | 167 bool IsFlingScrollEvent() const { |
| 167 return type_ == ET_SCROLL_FLING_CANCEL || | 168 return type_ == ET_SCROLL_FLING_CANCEL || |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 192 Event(const Event& copy); | 193 Event(const Event& copy); |
| 193 void SetType(EventType type); | 194 void SetType(EventType type); |
| 194 void set_delete_native_event(bool delete_native_event) { | 195 void set_delete_native_event(bool delete_native_event) { |
| 195 delete_native_event_ = delete_native_event; | 196 delete_native_event_ = delete_native_event; |
| 196 } | 197 } |
| 197 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } | 198 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } |
| 198 void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) { | 199 void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) { |
| 199 dispatch_to_hidden_targets_ = dispatch_to_hidden_targets; | 200 dispatch_to_hidden_targets_ = dispatch_to_hidden_targets; |
| 200 } | 201 } |
| 201 | 202 |
| 203 void set_time_stamp(const base::TimeDelta& time_stamp) { | |
|
sky
2013/01/22 18:05:01
We generally don't pass TimeDeltas by const-ref.
DaveMoore
2013/01/27 21:21:54
Done.
| |
| 204 time_stamp_ = time_stamp; | |
| 205 } | |
| 206 | |
| 202 void set_name(const std::string& name) { name_ = name; } | 207 void set_name(const std::string& name) { name_ = name; } |
| 203 | 208 |
| 204 private: | 209 private: |
| 205 void operator=(const Event&); | 210 void operator=(const Event&); |
| 206 | 211 |
| 207 // Safely initializes the native event members of this class. | 212 // Safely initializes the native event members of this class. |
| 208 void Init(); | 213 void Init(); |
| 209 void InitWithNativeEvent(const base::NativeEvent& native_event); | 214 void InitWithNativeEvent(const base::NativeEvent& native_event); |
| 210 | 215 |
| 211 base::NativeEvent native_event_; | 216 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); | 267 virtual void UpdateForRootTransform(const gfx::Transform& root_transform); |
| 263 | 268 |
| 264 template <class T> void ConvertLocationToTarget(T* source, T* target) { | 269 template <class T> void ConvertLocationToTarget(T* source, T* target) { |
| 265 if (target && target != source) | 270 if (target && target != source) |
| 266 T::ConvertPointToTarget(source, target, &location_); | 271 T::ConvertPointToTarget(source, target, &location_); |
| 267 } | 272 } |
| 268 | 273 |
| 269 protected: | 274 protected: |
| 270 explicit LocatedEvent(const base::NativeEvent& native_event); | 275 explicit LocatedEvent(const base::NativeEvent& native_event); |
| 271 | 276 |
| 277 LocatedEvent(const LocatedEvent& model); | |
|
sky
2013/01/22 18:05:01
explicit
DaveMoore
2013/01/27 21:21:54
Done.
| |
| 278 | |
| 272 // Create a new LocatedEvent which is identical to the provided model. | 279 // Create a new LocatedEvent which is identical to the provided model. |
| 273 // If source / target windows are provided, the model location will be | 280 // If source / target windows are provided, the model location will be |
| 274 // converted from |source| coordinate system to |target| coordinate system. | 281 // converted from |source| coordinate system to |target| coordinate system. |
| 275 template <class T> | 282 template <class T> |
| 276 LocatedEvent(const LocatedEvent& model, T* source, T* target) | 283 LocatedEvent(const LocatedEvent& model, T* source, T* target) |
| 277 : Event(model), | 284 : Event(model), |
| 278 location_(model.location_), | 285 location_(model.location_), |
| 279 root_location_(model.root_location_), | 286 root_location_(model.root_location_), |
| 280 valid_system_location_(model.valid_system_location_), | 287 valid_system_location_(model.valid_system_location_), |
| 281 system_location_(model.system_location_) { | 288 system_location_(model.system_location_) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 T* source, | 329 T* source, |
| 323 T* target, | 330 T* target, |
| 324 EventType type, | 331 EventType type, |
| 325 int flags) | 332 int flags) |
| 326 : LocatedEvent(model, source, target), | 333 : LocatedEvent(model, source, target), |
| 327 changed_button_flags_(model.changed_button_flags_) { | 334 changed_button_flags_(model.changed_button_flags_) { |
| 328 SetType(type); | 335 SetType(type); |
| 329 set_flags(flags); | 336 set_flags(flags); |
| 330 } | 337 } |
| 331 | 338 |
| 339 MouseEvent(const MouseEvent& model) | |
|
sky
2013/01/22 18:05:01
explicit
DaveMoore
2013/01/27 21:21:54
Done, but AutoFillDialogViews was depending on the
| |
| 340 : LocatedEvent(model), | |
| 341 changed_button_flags_(model.changed_button_flags_) { | |
| 342 } | |
| 343 | |
| 332 // Used for synthetic events in testing and by the gesture recognizer. | 344 // Used for synthetic events in testing and by the gesture recognizer. |
| 333 MouseEvent(EventType type, | 345 MouseEvent(EventType type, |
| 334 const gfx::Point& location, | 346 const gfx::Point& location, |
| 335 const gfx::Point& root_location, | 347 const gfx::Point& root_location, |
| 336 int flags); | 348 int flags); |
| 337 | 349 |
| 338 // Conveniences to quickly test what button is down | 350 // Conveniences to quickly test what button is down |
| 339 bool IsOnlyLeftMouseButton() const { | 351 bool IsOnlyLeftMouseButton() const { |
| 340 return (flags() & EF_LEFT_MOUSE_BUTTON) && | 352 return (flags() & EF_LEFT_MOUSE_BUTTON) && |
| 341 !(flags() & (EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON)); | 353 !(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_; | 517 float radius_x_; |
| 506 | 518 |
| 507 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. | 519 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. |
| 508 float radius_y_; | 520 float radius_y_; |
| 509 | 521 |
| 510 // Angle of the major axis away from the X axis. Default 0.0. | 522 // Angle of the major axis away from the X axis. Default 0.0. |
| 511 float rotation_angle_; | 523 float rotation_angle_; |
| 512 | 524 |
| 513 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. | 525 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. |
| 514 float force_; | 526 float force_; |
| 515 | |
| 516 DISALLOW_COPY_AND_ASSIGN(TouchEvent); | |
| 517 }; | 527 }; |
| 518 | 528 |
| 519 class UI_EXPORT KeyEvent : public Event { | 529 class UI_EXPORT KeyEvent : public Event { |
| 520 public: | 530 public: |
| 521 KeyEvent(const base::NativeEvent& native_event, bool is_char); | 531 KeyEvent(const base::NativeEvent& native_event, bool is_char); |
| 522 | 532 |
| 523 // Used for synthetic events in testing. | 533 // Used for synthetic events in testing. |
| 524 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); | 534 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); |
| 525 | 535 |
| 526 // These setters allow an I18N virtual keyboard to fabricate a keyboard event | 536 // These setters allow an I18N virtual keyboard to fabricate a keyboard event |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 557 void NormalizeFlags(); | 567 void NormalizeFlags(); |
| 558 | 568 |
| 559 private: | 569 private: |
| 560 KeyboardCode key_code_; | 570 KeyboardCode key_code_; |
| 561 // True if this is a translated character event (vs. a raw key down). Both | 571 // True if this is a translated character event (vs. a raw key down). Both |
| 562 // share the same type: ET_KEY_PRESSED. | 572 // share the same type: ET_KEY_PRESSED. |
| 563 bool is_char_; | 573 bool is_char_; |
| 564 | 574 |
| 565 uint16 character_; | 575 uint16 character_; |
| 566 uint16 unmodified_character_; | 576 uint16 unmodified_character_; |
| 567 | |
| 568 DISALLOW_COPY_AND_ASSIGN(KeyEvent); | |
| 569 }; | 577 }; |
| 570 | 578 |
| 571 // A key event which is translated by an input method (IME). | 579 // 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 | 580 // 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 | 581 // consume the key, the IME usually generates and dispatches a |
| 574 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and | 582 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and |
| 575 // it does consume the event, it might dispatch a | 583 // it does consume the event, it might dispatch a |
| 576 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. | 584 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. |
| 577 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { | 585 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { |
| 578 public: | 586 public: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 608 | 616 |
| 609 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); | 617 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); |
| 610 }; | 618 }; |
| 611 | 619 |
| 612 class UI_EXPORT ScrollEvent : public MouseEvent { | 620 class UI_EXPORT ScrollEvent : public MouseEvent { |
| 613 public: | 621 public: |
| 614 explicit ScrollEvent(const base::NativeEvent& native_event); | 622 explicit ScrollEvent(const base::NativeEvent& native_event); |
| 615 template <class T> | 623 template <class T> |
| 616 ScrollEvent(const ScrollEvent& model, | 624 ScrollEvent(const ScrollEvent& model, |
| 617 T* source, | 625 T* source, |
| 618 T* target, | 626 T* target) |
| 619 EventType type, | 627 : MouseEvent(model, source, target), |
| 620 int flags) | |
| 621 : MouseEvent(model, source, target, type, flags), | |
| 622 x_offset_(model.x_offset_), | 628 x_offset_(model.x_offset_), |
| 623 y_offset_(model.y_offset_), | 629 y_offset_(model.y_offset_), |
| 624 finger_count_(model.finger_count_){ | 630 finger_count_(model.finger_count_){ |
| 625 } | 631 } |
| 626 | 632 |
| 627 // Used for tests. | 633 // Used for tests. |
| 628 ScrollEvent(EventType type, | 634 ScrollEvent(EventType type, |
| 629 const gfx::Point& location, | 635 const gfx::Point& location, |
| 636 base::TimeDelta time_stamp, | |
| 630 int flags, | 637 int flags, |
| 631 float x_offset, | 638 float x_offset, |
| 632 float y_offset); | 639 float y_offset, |
| 640 int finger_count); | |
| 633 | 641 |
| 634 // Scale the scroll event's offset value. | 642 // Scale the scroll event's offset value. |
| 635 // This is useful in the multi-monitor setup where it needs to be scaled | 643 // This is useful in the multi-monitor setup where it needs to be scaled |
| 636 // to provide a consistent user experience. | 644 // to provide a consistent user experience. |
| 637 void Scale(const float factor); | 645 void Scale(const float factor); |
| 638 | 646 |
| 639 float x_offset() const { return x_offset_; } | 647 float x_offset() const { return x_offset_; } |
| 640 float y_offset() const { return y_offset_; } | 648 float y_offset() const { return y_offset_; } |
| 641 int finger_count() const { return finger_count_; } | 649 int finger_count() const { return finger_count_; } |
| 642 | 650 |
| 643 private: | 651 private: |
| 644 float x_offset_; | 652 float x_offset_; |
| 645 float y_offset_; | 653 float y_offset_; |
| 646 int finger_count_; | 654 int finger_count_; |
| 647 | |
| 648 DISALLOW_COPY_AND_ASSIGN(ScrollEvent); | |
| 649 }; | 655 }; |
| 650 | 656 |
| 651 class UI_EXPORT GestureEvent : public LocatedEvent { | 657 class UI_EXPORT GestureEvent : public LocatedEvent { |
| 652 public: | 658 public: |
| 653 GestureEvent(EventType type, | 659 GestureEvent(EventType type, |
| 654 int x, | 660 int x, |
| 655 int y, | 661 int y, |
| 656 int flags, | 662 int flags, |
| 657 base::TimeDelta time_stamp, | 663 base::TimeDelta time_stamp, |
| 658 const GestureEventDetails& details, | 664 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, | 690 // 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. | 691 // but we currently don't need more than 32 touches at a time. |
| 686 const unsigned int touch_ids_bitfield_; | 692 const unsigned int touch_ids_bitfield_; |
| 687 | 693 |
| 688 DISALLOW_COPY_AND_ASSIGN(GestureEvent); | 694 DISALLOW_COPY_AND_ASSIGN(GestureEvent); |
| 689 }; | 695 }; |
| 690 | 696 |
| 691 } // namespace ui | 697 } // namespace ui |
| 692 | 698 |
| 693 #endif // UI_BASE_EVENTS_EVENT_H_ | 699 #endif // UI_BASE_EVENTS_EVENT_H_ |
| OLD | NEW |