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

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

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge master Created 4 years, 6 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 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 10
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 316
317 void Event::SetHandled() { 317 void Event::SetHandled() {
318 // TODO(sad): Re-enable these checks once View uses dispatcher to dispatch 318 // TODO(sad): Re-enable these checks once View uses dispatcher to dispatch
319 // events. 319 // events.
320 // CHECK(phase_ != EP_PREDISPATCH && phase_ != EP_POSTDISPATCH); 320 // CHECK(phase_ != EP_PREDISPATCH && phase_ != EP_POSTDISPATCH);
321 CHECK(cancelable_); 321 CHECK(cancelable_);
322 result_ = static_cast<EventResult>(result_ | ER_HANDLED); 322 result_ = static_cast<EventResult>(result_ | ER_HANDLED);
323 } 323 }
324 324
325 Event::Event(EventType type, base::TimeDelta time_stamp, int flags) 325 Event::Event(EventType type, base::TimeTicks time_stamp, int flags)
326 : type_(type), 326 : type_(type),
327 time_stamp_(time_stamp), 327 time_stamp_(time_stamp),
328 flags_(flags), 328 flags_(flags),
329 native_event_(base::NativeEvent()), 329 native_event_(base::NativeEvent()),
330 delete_native_event_(false), 330 delete_native_event_(false),
331 cancelable_(true), 331 cancelable_(true),
332 target_(NULL), 332 target_(NULL),
333 phase_(EP_PREDISPATCH), 333 phase_(EP_PREDISPATCH),
334 result_(ER_UNHANDLED), 334 result_(ER_UNHANDLED),
335 source_device_id_(ED_UNKNOWN_DEVICE) { 335 source_device_id_(ED_UNKNOWN_DEVICE) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 name_ = std::string(); 404 name_ = std::string();
405 type_ = type; 405 type_ = type;
406 if (type_ < ET_LAST) 406 if (type_ < ET_LAST)
407 name_ = EventTypeName(type_); 407 name_ = EventTypeName(type_);
408 } 408 }
409 409
410 //////////////////////////////////////////////////////////////////////////////// 410 ////////////////////////////////////////////////////////////////////////////////
411 // CancelModeEvent 411 // CancelModeEvent
412 412
413 CancelModeEvent::CancelModeEvent() 413 CancelModeEvent::CancelModeEvent()
414 : Event(ET_CANCEL_MODE, base::TimeDelta(), 0) { 414 : Event(ET_CANCEL_MODE, base::TimeTicks(), 0) {
415 set_cancelable(false); 415 set_cancelable(false);
416 } 416 }
417 417
418 CancelModeEvent::~CancelModeEvent() { 418 CancelModeEvent::~CancelModeEvent() {
419 } 419 }
420 420
421 //////////////////////////////////////////////////////////////////////////////// 421 ////////////////////////////////////////////////////////////////////////////////
422 // LocatedEvent 422 // LocatedEvent
423 423
424 LocatedEvent::~LocatedEvent() { 424 LocatedEvent::~LocatedEvent() {
425 } 425 }
426 426
427 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) 427 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event)
428 : Event(native_event, 428 : Event(native_event,
429 EventTypeFromNative(native_event), 429 EventTypeFromNative(native_event),
430 EventFlagsFromNative(native_event)), 430 EventFlagsFromNative(native_event)),
431 location_(EventLocationFromNative(native_event)), 431 location_(EventLocationFromNative(native_event)),
432 root_location_(location_) { 432 root_location_(location_) {
433 } 433 }
434 434
435 LocatedEvent::LocatedEvent(EventType type, 435 LocatedEvent::LocatedEvent(EventType type,
436 const gfx::PointF& location, 436 const gfx::PointF& location,
437 const gfx::PointF& root_location, 437 const gfx::PointF& root_location,
438 base::TimeDelta time_stamp, 438 base::TimeTicks time_stamp,
439 int flags) 439 int flags)
440 : Event(type, time_stamp, flags), 440 : Event(type, time_stamp, flags),
441 location_(location), 441 location_(location),
442 root_location_(root_location) { 442 root_location_(root_location) {}
443 }
444 443
445 void LocatedEvent::UpdateForRootTransform( 444 void LocatedEvent::UpdateForRootTransform(
446 const gfx::Transform& reversed_root_transform) { 445 const gfx::Transform& reversed_root_transform) {
447 // Transform has to be done at root level. 446 // Transform has to be done at root level.
448 gfx::Point3F p(location_); 447 gfx::Point3F p(location_);
449 reversed_root_transform.TransformPoint(&p); 448 reversed_root_transform.TransformPoint(&p);
450 location_ = p.AsPointF(); 449 location_ = p.AsPointF();
451 root_location_ = location_; 450 root_location_ = location_;
452 } 451 }
453 452
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 break; 487 break;
489 488
490 default: 489 default:
491 NOTREACHED(); 490 NOTREACHED();
492 } 491 }
493 } 492 }
494 493
495 MouseEvent::MouseEvent(EventType type, 494 MouseEvent::MouseEvent(EventType type,
496 const gfx::Point& location, 495 const gfx::Point& location,
497 const gfx::Point& root_location, 496 const gfx::Point& root_location,
498 base::TimeDelta time_stamp, 497 base::TimeTicks time_stamp,
499 int flags, 498 int flags,
500 int changed_button_flags) 499 int changed_button_flags)
501 : LocatedEvent(type, 500 : LocatedEvent(type,
502 gfx::PointF(location), 501 gfx::PointF(location),
503 gfx::PointF(root_location), 502 gfx::PointF(root_location),
504 time_stamp, 503 time_stamp,
505 flags), 504 flags),
506 changed_button_flags_(changed_button_flags), 505 changed_button_flags_(changed_button_flags),
507 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { 506 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
508 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) 507 if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 650
652 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) 651 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event)
653 : MouseEvent(mouse_wheel_event), 652 : MouseEvent(mouse_wheel_event),
654 offset_(mouse_wheel_event.offset()) { 653 offset_(mouse_wheel_event.offset()) {
655 DCHECK(type() == ET_MOUSEWHEEL); 654 DCHECK(type() == ET_MOUSEWHEEL);
656 } 655 }
657 656
658 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, 657 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
659 const gfx::Point& location, 658 const gfx::Point& location,
660 const gfx::Point& root_location, 659 const gfx::Point& root_location,
661 base::TimeDelta time_stamp, 660 base::TimeTicks time_stamp,
662 int flags, 661 int flags,
663 int changed_button_flags) 662 int changed_button_flags)
664 : MouseEvent(ui::ET_MOUSEWHEEL, 663 : MouseEvent(ui::ET_MOUSEWHEEL,
665 location, 664 location,
666 root_location, 665 root_location,
667 time_stamp, 666 time_stamp,
668 flags, 667 flags,
669 changed_button_flags), 668 changed_button_flags),
670 offset_(offset) {} 669 offset_(offset) {}
671 670
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 break; 725 break;
727 726
728 default: 727 default:
729 NOTREACHED(); 728 NOTREACHED();
730 } 729 }
731 } 730 }
732 731
733 TouchEvent::TouchEvent(EventType type, 732 TouchEvent::TouchEvent(EventType type,
734 const gfx::Point& location, 733 const gfx::Point& location,
735 int touch_id, 734 int touch_id,
736 base::TimeDelta time_stamp) 735 base::TimeTicks time_stamp)
737 : LocatedEvent(type, 736 : LocatedEvent(type,
738 gfx::PointF(location), 737 gfx::PointF(location),
739 gfx::PointF(location), 738 gfx::PointF(location),
740 time_stamp, 739 time_stamp,
741 0), 740 0),
742 touch_id_(touch_id), 741 touch_id_(touch_id),
743 unique_event_id_(ui::GetNextTouchEventId()), 742 unique_event_id_(ui::GetNextTouchEventId()),
744 rotation_angle_(0.0f), 743 rotation_angle_(0.0f),
745 may_cause_scrolling_(false), 744 may_cause_scrolling_(false),
746 should_remove_native_touch_id_mapping_(false), 745 should_remove_native_touch_id_mapping_(false),
747 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { 746 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) {
748 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 747 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
749 } 748 }
750 749
751 TouchEvent::TouchEvent(EventType type, 750 TouchEvent::TouchEvent(EventType type,
752 const gfx::Point& location, 751 const gfx::Point& location,
753 int flags, 752 int flags,
754 int touch_id, 753 int touch_id,
755 base::TimeDelta time_stamp, 754 base::TimeTicks time_stamp,
756 float radius_x, 755 float radius_x,
757 float radius_y, 756 float radius_y,
758 float angle, 757 float angle,
759 float force) 758 float force)
760 : LocatedEvent(type, 759 : LocatedEvent(type,
761 gfx::PointF(location), 760 gfx::PointF(location),
762 gfx::PointF(location), 761 gfx::PointF(location),
763 time_stamp, 762 time_stamp,
764 flags), 763 flags),
765 touch_id_(touch_id), 764 touch_id_(touch_id),
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 NOTREACHED(); 909 NOTREACHED();
911 } 910 }
912 } 911 }
913 912
914 PointerEvent::PointerEvent(EventType type, 913 PointerEvent::PointerEvent(EventType type,
915 EventPointerType pointer_type, 914 EventPointerType pointer_type,
916 const gfx::Point& location, 915 const gfx::Point& location,
917 const gfx::Point& root_location, 916 const gfx::Point& root_location,
918 int flags, 917 int flags,
919 int pointer_id, 918 int pointer_id,
920 base::TimeDelta time_stamp) 919 base::TimeTicks time_stamp)
921 : LocatedEvent(type, 920 : LocatedEvent(type,
922 gfx::PointF(location), 921 gfx::PointF(location),
923 gfx::PointF(root_location), 922 gfx::PointF(root_location),
924 time_stamp, 923 time_stamp,
925 flags), 924 flags),
926 pointer_id_(pointer_id), 925 pointer_id_(pointer_id),
927 details_(PointerDetails(pointer_type)) {} 926 details_(PointerDetails(pointer_type)) {}
928 927
929 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); 928 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max();
930 929
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 kMaxAutoRepeatTimeMs) { 964 kMaxAutoRepeatTimeMs) {
966 last_key_event_->set_time_stamp(event.time_stamp()); 965 last_key_event_->set_time_stamp(event.time_stamp());
967 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT); 966 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT);
968 return true; 967 return true;
969 } 968 }
970 delete last_key_event_; 969 delete last_key_event_;
971 last_key_event_ = new KeyEvent(event); 970 last_key_event_ = new KeyEvent(event);
972 return false; 971 return false;
973 } 972 }
974 973
975 KeyEvent::KeyEvent(EventType type, base::TimeDelta time_stamp, int flags) 974 KeyEvent::KeyEvent(EventType type, base::TimeTicks time_stamp, int flags)
976 : Event(type, time_stamp, flags) {} 975 : Event(type, time_stamp, flags) {}
977 976
978 KeyEvent::KeyEvent(const base::NativeEvent& native_event) 977 KeyEvent::KeyEvent(const base::NativeEvent& native_event)
979 : Event(native_event, 978 : Event(native_event,
980 EventTypeFromNative(native_event), 979 EventTypeFromNative(native_event),
981 EventFlagsFromNative(native_event)), 980 EventFlagsFromNative(native_event)),
982 key_code_(KeyboardCodeFromNative(native_event)), 981 key_code_(KeyboardCodeFromNative(native_event)),
983 code_(CodeFromNative(native_event)), 982 code_(CodeFromNative(native_event)),
984 is_char_(IsCharFromNative(native_event)) { 983 is_char_(IsCharFromNative(native_event)) {
985 if (IsRepeated(*this)) 984 if (IsRepeated(*this))
(...skipping 26 matching lines...) Expand all
1012 : Event(type, EventTimeForNow(), flags), 1011 : Event(type, EventTimeForNow(), flags),
1013 key_code_(key_code), 1012 key_code_(key_code),
1014 code_(code) { 1013 code_(code) {
1015 } 1014 }
1016 1015
1017 KeyEvent::KeyEvent(EventType type, 1016 KeyEvent::KeyEvent(EventType type,
1018 KeyboardCode key_code, 1017 KeyboardCode key_code,
1019 DomCode code, 1018 DomCode code,
1020 int flags, 1019 int flags,
1021 DomKey key, 1020 DomKey key,
1022 base::TimeDelta time_stamp) 1021 base::TimeTicks time_stamp)
1023 : Event(type, time_stamp, flags), 1022 : Event(type, time_stamp, flags),
1024 key_code_(key_code), 1023 key_code_(key_code),
1025 code_(code), 1024 code_(code),
1026 key_(key) { 1025 key_(key) {}
1027 }
1028 1026
1029 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) 1027 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags)
1030 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), 1028 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags),
1031 key_code_(key_code), 1029 key_code_(key_code),
1032 code_(DomCode::NONE), 1030 code_(DomCode::NONE),
1033 is_char_(true), 1031 is_char_(true),
1034 key_(DomKey::FromCharacter(character)) { 1032 key_(DomKey::FromCharacter(character)) {
1035 } 1033 }
1036 1034
1037 KeyEvent::KeyEvent(const KeyEvent& rhs) 1035 KeyEvent::KeyEvent(const KeyEvent& rhs)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 &x_offset_ordinal_, &y_offset_ordinal_, 1231 &x_offset_ordinal_, &y_offset_ordinal_,
1234 NULL); 1232 NULL);
1235 } else { 1233 } else {
1236 NOTREACHED() << "Unexpected event type " << type() 1234 NOTREACHED() << "Unexpected event type " << type()
1237 << " when constructing a ScrollEvent."; 1235 << " when constructing a ScrollEvent.";
1238 } 1236 }
1239 } 1237 }
1240 1238
1241 ScrollEvent::ScrollEvent(EventType type, 1239 ScrollEvent::ScrollEvent(EventType type,
1242 const gfx::Point& location, 1240 const gfx::Point& location,
1243 base::TimeDelta time_stamp, 1241 base::TimeTicks time_stamp,
1244 int flags, 1242 int flags,
1245 float x_offset, 1243 float x_offset,
1246 float y_offset, 1244 float y_offset,
1247 float x_offset_ordinal, 1245 float x_offset_ordinal,
1248 float y_offset_ordinal, 1246 float y_offset_ordinal,
1249 int finger_count) 1247 int finger_count)
1250 : MouseEvent(type, location, location, time_stamp, flags, 0), 1248 : MouseEvent(type, location, location, time_stamp, flags, 0),
1251 x_offset_(x_offset), 1249 x_offset_(x_offset),
1252 y_offset_(y_offset), 1250 y_offset_(y_offset),
1253 x_offset_ordinal_(x_offset_ordinal), 1251 x_offset_ordinal_(x_offset_ordinal),
1254 y_offset_ordinal_(y_offset_ordinal), 1252 y_offset_ordinal_(y_offset_ordinal),
1255 finger_count_(finger_count) { 1253 finger_count_(finger_count) {
1256 CHECK(IsScrollEvent()); 1254 CHECK(IsScrollEvent());
1257 } 1255 }
1258 1256
1259 void ScrollEvent::Scale(const float factor) { 1257 void ScrollEvent::Scale(const float factor) {
1260 x_offset_ *= factor; 1258 x_offset_ *= factor;
1261 y_offset_ *= factor; 1259 y_offset_ *= factor;
1262 x_offset_ordinal_ *= factor; 1260 x_offset_ordinal_ *= factor;
1263 y_offset_ordinal_ *= factor; 1261 y_offset_ordinal_ *= factor;
1264 } 1262 }
1265 1263
1266 //////////////////////////////////////////////////////////////////////////////// 1264 ////////////////////////////////////////////////////////////////////////////////
1267 // GestureEvent 1265 // GestureEvent
1268 1266
1269 GestureEvent::GestureEvent(float x, 1267 GestureEvent::GestureEvent(float x,
1270 float y, 1268 float y,
1271 int flags, 1269 int flags,
1272 base::TimeDelta time_stamp, 1270 base::TimeTicks time_stamp,
1273 const GestureEventDetails& details) 1271 const GestureEventDetails& details)
1274 : LocatedEvent(details.type(), 1272 : LocatedEvent(details.type(),
1275 gfx::PointF(x, y), 1273 gfx::PointF(x, y),
1276 gfx::PointF(x, y), 1274 gfx::PointF(x, y),
1277 time_stamp, 1275 time_stamp,
1278 flags | EF_FROM_TOUCH), 1276 flags | EF_FROM_TOUCH),
1279 details_(details) { 1277 details_(details) {}
1280 }
1281 1278
1282 GestureEvent::~GestureEvent() { 1279 GestureEvent::~GestureEvent() {
1283 } 1280 }
1284 1281
1285 } // namespace ui 1282 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698