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

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: rebase 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
« no previous file with comments | « ui/events/event.h ('k') | ui/events/event_rewriter_unittest.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 #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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 break; 497 break;
499 498
500 default: 499 default:
501 NOTREACHED(); 500 NOTREACHED();
502 } 501 }
503 } 502 }
504 503
505 MouseEvent::MouseEvent(EventType type, 504 MouseEvent::MouseEvent(EventType type,
506 const gfx::Point& location, 505 const gfx::Point& location,
507 const gfx::Point& root_location, 506 const gfx::Point& root_location,
508 base::TimeDelta time_stamp, 507 base::TimeTicks time_stamp,
509 int flags, 508 int flags,
510 int changed_button_flags) 509 int changed_button_flags)
511 : LocatedEvent(type, 510 : LocatedEvent(type,
512 gfx::PointF(location), 511 gfx::PointF(location),
513 gfx::PointF(root_location), 512 gfx::PointF(root_location),
514 time_stamp, 513 time_stamp,
515 flags), 514 flags),
516 changed_button_flags_(changed_button_flags), 515 changed_button_flags_(changed_button_flags),
517 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { 516 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) {
518 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 517 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 661
663 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) 662 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event)
664 : MouseEvent(mouse_wheel_event), 663 : MouseEvent(mouse_wheel_event),
665 offset_(mouse_wheel_event.offset()) { 664 offset_(mouse_wheel_event.offset()) {
666 DCHECK(type() == ET_MOUSEWHEEL); 665 DCHECK(type() == ET_MOUSEWHEEL);
667 } 666 }
668 667
669 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, 668 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset,
670 const gfx::Point& location, 669 const gfx::Point& location,
671 const gfx::Point& root_location, 670 const gfx::Point& root_location,
672 base::TimeDelta time_stamp, 671 base::TimeTicks time_stamp,
673 int flags, 672 int flags,
674 int changed_button_flags) 673 int changed_button_flags)
675 : MouseEvent(ui::ET_MOUSEWHEEL, 674 : MouseEvent(ui::ET_MOUSEWHEEL,
676 location, 675 location,
677 root_location, 676 root_location,
678 time_stamp, 677 time_stamp,
679 flags, 678 flags,
680 changed_button_flags), 679 changed_button_flags),
681 offset_(offset) {} 680 offset_(offset) {}
682 681
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 break; 736 break;
738 737
739 default: 738 default:
740 NOTREACHED(); 739 NOTREACHED();
741 } 740 }
742 } 741 }
743 742
744 TouchEvent::TouchEvent(EventType type, 743 TouchEvent::TouchEvent(EventType type,
745 const gfx::Point& location, 744 const gfx::Point& location,
746 int touch_id, 745 int touch_id,
747 base::TimeDelta time_stamp) 746 base::TimeTicks time_stamp)
748 : LocatedEvent(type, 747 : LocatedEvent(type,
749 gfx::PointF(location), 748 gfx::PointF(location),
750 gfx::PointF(location), 749 gfx::PointF(location),
751 time_stamp, 750 time_stamp,
752 0), 751 0),
753 touch_id_(touch_id), 752 touch_id_(touch_id),
754 unique_event_id_(ui::GetNextTouchEventId()), 753 unique_event_id_(ui::GetNextTouchEventId()),
755 rotation_angle_(0.0f), 754 rotation_angle_(0.0f),
756 may_cause_scrolling_(false), 755 may_cause_scrolling_(false),
757 should_remove_native_touch_id_mapping_(false), 756 should_remove_native_touch_id_mapping_(false),
758 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { 757 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) {
759 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); 758 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
760 } 759 }
761 760
762 TouchEvent::TouchEvent(EventType type, 761 TouchEvent::TouchEvent(EventType type,
763 const gfx::Point& location, 762 const gfx::Point& location,
764 int flags, 763 int flags,
765 int touch_id, 764 int touch_id,
766 base::TimeDelta time_stamp, 765 base::TimeTicks time_stamp,
767 float radius_x, 766 float radius_x,
768 float radius_y, 767 float radius_y,
769 float angle, 768 float angle,
770 float force) 769 float force)
771 : LocatedEvent(type, 770 : LocatedEvent(type,
772 gfx::PointF(location), 771 gfx::PointF(location),
773 gfx::PointF(location), 772 gfx::PointF(location),
774 time_stamp, 773 time_stamp,
775 flags), 774 flags),
776 touch_id_(touch_id), 775 touch_id_(touch_id),
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 NOTREACHED(); 920 NOTREACHED();
922 } 921 }
923 } 922 }
924 923
925 PointerEvent::PointerEvent(EventType type, 924 PointerEvent::PointerEvent(EventType type,
926 const gfx::Point& location, 925 const gfx::Point& location,
927 const gfx::Point& root_location, 926 const gfx::Point& root_location,
928 int flags, 927 int flags,
929 int pointer_id, 928 int pointer_id,
930 const PointerDetails& pointer_details, 929 const PointerDetails& pointer_details,
931 base::TimeDelta time_stamp) 930 base::TimeTicks time_stamp)
932 : LocatedEvent(type, 931 : LocatedEvent(type,
933 gfx::PointF(location), 932 gfx::PointF(location),
934 gfx::PointF(root_location), 933 gfx::PointF(root_location),
935 time_stamp, 934 time_stamp,
936 flags), 935 flags),
937 pointer_id_(pointer_id), 936 pointer_id_(pointer_id),
938 details_(pointer_details) {} 937 details_(pointer_details) {}
939 938
940 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); 939 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max();
941 940
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 : Event(type, EventTimeForNow(), flags), 1019 : Event(type, EventTimeForNow(), flags),
1021 key_code_(key_code), 1020 key_code_(key_code),
1022 code_(code) { 1021 code_(code) {
1023 } 1022 }
1024 1023
1025 KeyEvent::KeyEvent(EventType type, 1024 KeyEvent::KeyEvent(EventType type,
1026 KeyboardCode key_code, 1025 KeyboardCode key_code,
1027 DomCode code, 1026 DomCode code,
1028 int flags, 1027 int flags,
1029 DomKey key, 1028 DomKey key,
1030 base::TimeDelta time_stamp) 1029 base::TimeTicks time_stamp)
1031 : Event(type, time_stamp, flags), 1030 : Event(type, time_stamp, flags),
1032 key_code_(key_code), 1031 key_code_(key_code),
1033 code_(code), 1032 code_(code),
1034 key_(key) { 1033 key_(key) {}
1035 }
1036 1034
1037 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) 1035 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags)
1038 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), 1036 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags),
1039 key_code_(key_code), 1037 key_code_(key_code),
1040 code_(DomCode::NONE), 1038 code_(DomCode::NONE),
1041 is_char_(true), 1039 is_char_(true),
1042 key_(DomKey::FromCharacter(character)) { 1040 key_(DomKey::FromCharacter(character)) {
1043 } 1041 }
1044 1042
1045 KeyEvent::KeyEvent(const KeyEvent& rhs) 1043 KeyEvent::KeyEvent(const KeyEvent& rhs)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 &x_offset_ordinal_, &y_offset_ordinal_, 1239 &x_offset_ordinal_, &y_offset_ordinal_,
1242 NULL); 1240 NULL);
1243 } else { 1241 } else {
1244 NOTREACHED() << "Unexpected event type " << type() 1242 NOTREACHED() << "Unexpected event type " << type()
1245 << " when constructing a ScrollEvent."; 1243 << " when constructing a ScrollEvent.";
1246 } 1244 }
1247 } 1245 }
1248 1246
1249 ScrollEvent::ScrollEvent(EventType type, 1247 ScrollEvent::ScrollEvent(EventType type,
1250 const gfx::Point& location, 1248 const gfx::Point& location,
1251 base::TimeDelta time_stamp, 1249 base::TimeTicks time_stamp,
1252 int flags, 1250 int flags,
1253 float x_offset, 1251 float x_offset,
1254 float y_offset, 1252 float y_offset,
1255 float x_offset_ordinal, 1253 float x_offset_ordinal,
1256 float y_offset_ordinal, 1254 float y_offset_ordinal,
1257 int finger_count) 1255 int finger_count)
1258 : MouseEvent(type, location, location, time_stamp, flags, 0), 1256 : MouseEvent(type, location, location, time_stamp, flags, 0),
1259 x_offset_(x_offset), 1257 x_offset_(x_offset),
1260 y_offset_(y_offset), 1258 y_offset_(y_offset),
1261 x_offset_ordinal_(x_offset_ordinal), 1259 x_offset_ordinal_(x_offset_ordinal),
1262 y_offset_ordinal_(y_offset_ordinal), 1260 y_offset_ordinal_(y_offset_ordinal),
1263 finger_count_(finger_count) { 1261 finger_count_(finger_count) {
1264 CHECK(IsScrollEvent()); 1262 CHECK(IsScrollEvent());
1265 } 1263 }
1266 1264
1267 void ScrollEvent::Scale(const float factor) { 1265 void ScrollEvent::Scale(const float factor) {
1268 x_offset_ *= factor; 1266 x_offset_ *= factor;
1269 y_offset_ *= factor; 1267 y_offset_ *= factor;
1270 x_offset_ordinal_ *= factor; 1268 x_offset_ordinal_ *= factor;
1271 y_offset_ordinal_ *= factor; 1269 y_offset_ordinal_ *= factor;
1272 } 1270 }
1273 1271
1274 //////////////////////////////////////////////////////////////////////////////// 1272 ////////////////////////////////////////////////////////////////////////////////
1275 // GestureEvent 1273 // GestureEvent
1276 1274
1277 GestureEvent::GestureEvent(float x, 1275 GestureEvent::GestureEvent(float x,
1278 float y, 1276 float y,
1279 int flags, 1277 int flags,
1280 base::TimeDelta time_stamp, 1278 base::TimeTicks time_stamp,
1281 const GestureEventDetails& details) 1279 const GestureEventDetails& details)
1282 : LocatedEvent(details.type(), 1280 : LocatedEvent(details.type(),
1283 gfx::PointF(x, y), 1281 gfx::PointF(x, y),
1284 gfx::PointF(x, y), 1282 gfx::PointF(x, y),
1285 time_stamp, 1283 time_stamp,
1286 flags | EF_FROM_TOUCH), 1284 flags | EF_FROM_TOUCH),
1287 details_(details) { 1285 details_(details) {}
1288 }
1289 1286
1290 GestureEvent::~GestureEvent() { 1287 GestureEvent::~GestureEvent() {
1291 } 1288 }
1292 1289
1293 } // namespace ui 1290 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event.h ('k') | ui/events/event_rewriter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698