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

Side by Side Diff: Source/core/page/EventHandler.cpp

Issue 1144313003: Added PointerEvent firing on touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed the gyp rule for nuked ThreadLocalEventNames.h Created 5 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 /* 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
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 , m_widgetIsLatched(false) 238 , m_widgetIsLatched(false)
238 , m_touchPressed(false) 239 , m_touchPressed(false)
239 , m_scrollGestureHandlingNode(nullptr) 240 , m_scrollGestureHandlingNode(nullptr)
240 , m_lastGestureScrollOverWidget(false) 241 , m_lastGestureScrollOverWidget(false)
241 , m_maxMouseMovedDuration(0) 242 , m_maxMouseMovedDuration(0)
242 , m_longTapShouldInvokeContextMenu(false) 243 , m_longTapShouldInvokeContextMenu(false)
243 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 244 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
244 , m_lastShowPressTimestamp(0) 245 , m_lastShowPressTimestamp(0)
245 , m_deltaConsumedForScrollSequence(false) 246 , m_deltaConsumedForScrollSequence(false)
246 { 247 {
248 m_primaryIdByPointerType.clear();
247 } 249 }
248 250
249 EventHandler::~EventHandler() 251 EventHandler::~EventHandler()
250 { 252 {
251 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); 253 ASSERT(!m_fakeMouseMoveEventTimer.isActive());
254 m_primaryIdByPointerType.clear();
252 } 255 }
253 256
254 DEFINE_TRACE(EventHandler) 257 DEFINE_TRACE(EventHandler)
255 { 258 {
256 #if ENABLE(OILPAN) 259 #if ENABLE(OILPAN)
257 visitor->trace(m_mousePressNode); 260 visitor->trace(m_mousePressNode);
258 visitor->trace(m_capturingMouseEventsNode); 261 visitor->trace(m_capturingMouseEventsNode);
259 visitor->trace(m_nodeUnderMouse); 262 visitor->trace(m_nodeUnderMouse);
260 visitor->trace(m_lastNodeUnderMouse); 263 visitor->trace(m_lastNodeUnderMouse);
261 visitor->trace(m_lastMouseMoveEventSubframe); 264 visitor->trace(m_lastMouseMoveEventSubframe);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 m_previousWheelScrolledNode = nullptr; 312 m_previousWheelScrolledNode = nullptr;
310 m_targetForTouchID.clear(); 313 m_targetForTouchID.clear();
311 m_touchSequenceDocument.clear(); 314 m_touchSequenceDocument.clear();
312 m_touchSequenceUserGestureToken.clear(); 315 m_touchSequenceUserGestureToken.clear();
313 m_scrollGestureHandlingNode = nullptr; 316 m_scrollGestureHandlingNode = nullptr;
314 m_lastGestureScrollOverWidget = false; 317 m_lastGestureScrollOverWidget = false;
315 m_previousGestureScrolledNode = nullptr; 318 m_previousGestureScrolledNode = nullptr;
316 m_scrollbarHandlingScrollGesture = nullptr; 319 m_scrollbarHandlingScrollGesture = nullptr;
317 m_maxMouseMovedDuration = 0; 320 m_maxMouseMovedDuration = 0;
318 m_touchPressed = false; 321 m_touchPressed = false;
322 m_primaryIdByPointerType.clear();
319 m_mouseDownMayStartSelect = false; 323 m_mouseDownMayStartSelect = false;
320 m_mouseDownMayStartDrag = false; 324 m_mouseDownMayStartDrag = false;
321 m_lastShowPressTimestamp = 0; 325 m_lastShowPressTimestamp = 0;
322 m_lastDeferredTapElement = nullptr; 326 m_lastDeferredTapElement = nullptr;
323 m_eventHandlerWillResetCapturingMouseEventsNode = false; 327 m_eventHandlerWillResetCapturingMouseEventsNode = false;
324 m_mouseDownWasSingleClickInSelection = false; 328 m_mouseDownWasSingleClickInSelection = false;
325 m_selectionInitiationState = HaveNotStartedSelection; 329 m_selectionInitiationState = HaveNotStartedSelection;
326 m_mouseDownMayStartAutoscroll = false; 330 m_mouseDownMayStartAutoscroll = false;
327 m_svgPan = false; 331 m_svgPan = false;
328 m_mouseDownPos = IntPoint(); 332 m_mouseDownPos = IntPoint();
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after
3770 m_lastScrollbarUnderMouse->mouseExited(); 3774 m_lastScrollbarUnderMouse->mouseExited();
3771 3775
3772 // Send mouse entered if we're setting a new scrollbar. 3776 // Send mouse entered if we're setting a new scrollbar.
3773 if (scrollbar && setLast) 3777 if (scrollbar && setLast)
3774 scrollbar->mouseEntered(); 3778 scrollbar->mouseEntered();
3775 3779
3776 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr; 3780 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr;
3777 } 3781 }
3778 } 3782 }
3779 3783
3780 static const AtomicString& eventNameForTouchPointState(PlatformTouchPoint::State state) 3784 static const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint:: State state)
3781 { 3785 {
3782 switch (state) { 3786 switch (state) {
3783 case PlatformTouchPoint::TouchReleased: 3787 case PlatformTouchPoint::TouchReleased:
3784 return EventTypeNames::touchend; 3788 return EventTypeNames::touchend;
3785 case PlatformTouchPoint::TouchCancelled: 3789 case PlatformTouchPoint::TouchCancelled:
3786 return EventTypeNames::touchcancel; 3790 return EventTypeNames::touchcancel;
3787 case PlatformTouchPoint::TouchPressed: 3791 case PlatformTouchPoint::TouchPressed:
3788 return EventTypeNames::touchstart; 3792 return EventTypeNames::touchstart;
3789 case PlatformTouchPoint::TouchMoved: 3793 case PlatformTouchPoint::TouchMoved:
3790 return EventTypeNames::touchmove; 3794 return EventTypeNames::touchmove;
3791 case PlatformTouchPoint::TouchStationary: 3795 case PlatformTouchPoint::TouchStationary:
3792 // TouchStationary state is not converted to touch events, so fall throu gh to assert. 3796 // TouchStationary state is not converted to touch events, so fall throu gh to assert.
3793 default: 3797 default:
3794 ASSERT_NOT_REACHED(); 3798 ASSERT_NOT_REACHED();
3795 return emptyAtom; 3799 return emptyAtom;
3796 } 3800 }
3797 } 3801 }
3798 3802
3803 static const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint ::State state)
3804 {
3805 switch (state) {
3806 case PlatformTouchPoint::TouchReleased:
3807 return EventTypeNames::pointerup;
3808 case PlatformTouchPoint::TouchCancelled:
3809 return EventTypeNames::pointercancel;
3810 case PlatformTouchPoint::TouchPressed:
3811 return EventTypeNames::pointerdown;
3812 case PlatformTouchPoint::TouchMoved:
3813 return EventTypeNames::pointermove;
3814 case PlatformTouchPoint::TouchStationary:
3815 // TouchStationary state is not converted to touch events, so fall throu gh to assert.
Rick Byers 2015/06/11 04:14:56 remove incorrect (and otherwise fairly useless) co
mustaq 2015/06/12 16:05:23 Done.
3816 default:
3817 ASSERT_NOT_REACHED();
3818 return emptyAtom;
3819 }
3820 }
3821
3799 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout Point& point, HitTestRequest::HitTestRequestType hitType) 3822 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout Point& point, HitTestRequest::HitTestRequestType hitType)
3800 { 3823 {
3801 HitTestResult result(HitTestRequest(hitType), point); 3824 HitTestResult result(HitTestRequest(hitType), point);
3802 3825
3803 if (!frame || !frame->contentLayoutObject()) 3826 if (!frame || !frame->contentLayoutObject())
3804 return result; 3827 return result;
3805 if (frame->view()) { 3828 if (frame->view()) {
3806 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars); 3829 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars);
3807 if (!rect.contains(roundedIntPoint(point))) 3830 if (!rect.contains(roundedIntPoint(point)))
3808 return result; 3831 return result;
3809 } 3832 }
3810 frame->contentLayoutObject()->hitTest(result); 3833 frame->contentLayoutObject()->hitTest(result);
3811 return result; 3834 return result;
3812 } 3835 }
3813 3836
3814 bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event) 3837 bool EventHandler::handleTouchEvent(const PlatformTouchEvent& event)
3815 { 3838 {
3816 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent"); 3839 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent");
3817 3840
3841 const String& PointerTypeTouch("touch");
3818 const Vector<PlatformTouchPoint>& points = event.touchPoints(); 3842 const Vector<PlatformTouchPoint>& points = event.touchPoints();
3819 3843
3820 unsigned i;
3821 bool freshTouchEvents = true; 3844 bool freshTouchEvents = true;
3822 bool allTouchReleased = true; 3845 bool allTouchReleased = true;
3823 for (i = 0; i < points.size(); ++i) { 3846 for (unsigned i = 0; i < points.size(); ++i) {
3824 const PlatformTouchPoint& point = points[i]; 3847 const PlatformTouchPoint& point = points[i];
3848
3825 if (point.state() != PlatformTouchPoint::TouchPressed) 3849 if (point.state() != PlatformTouchPoint::TouchPressed)
3826 freshTouchEvents = false; 3850 freshTouchEvents = false;
3827 if (point.state() != PlatformTouchPoint::TouchReleased && point.state() != PlatformTouchPoint::TouchCancelled) 3851 if (point.state() != PlatformTouchPoint::TouchReleased && point.state() != PlatformTouchPoint::TouchCancelled)
3828 allTouchReleased = false; 3852 allTouchReleased = false;
3829 } 3853 }
3830 if (freshTouchEvents) { 3854 if (freshTouchEvents) {
3831 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should 3855 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should
3832 // have cleared the active document when we saw the last release. But we 3856 // 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 3857 // have some tests that violate this, ClusterFuzz could trigger it, and
3834 // there may be cases where the browser doesn't reliably release all 3858 // there may be cases where the browser doesn't reliably release all
(...skipping 12 matching lines...) Expand all
3847 m_touchSequenceUserGestureToken = gestureIndicator->currentToken(); 3871 m_touchSequenceUserGestureToken = gestureIndicator->currentToken();
3848 3872
3849 ASSERT(m_frame->view()); 3873 ASSERT(m_frame->view());
3850 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) { 3874 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 3875 // If the active touch document has no frame or view, it's probably bein g destroyed
3852 // so we can't dispatch events. 3876 // so we can't dispatch events.
3853 return false; 3877 return false;
3854 } 3878 }
3855 3879
3856 // First do hit tests for any new touch points. 3880 // First do hit tests for any new touch points.
3857 for (i = 0; i < points.size(); ++i) { 3881 for (unsigned i = 0; i < points.size(); ++i) {
3858 const PlatformTouchPoint& point = points[i]; 3882 const PlatformTouchPoint& point = points[i];
3859 3883
3860 // Touch events implicitly capture to the touched node, and don't change 3884 // Touch events implicitly capture to the touched node, and don't change
3861 // active/hover states themselves (Gesture events do). So we only need 3885 // active/hover states themselves (Gesture events do). So we only need
3862 // to hit-test on touchstart, and it can be read-only. 3886 // to hit-test on touchstart, and it can be read-only.
3863 if (point.state() == PlatformTouchPoint::TouchPressed) { 3887 if (point.state() == PlatformTouchPoint::TouchPressed) {
3864 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv ent | HitTestRequest::ReadOnly | HitTestRequest::Active; 3888 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEv ent | HitTestRequest::ReadOnly | HitTestRequest::Active;
3865 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram eToContents(point.pos())); 3889 LayoutPoint pagePoint = roundedLayoutPoint(m_frame->view()->rootFram eToContents(point.pos()));
3866 HitTestResult result; 3890 HitTestResult result;
3867 if (!m_touchSequenceDocument) { 3891 if (!m_touchSequenceDocument) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3909 // document set to receive the events, then we can skip all the rest of 3933 // document set to receive the events, then we can skip all the rest of
3910 // this work. 3934 // this work.
3911 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_ touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) { 3935 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !m_ touchSequenceDocument->frameHost()->eventHandlerRegistry().hasEventHandlers(Even tHandlerRegistry::TouchEvent) || !m_touchSequenceDocument->frame()) {
3912 if (allTouchReleased) { 3936 if (allTouchReleased) {
3913 m_touchSequenceDocument.clear(); 3937 m_touchSequenceDocument.clear();
3914 m_touchSequenceUserGestureToken.clear(); 3938 m_touchSequenceUserGestureToken.clear();
3915 } 3939 }
3916 return false; 3940 return false;
3917 } 3941 }
3918 3942
3919 // Build up the lists to use for the 'touches', 'targetTouches' and 3943 // Compute and store the common info used by both PointerEvent and TouchEven t.
3920 // 'changedTouches' attributes in the JS event. See 3944 using TouchInfo = struct {
Rick Byers 2015/06/11 04:14:56 curious: how is this syntax different from the sim
mustaq 2015/06/12 16:05:24 I need to use 'typedef struct {...} TouchInfo' her
Rick Byers 2015/06/16 17:25:38 Ah, cool - thanks!
3921 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these 3945 EventTarget* touchTarget;
3922 // lists fit together. 3946 LocalFrame* targetFrame;
3947 FloatPoint adjustedPagePoint;
3948 FloatSize adjustedRadius;
3949 bool knownTarget;
3950 bool consumed;
3951 };
3952 Vector<TouchInfo> touchInfos(points.size());
3923 3953
3924 // Holds the complete set of touches on the screen. 3954 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]; 3955 const PlatformTouchPoint& point = points[i];
3944 PlatformTouchPoint::State pointState = point.state(); 3956 PlatformTouchPoint::State pointState = point.state();
3945 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr; 3957 RefPtrWillBeRawPtr<EventTarget> touchTarget = nullptr;
3946 3958
3947 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) { 3959 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) {
3948 // The target should be the original target for this touch, so get 3960 // 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 3961 // it from the hashmap. As it's a release or cancel we also remove
3950 // it from the map. 3962 // it from the map.
3951 touchTarget = m_targetForTouchID.take(point.id()); 3963 touchTarget = m_targetForTouchID.take(point.id());
3952 } else { 3964 } else {
(...skipping 28 matching lines...) Expand all
3981 // a Touch is a Node so using the window could be a breaking change. 3993 // 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 3994 // Since we know there was no handler invoked, the specific target
3983 // should be completely irrelevant to the application. 3995 // should be completely irrelevant to the application.
3984 touchTarget = m_touchSequenceDocument; 3996 touchTarget = m_touchSequenceDocument;
3985 targetFrame = m_touchSequenceDocument->frame(); 3997 targetFrame = m_touchSequenceDocument->frame();
3986 } 3998 }
3987 ASSERT(targetFrame); 3999 ASSERT(targetFrame);
3988 4000
3989 // pagePoint should always be in the target element's document coordinat es. 4001 // pagePoint should always be in the target element's document coordinat es.
3990 FloatPoint pagePoint = targetFrame->view()->rootFrameToContents(point.po s()); 4002 FloatPoint pagePoint = targetFrame->view()->rootFrameToContents(point.po s());
3991
3992 float scaleFactor = 1.0f / targetFrame->pageZoomFactor(); 4003 float scaleFactor = 1.0f / targetFrame->pageZoomFactor();
3993 4004
3994 FloatPoint adjustedPagePoint = pagePoint.scaledBy(scaleFactor); 4005 FloatPoint adjustedPagePoint = pagePoint.scaledBy(scaleFactor);
Rick Byers 2015/06/11 04:14:56 kind of silly to create these locals just to assig
mustaq 2015/06/12 16:05:24 Done.
3995 FloatSize adjustedRadius = point.radius().scaledBy(scaleFactor); 4006 FloatSize adjustedRadius = point.radius().scaledBy(scaleFactor);
3996 4007
4008 TouchInfo& touchInfo = touchInfos[i];
4009 touchInfo.touchTarget = touchTarget.get();
4010 touchInfo.targetFrame = targetFrame;
4011 touchInfo.adjustedPagePoint = adjustedPagePoint;
4012 touchInfo.adjustedRadius = adjustedRadius;
4013 touchInfo.knownTarget = knownTarget;
4014 touchInfo.consumed = false;
4015 }
4016
4017 if (RuntimeEnabledFeatures::pointerEventEnabled()) {
Rick Byers 2015/06/11 04:14:56 could some of this be factored out to another func
mustaq 2015/06/12 16:05:23 Done.
4018 bool hasPrimaryIdForTouch = m_primaryIdByPointerType.contains(PointerTyp eTouch);
4019 unsigned primaryIdForTouch = hasPrimaryIdForTouch? m_primaryIdByPointerT ype.get(PointerTypeTouch) : 0;
Rick Byers 2015/06/11 04:14:56 nit: space before ?
mustaq 2015/06/12 16:05:24 Done.
4020
4021 // Iterate through the touch points, sending PointerEvents to the target s as required.
4022 for (unsigned i = 0; i < points.size(); ++i) {
4023 const PlatformTouchPoint& point = points[i];
4024 TouchInfo& touchInfo = touchInfos[i];
4025
4026 const PlatformTouchPoint::State pointState = point.state();
4027 const AtomicString& eventName(pointerEventNameForTouchPointState(poi ntState));
USE eero AT chromium.org 2015/06/11 11:12:42 This does not handle correctly touch points whose
mustaq 2015/06/12 16:05:23 Done.
4028
4029 if (pointState == PlatformTouchPoint::TouchPressed && !hasPrimaryIdF orTouch) {
4030 primaryIdForTouch = point.id();
4031 m_primaryIdByPointerType.set(PointerTypeTouch, primaryIdForTouch );
4032 hasPrimaryIdForTouch = true;
4033 }
4034
4035 bool isEnterOrLeave = false;
4036 bool isCancelable = !(isEnterOrLeave || pointState == PlatformTouchP oint::TouchCancelled);
4037 bool isBubbling = !isEnterOrLeave;
4038
4039 PointerEventInit pointerEventInit;
4040 pointerEventInit.setPointerId(point.id());
4041 pointerEventInit.setWidth(touchInfo.adjustedRadius.width());
4042 pointerEventInit.setHeight(touchInfo.adjustedRadius.height());
4043 pointerEventInit.setPressure(point.force());
4044 pointerEventInit.setTiltX(0.0);
4045 pointerEventInit.setTiltY(0.0);
4046 pointerEventInit.setPointerType(PointerTypeTouch);
4047 pointerEventInit.setIsPrimary(hasPrimaryIdForTouch && primaryIdForTo uch == point.id());
4048 pointerEventInit.setScreenX(point.screenPos().x());
4049 pointerEventInit.setScreenY(point.screenPos().y());
4050 pointerEventInit.setClientX(0);
4051 pointerEventInit.setClientY(0);
Rick Byers 2015/06/11 04:14:56 These are wrong - it should have client co-ordinat
mustaq 2015/06/12 16:05:23 Done.
4052 pointerEventInit.setMovementX(0);
4053 pointerEventInit.setMovementY(0);
4054 pointerEventInit.setButton(0);
4055 pointerEventInit.setButtons(0);
Rick Byers 2015/06/11 04:14:56 This is wrong, should be 1 http://w3c.github.io/po
mustaq 2015/06/12 16:05:23 Done.
4056 pointerEventInit.setRelatedTarget(nullptr);
4057
4058 pointerEventInit.setCtrlKey(event.ctrlKey());
4059 pointerEventInit.setShiftKey(event.shiftKey());
4060 pointerEventInit.setAltKey(event.altKey());
4061 pointerEventInit.setMetaKey(event.metaKey());
4062
4063 pointerEventInit.setBubbles(isBubbling);
4064 pointerEventInit.setCancelable(isCancelable);
4065
4066 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create (eventName, pointerEventInit);
4067 touchInfo.touchTarget->toNode()->dispatchPointerEvent(pointerEvent.g et());
4068 touchInfo.consumed = pointerEvent->defaultPrevented() || pointerEven t->defaultHandled();
4069 }
4070
4071 if (allTouchReleased)
4072 m_primaryIdByPointerType.remove(PointerTypeTouch);
Rick Byers 2015/06/11 04:14:56 This logic deserves a test (at first I thought it
mustaq 2015/06/12 16:05:23 Done.
mustaq 2015/06/12 20:37:18 Just discovered that Chrome reuses 'retired' point
4073 }
4074
4075 bool swallowedEvent = false;
4076
4077 // Build up the lists to use for the 'touches', 'targetTouches' and
4078 // 'changedTouches' attributes in the JS event. See
4079 // http://www.w3.org/TR/touch-events/#touchevent-interface for how these
4080 // lists fit together.
4081
4082 // Holds the complete set of touches on the screen.
4083 RefPtrWillBeRawPtr<TouchList> touches = TouchList::create();
4084
4085 // A different view on the 'touches' list above, filtered and grouped by
4086 // event target. Used for the 'targetTouches' list in the JS event.
4087 using TargetTouchesHeapMap = WillBeHeapHashMap<EventTarget*, RefPtrWillBeMem ber<TouchList>>;
4088 TargetTouchesHeapMap touchesByTarget;
4089
4090 // Array of touches per state, used to assemble the 'changedTouches' list.
4091 using EventTargetSet = WillBeHeapHashSet<RefPtrWillBeMember<EventTarget>>;
4092 struct {
4093 // The touches corresponding to the particular change state this struct
4094 // instance represents.
4095 RefPtrWillBeMember<TouchList> m_touches;
4096 // Set of targets involved in m_touches.
4097 EventTargetSet m_targets;
4098 } changedTouches[PlatformTouchPoint::TouchStateEnd];
4099
4100 for (unsigned i = 0; i < points.size(); ++i) {
4101 const PlatformTouchPoint& point = points[i];
4102 const TouchInfo& touchInfo = touchInfos[i];
4103 PlatformTouchPoint::State pointState = point.state();
4104
4105 if (touchInfo.consumed)
4106 continue;
4107
3997 RefPtrWillBeRawPtr<Touch> touch = Touch::create( 4108 RefPtrWillBeRawPtr<Touch> touch = Touch::create(
3998 targetFrame, touchTarget.get(), point.id(), point.screenPos(), adjus tedPagePoint, adjustedRadius, point.rotationAngle(), point.force()); 4109 touchInfo.targetFrame,
4110 touchInfo.touchTarget,
4111 point.id(),
4112 point.screenPos(),
4113 touchInfo.adjustedPagePoint,
4114 touchInfo.adjustedRadius,
4115 point.rotationAngle(),
4116 point.force());
3999 4117
4000 // Ensure this target's touch list exists, even if it ends up empty, so 4118 // Ensure this target's touch list exists, even if it ends up empty, so
4001 // it can always be passed to TouchEvent::Create below. 4119 // it can always be passed to TouchEvent::Create below.
4002 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f ind(touchTarget.get()); 4120 TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.f ind(touchInfo.touchTarget);
4003 if (targetTouchesIterator == touchesByTarget.end()) { 4121 if (targetTouchesIterator == touchesByTarget.end()) {
4004 touchesByTarget.set(touchTarget.get(), TouchList::create()); 4122 touchesByTarget.set(touchInfo.touchTarget, TouchList::create());
4005 targetTouchesIterator = touchesByTarget.find(touchTarget.get()); 4123 targetTouchesIterator = touchesByTarget.find(touchInfo.touchTarget);
4006 } 4124 }
4007 4125
4008 // touches and targetTouches should only contain information about 4126 // touches and targetTouches should only contain information about
4009 // touches still on the screen, so if this point is released or 4127 // touches still on the screen, so if this point is released or
4010 // cancelled it will only appear in the changedTouches list. 4128 // cancelled it will only appear in the changedTouches list.
4011 if (pointState != PlatformTouchPoint::TouchReleased && pointState != Pla tformTouchPoint::TouchCancelled) { 4129 if (pointState != PlatformTouchPoint::TouchReleased && pointState != Pla tformTouchPoint::TouchCancelled) {
4012 touches->append(touch); 4130 touches->append(touch);
4013 targetTouchesIterator->value->append(touch); 4131 targetTouchesIterator->value->append(touch);
4014 } 4132 }
4015 4133
4016 // Now build up the correct list for changedTouches. 4134 // Now build up the correct list for changedTouches.
4017 // Note that any touches that are in the TouchStationary state (e.g. if 4135 // 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 4136 // 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 4137 // 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 4138 // explicitly here. See https://bugs.webkit.org/show_bug.cgi?id=37609
4021 // for further discussion about the TouchStationary state. 4139 // for further discussion about the TouchStationary state.
4022 if (pointState != PlatformTouchPoint::TouchStationary && knownTarget) { 4140 if (pointState != PlatformTouchPoint::TouchStationary && touchInfo.known Target) {
4023 ASSERT(pointState < PlatformTouchPoint::TouchStateEnd); 4141 ASSERT(pointState < PlatformTouchPoint::TouchStateEnd);
4024 if (!changedTouches[pointState].m_touches) 4142 if (!changedTouches[pointState].m_touches)
4025 changedTouches[pointState].m_touches = TouchList::create(); 4143 changedTouches[pointState].m_touches = TouchList::create();
4026 changedTouches[pointState].m_touches->append(touch); 4144 changedTouches[pointState].m_touches->append(touch);
4027 changedTouches[pointState].m_targets.add(touchTarget); 4145 changedTouches[pointState].m_targets.add(touchInfo.touchTarget);
4028 } 4146 }
4029 } 4147 }
4030 if (allTouchReleased) { 4148 if (allTouchReleased) {
4031 m_touchSequenceDocument.clear(); 4149 m_touchSequenceDocument.clear();
4032 m_touchSequenceUserGestureToken.clear(); 4150 m_touchSequenceUserGestureToken.clear();
4033 } 4151 }
4034 4152
4035 // Now iterate the changedTouches list and m_targets within it, sending 4153 // Now iterate through the changedTouches list and m_targets within it, send ing
4036 // events to the targets as required. 4154 // TouchEvents to the targets as required.
4037 bool swallowedEvent = false;
4038 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state ) { 4155 for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state ) {
4039 if (!changedTouches[state].m_touches) 4156 if (!changedTouches[state].m_touches)
4040 continue; 4157 continue;
4041 4158
4042 const AtomicString& stateName(eventNameForTouchPointState(static_cast<Pl atformTouchPoint::State>(state))); 4159 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca st<PlatformTouchPoint::State>(state)));
4043 const EventTargetSet& targetsForState = changedTouches[state].m_targets; 4160 const EventTargetSet& targetsForState = changedTouches[state].m_targets;
4044 for (const RefPtrWillBeMember<EventTarget>& eventTarget : targetsForStat e) { 4161 for (const RefPtrWillBeMember<EventTarget>& eventTarget : targetsForStat e) {
4045 EventTarget* touchEventTarget = eventTarget.get(); 4162 EventTarget* touchEventTarget = eventTarget.get();
4046 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create( 4163 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(
4047 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(), 4164 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(),
4048 stateName, touchEventTarget->toNode()->document().domWindow(), 4165 eventName, touchEventTarget->toNode()->document().domWindow(),
4049 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey (), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp()); 4166 event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey (), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp());
4050 touchEventTarget->toNode()->dispatchTouchEvent(touchEvent.get()); 4167 touchEventTarget->toNode()->dispatchTouchEvent(touchEvent.get());
4051 swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() || touchEvent->defaultHandled(); 4168 swallowedEvent = swallowedEvent || touchEvent->defaultPrevented() || touchEvent->defaultHandled();
4052 } 4169 }
4053 } 4170 }
4054 4171
4055 return swallowedEvent; 4172 return swallowedEvent;
4056 } 4173 }
4057 4174
4058 TouchAction EventHandler::intersectTouchAction(TouchAction action1, TouchAction action2) 4175 TouchAction EventHandler::intersectTouchAction(TouchAction action1, TouchAction action2)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
4170 unsigned EventHandler::accessKeyModifiers() 4287 unsigned EventHandler::accessKeyModifiers()
4171 { 4288 {
4172 #if OS(MACOSX) 4289 #if OS(MACOSX)
4173 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 4290 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
4174 #else 4291 #else
4175 return PlatformEvent::AltKey; 4292 return PlatformEvent::AltKey;
4176 #endif 4293 #endif
4177 } 4294 }
4178 4295
4179 } // namespace blink 4296 } // namespace blink
OLDNEW
« Source/core/page/EventHandler.h ('K') | « Source/core/page/EventHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698