| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/events/blink/blink_event_util.h" | 8 #include "ui/events/blink/blink_event_util.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 return std::make_pair(scroll_event, pinch_event); | 525 return std::make_pair(scroll_event, pinch_event); |
| 526 } | 526 } |
| 527 | 527 |
| 528 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( | 528 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( |
| 529 const MotionEvent& event, | 529 const MotionEvent& event, |
| 530 bool moved_beyond_slop_region) { | 530 bool moved_beyond_slop_region) { |
| 531 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == | 531 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == |
| 532 static_cast<int>(blink::WebTouchEvent::kTouchesLengthCap), | 532 static_cast<int>(blink::WebTouchEvent::kTouchesLengthCap), |
| 533 "inconsistent maximum number of active touch points"); | 533 "inconsistent maximum number of active touch points"); |
| 534 | 534 |
| 535 blink::WebTouchEvent result; | 535 blink::WebTouchEvent result( |
| 536 | 536 ToWebTouchEventType(event.GetAction()), |
| 537 result.type = ToWebTouchEventType(event.GetAction()); | 537 EventFlagsToWebEventModifiers(event.GetFlags()), |
| 538 ui::EventTimeStampToSeconds(event.GetEventTime())); |
| 538 result.dispatchType = result.type == WebInputEvent::TouchCancel | 539 result.dispatchType = result.type == WebInputEvent::TouchCancel |
| 539 ? WebInputEvent::EventNonBlocking | 540 ? WebInputEvent::EventNonBlocking |
| 540 : WebInputEvent::Blocking; | 541 : WebInputEvent::Blocking; |
| 541 result.timeStampSeconds = ui::EventTimeStampToSeconds(event.GetEventTime()); | |
| 542 result.movedBeyondSlopRegion = moved_beyond_slop_region; | 542 result.movedBeyondSlopRegion = moved_beyond_slop_region; |
| 543 | 543 |
| 544 result.modifiers = EventFlagsToWebEventModifiers(event.GetFlags()); | |
| 545 // TODO(mustaq): MotionEvent flags seems unrelated, should use | 544 // TODO(mustaq): MotionEvent flags seems unrelated, should use |
| 546 // metaState instead? | 545 // metaState instead? |
| 547 | 546 |
| 548 DCHECK_NE(event.GetUniqueEventId(), 0U); | 547 DCHECK_NE(event.GetUniqueEventId(), 0U); |
| 549 result.uniqueTouchEventId = event.GetUniqueEventId(); | 548 result.uniqueTouchEventId = event.GetUniqueEventId(); |
| 550 result.touchesLength = | 549 result.touchesLength = |
| 551 std::min(static_cast<unsigned>(event.GetPointerCount()), | 550 std::min(static_cast<unsigned>(event.GetPointerCount()), |
| 552 static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap)); | 551 static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap)); |
| 553 DCHECK_GT(result.touchesLength, 0U); | 552 DCHECK_GT(result.touchesLength, 0U); |
| 554 | 553 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 589 |
| 591 return modifiers; | 590 return modifiers; |
| 592 } | 591 } |
| 593 | 592 |
| 594 WebGestureEvent CreateWebGestureEvent(const GestureEventDetails& details, | 593 WebGestureEvent CreateWebGestureEvent(const GestureEventDetails& details, |
| 595 base::TimeTicks timestamp, | 594 base::TimeTicks timestamp, |
| 596 const gfx::PointF& location, | 595 const gfx::PointF& location, |
| 597 const gfx::PointF& raw_location, | 596 const gfx::PointF& raw_location, |
| 598 int flags, | 597 int flags, |
| 599 uint32_t unique_touch_event_id) { | 598 uint32_t unique_touch_event_id) { |
| 600 WebGestureEvent gesture; | 599 WebGestureEvent gesture(WebInputEvent::Undefined, |
| 601 gesture.timeStampSeconds = ui::EventTimeStampToSeconds(timestamp); | 600 EventFlagsToWebEventModifiers(flags), |
| 601 ui::EventTimeStampToSeconds(timestamp)); |
| 602 gesture.x = gfx::ToFlooredInt(location.x()); | 602 gesture.x = gfx::ToFlooredInt(location.x()); |
| 603 gesture.y = gfx::ToFlooredInt(location.y()); | 603 gesture.y = gfx::ToFlooredInt(location.y()); |
| 604 gesture.globalX = gfx::ToFlooredInt(raw_location.x()); | 604 gesture.globalX = gfx::ToFlooredInt(raw_location.x()); |
| 605 gesture.globalY = gfx::ToFlooredInt(raw_location.y()); | 605 gesture.globalY = gfx::ToFlooredInt(raw_location.y()); |
| 606 gesture.modifiers = EventFlagsToWebEventModifiers(flags); | |
| 607 | 606 |
| 608 switch (details.device_type()) { | 607 switch (details.device_type()) { |
| 609 case GestureDeviceType::DEVICE_TOUCHSCREEN: | 608 case GestureDeviceType::DEVICE_TOUCHSCREEN: |
| 610 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; | 609 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 611 break; | 610 break; |
| 612 case GestureDeviceType::DEVICE_TOUCHPAD: | 611 case GestureDeviceType::DEVICE_TOUCHPAD: |
| 613 gesture.sourceDevice = blink::WebGestureDeviceTouchpad; | 612 gesture.sourceDevice = blink::WebGestureDeviceTouchpad; |
| 614 break; | 613 break; |
| 615 case GestureDeviceType::DEVICE_UNKNOWN: | 614 case GestureDeviceType::DEVICE_UNKNOWN: |
| 616 NOTREACHED() << "Unknown device type is not allowed"; | 615 NOTREACHED() << "Unknown device type is not allowed"; |
| 617 gesture.sourceDevice = blink::WebGestureDeviceUninitialized; | 616 gesture.sourceDevice = blink::WebGestureDeviceUninitialized; |
| 618 break; | 617 break; |
| 619 } | 618 } |
| 620 | 619 |
| 621 gesture.uniqueTouchEventId = unique_touch_event_id; | 620 gesture.uniqueTouchEventId = unique_touch_event_id; |
| 622 | 621 |
| 623 switch (details.type()) { | 622 switch (details.type()) { |
| 624 case ET_GESTURE_SHOW_PRESS: | 623 case ET_GESTURE_SHOW_PRESS: |
| 625 gesture.type = WebInputEvent::GestureShowPress; | 624 gesture.setType(WebInputEvent::GestureShowPress); |
| 626 gesture.data.showPress.width = details.bounding_box_f().width(); | 625 gesture.data.showPress.width = details.bounding_box_f().width(); |
| 627 gesture.data.showPress.height = details.bounding_box_f().height(); | 626 gesture.data.showPress.height = details.bounding_box_f().height(); |
| 628 break; | 627 break; |
| 629 case ET_GESTURE_DOUBLE_TAP: | 628 case ET_GESTURE_DOUBLE_TAP: |
| 630 gesture.type = WebInputEvent::GestureDoubleTap; | 629 gesture.setType(WebInputEvent::GestureDoubleTap); |
| 631 DCHECK_EQ(1, details.tap_count()); | 630 DCHECK_EQ(1, details.tap_count()); |
| 632 gesture.data.tap.tapCount = details.tap_count(); | 631 gesture.data.tap.tapCount = details.tap_count(); |
| 633 gesture.data.tap.width = details.bounding_box_f().width(); | 632 gesture.data.tap.width = details.bounding_box_f().width(); |
| 634 gesture.data.tap.height = details.bounding_box_f().height(); | 633 gesture.data.tap.height = details.bounding_box_f().height(); |
| 635 break; | 634 break; |
| 636 case ET_GESTURE_TAP: | 635 case ET_GESTURE_TAP: |
| 637 gesture.type = WebInputEvent::GestureTap; | 636 gesture.setType(WebInputEvent::GestureTap); |
| 638 DCHECK_GE(details.tap_count(), 1); | 637 DCHECK_GE(details.tap_count(), 1); |
| 639 gesture.data.tap.tapCount = details.tap_count(); | 638 gesture.data.tap.tapCount = details.tap_count(); |
| 640 gesture.data.tap.width = details.bounding_box_f().width(); | 639 gesture.data.tap.width = details.bounding_box_f().width(); |
| 641 gesture.data.tap.height = details.bounding_box_f().height(); | 640 gesture.data.tap.height = details.bounding_box_f().height(); |
| 642 break; | 641 break; |
| 643 case ET_GESTURE_TAP_UNCONFIRMED: | 642 case ET_GESTURE_TAP_UNCONFIRMED: |
| 644 gesture.type = WebInputEvent::GestureTapUnconfirmed; | 643 gesture.setType(WebInputEvent::GestureTapUnconfirmed); |
| 645 DCHECK_EQ(1, details.tap_count()); | 644 DCHECK_EQ(1, details.tap_count()); |
| 646 gesture.data.tap.tapCount = details.tap_count(); | 645 gesture.data.tap.tapCount = details.tap_count(); |
| 647 gesture.data.tap.width = details.bounding_box_f().width(); | 646 gesture.data.tap.width = details.bounding_box_f().width(); |
| 648 gesture.data.tap.height = details.bounding_box_f().height(); | 647 gesture.data.tap.height = details.bounding_box_f().height(); |
| 649 break; | 648 break; |
| 650 case ET_GESTURE_LONG_PRESS: | 649 case ET_GESTURE_LONG_PRESS: |
| 651 gesture.type = WebInputEvent::GestureLongPress; | 650 gesture.setType(WebInputEvent::GestureLongPress); |
| 652 gesture.data.longPress.width = details.bounding_box_f().width(); | 651 gesture.data.longPress.width = details.bounding_box_f().width(); |
| 653 gesture.data.longPress.height = details.bounding_box_f().height(); | 652 gesture.data.longPress.height = details.bounding_box_f().height(); |
| 654 break; | 653 break; |
| 655 case ET_GESTURE_LONG_TAP: | 654 case ET_GESTURE_LONG_TAP: |
| 656 gesture.type = WebInputEvent::GestureLongTap; | 655 gesture.setType(WebInputEvent::GestureLongTap); |
| 657 gesture.data.longPress.width = details.bounding_box_f().width(); | 656 gesture.data.longPress.width = details.bounding_box_f().width(); |
| 658 gesture.data.longPress.height = details.bounding_box_f().height(); | 657 gesture.data.longPress.height = details.bounding_box_f().height(); |
| 659 break; | 658 break; |
| 660 case ET_GESTURE_TWO_FINGER_TAP: | 659 case ET_GESTURE_TWO_FINGER_TAP: |
| 661 gesture.type = blink::WebInputEvent::GestureTwoFingerTap; | 660 gesture.setType(blink::WebInputEvent::GestureTwoFingerTap); |
| 662 gesture.data.twoFingerTap.firstFingerWidth = details.first_finger_width(); | 661 gesture.data.twoFingerTap.firstFingerWidth = details.first_finger_width(); |
| 663 gesture.data.twoFingerTap.firstFingerHeight = | 662 gesture.data.twoFingerTap.firstFingerHeight = |
| 664 details.first_finger_height(); | 663 details.first_finger_height(); |
| 665 break; | 664 break; |
| 666 case ET_GESTURE_SCROLL_BEGIN: | 665 case ET_GESTURE_SCROLL_BEGIN: |
| 667 gesture.type = WebInputEvent::GestureScrollBegin; | 666 gesture.setType(WebInputEvent::GestureScrollBegin); |
| 668 gesture.data.scrollBegin.pointerCount = details.touch_points(); | 667 gesture.data.scrollBegin.pointerCount = details.touch_points(); |
| 669 gesture.data.scrollBegin.deltaXHint = details.scroll_x_hint(); | 668 gesture.data.scrollBegin.deltaXHint = details.scroll_x_hint(); |
| 670 gesture.data.scrollBegin.deltaYHint = details.scroll_y_hint(); | 669 gesture.data.scrollBegin.deltaYHint = details.scroll_y_hint(); |
| 671 break; | 670 break; |
| 672 case ET_GESTURE_SCROLL_UPDATE: | 671 case ET_GESTURE_SCROLL_UPDATE: |
| 673 gesture.type = WebInputEvent::GestureScrollUpdate; | 672 gesture.setType(WebInputEvent::GestureScrollUpdate); |
| 674 gesture.data.scrollUpdate.deltaX = details.scroll_x(); | 673 gesture.data.scrollUpdate.deltaX = details.scroll_x(); |
| 675 gesture.data.scrollUpdate.deltaY = details.scroll_y(); | 674 gesture.data.scrollUpdate.deltaY = details.scroll_y(); |
| 676 gesture.data.scrollUpdate.previousUpdateInSequencePrevented = | 675 gesture.data.scrollUpdate.previousUpdateInSequencePrevented = |
| 677 details.previous_scroll_update_in_sequence_prevented(); | 676 details.previous_scroll_update_in_sequence_prevented(); |
| 678 break; | 677 break; |
| 679 case ET_GESTURE_SCROLL_END: | 678 case ET_GESTURE_SCROLL_END: |
| 680 gesture.type = WebInputEvent::GestureScrollEnd; | 679 gesture.setType(WebInputEvent::GestureScrollEnd); |
| 681 break; | 680 break; |
| 682 case ET_SCROLL_FLING_START: | 681 case ET_SCROLL_FLING_START: |
| 683 gesture.type = WebInputEvent::GestureFlingStart; | 682 gesture.setType(WebInputEvent::GestureFlingStart); |
| 684 gesture.data.flingStart.velocityX = details.velocity_x(); | 683 gesture.data.flingStart.velocityX = details.velocity_x(); |
| 685 gesture.data.flingStart.velocityY = details.velocity_y(); | 684 gesture.data.flingStart.velocityY = details.velocity_y(); |
| 686 break; | 685 break; |
| 687 case ET_SCROLL_FLING_CANCEL: | 686 case ET_SCROLL_FLING_CANCEL: |
| 688 gesture.type = WebInputEvent::GestureFlingCancel; | 687 gesture.setType(WebInputEvent::GestureFlingCancel); |
| 689 break; | 688 break; |
| 690 case ET_GESTURE_PINCH_BEGIN: | 689 case ET_GESTURE_PINCH_BEGIN: |
| 691 gesture.type = WebInputEvent::GesturePinchBegin; | 690 gesture.setType(WebInputEvent::GesturePinchBegin); |
| 692 break; | 691 break; |
| 693 case ET_GESTURE_PINCH_UPDATE: | 692 case ET_GESTURE_PINCH_UPDATE: |
| 694 gesture.type = WebInputEvent::GesturePinchUpdate; | 693 gesture.setType(WebInputEvent::GesturePinchUpdate); |
| 695 gesture.data.pinchUpdate.scale = details.scale(); | 694 gesture.data.pinchUpdate.scale = details.scale(); |
| 696 break; | 695 break; |
| 697 case ET_GESTURE_PINCH_END: | 696 case ET_GESTURE_PINCH_END: |
| 698 gesture.type = WebInputEvent::GesturePinchEnd; | 697 gesture.setType(WebInputEvent::GesturePinchEnd); |
| 699 break; | 698 break; |
| 700 case ET_GESTURE_TAP_CANCEL: | 699 case ET_GESTURE_TAP_CANCEL: |
| 701 gesture.type = WebInputEvent::GestureTapCancel; | 700 gesture.setType(WebInputEvent::GestureTapCancel); |
| 702 break; | 701 break; |
| 703 case ET_GESTURE_TAP_DOWN: | 702 case ET_GESTURE_TAP_DOWN: |
| 704 gesture.type = WebInputEvent::GestureTapDown; | 703 gesture.setType(WebInputEvent::GestureTapDown); |
| 705 gesture.data.tapDown.width = details.bounding_box_f().width(); | 704 gesture.data.tapDown.width = details.bounding_box_f().width(); |
| 706 gesture.data.tapDown.height = details.bounding_box_f().height(); | 705 gesture.data.tapDown.height = details.bounding_box_f().height(); |
| 707 break; | 706 break; |
| 708 case ET_GESTURE_BEGIN: | 707 case ET_GESTURE_BEGIN: |
| 709 case ET_GESTURE_END: | 708 case ET_GESTURE_END: |
| 710 case ET_GESTURE_SWIPE: | 709 case ET_GESTURE_SWIPE: |
| 711 // The caller is responsible for discarding these gestures appropriately. | 710 // The caller is responsible for discarding these gestures appropriately. |
| 712 gesture.type = WebInputEvent::Undefined; | 711 gesture.setType(WebInputEvent::Undefined); |
| 713 break; | 712 break; |
| 714 default: | 713 default: |
| 715 NOTREACHED() << "EventType provided wasn't a valid gesture event: " | 714 NOTREACHED() << "EventType provided wasn't a valid gesture event: " |
| 716 << details.type(); | 715 << details.type(); |
| 717 } | 716 } |
| 718 | 717 |
| 719 return gesture; | 718 return gesture; |
| 720 } | 719 } |
| 721 | 720 |
| 722 WebGestureEvent CreateWebGestureEventFromGestureEventData( | 721 WebGestureEvent CreateWebGestureEventFromGestureEventData( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 switch (type) { | 961 switch (type) { |
| 963 case blink::WebGestureEvent::GestureScrollUpdate: | 962 case blink::WebGestureEvent::GestureScrollUpdate: |
| 964 case blink::WebGestureEvent::GesturePinchUpdate: | 963 case blink::WebGestureEvent::GesturePinchUpdate: |
| 965 return true; | 964 return true; |
| 966 default: | 965 default: |
| 967 return false; | 966 return false; |
| 968 } | 967 } |
| 969 } | 968 } |
| 970 | 969 |
| 971 } // namespace ui | 970 } // namespace ui |
| OLD | NEW |