Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: ui/base/events/event.h

Issue 12088015: Add ability for EventGenerator to generate Scroll events asynchronously (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Free any leftover events in destructor Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.cc ('k') | ui/base/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 float radius_x_; 512 float radius_x_;
506 513
507 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. 514 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
508 float radius_y_; 515 float radius_y_;
509 516
510 // Angle of the major axis away from the X axis. Default 0.0. 517 // Angle of the major axis away from the X axis. Default 0.0.
511 float rotation_angle_; 518 float rotation_angle_;
512 519
513 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0. 520 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
514 float force_; 521 float force_;
515
516 DISALLOW_COPY_AND_ASSIGN(TouchEvent);
517 }; 522 };
518 523
519 class UI_EXPORT KeyEvent : public Event { 524 class UI_EXPORT KeyEvent : public Event {
520 public: 525 public:
521 KeyEvent(const base::NativeEvent& native_event, bool is_char); 526 KeyEvent(const base::NativeEvent& native_event, bool is_char);
522 527
523 // Used for synthetic events in testing. 528 // Used for synthetic events in testing.
524 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char); 529 KeyEvent(EventType type, KeyboardCode key_code, int flags, bool is_char);
525 530
526 // These setters allow an I18N virtual keyboard to fabricate a keyboard event 531 // These setters allow an I18N virtual keyboard to fabricate a keyboard event
(...skipping 30 matching lines...) Expand all
557 void NormalizeFlags(); 562 void NormalizeFlags();
558 563
559 private: 564 private:
560 KeyboardCode key_code_; 565 KeyboardCode key_code_;
561 // True if this is a translated character event (vs. a raw key down). Both 566 // True if this is a translated character event (vs. a raw key down). Both
562 // share the same type: ET_KEY_PRESSED. 567 // share the same type: ET_KEY_PRESSED.
563 bool is_char_; 568 bool is_char_;
564 569
565 uint16 character_; 570 uint16 character_;
566 uint16 unmodified_character_; 571 uint16 unmodified_character_;
567
568 DISALLOW_COPY_AND_ASSIGN(KeyEvent);
569 }; 572 };
570 573
571 // A key event which is translated by an input method (IME). 574 // 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 575 // 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 576 // consume the key, the IME usually generates and dispatches a
574 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and 577 // TranslatedKeyEvent(VKEY_SPACE) event. If the IME receives a KeyEvent and
575 // it does consume the event, it might dispatch a 578 // it does consume the event, it might dispatch a
576 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec. 579 // TranslatedKeyEvent(VKEY_PROCESSKEY) event as defined in the DOM spec.
577 class UI_EXPORT TranslatedKeyEvent : public KeyEvent { 580 class UI_EXPORT TranslatedKeyEvent : public KeyEvent {
578 public: 581 public:
(...skipping 29 matching lines...) Expand all
608 611
609 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent); 612 DISALLOW_COPY_AND_ASSIGN(DropTargetEvent);
610 }; 613 };
611 614
612 class UI_EXPORT ScrollEvent : public MouseEvent { 615 class UI_EXPORT ScrollEvent : public MouseEvent {
613 public: 616 public:
614 explicit ScrollEvent(const base::NativeEvent& native_event); 617 explicit ScrollEvent(const base::NativeEvent& native_event);
615 template <class T> 618 template <class T>
616 ScrollEvent(const ScrollEvent& model, 619 ScrollEvent(const ScrollEvent& model,
617 T* source, 620 T* source,
618 T* target, 621 T* target)
619 EventType type, 622 : MouseEvent(model, source, target),
620 int flags)
621 : MouseEvent(model, source, target, type, flags),
622 x_offset_(model.x_offset_), 623 x_offset_(model.x_offset_),
623 y_offset_(model.y_offset_), 624 y_offset_(model.y_offset_),
624 finger_count_(model.finger_count_){ 625 finger_count_(model.finger_count_){
625 } 626 }
626 627
627 // Used for tests. 628 // Used for tests.
628 ScrollEvent(EventType type, 629 ScrollEvent(EventType type,
629 const gfx::Point& location, 630 const gfx::Point& location,
631 base::TimeDelta time_stamp,
630 int flags, 632 int flags,
631 float x_offset, 633 float x_offset,
632 float y_offset); 634 float y_offset,
635 int finger_count);
633 636
634 // Scale the scroll event's offset value. 637 // Scale the scroll event's offset value.
635 // This is useful in the multi-monitor setup where it needs to be scaled 638 // This is useful in the multi-monitor setup where it needs to be scaled
636 // to provide a consistent user experience. 639 // to provide a consistent user experience.
637 void Scale(const float factor); 640 void Scale(const float factor);
638 641
639 float x_offset() const { return x_offset_; } 642 float x_offset() const { return x_offset_; }
640 float y_offset() const { return y_offset_; } 643 float y_offset() const { return y_offset_; }
641 int finger_count() const { return finger_count_; } 644 int finger_count() const { return finger_count_; }
642 645
643 private: 646 private:
644 float x_offset_; 647 float x_offset_;
645 float y_offset_; 648 float y_offset_;
646 int finger_count_; 649 int finger_count_;
647
648 DISALLOW_COPY_AND_ASSIGN(ScrollEvent);
649 }; 650 };
650 651
651 class UI_EXPORT GestureEvent : public LocatedEvent { 652 class UI_EXPORT GestureEvent : public LocatedEvent {
652 public: 653 public:
653 GestureEvent(EventType type, 654 GestureEvent(EventType type,
654 int x, 655 int x,
655 int y, 656 int y,
656 int flags, 657 int flags,
657 base::TimeDelta time_stamp, 658 base::TimeDelta time_stamp,
658 const GestureEventDetails& details, 659 const GestureEventDetails& details,
(...skipping 25 matching lines...) Expand all
684 // This value is stored as a bitfield because the number of touch ids varies, 685 // 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. 686 // but we currently don't need more than 32 touches at a time.
686 const unsigned int touch_ids_bitfield_; 687 const unsigned int touch_ids_bitfield_;
687 688
688 DISALLOW_COPY_AND_ASSIGN(GestureEvent); 689 DISALLOW_COPY_AND_ASSIGN(GestureEvent);
689 }; 690 };
690 691
691 } // namespace ui 692 } // namespace ui
692 693
693 #endif // UI_BASE_EVENTS_EVENT_H_ 694 #endif // UI_BASE_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.cc ('k') | ui/base/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698