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

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

Issue 519113002: Do not mutate ui::Event properties during nested event processing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | ui/events/event.cc » ('j') | ui/events/event_processor.cc » ('J')
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_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 "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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); } 208 bool stopped_propagation() const { return !!(result_ & ER_CONSUMED); }
209 209
210 // Marks the event as having been handled. A handled event does not reach the 210 // Marks the event as having been handled. A handled event does not reach the
211 // next event phase. For example, if an event is handled during the pre-target 211 // next event phase. For example, if an event is handled during the pre-target
212 // phase, then the event is dispatched to all pre-target handlers, but not to 212 // phase, then the event is dispatched to all pre-target handlers, but not to
213 // the target or post-target handlers. 213 // the target or post-target handlers.
214 // Note that SetHandled() can be called only for cancelable events. 214 // Note that SetHandled() can be called only for cancelable events.
215 void SetHandled(); 215 void SetHandled();
216 bool handled() const { return result_ != ER_UNHANDLED; } 216 bool handled() const { return result_ != ER_UNHANDLED; }
217 217
218 // Used to create a copy of |this|.
219 virtual scoped_ptr<Event> Clone() const = 0;
sadrul 2014/08/29 21:12:17 Can we have a static Event::Clone(const Event& eve
tdanderson 2014/09/02 22:57:09 Done.
220
218 protected: 221 protected:
219 Event(EventType type, base::TimeDelta time_stamp, int flags); 222 Event(EventType type, base::TimeDelta time_stamp, int flags);
220 Event(const base::NativeEvent& native_event, EventType type, int flags); 223 Event(const base::NativeEvent& native_event, EventType type, int flags);
221 Event(const Event& copy); 224 Event(const Event& copy);
222 void SetType(EventType type); 225 void SetType(EventType type);
223 void set_delete_native_event(bool delete_native_event) { 226 void set_delete_native_event(bool delete_native_event) {
224 delete_native_event_ = delete_native_event; 227 delete_native_event_ = delete_native_event;
225 } 228 }
226 void set_cancelable(bool cancelable) { cancelable_ = cancelable; } 229 void set_cancelable(bool cancelable) { cancelable_ = cancelable; }
227 230
(...skipping 20 matching lines...) Expand all
248 251
249 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information 252 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information
250 // is not available. 253 // is not available.
251 int source_device_id_; 254 int source_device_id_;
252 }; 255 };
253 256
254 class EVENTS_EXPORT CancelModeEvent : public Event { 257 class EVENTS_EXPORT CancelModeEvent : public Event {
255 public: 258 public:
256 CancelModeEvent(); 259 CancelModeEvent();
257 virtual ~CancelModeEvent(); 260 virtual ~CancelModeEvent();
261
262 // Event:
263 virtual scoped_ptr<Event> Clone() const OVERRIDE;
258 }; 264 };
259 265
260 class EVENTS_EXPORT LocatedEvent : public Event { 266 class EVENTS_EXPORT LocatedEvent : public Event {
261 public: 267 public:
262 virtual ~LocatedEvent(); 268 virtual ~LocatedEvent();
263 269
264 float x() const { return location_.x(); } 270 float x() const { return location_.x(); }
265 float y() const { return location_.y(); } 271 float y() const { return location_.y(); }
266 void set_location(const gfx::PointF& location) { location_ = location; } 272 void set_location(const gfx::PointF& location) { location_ = location; }
267 // TODO(tdresser): Always return floating point location. See 273 // TODO(tdresser): Always return floating point location. See
(...skipping 19 matching lines...) Expand all
287 if (!target || target == source) 293 if (!target || target == source)
288 return; 294 return;
289 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See 295 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See
290 // crbug.com/337824. 296 // crbug.com/337824.
291 gfx::Point offset = gfx::ToFlooredPoint(location_); 297 gfx::Point offset = gfx::ToFlooredPoint(location_);
292 T::ConvertPointToTarget(source, target, &offset); 298 T::ConvertPointToTarget(source, target, &offset);
293 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset; 299 gfx::Vector2d diff = gfx::ToFlooredPoint(location_) - offset;
294 location_= location_ - diff; 300 location_= location_ - diff;
295 } 301 }
296 302
303 // Event:
304 virtual scoped_ptr<Event> Clone() const OVERRIDE;
305
297 protected: 306 protected:
298 friend class LocatedEventTestApi; 307 friend class LocatedEventTestApi;
299 explicit LocatedEvent(const base::NativeEvent& native_event); 308 explicit LocatedEvent(const base::NativeEvent& native_event);
300 309
301 // Create a new LocatedEvent which is identical to the provided model. 310 // Create a new LocatedEvent which is identical to the provided model.
302 // If source / target windows are provided, the model location will be 311 // If source / target windows are provided, the model location will be
303 // converted from |source| coordinate system to |target| coordinate system. 312 // converted from |source| coordinate system to |target| coordinate system.
304 template <class T> 313 template <class T>
305 LocatedEvent(const LocatedEvent& model, T* source, T* target) 314 LocatedEvent(const LocatedEvent& model, T* source, T* target)
306 : Event(model), 315 : Event(model),
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 static bool IsRepeatedClickEvent( 403 static bool IsRepeatedClickEvent(
395 const MouseEvent& event1, 404 const MouseEvent& event1,
396 const MouseEvent& event2); 405 const MouseEvent& event2);
397 406
398 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise. 407 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
399 int GetClickCount() const; 408 int GetClickCount() const;
400 409
401 // Set the click count for a mousedown message. Can be 1, 2 or 3. 410 // Set the click count for a mousedown message. Can be 1, 2 or 3.
402 void SetClickCount(int click_count); 411 void SetClickCount(int click_count);
403 412
413 // Event:
414 virtual scoped_ptr<Event> Clone() const OVERRIDE;
415
404 // Identifies the button that changed. During a press this corresponds to the 416 // Identifies the button that changed. During a press this corresponds to the
405 // button that was pressed and during a release this corresponds to the button 417 // button that was pressed and during a release this corresponds to the button
406 // that was released. 418 // that was released.
407 // NOTE: during a press and release flags() contains the complete set of 419 // NOTE: during a press and release flags() contains the complete set of
408 // flags. Use this to determine the button that was pressed or released. 420 // flags. Use this to determine the button that was pressed or released.
409 int changed_button_flags() const { return changed_button_flags_; } 421 int changed_button_flags() const { return changed_button_flags_; }
410 422
411 // Updates the button that changed. 423 // Updates the button that changed.
412 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } 424 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; }
413 425
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 // The amount to scroll. This is in multiples of kWheelDelta. 475 // The amount to scroll. This is in multiples of kWheelDelta.
464 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up. 476 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up.
465 int x_offset() const { return offset_.x(); } 477 int x_offset() const { return offset_.x(); }
466 int y_offset() const { return offset_.y(); } 478 int y_offset() const { return offset_.y(); }
467 const gfx::Vector2d& offset() const { return offset_; } 479 const gfx::Vector2d& offset() const { return offset_; }
468 480
469 // Overridden from LocatedEvent. 481 // Overridden from LocatedEvent.
470 virtual void UpdateForRootTransform( 482 virtual void UpdateForRootTransform(
471 const gfx::Transform& inverted_root_transform) OVERRIDE; 483 const gfx::Transform& inverted_root_transform) OVERRIDE;
472 484
485 // Event:
486 virtual scoped_ptr<Event> Clone() const OVERRIDE;
487
473 private: 488 private:
474 gfx::Vector2d offset_; 489 gfx::Vector2d offset_;
475 }; 490 };
476 491
477 class EVENTS_EXPORT TouchEvent : public LocatedEvent { 492 class EVENTS_EXPORT TouchEvent : public LocatedEvent {
478 public: 493 public:
479 explicit TouchEvent(const base::NativeEvent& native_event); 494 explicit TouchEvent(const base::NativeEvent& native_event);
480 495
481 // Create a new TouchEvent which is identical to the provided model. 496 // Create a new TouchEvent which is identical to the provided model.
482 // If source / target windows are provided, the model location will be 497 // If source / target windows are provided, the model location will be
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 float force() const { return force_; } 530 float force() const { return force_; }
516 531
517 // Used for unit tests. 532 // Used for unit tests.
518 void set_radius_x(const float r) { radius_x_ = r; } 533 void set_radius_x(const float r) { radius_x_ = r; }
519 void set_radius_y(const float r) { radius_y_ = r; } 534 void set_radius_y(const float r) { radius_y_ = r; }
520 535
521 // Overridden from LocatedEvent. 536 // Overridden from LocatedEvent.
522 virtual void UpdateForRootTransform( 537 virtual void UpdateForRootTransform(
523 const gfx::Transform& inverted_root_transform) OVERRIDE; 538 const gfx::Transform& inverted_root_transform) OVERRIDE;
524 539
540 // Event:
541 virtual scoped_ptr<Event> Clone() const OVERRIDE;
542
525 protected: 543 protected:
526 void set_radius(float radius_x, float radius_y) { 544 void set_radius(float radius_x, float radius_y) {
527 radius_x_ = radius_x; 545 radius_x_ = radius_x;
528 radius_y_ = radius_y; 546 radius_y_ = radius_y;
529 } 547 }
530 548
531 void set_rotation_angle(float rotation_angle) { 549 void set_rotation_angle(float rotation_angle) {
532 rotation_angle_ = rotation_angle; 550 rotation_angle_ = rotation_angle;
533 } 551 }
534 552
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // Normalizes flags_ so that it describes the state after the event. 675 // Normalizes flags_ so that it describes the state after the event.
658 // (Native X11 event flags describe the state before the event.) 676 // (Native X11 event flags describe the state before the event.)
659 void NormalizeFlags(); 677 void NormalizeFlags();
660 678
661 // Returns true if the key event has already been processed by an input method 679 // Returns true if the key event has already been processed by an input method
662 // and there is no need to pass the key event to the input method again. 680 // and there is no need to pass the key event to the input method again.
663 bool IsTranslated() const; 681 bool IsTranslated() const;
664 // Marks this key event as translated or not translated. 682 // Marks this key event as translated or not translated.
665 void SetTranslated(bool translated); 683 void SetTranslated(bool translated);
666 684
685 // Event:
686 virtual scoped_ptr<Event> Clone() const OVERRIDE;
687
667 protected: 688 protected:
668 friend class KeyEventTestApi; 689 friend class KeyEventTestApi;
669 690
670 // This allows a subclass TranslatedKeyEvent to be a non character event. 691 // This allows a subclass TranslatedKeyEvent to be a non character event.
671 void set_is_char(bool is_char) { is_char_ = is_char; } 692 void set_is_char(bool is_char) { is_char_ = is_char; }
672 693
673 private: 694 private:
674 KeyboardCode key_code_; 695 KeyboardCode key_code_;
675 696
676 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space') 697 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space')
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 float y_offset, 751 float y_offset,
731 float x_offset_ordinal, 752 float x_offset_ordinal,
732 float y_offset_ordinal, 753 float y_offset_ordinal,
733 int finger_count); 754 int finger_count);
734 755
735 // Scale the scroll event's offset value. 756 // Scale the scroll event's offset value.
736 // This is useful in the multi-monitor setup where it needs to be scaled 757 // This is useful in the multi-monitor setup where it needs to be scaled
737 // to provide a consistent user experience. 758 // to provide a consistent user experience.
738 void Scale(const float factor); 759 void Scale(const float factor);
739 760
761 // Event:
762 virtual scoped_ptr<Event> Clone() const OVERRIDE;
763
740 float x_offset() const { return x_offset_; } 764 float x_offset() const { return x_offset_; }
741 float y_offset() const { return y_offset_; } 765 float y_offset() const { return y_offset_; }
742 float x_offset_ordinal() const { return x_offset_ordinal_; } 766 float x_offset_ordinal() const { return x_offset_ordinal_; }
743 float y_offset_ordinal() const { return y_offset_ordinal_; } 767 float y_offset_ordinal() const { return y_offset_ordinal_; }
744 int finger_count() const { return finger_count_; } 768 int finger_count() const { return finger_count_; }
745 769
746 private: 770 private:
747 // Potential accelerated offsets. 771 // Potential accelerated offsets.
748 float x_offset_; 772 float x_offset_;
749 float y_offset_; 773 float y_offset_;
(...skipping 16 matching lines...) Expand all
766 // If source / target windows are provided, the model location will be 790 // If source / target windows are provided, the model location will be
767 // converted from |source| coordinate system to |target| coordinate system. 791 // converted from |source| coordinate system to |target| coordinate system.
768 template <typename T> 792 template <typename T>
769 GestureEvent(const GestureEvent& model, T* source, T* target) 793 GestureEvent(const GestureEvent& model, T* source, T* target)
770 : LocatedEvent(model, source, target), 794 : LocatedEvent(model, source, target),
771 details_(model.details_) { 795 details_(model.details_) {
772 } 796 }
773 797
774 virtual ~GestureEvent(); 798 virtual ~GestureEvent();
775 799
800 // Event:
801 virtual scoped_ptr<Event> Clone() const OVERRIDE;
802
776 const GestureEventDetails& details() const { return details_; } 803 const GestureEventDetails& details() const { return details_; }
777 804
778 private: 805 private:
779 GestureEventDetails details_; 806 GestureEventDetails details_;
780 }; 807 };
781 808
782 } // namespace ui 809 } // namespace ui
783 810
784 #endif // UI_EVENTS_EVENT_H_ 811 #endif // UI_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/events/event.cc » ('j') | ui/events/event_processor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698