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

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

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
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 #include "ui/events/event.h" 5 #include "ui/events/event.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #endif 10 #endif
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // CancelModeEvent 229 // CancelModeEvent
230 230
231 CancelModeEvent::CancelModeEvent() 231 CancelModeEvent::CancelModeEvent()
232 : Event(ET_CANCEL_MODE, base::TimeDelta(), 0) { 232 : Event(ET_CANCEL_MODE, base::TimeDelta(), 0) {
233 set_cancelable(false); 233 set_cancelable(false);
234 } 234 }
235 235
236 CancelModeEvent::~CancelModeEvent() { 236 CancelModeEvent::~CancelModeEvent() {
237 } 237 }
238 238
239 scoped_ptr<Event> CancelModeEvent::Clone() const {
240 return scoped_ptr<Event>(new CancelModeEvent(*this));
241 }
242
239 //////////////////////////////////////////////////////////////////////////////// 243 ////////////////////////////////////////////////////////////////////////////////
240 // LocatedEvent 244 // LocatedEvent
241 245
242 LocatedEvent::~LocatedEvent() { 246 LocatedEvent::~LocatedEvent() {
243 } 247 }
244 248
245 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) 249 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event)
246 : Event(native_event, 250 : Event(native_event,
247 EventTypeFromNative(native_event), 251 EventTypeFromNative(native_event),
248 EventFlagsFromNative(native_event)), 252 EventFlagsFromNative(native_event)),
(...skipping 13 matching lines...) Expand all
262 266
263 void LocatedEvent::UpdateForRootTransform( 267 void LocatedEvent::UpdateForRootTransform(
264 const gfx::Transform& reversed_root_transform) { 268 const gfx::Transform& reversed_root_transform) {
265 // Transform has to be done at root level. 269 // Transform has to be done at root level.
266 gfx::Point3F p(location_); 270 gfx::Point3F p(location_);
267 reversed_root_transform.TransformPoint(&p); 271 reversed_root_transform.TransformPoint(&p);
268 location_ = p.AsPointF(); 272 location_ = p.AsPointF();
269 root_location_ = location_; 273 root_location_ = location_;
270 } 274 }
271 275
276 scoped_ptr<Event> LocatedEvent::Clone() const {
277 return scoped_ptr<Event>(new LocatedEvent(*this));
278 }
279
272 //////////////////////////////////////////////////////////////////////////////// 280 ////////////////////////////////////////////////////////////////////////////////
273 // MouseEvent 281 // MouseEvent
274 282
275 MouseEvent::MouseEvent(const base::NativeEvent& native_event) 283 MouseEvent::MouseEvent(const base::NativeEvent& native_event)
276 : LocatedEvent(native_event), 284 : LocatedEvent(native_event),
277 changed_button_flags_( 285 changed_button_flags_(
278 GetChangedMouseButtonFlagsFromNative(native_event)) { 286 GetChangedMouseButtonFlagsFromNative(native_event)) {
279 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) 287 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED)
280 SetClickCount(GetRepeatCount(*this)); 288 SetClickCount(GetRepeatCount(*this));
281 } 289 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 f &= ~EF_IS_TRIPLE_CLICK; 406 f &= ~EF_IS_TRIPLE_CLICK;
399 break; 407 break;
400 case 3: 408 case 3:
401 f &= ~EF_IS_DOUBLE_CLICK; 409 f &= ~EF_IS_DOUBLE_CLICK;
402 f |= EF_IS_TRIPLE_CLICK; 410 f |= EF_IS_TRIPLE_CLICK;
403 break; 411 break;
404 } 412 }
405 set_flags(f); 413 set_flags(f);
406 } 414 }
407 415
416 scoped_ptr<Event> MouseEvent::Clone() const {
417 return scoped_ptr<Event>(new MouseEvent(*this));
418 }
419
408 //////////////////////////////////////////////////////////////////////////////// 420 ////////////////////////////////////////////////////////////////////////////////
409 // MouseWheelEvent 421 // MouseWheelEvent
410 422
411 MouseWheelEvent::MouseWheelEvent(const base::NativeEvent& native_event) 423 MouseWheelEvent::MouseWheelEvent(const base::NativeEvent& native_event)
412 : MouseEvent(native_event), 424 : MouseEvent(native_event),
413 offset_(GetMouseWheelOffset(native_event)) { 425 offset_(GetMouseWheelOffset(native_event)) {
414 } 426 }
415 427
416 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event) 428 MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event)
417 : MouseEvent(scroll_event), 429 : MouseEvent(scroll_event),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 LocatedEvent::UpdateForRootTransform(inverted_root_transform); 468 LocatedEvent::UpdateForRootTransform(inverted_root_transform);
457 gfx::DecomposedTransform decomp; 469 gfx::DecomposedTransform decomp;
458 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); 470 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform);
459 DCHECK(success); 471 DCHECK(success);
460 if (decomp.scale[0]) 472 if (decomp.scale[0])
461 offset_.set_x(offset_.x() * decomp.scale[0]); 473 offset_.set_x(offset_.x() * decomp.scale[0]);
462 if (decomp.scale[1]) 474 if (decomp.scale[1])
463 offset_.set_y(offset_.y() * decomp.scale[1]); 475 offset_.set_y(offset_.y() * decomp.scale[1]);
464 } 476 }
465 477
478 scoped_ptr<Event> MouseWheelEvent::Clone() const {
479 return scoped_ptr<Event>(new MouseWheelEvent(*this));
480 }
481
466 //////////////////////////////////////////////////////////////////////////////// 482 ////////////////////////////////////////////////////////////////////////////////
467 // TouchEvent 483 // TouchEvent
468 484
469 TouchEvent::TouchEvent(const base::NativeEvent& native_event) 485 TouchEvent::TouchEvent(const base::NativeEvent& native_event)
470 : LocatedEvent(native_event), 486 : LocatedEvent(native_event),
471 touch_id_(GetTouchId(native_event)), 487 touch_id_(GetTouchId(native_event)),
472 radius_x_(GetTouchRadiusX(native_event)), 488 radius_x_(GetTouchRadiusX(native_event)),
473 radius_y_(GetTouchRadiusY(native_event)), 489 radius_y_(GetTouchRadiusY(native_event)),
474 rotation_angle_(GetTouchAngle(native_event)), 490 rotation_angle_(GetTouchAngle(native_event)),
475 force_(GetTouchForce(native_event)) { 491 force_(GetTouchForce(native_event)) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 LocatedEvent::UpdateForRootTransform(inverted_root_transform); 546 LocatedEvent::UpdateForRootTransform(inverted_root_transform);
531 gfx::DecomposedTransform decomp; 547 gfx::DecomposedTransform decomp;
532 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform); 548 bool success = gfx::DecomposeTransform(&decomp, inverted_root_transform);
533 DCHECK(success); 549 DCHECK(success);
534 if (decomp.scale[0]) 550 if (decomp.scale[0])
535 radius_x_ *= decomp.scale[0]; 551 radius_x_ *= decomp.scale[0];
536 if (decomp.scale[1]) 552 if (decomp.scale[1])
537 radius_y_ *= decomp.scale[1]; 553 radius_y_ *= decomp.scale[1];
538 } 554 }
539 555
556 scoped_ptr<Event> TouchEvent::Clone() const {
557 return scoped_ptr<Event>(new TouchEvent(*this));
558 }
559
540 //////////////////////////////////////////////////////////////////////////////// 560 ////////////////////////////////////////////////////////////////////////////////
541 // KeyEvent 561 // KeyEvent
542 562
543 // static 563 // static
544 KeyEvent* KeyEvent::last_key_event_ = NULL; 564 KeyEvent* KeyEvent::last_key_event_ = NULL;
545 565
546 // static 566 // static
547 bool KeyEvent::IsRepeated(const KeyEvent& event) { 567 bool KeyEvent::IsRepeated(const KeyEvent& event) {
548 // A safe guard in case if there were continous key pressed events that are 568 // A safe guard in case if there were continous key pressed events that are
549 // not auto repeat. 569 // not auto repeat.
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 break; 776 break;
757 case ET_KEY_RELEASED: 777 case ET_KEY_RELEASED:
758 case ET_TRANSLATED_KEY_RELEASE: 778 case ET_TRANSLATED_KEY_RELEASE:
759 SetType(translated ? ET_TRANSLATED_KEY_RELEASE : ET_KEY_RELEASED); 779 SetType(translated ? ET_TRANSLATED_KEY_RELEASE : ET_KEY_RELEASED);
760 break; 780 break;
761 default: 781 default:
762 NOTREACHED(); 782 NOTREACHED();
763 } 783 }
764 } 784 }
765 785
786 scoped_ptr<Event> KeyEvent::Clone() const {
787 return scoped_ptr<Event>(new KeyEvent(*this));
788 }
789
766 //////////////////////////////////////////////////////////////////////////////// 790 ////////////////////////////////////////////////////////////////////////////////
767 // ScrollEvent 791 // ScrollEvent
768 792
769 ScrollEvent::ScrollEvent(const base::NativeEvent& native_event) 793 ScrollEvent::ScrollEvent(const base::NativeEvent& native_event)
770 : MouseEvent(native_event) { 794 : MouseEvent(native_event) {
771 if (type() == ET_SCROLL) { 795 if (type() == ET_SCROLL) {
772 GetScrollOffsets(native_event, 796 GetScrollOffsets(native_event,
773 &x_offset_, &y_offset_, 797 &x_offset_, &y_offset_,
774 &x_offset_ordinal_, &y_offset_ordinal_, 798 &x_offset_ordinal_, &y_offset_ordinal_,
775 &finger_count_); 799 &finger_count_);
(...skipping 28 matching lines...) Expand all
804 CHECK(IsScrollEvent()); 828 CHECK(IsScrollEvent());
805 } 829 }
806 830
807 void ScrollEvent::Scale(const float factor) { 831 void ScrollEvent::Scale(const float factor) {
808 x_offset_ *= factor; 832 x_offset_ *= factor;
809 y_offset_ *= factor; 833 y_offset_ *= factor;
810 x_offset_ordinal_ *= factor; 834 x_offset_ordinal_ *= factor;
811 y_offset_ordinal_ *= factor; 835 y_offset_ordinal_ *= factor;
812 } 836 }
813 837
838 scoped_ptr<Event> ScrollEvent::Clone() const {
839 return scoped_ptr<Event>(new ScrollEvent(*this));
840 }
841
814 //////////////////////////////////////////////////////////////////////////////// 842 ////////////////////////////////////////////////////////////////////////////////
815 // GestureEvent 843 // GestureEvent
816 844
817 GestureEvent::GestureEvent(float x, 845 GestureEvent::GestureEvent(float x,
818 float y, 846 float y,
819 int flags, 847 int flags,
820 base::TimeDelta time_stamp, 848 base::TimeDelta time_stamp,
821 const GestureEventDetails& details) 849 const GestureEventDetails& details)
822 : LocatedEvent(details.type(), 850 : LocatedEvent(details.type(),
823 gfx::PointF(x, y), 851 gfx::PointF(x, y),
824 gfx::PointF(x, y), 852 gfx::PointF(x, y),
825 time_stamp, 853 time_stamp,
826 flags | EF_FROM_TOUCH), 854 flags | EF_FROM_TOUCH),
827 details_(details) { 855 details_(details) {
828 } 856 }
829 857
830 GestureEvent::~GestureEvent() { 858 GestureEvent::~GestureEvent() {
831 } 859 }
832 860
861 scoped_ptr<Event> GestureEvent::Clone() const {
862 return scoped_ptr<Event>(new GestureEvent(*this));
863 }
864
833 } // namespace ui 865 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698