OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/dom/TouchList.h" | 38 #include "core/dom/TouchList.h" |
39 #include "core/dom/shadow/ComposedTreeTraversal.h" | 39 #include "core/dom/shadow/ComposedTreeTraversal.h" |
40 #include "core/dom/shadow/ShadowRoot.h" | 40 #include "core/dom/shadow/ShadowRoot.h" |
41 #include "core/editing/Editor.h" | 41 #include "core/editing/Editor.h" |
42 #include "core/editing/FrameSelection.h" | 42 #include "core/editing/FrameSelection.h" |
43 #include "core/editing/htmlediting.h" | 43 #include "core/editing/htmlediting.h" |
44 #include "core/editing/iterators/TextIterator.h" | 44 #include "core/editing/iterators/TextIterator.h" |
45 #include "core/events/EventPath.h" | 45 #include "core/events/EventPath.h" |
46 #include "core/events/KeyboardEvent.h" | 46 #include "core/events/KeyboardEvent.h" |
47 #include "core/events/MouseEvent.h" | 47 #include "core/events/MouseEvent.h" |
| 48 #include "core/events/PointerEvent.h" |
48 #include "core/events/TextEvent.h" | 49 #include "core/events/TextEvent.h" |
49 #include "core/events/TouchEvent.h" | 50 #include "core/events/TouchEvent.h" |
50 #include "core/events/WheelEvent.h" | 51 #include "core/events/WheelEvent.h" |
51 #include "core/fetch/ImageResource.h" | 52 #include "core/fetch/ImageResource.h" |
52 #include "core/frame/EventHandlerRegistry.h" | 53 #include "core/frame/EventHandlerRegistry.h" |
53 #include "core/frame/FrameHost.h" | 54 #include "core/frame/FrameHost.h" |
54 #include "core/frame/FrameView.h" | 55 #include "core/frame/FrameView.h" |
55 #include "core/frame/LocalFrame.h" | 56 #include "core/frame/LocalFrame.h" |
56 #include "core/frame/PinchViewport.h" | 57 #include "core/frame/PinchViewport.h" |
57 #include "core/frame/Settings.h" | 58 #include "core/frame/Settings.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 m_previousWheelScrolledNode = nullptr; | 310 m_previousWheelScrolledNode = nullptr; |
310 m_targetForTouchID.clear(); | 311 m_targetForTouchID.clear(); |
311 m_touchSequenceDocument.clear(); | 312 m_touchSequenceDocument.clear(); |
312 m_touchSequenceUserGestureToken.clear(); | 313 m_touchSequenceUserGestureToken.clear(); |
313 m_scrollGestureHandlingNode = nullptr; | 314 m_scrollGestureHandlingNode = nullptr; |
314 m_lastGestureScrollOverWidget = false; | 315 m_lastGestureScrollOverWidget = false; |
315 m_previousGestureScrolledNode = nullptr; | 316 m_previousGestureScrolledNode = nullptr; |
316 m_scrollbarHandlingScrollGesture = nullptr; | 317 m_scrollbarHandlingScrollGesture = nullptr; |
317 m_maxMouseMovedDuration = 0; | 318 m_maxMouseMovedDuration = 0; |
318 m_touchPressed = false; | 319 m_touchPressed = false; |
| 320 m_pointerIdManager.clear(); |
319 m_mouseDownMayStartSelect = false; | 321 m_mouseDownMayStartSelect = false; |
320 m_mouseDownMayStartDrag = false; | 322 m_mouseDownMayStartDrag = false; |
321 m_lastShowPressTimestamp = 0; | 323 m_lastShowPressTimestamp = 0; |
322 m_lastDeferredTapElement = nullptr; | 324 m_lastDeferredTapElement = nullptr; |
323 m_eventHandlerWillResetCapturingMouseEventsNode = false; | 325 m_eventHandlerWillResetCapturingMouseEventsNode = false; |
324 m_mouseDownWasSingleClickInSelection = false; | 326 m_mouseDownWasSingleClickInSelection = false; |
325 m_selectionInitiationState = HaveNotStartedSelection; | 327 m_selectionInitiationState = HaveNotStartedSelection; |
326 m_mouseDownMayStartAutoscroll = false; | 328 m_mouseDownMayStartAutoscroll = false; |
327 m_svgPan = false; | 329 m_svgPan = false; |
328 m_mouseDownPos = IntPoint(); | 330 m_mouseDownPos = IntPoint(); |
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3770 m_lastScrollbarUnderMouse->mouseExited(); | 3772 m_lastScrollbarUnderMouse->mouseExited(); |
3771 | 3773 |
3772 // Send mouse entered if we're setting a new scrollbar. | 3774 // Send mouse entered if we're setting a new scrollbar. |
3773 if (scrollbar && setLast) | 3775 if (scrollbar && setLast) |
3774 scrollbar->mouseEntered(); | 3776 scrollbar->mouseEntered(); |
3775 | 3777 |
3776 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr; | 3778 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr; |
3777 } | 3779 } |
3778 } | 3780 } |
3779 | 3781 |
3780 static const AtomicString& eventNameForTouchPointState(PlatformTouchPoint::State
state) | 3782 static const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::
State state) |
3781 { | 3783 { |
3782 switch (state) { | 3784 switch (state) { |
3783 case PlatformTouchPoint::TouchReleased: | 3785 case PlatformTouchPoint::TouchReleased: |
3784 return EventTypeNames::touchend; | 3786 return EventTypeNames::touchend; |
3785 case PlatformTouchPoint::TouchCancelled: | 3787 case PlatformTouchPoint::TouchCancelled: |
3786 return EventTypeNames::touchcancel; | 3788 return EventTypeNames::touchcancel; |
3787 case PlatformTouchPoint::TouchPressed: | 3789 case PlatformTouchPoint::TouchPressed: |
3788 return EventTypeNames::touchstart; | 3790 return EventTypeNames::touchstart; |
3789 case PlatformTouchPoint::TouchMoved: | 3791 case PlatformTouchPoint::TouchMoved: |
3790 return EventTypeNames::touchmove; | 3792 return EventTypeNames::touchmove; |
3791 case PlatformTouchPoint::TouchStationary: | 3793 case PlatformTouchPoint::TouchStationary: |
3792 // TouchStationary state is not converted to touch events, so fall throu
gh to assert. | 3794 // Fall through to default |
3793 default: | 3795 default: |
3794 ASSERT_NOT_REACHED(); | 3796 ASSERT_NOT_REACHED(); |
3795 return emptyAtom; | 3797 return emptyAtom; |
| 3798 } |
| 3799 } |
| 3800 |
| 3801 static const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint
::State state) |
| 3802 { |
| 3803 switch (state) { |
| 3804 case PlatformTouchPoint::TouchReleased: |
| 3805 return EventTypeNames::pointerup; |
| 3806 case PlatformTouchPoint::TouchCancelled: |
| 3807 return EventTypeNames::pointercancel; |
| 3808 case PlatformTouchPoint::TouchPressed: |
| 3809 return EventTypeNames::pointerdown; |
| 3810 case PlatformTouchPoint::TouchMoved: |
| 3811 return EventTypeNames::pointermove; |
| 3812 case PlatformTouchPoint::TouchStationary: |
| 3813 // Fall through to default |
| 3814 default: |
| 3815 ASSERT_NOT_REACHED(); |
| 3816 return emptyAtom; |
3796 } | 3817 } |
3797 } | 3818 } |
3798 | 3819 |
3799 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout
Point& point, HitTestRequest::HitTestRequestType hitType) | 3820 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout
Point& point, HitTestRequest::HitTestRequestType hitType) |
3800 { | 3821 { |
3801 HitTestResult result(HitTestRequest(hitType), point); | 3822 HitTestResult result(HitTestRequest(hitType), point); |
3802 | 3823 |
3803 if (!frame || !frame->contentLayoutObject()) | 3824 if (!frame || !frame->contentLayoutObject()) |
3804 return result; | 3825 return result; |
3805 if (frame->view()) { | 3826 if (frame->view()) { |
3806 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars); | 3827 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars); |
3807 if (!rect.contains(roundedIntPoint(point))) | 3828 if (!rect.contains(roundedIntPoint(point))) |
3808 return result; | 3829 return result; |
3809 } | 3830 } |
3810 frame->contentLayoutObject()->hitTest(result); | 3831 frame->contentLayoutObject()->hitTest(result); |
3811 return result; | 3832 return result; |
3812 } | 3833 } |
3813 | 3834 |
| 3835 void EventHandler::handlePointerEventsFromTouchEvent(const PlatformTouchEvent& e
vent, |
| 3836 const Vector<PlatformTouchPoint>& points, Vector<TouchInfo>& touchInfos) |
| 3837 { |
| 3838 const String& PointerTypeTouch("touch"); |
| 3839 |
| 3840 // Iterate through the touch points, sending PointerEvents to the targets as
required. |
| 3841 for (unsigned i = 0; i < points.size(); ++i) { |
| 3842 const PlatformTouchPoint& point = points[i]; |
| 3843 TouchInfo& touchInfo = touchInfos[i]; |
| 3844 |
| 3845 unsigned pointerId = point.id(); |
| 3846 const PlatformTouchPoint::State pointState = point.state(); |
| 3847 |
| 3848 if (pointState == PlatformTouchPoint::TouchStationary) |
| 3849 continue; |
| 3850 bool pointerReleasedOrCancelled = |
| 3851 pointState == PlatformTouchPoint::TouchReleased || pointState == Pla
tformTouchPoint::TouchCancelled; |
| 3852 const AtomicString& eventName(pointerEventNameForTouchPointState(pointSt
ate)); |
| 3853 |
| 3854 if (pointState == PlatformTouchPoint::TouchPressed) |
| 3855 m_pointerIdManager.add(pointerId); |
| 3856 |
| 3857 bool isEnterOrLeave = false; |
| 3858 bool isCancelable = !(isEnterOrLeave || pointState == PlatformTouchPoint
::TouchCancelled); |
| 3859 bool isBubbling = !isEnterOrLeave; |
| 3860 |
| 3861 PointerEventInit pointerEventInit; |
| 3862 pointerEventInit.setPointerId(pointerId); |
| 3863 pointerEventInit.setWidth(touchInfo.adjustedRadius.width()); |
| 3864 pointerEventInit.setHeight(touchInfo.adjustedRadius.height()); |
| 3865 pointerEventInit.setPressure(point.force()); |
| 3866 pointerEventInit.setPointerType(PointerTypeTouch); |
| 3867 pointerEventInit.setIsPrimary(m_pointerIdManager.isPrimary(pointerId)); |
| 3868 pointerEventInit.setScreenX(point.screenPos().x()); |
| 3869 pointerEventInit.setScreenY(point.screenPos().y()); |
| 3870 pointerEventInit.setClientX(touchInfo.adjustedPagePoint.x()); |
| 3871 pointerEventInit.setClientY(touchInfo.adjustedPagePoint.y()); |
| 3872 pointerEventInit.setButton(0); |
| 3873 pointerEventInit.setButtons(pointerReleasedOrCancelled ? 0 : 1); |
| 3874 |
| 3875 pointerEventInit.setCtrlKey(event.ctrlKey()); |
| 3876 pointerEventInit.setShiftKey(event.shiftKey()); |
| 3877 pointerEventInit.setAltKey(event.altKey()); |
| 3878 pointerEventInit.setMetaKey(event.metaKey()); |
| 3879 |
| 3880 pointerEventInit.setBubbles(isBubbling); |
| 3881 pointerEventInit.setCancelable(isCancelable); |
| 3882 |
| 3883 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eve
ntName, pointerEventInit); |
| 3884 touchInfo.touchTarget->toNode()->dispatchPointerEvent(pointerEvent.get()
); |
| 3885 touchInfo.consumed = pointerEvent->defaultPrevented() || pointerEvent->d
efaultHandled(); |
| 3886 |
| 3887 // Remove the released/cancelled id at the end to correctly determine pr
imary id above. |
| 3888 if (pointerReleasedOrCancelled) |
| 3889 m_pointerIdManager.remove(pointerId); |
| 3890 } |
| 3891 } |
| 3892 |
3814 bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event) | 3893 bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event) |
3815 { | 3894 { |
3816 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent"); | 3895 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent"); |
3817 | 3896 |
3818 const Vector<PlatformTouchPoint>& points = event.touchPoints(); | 3897 const Vector<PlatformTouchPoint>& points = event.touchPoints(); |
3819 | 3898 |
3820 unsigned i; | |
3821 bool freshTouchEvents = true; | 3899 bool freshTouchEvents = true; |
3822 bool allTouchReleased = true; | 3900 bool allTouchReleased = true; |
3823 for (i = 0; i < points.size(); ++i) { | 3901 for (unsigned i = 0; i < points.size(); ++i) { |
3824 const PlatformTouchPoint& point = points[i]; | 3902 const PlatformTouchPoint& point = points[i]; |
| 3903 |
3825 if (point.state() != PlatformTouchPoint::TouchPressed) | 3904 if (point.state() != PlatformTouchPoint::TouchPressed) |
3826 freshTouchEvents = false; | 3905 freshTouchEvents = false; |
3827 if (point.state() != PlatformTouchPoint::TouchReleased && point.state()
!= PlatformTouchPoint::TouchCancelled) | 3906 if (point.state() != PlatformTouchPoint::TouchReleased && point.state()
!= PlatformTouchPoint::TouchCancelled) |
3828 allTouchReleased = false; | 3907 allTouchReleased = false; |
3829 } | 3908 } |
3830 if (freshTouchEvents) { | 3909 if (freshTouchEvents) { |
3831 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should | 3910 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should |
3832 // have cleared the active document when we saw the last release. But we | 3911 // have cleared the active document when we saw the last release. But we |
3833 // have some tests that violate this, ClusterFuzz could trigger it, and | 3912 // have some tests that violate this, ClusterFuzz could trigger it, and |
3834 // there may be cases where the browser doesn't reliably release all | 3913 // there may be cases where the browser doesn't reliably release all |
(...skipping 12 matching lines...) Expand all Loading... |
3847 m_touchSequenceUserGestureToken = gestureIndicator->currentToken(); | 3926 m_touchSequenceUserGestureToken = gestureIndicator->currentToken(); |
3848 | 3927 |
3849 ASSERT(m_frame->view()); | 3928 ASSERT(m_frame->view()); |
3850 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc
hSequenceDocument->frame()->view())) { | 3929 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc
hSequenceDocument->frame()->view())) { |
3851 // If the active touch document has no frame or view, it's probably bein
g destroyed | 3930 // If the active touch document has no frame or view, it's probably bein
g destroyed |
3852 // so we can't dispatch events. | 3931 // so we can't dispatch events. |
3853 return false; | 3932 return false; |
3854 } | 3933 } |
3855 | 3934 |
3856 // First do hit tests for any new touch points. | 3935 // First do hit tests for any new touch points. |
3857 for (i = 0; i < points.size(); ++i) { | 3936 for (unsigned i = 0; i < points.size(); ++i) { |
3858 const PlatformTouchPoint& point = points[i]; | 3937 const PlatformTouchPoint& point = points[i]; |
3859 | 3938 |
3860 // Touch events implicitly capture to the touched node, and don't change | 3939 // Touch events implicitly capture to the touched node, and don't change |
3861 // active/hover states themselves (Gesture events do). So we only need | 3940 // active/hover states themselves (Gesture events do). So we only need |
3862 // to hit-test on touchstart, and it can be read-only. | 3941 // to hit-test on touchstart, and it can be read-only. |
3863 if (point.state() == PlatformTouchPoint::TouchPressed) { | 3942 if (point.state() == PlatformTouchPoint::TouchPressed) { |
3864 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv
ent | HitTestRequest::ReadOnly | HitTestRequest::Active; | 3943 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv
ent | HitTestRequest::ReadOnly | HitTestRequest::Active; |
3865 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram
eToContents(point.pos())); | 3944 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram
eToContents(point.pos())); |
3866 HitTestResult result; | 3945 HitTestResult result; |
3867 if (!m_touchSequenceDocument) { | 3946 if (!m_touchSequenceDocument) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3909 // document set to receive the events, then we can skip all the rest of | 3988 // document set to receive the events, then we can skip all the rest of |
3910 // this work. | 3989 // this work. |
3911 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_
touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even
tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) { | 3990 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_
touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even
tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) { |
3912 if (allTouchReleased) { | 3991 if (allTouchReleased) { |
3913 m_touchSequenceDocument.clear(); | 3992 m_touchSequenceDocument.clear(); |
3914 m_touchSequenceUserGestureToken.clear(); | 3993 m_touchSequenceUserGestureToken.clear(); |
3915 } | 3994 } |
3916 return false; | 3995 return false; |
3917 } | 3996 } |
3918 | 3997 |
3919 // Build up the lists to use for the 'touches', 'targetTouches' and | 3998 // Compute and store the common info used by both PointerEvent and TouchEven
t. |
3920 // 'changedTouches' attributes in the JS event. See | 3999 Vector<TouchInfo> touchInfos(points.size()); |
3921 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these | |
3922 // lists fit together. | |
3923 | 4000 |
3924 // Holds the complete set of touches on the screen. | 4001 for (unsigned i = 0; i < points.size(); ++i) { |
3925 RefPtrWillBeRawPtr<TouchList> touches = TouchList::create(); | |
3926 | |
3927 // A different view on the 'touches' list above, filtered and grouped by | |
3928 // event target. Used for the 'targetTouches' list in the JS event. | |
3929 using TargetTouchesHeapMap = WillBeHeapHashMap<EventTarget*, RefPtrWillBeMem
ber<TouchList>>; | |
3930 TargetTouchesHeapMap touchesByTarget; | |
3931 | |
3932 // Array of touches per state, used to assemble the 'changedTouches' list. | |
3933 using EventTargetSet = WillBeHeapHashSet<RefPtrWillBeMember<EventTarget>>; | |
3934 struct { | |
3935 // The touches corresponding to the particular change state this struct | |
3936 // instance represents. | |
3937 RefPtrWillBeMember<TouchList> m_touches; | |
3938 // Set of targets involved in m_touches. | |
3939 EventTargetSet m_targets; | |
3940 } changedTouches[PlatformTouchPoint::TouchStateEnd]; | |
3941 | |
3942 for (i = 0; i < points.size(); ++i) { | |
3943 const PlatformTouchPoint& point = points[i]; | 4002 const PlatformTouchPoint& point = points[i]; |
3944 PlatformTouchPoint::State pointState = point.state(); | 4003 PlatformTouchPoint::State pointState = point.state(); |
3945 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr; | 4004 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr; |
3946 | 4005 |
3947 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla
tformTouchPoint::TouchCancelled) { | 4006 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla
tformTouchPoint::TouchCancelled) { |
3948 // The target should be the original target for this touch, so get | 4007 // The target should be the original target for this touch, so get |
3949 // it from the hashmap. As it's a release or cancel we also remove | 4008 // it from the hashmap. As it's a release or cancel we also remove |
3950 // it from the map. | 4009 // it from the map. |
3951 touchTarget = m_targetForTouchID.take(point.id()); | 4010 touchTarget = m_targetForTouchID.take(point.id()); |
3952 } else { | 4011 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
3981 // a Touch is a Node so using the window could be a breaking change. | 4040 // a Touch is a Node so using the window could be a breaking change. |
3982 // Since we know there was no handler invoked, the specific target | 4041 // Since we know there was no handler invoked, the specific target |
3983 // should be completely irrelevant to the application. | 4042 // should be completely irrelevant to the application. |
3984 touchTarget = m_touchSequenceDocument; | 4043 touchTarget = m_touchSequenceDocument; |
3985 targetFrame = m_touchSequenceDocument->frame(); | 4044 targetFrame = m_touchSequenceDocument->frame(); |
3986 } | 4045 } |
3987 ASSERT(targetFrame); | 4046 ASSERT(targetFrame); |
3988 | 4047 |
3989 // pagePoint should always be in the target element's document coordinat
es. | 4048 // pagePoint should always be in the target element's document coordinat
es. |
3990 FloatPoint pagePoint = targetFrame->view()->rootFrameToContents(point.po
s()); | 4049 FloatPoint pagePoint = targetFrame->view()->rootFrameToContents(point.po
s()); |
3991 | |
3992 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); | 4050 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); |
3993 | 4051 |
3994 FloatPoint adjustedPagePoint = pagePoint.scaledBy(scaleFactor); | 4052 TouchInfo& touchInfo = touchInfos[i]; |
3995 FloatSize adjustedRadius = point.radius().scaledBy(scaleFactor); | 4053 touchInfo.touchTarget = touchTarget.get(); |
| 4054 touchInfo.targetFrame = targetFrame; |
| 4055 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor); |
| 4056 touchInfo.adjustedRadius = point.radius().scaledBy(scaleFactor); |
| 4057 touchInfo.knownTarget = knownTarget; |
| 4058 touchInfo.consumed = false; |
| 4059 } |
| 4060 |
| 4061 if (RuntimeEnabledFeatures::pointerEventEnabled()) |
| 4062 handlePointerEventsFromTouchEvent(event, points, touchInfos); |
| 4063 |
| 4064 bool swallowedEvent = false; |
| 4065 |
| 4066 // Build up the lists to use for the 'touches', 'targetTouches' and |
| 4067 // 'changedTouches' attributes in the JS event. See |
| 4068 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these |
| 4069 // lists fit together. |
| 4070 |
| 4071 // Holds the complete set of touches on the screen. |
| 4072 RefPtrWillBeRawPtr<TouchList> touches = TouchList::create(); |
| 4073 |
| 4074 // A different view on the 'touches' list above, filtered and grouped by |
| 4075 // event target. Used for the 'targetTouches' list in the JS event. |
| 4076 using TargetTouchesHeapMap = WillBeHeapHashMap<EventTarget*, RefPtrWillBeMem
ber<TouchList>>; |
| 4077 TargetTouchesHeapMap touchesByTarget; |
| 4078 |
| 4079 // Array of touches per state, used to assemble the 'changedTouches' list. |
| 4080 using EventTargetSet = WillBeHeapHashSet<RefPtrWillBeMember<EventTarget>>; |
| 4081 struct { |
| 4082 // The touches corresponding to the particular change state this struct |
| 4083 // instance represents. |
| 4084 RefPtrWillBeMember<TouchList> m_touches; |
| 4085 // Set of targets involved in m_touches. |
| 4086 EventTargetSet m_targets; |
| 4087 } changedTouches[PlatformTouchPoint::TouchStateEnd]; |
| 4088 |
| 4089 for (unsigned i = 0; i < points.size(); ++i) { |
| 4090 const PlatformTouchPoint& point = points[i]; |
| 4091 const TouchInfo& touchInfo = touchInfos[i]; |
| 4092 PlatformTouchPoint::State pointState = point.state(); |
| 4093 |
| 4094 if (touchInfo.consumed) |
| 4095 continue; |
3996 | 4096 |
3997 RefPtrWillBeRawPtr<Touch> touch = Touch::create( | 4097 RefPtrWillBeRawPtr<Touch> touch = Touch::create( |
3998 targetFrame, touchTarget.get(), point.id(), point.screenPos(), adjus
tedPagePoint, adjustedRadius, point.rotationAngle(), point.force()); | 4098 touchInfo.targetFrame, |
| 4099 touchInfo.touchTarget, |
| 4100 point.id(), |
| 4101 point.screenPos(), |
| 4102 touchInfo.adjustedPagePoint, |
| 4103 touchInfo.adjustedRadius, |
| 4104 point.rotationAngle(), |
| 4105 point.force()); |
3999 | 4106 |
4000 // Ensure this target's touch list exists, even if it ends up empty, so | 4107 // Ensure this target's touch list exists, even if it ends up empty, so |
4001 // it can always be passed to TouchEvent::Create below. | 4108 // it can always be passed to TouchEvent::Create below. |
4002 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f
ind(touchTarget.get()); | 4109 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f
ind(touchInfo.touchTarget); |
4003 if (targetTouchesIterator == touchesByTarget.end()) { | 4110 if (targetTouchesIterator == touchesByTarget.end()) { |
4004 touchesByTarget.set(touchTarget.get(), TouchList::create()); | 4111 touchesByTarget.set(touchInfo.touchTarget, TouchList::create()); |
4005 targetTouchesIterator = touchesByTarget.find(touchTarget.get()); | 4112 targetTouchesIterator = touchesByTarget.find(touchInfo.touchTarget); |
4006 } | 4113 } |
4007 | 4114 |
4008 // touches and targetTouches should only contain information about | 4115 // touches and targetTouches should only contain information about |
4009 // touches still on the screen, so if this point is released or | 4116 // touches still on the screen, so if this point is released or |
4010 // cancelled it will only appear in the changedTouches list. | 4117 // cancelled it will only appear in the changedTouches list. |
4011 if (pointState != PlatformTouchPoint::TouchReleased && pointState != Pla
tformTouchPoint::TouchCancelled) { | 4118 if (pointState != PlatformTouchPoint::TouchReleased && pointState != Pla
tformTouchPoint::TouchCancelled) { |
4012 touches->append(touch); | 4119 touches->append(touch); |
4013 targetTouchesIterator->value->append(touch); | 4120 targetTouchesIterator->value->append(touch); |
4014 } | 4121 } |
4015 | 4122 |
4016 // Now build up the correct list for changedTouches. | 4123 // Now build up the correct list for changedTouches. |
4017 // Note that any touches that are in the TouchStationary state (e.g. if | 4124 // Note that any touches that are in the TouchStationary state (e.g. if |
4018 // the user had several points touched but did not move them all) should | 4125 // the user had several points touched but did not move them all) should |
4019 // never be in the changedTouches list so we do not handle them | 4126 // never be in the changedTouches list so we do not handle them |
4020 // explicitly here. See https://bugs.webkit.org/show_bug.cgi?id=37609 | 4127 // explicitly here. See https://bugs.webkit.org/show_bug.cgi?id=37609 |
4021 // for further discussion about the TouchStationary state. | 4128 // for further discussion about the TouchStationary state. |
4022 if (pointState != PlatformTouchPoint::TouchStationary && knownTarget) { | 4129 if (pointState != PlatformTouchPoint::TouchStationary && touchInfo.known
Target) { |
4023 ASSERT(pointState < PlatformTouchPoint::TouchStateEnd); | 4130 ASSERT(pointState < PlatformTouchPoint::TouchStateEnd); |
4024 if (!changedTouches[pointState].m_touches) | 4131 if (!changedTouches[pointState].m_touches) |
4025 changedTouches[pointState].m_touches = TouchList::create(); | 4132 changedTouches[pointState].m_touches = TouchList::create(); |
4026 changedTouches[pointState].m_touches->append(touch); | 4133 changedTouches[pointState].m_touches->append(touch); |
4027 changedTouches[pointState].m_targets.add(touchTarget); | 4134 changedTouches[pointState].m_targets.add(touchInfo.touchTarget); |
4028 } | 4135 } |
4029 } | 4136 } |
4030 if (allTouchReleased) { | 4137 if (allTouchReleased) { |
4031 m_touchSequenceDocument.clear(); | 4138 m_touchSequenceDocument.clear(); |
4032 m_touchSequenceUserGestureToken.clear(); | 4139 m_touchSequenceUserGestureToken.clear(); |
4033 } | 4140 } |
4034 | 4141 |
4035 // Now iterate the changedTouches list and m_targets within it, sending | 4142 // Now iterate through the changedTouches list and m_targets within it, send
ing |
4036 // events to the targets as required. | 4143 // TouchEvents to the targets as required. |
4037 bool swallowedEvent = false; | |
4038 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state
) { | 4144 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state
) { |
4039 if (!changedTouches[state].m_touches) | 4145 if (!changedTouches[state].m_touches) |
4040 continue; | 4146 continue; |
4041 | 4147 |
4042 const AtomicString& stateName(eventNameForTouchPointState(static_cast<Pl
atformTouchPoint::State>(state))); | 4148 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca
st<PlatformTouchPoint::State>(state))); |
4043 const EventTargetSet& targetsForState = changedTouches[state].m_targets; | 4149 const EventTargetSet& targetsForState = changedTouches[state].m_targets; |
4044 for (const RefPtrWillBeMember<EventTarget>& eventTarget : targetsForStat
e) { | 4150 for (const RefPtrWillBeMember<EventTarget>& eventTarget : targetsForStat
e) { |
4045 EventTarget* touchEventTarget = eventTarget.get(); | 4151 EventTarget* touchEventTarget = eventTarget.get(); |
4046 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create( | 4152 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create( |
4047 touches.get(), touchesByTarget.get(touchEventTarget), changedTou
ches[state].m_touches.get(), | 4153 touches.get(), touchesByTarget.get(touchEventTarget), changedTou
ches[state].m_touches.get(), |
4048 stateName, touchEventTarget->toNode()->document().domWindow(), | 4154 eventName, touchEventTarget->toNode()->document().domWindow(), |
4049 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey
(), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp()); | 4155 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey
(), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp()); |
4050 touchEventTarget->toNode()->dispatchTouchEvent(touchEvent.get()); | 4156 touchEventTarget->toNode()->dispatchTouchEvent(touchEvent.get()); |
4051 swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() ||
touchEvent->defaultHandled(); | 4157 swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() ||
touchEvent->defaultHandled(); |
4052 } | 4158 } |
4053 } | 4159 } |
4054 | 4160 |
4055 return swallowedEvent; | 4161 return swallowedEvent; |
4056 } | 4162 } |
4057 | 4163 |
4058 TouchAction EventHandler::intersectTouchAction(TouchAction action1, TouchAction
action2) | 4164 TouchAction EventHandler::intersectTouchAction(TouchAction action1, TouchAction
action2) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4170 unsigned EventHandler::accessKeyModifiers() | 4276 unsigned EventHandler::accessKeyModifiers() |
4171 { | 4277 { |
4172 #if OS(MACOSX) | 4278 #if OS(MACOSX) |
4173 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; | 4279 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; |
4174 #else | 4280 #else |
4175 return PlatformEvent::AltKey; | 4281 return PlatformEvent::AltKey; |
4176 #endif | 4282 #endif |
4177 } | 4283 } |
4178 | 4284 |
4179 } // namespace blink | 4285 } // namespace blink |
OLD | NEW |