| OLD | NEW |
| 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 Loading... |
| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 name_ = std::string(); | 403 name_ = std::string(); |
| 404 type_ = type; | 404 type_ = type; |
| 405 if (type_ < ET_LAST) | 405 if (type_ < ET_LAST) |
| 406 name_ = EventTypeName(type_); | 406 name_ = EventTypeName(type_); |
| 407 } | 407 } |
| 408 | 408 |
| 409 //////////////////////////////////////////////////////////////////////////////// | 409 //////////////////////////////////////////////////////////////////////////////// |
| 410 // CancelModeEvent | 410 // CancelModeEvent |
| 411 | 411 |
| 412 CancelModeEvent::CancelModeEvent() | 412 CancelModeEvent::CancelModeEvent() |
| 413 : Event(ET_CANCEL_MODE, base::TimeDelta(), 0) { | 413 : Event(ET_CANCEL_MODE, base::TimeTicks(), 0) { |
| 414 set_cancelable(false); | 414 set_cancelable(false); |
| 415 } | 415 } |
| 416 | 416 |
| 417 CancelModeEvent::~CancelModeEvent() { | 417 CancelModeEvent::~CancelModeEvent() { |
| 418 } | 418 } |
| 419 | 419 |
| 420 //////////////////////////////////////////////////////////////////////////////// | 420 //////////////////////////////////////////////////////////////////////////////// |
| 421 // LocatedEvent | 421 // LocatedEvent |
| 422 | 422 |
| 423 LocatedEvent::~LocatedEvent() { | 423 LocatedEvent::~LocatedEvent() { |
| 424 } | 424 } |
| 425 | 425 |
| 426 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) | 426 LocatedEvent::LocatedEvent(const base::NativeEvent& native_event) |
| 427 : Event(native_event, | 427 : Event(native_event, |
| 428 EventTypeFromNative(native_event), | 428 EventTypeFromNative(native_event), |
| 429 EventFlagsFromNative(native_event)), | 429 EventFlagsFromNative(native_event)), |
| 430 location_(EventLocationFromNative(native_event)), | 430 location_(EventLocationFromNative(native_event)), |
| 431 root_location_(location_) { | 431 root_location_(location_) { |
| 432 } | 432 } |
| 433 | 433 |
| 434 LocatedEvent::LocatedEvent(EventType type, | 434 LocatedEvent::LocatedEvent(EventType type, |
| 435 const gfx::PointF& location, | 435 const gfx::PointF& location, |
| 436 const gfx::PointF& root_location, | 436 const gfx::PointF& root_location, |
| 437 base::TimeDelta time_stamp, | 437 base::TimeTicks time_stamp, |
| 438 int flags) | 438 int flags) |
| 439 : Event(type, time_stamp, flags), | 439 : Event(type, time_stamp, flags), |
| 440 location_(location), | 440 location_(location), |
| 441 root_location_(root_location) { | 441 root_location_(root_location) {} |
| 442 } | |
| 443 | 442 |
| 444 void LocatedEvent::UpdateForRootTransform( | 443 void LocatedEvent::UpdateForRootTransform( |
| 445 const gfx::Transform& reversed_root_transform) { | 444 const gfx::Transform& reversed_root_transform) { |
| 446 // Transform has to be done at root level. | 445 // Transform has to be done at root level. |
| 447 gfx::Point3F p(location_); | 446 gfx::Point3F p(location_); |
| 448 reversed_root_transform.TransformPoint(&p); | 447 reversed_root_transform.TransformPoint(&p); |
| 449 location_ = p.AsPointF(); | 448 location_ = p.AsPointF(); |
| 450 root_location_ = location_; | 449 root_location_ = location_; |
| 451 } | 450 } |
| 452 | 451 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 452 //////////////////////////////////////////////////////////////////////////////// |
| 454 // MouseEvent | 453 // MouseEvent |
| 455 | 454 |
| 456 MouseEvent::MouseEvent(const base::NativeEvent& native_event) | 455 MouseEvent::MouseEvent(const base::NativeEvent& native_event) |
| 457 : LocatedEvent(native_event), | 456 : LocatedEvent(native_event), |
| 458 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), | 457 changed_button_flags_(GetChangedMouseButtonFlagsFromNative(native_event)), |
| 459 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { | 458 pointer_details_(GetMousePointerDetailsFromNative(native_event)) { |
| 460 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) | 459 if (type() == ET_MOUSE_PRESSED || type() == ET_MOUSE_RELEASED) |
| 461 SetClickCount(GetRepeatCount(*this)); | 460 SetClickCount(GetRepeatCount(*this)); |
| 462 } | 461 } |
| 463 | 462 |
| 464 MouseEvent::MouseEvent(EventType type, | 463 MouseEvent::MouseEvent(EventType type, |
| 465 const gfx::Point& location, | 464 const gfx::Point& location, |
| 466 const gfx::Point& root_location, | 465 const gfx::Point& root_location, |
| 467 base::TimeDelta time_stamp, | 466 base::TimeTicks time_stamp, |
| 468 int flags, | 467 int flags, |
| 469 int changed_button_flags) | 468 int changed_button_flags) |
| 470 : LocatedEvent(type, | 469 : LocatedEvent(type, |
| 471 gfx::PointF(location), | 470 gfx::PointF(location), |
| 472 gfx::PointF(root_location), | 471 gfx::PointF(root_location), |
| 473 time_stamp, | 472 time_stamp, |
| 474 flags), | 473 flags), |
| 475 changed_button_flags_(changed_button_flags), | 474 changed_button_flags_(changed_button_flags), |
| 476 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { | 475 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_MOUSE)) { |
| 477 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) | 476 if (this->type() == ET_MOUSE_MOVED && IsAnyButton()) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 619 |
| 621 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) | 620 MouseWheelEvent::MouseWheelEvent(const MouseWheelEvent& mouse_wheel_event) |
| 622 : MouseEvent(mouse_wheel_event), | 621 : MouseEvent(mouse_wheel_event), |
| 623 offset_(mouse_wheel_event.offset()) { | 622 offset_(mouse_wheel_event.offset()) { |
| 624 DCHECK(type() == ET_MOUSEWHEEL); | 623 DCHECK(type() == ET_MOUSEWHEEL); |
| 625 } | 624 } |
| 626 | 625 |
| 627 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, | 626 MouseWheelEvent::MouseWheelEvent(const gfx::Vector2d& offset, |
| 628 const gfx::Point& location, | 627 const gfx::Point& location, |
| 629 const gfx::Point& root_location, | 628 const gfx::Point& root_location, |
| 630 base::TimeDelta time_stamp, | 629 base::TimeTicks time_stamp, |
| 631 int flags, | 630 int flags, |
| 632 int changed_button_flags) | 631 int changed_button_flags) |
| 633 : MouseEvent(ui::ET_MOUSEWHEEL, | 632 : MouseEvent(ui::ET_MOUSEWHEEL, |
| 634 location, | 633 location, |
| 635 root_location, | 634 root_location, |
| 636 time_stamp, | 635 time_stamp, |
| 637 flags, | 636 flags, |
| 638 changed_button_flags), | 637 changed_button_flags), |
| 639 offset_(offset) {} | 638 offset_(offset) {} |
| 640 | 639 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 664 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 663 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 665 | 664 |
| 666 FixRotationAngle(); | 665 FixRotationAngle(); |
| 667 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) | 666 if (type() == ET_TOUCH_RELEASED || type() == ET_TOUCH_CANCELLED) |
| 668 should_remove_native_touch_id_mapping_ = true; | 667 should_remove_native_touch_id_mapping_ = true; |
| 669 } | 668 } |
| 670 | 669 |
| 671 TouchEvent::TouchEvent(EventType type, | 670 TouchEvent::TouchEvent(EventType type, |
| 672 const gfx::Point& location, | 671 const gfx::Point& location, |
| 673 int touch_id, | 672 int touch_id, |
| 674 base::TimeDelta time_stamp) | 673 base::TimeTicks time_stamp) |
| 675 : LocatedEvent(type, | 674 : LocatedEvent(type, |
| 676 gfx::PointF(location), | 675 gfx::PointF(location), |
| 677 gfx::PointF(location), | 676 gfx::PointF(location), |
| 678 time_stamp, | 677 time_stamp, |
| 679 0), | 678 0), |
| 680 touch_id_(touch_id), | 679 touch_id_(touch_id), |
| 681 unique_event_id_(ui::GetNextTouchEventId()), | 680 unique_event_id_(ui::GetNextTouchEventId()), |
| 682 rotation_angle_(0.0f), | 681 rotation_angle_(0.0f), |
| 683 may_cause_scrolling_(false), | 682 may_cause_scrolling_(false), |
| 684 should_remove_native_touch_id_mapping_(false), | 683 should_remove_native_touch_id_mapping_(false), |
| 685 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { | 684 pointer_details_(PointerDetails(EventPointerType::POINTER_TYPE_TOUCH)) { |
| 686 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); | 685 latency()->AddLatencyNumber(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0); |
| 687 } | 686 } |
| 688 | 687 |
| 689 TouchEvent::TouchEvent(EventType type, | 688 TouchEvent::TouchEvent(EventType type, |
| 690 const gfx::Point& location, | 689 const gfx::Point& location, |
| 691 int flags, | 690 int flags, |
| 692 int touch_id, | 691 int touch_id, |
| 693 base::TimeDelta time_stamp, | 692 base::TimeTicks time_stamp, |
| 694 float radius_x, | 693 float radius_x, |
| 695 float radius_y, | 694 float radius_y, |
| 696 float angle, | 695 float angle, |
| 697 float force) | 696 float force) |
| 698 : LocatedEvent(type, | 697 : LocatedEvent(type, |
| 699 gfx::PointF(location), | 698 gfx::PointF(location), |
| 700 gfx::PointF(location), | 699 gfx::PointF(location), |
| 701 time_stamp, | 700 time_stamp, |
| 702 flags), | 701 flags), |
| 703 touch_id_(touch_id), | 702 touch_id_(touch_id), |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 NOTREACHED(); | 847 NOTREACHED(); |
| 849 } | 848 } |
| 850 } | 849 } |
| 851 | 850 |
| 852 PointerEvent::PointerEvent(EventType type, | 851 PointerEvent::PointerEvent(EventType type, |
| 853 EventPointerType pointer_type, | 852 EventPointerType pointer_type, |
| 854 const gfx::Point& location, | 853 const gfx::Point& location, |
| 855 const gfx::Point& root_location, | 854 const gfx::Point& root_location, |
| 856 int flags, | 855 int flags, |
| 857 int pointer_id, | 856 int pointer_id, |
| 858 base::TimeDelta time_stamp) | 857 base::TimeTicks time_stamp) |
| 859 : LocatedEvent(type, | 858 : LocatedEvent(type, |
| 860 gfx::PointF(location), | 859 gfx::PointF(location), |
| 861 gfx::PointF(root_location), | 860 gfx::PointF(root_location), |
| 862 time_stamp, | 861 time_stamp, |
| 863 flags), | 862 flags), |
| 864 pointer_id_(pointer_id), | 863 pointer_id_(pointer_id), |
| 865 details_(PointerDetails(pointer_type)) {} | 864 details_(PointerDetails(pointer_type)) {} |
| 866 | 865 |
| 867 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); | 866 const int PointerEvent::kMousePointerId = std::numeric_limits<int32_t>::max(); |
| 868 | 867 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 kMaxAutoRepeatTimeMs) { | 902 kMaxAutoRepeatTimeMs) { |
| 904 last_key_event_->set_time_stamp(event.time_stamp()); | 903 last_key_event_->set_time_stamp(event.time_stamp()); |
| 905 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT); | 904 last_key_event_->set_flags(last_key_event_->flags() | ui::EF_IS_REPEAT); |
| 906 return true; | 905 return true; |
| 907 } | 906 } |
| 908 delete last_key_event_; | 907 delete last_key_event_; |
| 909 last_key_event_ = new KeyEvent(event); | 908 last_key_event_ = new KeyEvent(event); |
| 910 return false; | 909 return false; |
| 911 } | 910 } |
| 912 | 911 |
| 913 KeyEvent::KeyEvent(EventType type, base::TimeDelta time_stamp, int flags) | 912 KeyEvent::KeyEvent(EventType type, base::TimeTicks time_stamp, int flags) |
| 914 : Event(type, time_stamp, flags) {} | 913 : Event(type, time_stamp, flags) {} |
| 915 | 914 |
| 916 KeyEvent::KeyEvent(const base::NativeEvent& native_event) | 915 KeyEvent::KeyEvent(const base::NativeEvent& native_event) |
| 917 : Event(native_event, | 916 : Event(native_event, |
| 918 EventTypeFromNative(native_event), | 917 EventTypeFromNative(native_event), |
| 919 EventFlagsFromNative(native_event)), | 918 EventFlagsFromNative(native_event)), |
| 920 key_code_(KeyboardCodeFromNative(native_event)), | 919 key_code_(KeyboardCodeFromNative(native_event)), |
| 921 code_(CodeFromNative(native_event)), | 920 code_(CodeFromNative(native_event)), |
| 922 is_char_(IsCharFromNative(native_event)) { | 921 is_char_(IsCharFromNative(native_event)) { |
| 923 if (IsRepeated(*this)) | 922 if (IsRepeated(*this)) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 950 : Event(type, EventTimeForNow(), flags), | 949 : Event(type, EventTimeForNow(), flags), |
| 951 key_code_(key_code), | 950 key_code_(key_code), |
| 952 code_(code) { | 951 code_(code) { |
| 953 } | 952 } |
| 954 | 953 |
| 955 KeyEvent::KeyEvent(EventType type, | 954 KeyEvent::KeyEvent(EventType type, |
| 956 KeyboardCode key_code, | 955 KeyboardCode key_code, |
| 957 DomCode code, | 956 DomCode code, |
| 958 int flags, | 957 int flags, |
| 959 DomKey key, | 958 DomKey key, |
| 960 base::TimeDelta time_stamp) | 959 base::TimeTicks time_stamp) |
| 961 : Event(type, time_stamp, flags), | 960 : Event(type, time_stamp, flags), |
| 962 key_code_(key_code), | 961 key_code_(key_code), |
| 963 code_(code), | 962 code_(code), |
| 964 key_(key) { | 963 key_(key) {} |
| 965 } | |
| 966 | 964 |
| 967 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) | 965 KeyEvent::KeyEvent(base::char16 character, KeyboardCode key_code, int flags) |
| 968 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), | 966 : Event(ET_KEY_PRESSED, EventTimeForNow(), flags), |
| 969 key_code_(key_code), | 967 key_code_(key_code), |
| 970 code_(DomCode::NONE), | 968 code_(DomCode::NONE), |
| 971 is_char_(true), | 969 is_char_(true), |
| 972 key_(DomKey::FromCharacter(character)) { | 970 key_(DomKey::FromCharacter(character)) { |
| 973 } | 971 } |
| 974 | 972 |
| 975 KeyEvent::KeyEvent(const KeyEvent& rhs) | 973 KeyEvent::KeyEvent(const KeyEvent& rhs) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 &x_offset_ordinal_, &y_offset_ordinal_, | 1169 &x_offset_ordinal_, &y_offset_ordinal_, |
| 1172 NULL); | 1170 NULL); |
| 1173 } else { | 1171 } else { |
| 1174 NOTREACHED() << "Unexpected event type " << type() | 1172 NOTREACHED() << "Unexpected event type " << type() |
| 1175 << " when constructing a ScrollEvent."; | 1173 << " when constructing a ScrollEvent."; |
| 1176 } | 1174 } |
| 1177 } | 1175 } |
| 1178 | 1176 |
| 1179 ScrollEvent::ScrollEvent(EventType type, | 1177 ScrollEvent::ScrollEvent(EventType type, |
| 1180 const gfx::Point& location, | 1178 const gfx::Point& location, |
| 1181 base::TimeDelta time_stamp, | 1179 base::TimeTicks time_stamp, |
| 1182 int flags, | 1180 int flags, |
| 1183 float x_offset, | 1181 float x_offset, |
| 1184 float y_offset, | 1182 float y_offset, |
| 1185 float x_offset_ordinal, | 1183 float x_offset_ordinal, |
| 1186 float y_offset_ordinal, | 1184 float y_offset_ordinal, |
| 1187 int finger_count) | 1185 int finger_count) |
| 1188 : MouseEvent(type, location, location, time_stamp, flags, 0), | 1186 : MouseEvent(type, location, location, time_stamp, flags, 0), |
| 1189 x_offset_(x_offset), | 1187 x_offset_(x_offset), |
| 1190 y_offset_(y_offset), | 1188 y_offset_(y_offset), |
| 1191 x_offset_ordinal_(x_offset_ordinal), | 1189 x_offset_ordinal_(x_offset_ordinal), |
| 1192 y_offset_ordinal_(y_offset_ordinal), | 1190 y_offset_ordinal_(y_offset_ordinal), |
| 1193 finger_count_(finger_count) { | 1191 finger_count_(finger_count) { |
| 1194 CHECK(IsScrollEvent()); | 1192 CHECK(IsScrollEvent()); |
| 1195 } | 1193 } |
| 1196 | 1194 |
| 1197 void ScrollEvent::Scale(const float factor) { | 1195 void ScrollEvent::Scale(const float factor) { |
| 1198 x_offset_ *= factor; | 1196 x_offset_ *= factor; |
| 1199 y_offset_ *= factor; | 1197 y_offset_ *= factor; |
| 1200 x_offset_ordinal_ *= factor; | 1198 x_offset_ordinal_ *= factor; |
| 1201 y_offset_ordinal_ *= factor; | 1199 y_offset_ordinal_ *= factor; |
| 1202 } | 1200 } |
| 1203 | 1201 |
| 1204 //////////////////////////////////////////////////////////////////////////////// | 1202 //////////////////////////////////////////////////////////////////////////////// |
| 1205 // GestureEvent | 1203 // GestureEvent |
| 1206 | 1204 |
| 1207 GestureEvent::GestureEvent(float x, | 1205 GestureEvent::GestureEvent(float x, |
| 1208 float y, | 1206 float y, |
| 1209 int flags, | 1207 int flags, |
| 1210 base::TimeDelta time_stamp, | 1208 base::TimeTicks time_stamp, |
| 1211 const GestureEventDetails& details) | 1209 const GestureEventDetails& details) |
| 1212 : LocatedEvent(details.type(), | 1210 : LocatedEvent(details.type(), |
| 1213 gfx::PointF(x, y), | 1211 gfx::PointF(x, y), |
| 1214 gfx::PointF(x, y), | 1212 gfx::PointF(x, y), |
| 1215 time_stamp, | 1213 time_stamp, |
| 1216 flags | EF_FROM_TOUCH), | 1214 flags | EF_FROM_TOUCH), |
| 1217 details_(details) { | 1215 details_(details) {} |
| 1218 } | |
| 1219 | 1216 |
| 1220 GestureEvent::~GestureEvent() { | 1217 GestureEvent::~GestureEvent() { |
| 1221 } | 1218 } |
| 1222 | 1219 |
| 1223 } // namespace ui | 1220 } // namespace ui |
| OLD | NEW |