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

Side by Side Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 1425053002: Fire pointermoves for mousemove events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TestExpectations Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 namespace blink { 102 namespace blink {
103 103
104 namespace { 104 namespace {
105 105
106 bool isNodeInDocument(Node* n) 106 bool isNodeInDocument(Node* n)
107 { 107 {
108 return n && n->inDocument(); 108 return n && n->inDocument();
109 } 109 }
110 110
111 const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::State s tate)
112 {
113 switch (state) {
114 case PlatformTouchPoint::TouchReleased:
115 return EventTypeNames::touchend;
116 case PlatformTouchPoint::TouchCancelled:
117 return EventTypeNames::touchcancel;
118 case PlatformTouchPoint::TouchPressed:
119 return EventTypeNames::touchstart;
120 case PlatformTouchPoint::TouchMoved:
121 return EventTypeNames::touchmove;
122 case PlatformTouchPoint::TouchStationary:
123 // Fall through to default
124 default:
125 ASSERT_NOT_REACHED();
126 return emptyAtom;
127 }
111 } 128 }
112 129
130 const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint::State state)
131 {
132 switch (state) {
133 case PlatformTouchPoint::TouchReleased:
134 return EventTypeNames::pointerup;
135 case PlatformTouchPoint::TouchCancelled:
136 return EventTypeNames::pointercancel;
137 case PlatformTouchPoint::TouchPressed:
138 return EventTypeNames::pointerdown;
139 case PlatformTouchPoint::TouchMoved:
140 return EventTypeNames::pointermove;
141 case PlatformTouchPoint::TouchStationary:
142 // Fall through to default
143 default:
144 ASSERT_NOT_REACHED();
145 return emptyAtom;
146 }
147 }
148
149 const AtomicString& pointerEventNameForMouseEventName(const AtomicString& mouseE ventName)
150 {
151 #define RETURN_CORRESPONDING_PE_NAME(eventSuffix) \
152 if (mouseEventName == EventTypeNames::mouse##eventSuffix) {\
153 return EventTypeNames::pointer##eventSuffix;\
154 }
155
156 RETURN_CORRESPONDING_PE_NAME(down);
157 RETURN_CORRESPONDING_PE_NAME(enter);
158 RETURN_CORRESPONDING_PE_NAME(leave);
159 RETURN_CORRESPONDING_PE_NAME(move);
160 RETURN_CORRESPONDING_PE_NAME(out);
161 RETURN_CORRESPONDING_PE_NAME(over);
162 RETURN_CORRESPONDING_PE_NAME(up);
163
164 #undef RETURN_CORRESPONDING_PE_NAME
165
166 ASSERT_NOT_REACHED();
167 return emptyAtom;
168 }
169
170 } // namespace
171
113 using namespace HTMLNames; 172 using namespace HTMLNames;
114 173
115 // The link drag hysteresis is much larger than the others because there 174 // The link drag hysteresis is much larger than the others because there
116 // needs to be enough space to cancel the link press without starting a link dra g, 175 // needs to be enough space to cancel the link press without starting a link dra g,
117 // and because dragging links is rare. 176 // and because dragging links is rare.
118 static const int LinkDragHysteresis = 40; 177 static const int LinkDragHysteresis = 40;
119 static const int ImageDragHysteresis = 5; 178 static const int ImageDragHysteresis = 5;
120 static const int TextDragHysteresis = 3; 179 static const int TextDragHysteresis = 3;
121 static const int GeneralDragHysteresis = 3; 180 static const int GeneralDragHysteresis = 3;
122 181
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 m_resizeScrollableArea = layer->scrollableArea(); 1023 m_resizeScrollableArea = layer->scrollableArea();
965 m_resizeScrollableArea->setInResizeMode(true); 1024 m_resizeScrollableArea->setInResizeMode(true);
966 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p)); 1025 m_offsetFromResizeCorner = LayoutSize(m_resizeScrollableArea->offset FromResizeCorner(p));
967 invalidateClick(); 1026 invalidateClick();
968 return true; 1027 return true;
969 } 1028 }
970 } 1029 }
971 1030
972 m_frame->selection().setCaretBlinkingSuspended(true); 1031 m_frame->selection().setCaretBlinkingSuspended(true);
973 1032
974 bool swallowEvent = dispatchPointerEventForMouseEvent(mev.innerNode(), Event TypeNames::pointerdown, mouseEvent); 1033 bool swallowEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::mou sedown, mev.innerNode(), m_clickCount, mouseEvent);
975
976 if (swallowEvent) {
977 m_preventMouseEventForPointerTypeMouse = true;
978 }
979 if (!m_preventMouseEventForPointerTypeMouse)
980 swallowEvent = swallowEvent || !dispatchMouseEvent(EventTypeNames::mouse down, mev.innerNode(), m_clickCount, mouseEvent);
981 1034
982 // m_selectionInitiationState is initialized after dispatching mousedown 1035 // m_selectionInitiationState is initialized after dispatching mousedown
983 // event in order not to keep the selection by DOM APIs Because we can't 1036 // event in order not to keep the selection by DOM APIs Because we can't
984 // give the user the chance to handle the selection by user action like 1037 // give the user the chance to handle the selection by user action like
985 // dragging if we keep the selection in case of mousedown. FireFox also has 1038 // dragging if we keep the selection in case of mousedown. FireFox also has
986 // the same behavior and it's more compatible with other browsers. 1039 // the same behavior and it's more compatible with other browsers.
987 selectionController().initializeSelectionState(); 1040 selectionController().initializeSelectionState();
988 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly); 1041 HitTestResult hitTestResult = hitTestResultInFrame(m_frame, documentPoint, H itTestRequest::ReadOnly);
989 InputDeviceCapabilities* sourceCapabilities = mouseEvent.syntheticEventType( ) == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEventsSo urceCapabilities() : 1042 InputDeviceCapabilities* sourceCapabilities = mouseEvent.syntheticEventType( ) == PlatformMouseEvent::FromTouch ? InputDeviceCapabilities::firesTouchEventsSo urceCapabilities() :
990 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities(); 1043 InputDeviceCapabilities::doesntFireTouchEventsSourceCapabilities();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 m_cursorUpdateTimer.stop(); 1157 m_cursorUpdateTimer.stop();
1105 1158
1106 cancelFakeMouseMoveEvent(); 1159 cancelFakeMouseMoveEvent();
1107 1160
1108 if (m_svgPan) { 1161 if (m_svgPan) {
1109 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition)); 1162 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition));
1110 return true; 1163 return true;
1111 } 1164 }
1112 1165
1113 if (m_frameSetBeingResized) 1166 if (m_frameSetBeingResized)
1114 return !dispatchMouseEvent(EventTypeNames::mousemove, m_frameSetBeingRes ized.get(), 0, mouseEvent); 1167 return updatePointerTargetAndDispatchEvents(EventTypeNames::mousemove, m _frameSetBeingResized.get(), 0, mouseEvent);
1115 1168
1116 // Send events right to a scrollbar if the mouse is pressed. 1169 // Send events right to a scrollbar if the mouse is pressed.
1117 if (m_lastScrollbarUnderMouse && m_mousePressed) { 1170 if (m_lastScrollbarUnderMouse && m_mousePressed) {
1118 m_lastScrollbarUnderMouse->mouseMoved(mouseEvent); 1171 m_lastScrollbarUnderMouse->mouseMoved(mouseEvent);
1119 return true; 1172 return true;
1120 } 1173 }
1121 1174
1122 // Mouse events simulated from touch should not hit-test again. 1175 // Mouse events simulated from touch should not hit-test again.
1123 ASSERT(!mouseEvent.fromTouch()); 1176 ASSERT(!mouseEvent.fromTouch());
1124 1177
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 view->setCursor(optionalCursor.cursor()); 1239 view->setCursor(optionalCursor.cursor());
1187 } 1240 }
1188 } 1241 }
1189 } 1242 }
1190 1243
1191 m_lastMouseMoveEventSubframe = newSubframe; 1244 m_lastMouseMoveEventSubframe = newSubframe;
1192 1245
1193 if (swallowEvent) 1246 if (swallowEvent)
1194 return true; 1247 return true;
1195 1248
1196 swallowEvent = !dispatchMouseEvent(EventTypeNames::mousemove, mev.innerNode( ), 0, mouseEvent); 1249 swallowEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::mousemov e, mev.innerNode(), 0, mouseEvent);
1250
1197 if (!swallowEvent) 1251 if (!swallowEvent)
1198 swallowEvent = handleMouseDraggedEvent(mev); 1252 swallowEvent = handleMouseDraggedEvent(mev);
1199 1253
1200 return swallowEvent; 1254 return swallowEvent;
1201 } 1255 }
1202 1256
1203 void EventHandler::invalidateClick() 1257 void EventHandler::invalidateClick()
1204 { 1258 {
1205 m_clickCount = 0; 1259 m_clickCount = 0;
1206 m_clickNode = nullptr; 1260 m_clickNode = nullptr;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 m_mousePressed = false; 1293 m_mousePressed = false;
1240 setLastKnownMousePosition(mouseEvent); 1294 setLastKnownMousePosition(mouseEvent);
1241 1295
1242 if (m_svgPan) { 1296 if (m_svgPan) {
1243 m_svgPan = false; 1297 m_svgPan = false;
1244 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition)); 1298 m_frame->document()->accessSVGExtensions().updatePan(m_frame->view()->ro otFrameToContents(m_lastKnownMousePosition));
1245 return true; 1299 return true;
1246 } 1300 }
1247 1301
1248 if (m_frameSetBeingResized) 1302 if (m_frameSetBeingResized)
1249 return !dispatchMouseEvent(EventTypeNames::mouseup, m_frameSetBeingResiz ed.get(), m_clickCount, mouseEvent); 1303 return dispatchMouseEvent(EventTypeNames::mouseup, m_frameSetBeingResize d.get(), m_clickCount, mouseEvent);
1250 1304
1251 if (m_lastScrollbarUnderMouse) { 1305 if (m_lastScrollbarUnderMouse) {
1252 invalidateClick(); 1306 invalidateClick();
1253 m_lastScrollbarUnderMouse->mouseUp(mouseEvent); 1307 m_lastScrollbarUnderMouse->mouseUp(mouseEvent);
1254 return !dispatchMouseEvent(EventTypeNames::mouseup, m_nodeUnderMouse.get (), m_clickCount, mouseEvent); 1308 return dispatchMouseEvent(EventTypeNames::mouseup, m_nodeUnderMouse.get( ), m_clickCount, mouseEvent);
1255 } 1309 }
1256 1310
1257 // Mouse events simulated from touch should not hit-test again. 1311 // Mouse events simulated from touch should not hit-test again.
1258 ASSERT(!mouseEvent.fromTouch()); 1312 ASSERT(!mouseEvent.fromTouch());
1259 1313
1260 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Release; 1314 HitTestRequest::HitTestRequestType hitType = HitTestRequest::Release;
1261 HitTestRequest request(hitType); 1315 HitTestRequest request(hitType);
1262 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent); 1316 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent);
1263 LocalFrame* subframe = m_capturingMouseEventsNode.get() ? subframeForTargetN ode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev); 1317 LocalFrame* subframe = m_capturingMouseEventsNode.get() ? subframeForTargetN ode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev);
1264 if (m_eventHandlerWillResetCapturingMouseEventsNode) 1318 if (m_eventHandlerWillResetCapturingMouseEventsNode)
1265 m_capturingMouseEventsNode = nullptr; 1319 m_capturingMouseEventsNode = nullptr;
1266 if (subframe && passMouseReleaseEventToSubframe(mev, subframe)) 1320 if (subframe && passMouseReleaseEventToSubframe(mev, subframe))
1267 return true; 1321 return true;
1268 1322
1269 bool swallowPointerUpEvent = dispatchPointerEventForMouseEvent(mev.innerNode (), EventTypeNames::pointerup, mouseEvent); 1323 bool swallowUpEvent = updatePointerTargetAndDispatchEvents(EventTypeNames::m ouseup, mev.innerNode(), m_clickCount, mouseEvent);
1270 bool swallowMouseUpEvent = false; 1324
1271 if (!m_preventMouseEventForPointerTypeMouse) { 1325 // TODO(crbug/545647): This state should reset with pointercancel too.
1272 swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, mev.i nnerNode(), m_clickCount, mouseEvent); 1326 m_preventMouseEventForPointerTypeMouse = false;
1273 } else {
1274 // TODO(crbug/545647): This state should reset with pointercancel too.
1275 m_preventMouseEventForPointerTypeMouse = false;
1276 }
1277 1327
1278 bool contextMenuEvent = mouseEvent.button() == RightButton; 1328 bool contextMenuEvent = mouseEvent.button() == RightButton;
1279 #if OS(MACOSX) 1329 #if OS(MACOSX)
1280 // FIXME: The Mac port achieves the same behavior by checking whether the co ntext menu is currently open in WebPage::mouseEvent(). Consider merging the impl ementations. 1330 // FIXME: The Mac port achieves the same behavior by checking whether the co ntext menu is currently open in WebPage::mouseEvent(). Consider merging the impl ementations.
1281 if (mouseEvent.button() == LeftButton && mouseEvent.modifiers() & PlatformEv ent::CtrlKey) 1331 if (mouseEvent.button() == LeftButton && mouseEvent.modifiers() & PlatformEv ent::CtrlKey)
1282 contextMenuEvent = true; 1332 contextMenuEvent = true;
1283 #endif 1333 #endif
1284 1334
1285 bool swallowClickEvent = false; 1335 bool swallowClickEvent = false;
1286 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInComposedTree() && m_clickNode->canParticipat eInComposedTree()) { 1336 if (m_clickCount > 0 && !contextMenuEvent && mev.innerNode() && m_clickNode && mev.innerNode()->canParticipateInComposedTree() && m_clickNode->canParticipat eInComposedTree()) {
(...skipping 14 matching lines...) Expand all
1301 EventTypeNames::click, m_clickCount); 1351 EventTypeNames::click, m_clickCount);
1302 } 1352 }
1303 } 1353 }
1304 1354
1305 if (m_resizeScrollableArea) { 1355 if (m_resizeScrollableArea) {
1306 m_resizeScrollableArea->setInResizeMode(false); 1356 m_resizeScrollableArea->setInResizeMode(false);
1307 m_resizeScrollableArea = nullptr; 1357 m_resizeScrollableArea = nullptr;
1308 } 1358 }
1309 1359
1310 bool swallowMouseReleaseEvent = false; 1360 bool swallowMouseReleaseEvent = false;
1311 if (!swallowPointerUpEvent && !swallowMouseUpEvent) 1361 if (!swallowUpEvent)
1312 swallowMouseReleaseEvent = handleMouseReleaseEvent(mev); 1362 swallowMouseReleaseEvent = handleMouseReleaseEvent(mev);
1313 1363
1314 invalidateClick(); 1364 invalidateClick();
1315 1365
1316 return swallowPointerUpEvent || swallowMouseUpEvent || swallowClickEvent || swallowMouseReleaseEvent; 1366 return swallowUpEvent || swallowClickEvent || swallowMouseReleaseEvent;
1317 } 1367 }
1318 1368
1319 bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa rget, const PlatformMouseEvent& event, DataTransfer* dataTransfer) 1369 bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTa rget, const PlatformMouseEvent& event, DataTransfer* dataTransfer)
1320 { 1370 {
1321 FrameView* view = m_frame->view(); 1371 FrameView* view = m_frame->view();
1322 1372
1323 // FIXME: We might want to dispatch a dragleave even if the view is gone. 1373 // FIXME: We might want to dispatch a dragleave even if the view is gone.
1324 if (!view) 1374 if (!view)
1325 return false; 1375 return false;
1326 1376
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1605
1556 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) { 1606 if (lastNodeUnderMouse && lastNodeUnderMouse->document() != m_frame->documen t()) {
1557 lastNodeUnderMouse = nullptr; 1607 lastNodeUnderMouse = nullptr;
1558 m_lastScrollbarUnderMouse = nullptr; 1608 m_lastScrollbarUnderMouse = nullptr;
1559 } 1609 }
1560 1610
1561 if (lastNodeUnderMouse != m_nodeUnderMouse) 1611 if (lastNodeUnderMouse != m_nodeUnderMouse)
1562 sendMouseEventsForNodeTransition(lastNodeUnderMouse.get(), m_nodeUnderMo use.get(), mouseEvent); 1612 sendMouseEventsForNodeTransition(lastNodeUnderMouse.get(), m_nodeUnderMo use.get(), mouseEvent);
1563 } 1613 }
1564 1614
1565 bool EventHandler::dispatchPointerEventForMouseEvent(Node* target, const AtomicS tring& eventType, 1615 bool EventHandler::dispatchPointerEvent(Node* target, const AtomicString& eventT ype,
1566 const PlatformMouseEvent& mouseEvent, Node* relatedTarget) 1616 const PlatformMouseEvent& mouseEvent, Node* relatedTarget)
1567 { 1617 {
1568 if (!RuntimeEnabledFeatures::pointerEventEnabled()) 1618 if (!RuntimeEnabledFeatures::pointerEventEnabled())
1569 return false; 1619 return false;
1570 1620
1571 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true, 1621 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true,
1572 mouseEvent, relatedTarget, m_frame->document()->domWindow()); 1622 mouseEvent, relatedTarget, m_frame->document()->domWindow());
1573 target->dispatchEvent(pointerEvent.get()); 1623 target->dispatchEvent(pointerEvent.get());
1574 return pointerEvent->defaultPrevented() || pointerEvent->defaultHandled(); 1624 return pointerEvent->defaultPrevented() || pointerEvent->defaultHandled();
1575 } 1625 }
1576 1626
1577 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode, 1627 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode,
1578 const PlatformMouseEvent& mouseEvent) 1628 const PlatformMouseEvent& mouseEvent)
1579 { 1629 {
1580 ASSERT(exitedNode != enteredNode); 1630 ASSERT(exitedNode != enteredNode);
1581 1631
1582 // Dispatch pointerout/mouseout events 1632 // Dispatch pointerout/mouseout events
1583 if (isNodeInDocument(exitedNode)) { 1633 if (isNodeInDocument(exitedNode)) {
1584 dispatchPointerEventForMouseEvent(exitedNode, EventTypeNames::pointerout , mouseEvent, enteredNode); 1634 dispatchPointerEvent(exitedNode, EventTypeNames::pointerout, mouseEvent, enteredNode);
1585 exitedNode->dispatchMouseEvent(mouseEvent, EventTypeNames::mouseout, 0, enteredNode); 1635 exitedNode->dispatchMouseEvent(mouseEvent, EventTypeNames::mouseout, 0, enteredNode);
1586 } 1636 }
1587 1637
1588 // A note on mouseenter and mouseleave: These are non-bubbling events, and t hey are dispatched if there 1638 // A note on mouseenter and mouseleave: These are non-bubbling events, and t hey are dispatched if there
1589 // is a capturing event handler on an ancestor or a normal event handler on the element itself. This special 1639 // is a capturing event handler on an ancestor or a normal event handler on the element itself. This special
1590 // handling is necessary to avoid O(n^2) capturing event handler checks. 1640 // handling is necessary to avoid O(n^2) capturing event handler checks.
1591 // 1641 //
1592 // Note, however, that this optimization can possibly cause some unanswere d/missing/redundant mouseenter or 1642 // Note, however, that this optimization can possibly cause some unanswere d/missing/redundant mouseenter or
1593 // mouseleave events in certain contrived eventhandling scenarios, e.g., whe n: 1643 // mouseleave events in certain contrived eventhandling scenarios, e.g., whe n:
1594 // - the mouseleave handler for a node sets the only capturing-mouseleave-li stener in its ancestor, or 1644 // - the mouseleave handler for a node sets the only capturing-mouseleave-li stener in its ancestor, or
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 for (size_t j = 0; j < numExitedAncestors; j++) { 1686 for (size_t j = 0; j < numExitedAncestors; j++) {
1637 if (exitedAncestors[j]->hasCapturingEventListeners(EventTypeNames::mouse leave) 1687 if (exitedAncestors[j]->hasCapturingEventListeners(EventTypeNames::mouse leave)
1638 || (RuntimeEnabledFeatures::pointerEventEnabled() 1688 || (RuntimeEnabledFeatures::pointerEventEnabled()
1639 && exitedAncestors[j]->hasCapturingEventListeners(EventTypeNames::po interleave))) 1689 && exitedAncestors[j]->hasCapturingEventListeners(EventTypeNames::po interleave)))
1640 exitedNodeHasCapturingAncestor = true; 1690 exitedNodeHasCapturingAncestor = true;
1641 } 1691 }
1642 1692
1643 // Dispatch pointerleave/mouseleave events, in child-to-parent order. 1693 // Dispatch pointerleave/mouseleave events, in child-to-parent order.
1644 for (size_t j = 0; j < exitedAncestorIndex; j++) { 1694 for (size_t j = 0; j < exitedAncestorIndex; j++) {
1645 if (exitedNodeHasCapturingAncestor || exitedAncestors[j]->hasEventListen ers(EventTypeNames::pointerleave)) { 1695 if (exitedNodeHasCapturingAncestor || exitedAncestors[j]->hasEventListen ers(EventTypeNames::pointerleave)) {
1646 dispatchPointerEventForMouseEvent(exitedAncestors[j].get(), EventTyp eNames::pointerleave, mouseEvent, 1696 dispatchPointerEvent(exitedAncestors[j].get(), EventTypeNames::point erleave, mouseEvent,
1647 enteredNode); 1697 enteredNode);
1648 } 1698 }
1649 if (exitedNodeHasCapturingAncestor || exitedAncestors[j]->hasEventListen ers(EventTypeNames::mouseleave)) 1699 if (exitedNodeHasCapturingAncestor || exitedAncestors[j]->hasEventListen ers(EventTypeNames::mouseleave))
1650 exitedAncestors[j]->dispatchMouseEvent(mouseEvent, EventTypeNames::m ouseleave, 0, enteredNode); 1700 exitedAncestors[j]->dispatchMouseEvent(mouseEvent, EventTypeNames::m ouseleave, 0, enteredNode);
1651 } 1701 }
1652 1702
1653 // Dispatch pointerover/mouseover. 1703 // Dispatch pointerover/mouseover.
1654 if (isNodeInDocument(enteredNode)) { 1704 if (isNodeInDocument(enteredNode)) {
1655 dispatchPointerEventForMouseEvent(enteredNode, EventTypeNames::pointerov er, mouseEvent, exitedNode); 1705 dispatchPointerEvent(enteredNode, EventTypeNames::pointerover, mouseEven t, exitedNode);
1656 enteredNode->dispatchMouseEvent(mouseEvent, EventTypeNames::mouseover, 0 , exitedNode); 1706 enteredNode->dispatchMouseEvent(mouseEvent, EventTypeNames::mouseover, 0 , exitedNode);
1657 } 1707 }
1658 1708
1659 // Defer locating capturing pointeenter/mouseenter listener until /after/ di spatching the leave events because 1709 // Defer locating capturing pointeenter/mouseenter listener until /after/ di spatching the leave events because
1660 // the leave handlers might set a capturing enter handler. 1710 // the leave handlers might set a capturing enter handler.
1661 bool enteredNodeHasCapturingAncestor = false; 1711 bool enteredNodeHasCapturingAncestor = false;
1662 for (size_t i = 0; i < numEnteredAncestors; i++) { 1712 for (size_t i = 0; i < numEnteredAncestors; i++) {
1663 if (enteredAncestors[i]->hasCapturingEventListeners(EventTypeNames::mous eenter) 1713 if (enteredAncestors[i]->hasCapturingEventListeners(EventTypeNames::mous eenter)
1664 || (RuntimeEnabledFeatures::pointerEventEnabled() 1714 || (RuntimeEnabledFeatures::pointerEventEnabled()
1665 && enteredAncestors[i]->hasCapturingEventListeners(EventTypeNames::p ointerenter))) 1715 && enteredAncestors[i]->hasCapturingEventListeners(EventTypeNames::p ointerenter)))
1666 enteredNodeHasCapturingAncestor = true; 1716 enteredNodeHasCapturingAncestor = true;
1667 } 1717 }
1668 1718
1669 // Dispatch pointerenter/mouseenter events, in parent-to-child order. 1719 // Dispatch pointerenter/mouseenter events, in parent-to-child order.
1670 for (size_t i = enteredAncestorIndex; i > 0; i--) { 1720 for (size_t i = enteredAncestorIndex; i > 0; i--) {
1671 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::pointerenter)) { 1721 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::pointerenter)) {
1672 dispatchPointerEventForMouseEvent(enteredAncestors[i-1].get(), Event TypeNames::pointerenter, mouseEvent, 1722 dispatchPointerEvent(enteredAncestors[i-1].get(), EventTypeNames::po interenter, mouseEvent,
1673 exitedNode); 1723 exitedNode);
1674 } 1724 }
1675 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::mouseenter)) 1725 if (enteredNodeHasCapturingAncestor || enteredAncestors[i-1]->hasEventLi steners(EventTypeNames::mouseenter))
1676 enteredAncestors[i-1]->dispatchMouseEvent(mouseEvent, EventTypeNames ::mouseenter, 0, exitedNode); 1726 enteredAncestors[i-1]->dispatchMouseEvent(mouseEvent, EventTypeNames ::mouseenter, 0, exitedNode);
1677 } 1727 }
1678 } 1728 }
1679 1729
1680 // The return value means 'continue default handling.'
1681 bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe tNode, int clickCount, const PlatformMouseEvent& mouseEvent) 1730 bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe tNode, int clickCount, const PlatformMouseEvent& mouseEvent)
1682 { 1731 {
1683 updateMouseEventTargetNode(targetNode, mouseEvent); 1732 updateMouseEventTargetNode(targetNode, mouseEvent);
1684 return !m_nodeUnderMouse || m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventType, clickCount); 1733 return m_nodeUnderMouse && !m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventType, clickCount);
1685 } 1734 }
1686 1735
1687 // The return value means 'swallow event' (was handled), as for other handle* fu nctions. 1736 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
1737 bool EventHandler::updatePointerTargetAndDispatchEvents(const AtomicString& mous eEventType, Node* targetNode, int clickCount, const PlatformMouseEvent& mouseEve nt)
1738 {
1739 ASSERT(mouseEventType == EventTypeNames::mousedown
1740 || mouseEventType == EventTypeNames::mousemove
1741 || mouseEventType == EventTypeNames::mouseup);
1742
1743 updateMouseEventTargetNode(targetNode, mouseEvent);
1744 if (!m_nodeUnderMouse)
1745 return false;
1746
1747 bool swallowEvent = dispatchPointerEvent(m_nodeUnderMouse.get(),
1748 pointerEventNameForMouseEventName(mouseEventType),
1749 mouseEvent);
1750
1751 if (swallowEvent && mouseEventType == EventTypeNames::mousedown) {
1752 m_preventMouseEventForPointerTypeMouse = true;
1753 }
1754
1755 if (!m_preventMouseEventForPointerTypeMouse) {
1756 swallowEvent |= !m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, mouseE ventType, clickCount);
1757 }
1758
1759 return swallowEvent;
1760 }
1761
1688 bool EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targeted Event, InputDeviceCapabilities* sourceCapabilities) 1762 bool EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targeted Event, InputDeviceCapabilities* sourceCapabilities)
1689 { 1763 {
1690 // If clicking on a frame scrollbar, do not mess up with content focus. 1764 // If clicking on a frame scrollbar, do not mess up with content focus.
1691 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) { 1765 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) {
1692 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea()) 1766 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea())
1693 return false; 1767 return false;
1694 } 1768 }
1695 1769
1696 // The layout needs to be up to date to determine if an element is focusable . 1770 // The layout needs to be up to date to determine if an element is focusable .
1697 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1771 m_frame->document()->updateLayoutIgnorePendingStylesheets();
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 RefPtrWillBeRawPtr<Node> tappedNode = m_clickNode; 2193 RefPtrWillBeRawPtr<Node> tappedNode = m_clickNode;
2120 IntPoint tappedPosition = gestureEvent.position(); 2194 IntPoint tappedPosition = gestureEvent.position();
2121 2195
2122 if (m_clickNode && m_clickNode->isTextNode()) 2196 if (m_clickNode && m_clickNode->isTextNode())
2123 m_clickNode = ComposedTreeTraversal::parent(*m_clickNode); 2197 m_clickNode = ComposedTreeTraversal::parent(*m_clickNode);
2124 2198
2125 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(), 2199 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa lPosition(),
2126 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), 2200 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(),
2127 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut tonDown), 2201 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut tonDown),
2128 PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2202 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2129 bool swallowMouseDownEvent = !dispatchMouseEvent(EventTypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown); 2203 bool swallowMouseDownEvent = dispatchMouseEvent(EventTypeNames::mousedown, c urrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseDown);
2130 selectionController().initializeSelectionState(); 2204 selectionController().initializeSelectionState();
2131 if (!swallowMouseDownEvent) 2205 if (!swallowMouseDownEvent)
2132 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest), InputDeviceCapabilities::firesTouchEventsSourceCap abilities()); 2206 swallowMouseDownEvent = handleMouseFocus(MouseEventWithHitTestResults(fa keMouseDown, currentHitTest), InputDeviceCapabilities::firesTouchEventsSourceCap abilities());
2133 if (!swallowMouseDownEvent) 2207 if (!swallowMouseDownEvent)
2134 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest)); 2208 swallowMouseDownEvent = handleMousePressEvent(MouseEventWithHitTestResul ts(fakeMouseDown, currentHitTest));
2135 2209
2136 if (currentHitTest.innerNode()) { 2210 if (currentHitTest.innerNode()) {
2137 ASSERT(gestureEvent.type() == PlatformEvent::GestureTap); 2211 ASSERT(gestureEvent.type() == PlatformEvent::GestureTap);
2138 HitTestResult result = currentHitTest; 2212 HitTestResult result = currentHitTest;
2139 result.setToShadowHostIfInUserAgentShadowRoot(); 2213 result.setToShadowHostIfInUserAgentShadowRoot();
2140 m_frame->chromeClient().onMouseDown(result.innerNode()); 2214 m_frame->chromeClient().onMouseDown(result.innerNode());
2141 } 2215 }
2142 2216
2143 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 2217 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
2144 if (currentHitTest.innerNode()) { 2218 if (currentHitTest.innerNode()) {
2145 LocalFrame* mainFrame = m_frame->localFrameRoot(); 2219 LocalFrame* mainFrame = m_frame->localFrameRoot();
2146 if (mainFrame && mainFrame->view()) 2220 if (mainFrame && mainFrame->view())
2147 mainFrame->view()->updateAllLifecyclePhases(); 2221 mainFrame->view()->updateAllLifecyclePhases();
2148 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); 2222 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position());
2149 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType); 2223 currentHitTest = hitTestResultInFrame(m_frame, adjustedPoint, hitType);
2150 } 2224 }
2151 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(), 2225 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(),
2152 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), 2226 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(),
2153 static_cast<PlatformEvent::Modifiers>(modifiers), 2227 static_cast<PlatformEvent::Modifiers>(modifiers),
2154 PlatformMouseEvent::FromTouch, gestureEvent.timestamp()); 2228 PlatformMouseEvent::FromTouch, gestureEvent.timestamp());
2155 bool swallowMouseUpEvent = !dispatchMouseEvent(EventTypeNames::mouseup, curr entHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); 2229 bool swallowMouseUpEvent = dispatchMouseEvent(EventTypeNames::mouseup, curre ntHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp);
2156 2230
2157 bool swallowClickEvent = false; 2231 bool swallowClickEvent = false;
2158 if (m_clickNode) { 2232 if (m_clickNode) {
2159 if (currentHitTest.innerNode()) { 2233 if (currentHitTest.innerNode()) {
2160 // Updates distribution because a mouseup (or mousedown) event liste ner can make the 2234 // Updates distribution because a mouseup (or mousedown) event liste ner can make the
2161 // tree dirty at dispatchMouseEvent() invocation above. 2235 // tree dirty at dispatchMouseEvent() invocation above.
2162 // Unless distribution is updated, commonAncestor would hit ASSERT. 2236 // Unless distribution is updated, commonAncestor would hit ASSERT.
2163 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated 2237 // Both m_clickNode and currentHitTest.innerNode()) don't need to be updated
2164 // because commonAncestor() will exit early if their documents are d ifferent. 2238 // because commonAncestor() will exit early if their documents are d ifferent.
2165 m_clickNode->updateDistribution(); 2239 m_clickNode->updateDistribution();
2166 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent); 2240 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* m_clickNode, parentForClickEvent);
2167 swallowClickEvent = !dispatchMouseEvent(EventTypeNames::click, click TargetNode, gestureEvent.tapCount(), fakeMouseUp); 2241 swallowClickEvent = dispatchMouseEvent(EventTypeNames::click, clickT argetNode, gestureEvent.tapCount(), fakeMouseUp);
2168 } 2242 }
2169 m_clickNode = nullptr; 2243 m_clickNode = nullptr;
2170 } 2244 }
2171 2245
2172 if (!swallowMouseUpEvent) 2246 if (!swallowMouseUpEvent)
2173 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest)); 2247 swallowMouseUpEvent = handleMouseReleaseEvent(MouseEventWithHitTestResul ts(fakeMouseUp, currentHitTest));
2174 2248
2175 bool swallowed = swallowMouseDownEvent | swallowMouseUpEvent | swallowClickE vent; 2249 bool swallowed = swallowMouseDownEvent | swallowMouseUpEvent | swallowClickE vent;
2176 if (!swallowed && tappedNode && m_frame->page()) { 2250 if (!swallowed && tappedNode && m_frame->page()) {
2177 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion(); 2251 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion();
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
2804 2878
2805 // Clear mouse press state to avoid initiating a drag while context menu is up. 2879 // Clear mouse press state to avoid initiating a drag while context menu is up.
2806 m_mousePressed = false; 2880 m_mousePressed = false;
2807 LayoutPoint positionInContents = v->rootFrameToContents(event.position()); 2881 LayoutPoint positionInContents = v->rootFrameToContents(event.position());
2808 HitTestRequest request(HitTestRequest::Active); 2882 HitTestRequest request(HitTestRequest::Active);
2809 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, positionInContents, event); 2883 MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(re quest, positionInContents, event);
2810 2884
2811 selectionController().sendContextMenuEvent(mev, positionInContents); 2885 selectionController().sendContextMenuEvent(mev, positionInContents);
2812 2886
2813 Node* targetNode = overrideTargetNode ? overrideTargetNode : mev.innerNode() ; 2887 Node* targetNode = overrideTargetNode ? overrideTargetNode : mev.innerNode() ;
2814 return !dispatchMouseEvent(EventTypeNames::contextmenu, targetNode, 0, event ); 2888 return dispatchMouseEvent(EventTypeNames::contextmenu, targetNode, 0, event) ;
2815 } 2889 }
2816 2890
2817 bool EventHandler::sendContextMenuEventForKey(Element* overrideTargetElement) 2891 bool EventHandler::sendContextMenuEventForKey(Element* overrideTargetElement)
2818 { 2892 {
2819 FrameView* view = m_frame->view(); 2893 FrameView* view = m_frame->view();
2820 if (!view) 2894 if (!view)
2821 return false; 2895 return false;
2822 2896
2823 Document* doc = m_frame->document(); 2897 Document* doc = m_frame->document();
2824 if (!doc) 2898 if (!doc)
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 void EventHandler::updateDragStateAfterEditDragIfNeeded(Element* rootEditableEle ment) 3338 void EventHandler::updateDragStateAfterEditDragIfNeeded(Element* rootEditableEle ment)
3265 { 3339 {
3266 // If inserting the dragged contents removed the drag source, we still want to fire dragend at the root editble element. 3340 // If inserting the dragged contents removed the drag source, we still want to fire dragend at the root editble element.
3267 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument()) 3341 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument())
3268 dragState().m_dragSrc = rootEditableElement; 3342 dragState().m_dragSrc = rootEditableElement;
3269 } 3343 }
3270 3344
3271 // returns if we should continue "default processing", i.e., whether eventhandle r canceled 3345 // returns if we should continue "default processing", i.e., whether eventhandle r canceled
3272 bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla tformMouseEvent& event) 3346 bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla tformMouseEvent& event)
3273 { 3347 {
3274 return !dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, dra gState().m_dragDataTransfer.get()); 3348 return dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, drag State().m_dragDataTransfer.get());
3275 } 3349 }
3276 3350
3277 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, DragIni tiator initiator) 3351 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, DragIni tiator initiator)
3278 { 3352 {
3279 ASSERT(event.event().type() == PlatformEvent::MouseMoved); 3353 ASSERT(event.event().type() == PlatformEvent::MouseMoved);
3280 // Callers must protect the reference to FrameView, since this function may dispatch DOM 3354 // Callers must protect the reference to FrameView, since this function may dispatch DOM
3281 // events, causing page/FrameView to go away. 3355 // events, causing page/FrameView to go away.
3282 ASSERT(m_frame); 3356 ASSERT(m_frame);
3283 ASSERT(m_frame->view()); 3357 ASSERT(m_frame->view());
3284 if (!m_frame->page()) 3358 if (!m_frame->page())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3351 DragController& dragController = m_frame->page()->dragController(); 3425 DragController& dragController = m_frame->page()->dragController();
3352 if (!dragController.populateDragDataTransfer(m_frame, dragState(), m_mouseDo wnPos)) 3426 if (!dragController.populateDragDataTransfer(m_frame, dragState(), m_mouseDo wnPos))
3353 return false; 3427 return false;
3354 3428
3355 // If dispatching dragstart brings about another mouse down -- one way 3429 // If dispatching dragstart brings about another mouse down -- one way
3356 // this will happen is if a DevTools user breaks within a dragstart 3430 // this will happen is if a DevTools user breaks within a dragstart
3357 // handler and then clicks on the suspended page -- the drag state is 3431 // handler and then clicks on the suspended page -- the drag state is
3358 // reset. Hence, need to check if this particular drag operation can 3432 // reset. Hence, need to check if this particular drag operation can
3359 // continue even if dispatchEvent() indicates no (direct) cancellation. 3433 // continue even if dispatchEvent() indicates no (direct) cancellation.
3360 // Do that by checking if m_dragSrc is still set. 3434 // Do that by checking if m_dragSrc is still set.
3361 m_mouseDownMayStartDrag = dispatchDragSrcEvent(EventTypeNames::dragstart, m_ mouseDown) 3435 m_mouseDownMayStartDrag = !dispatchDragSrcEvent(EventTypeNames::dragstart, m _mouseDown)
3362 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc; 3436 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc;
3363 3437
3364 // Invalidate clipboard here against anymore pasteboard writing for security . The drag 3438 // Invalidate clipboard here against anymore pasteboard writing for security . The drag
3365 // image can still be changed as we drag, but not the pasteboard data. 3439 // image can still be changed as we drag, but not the pasteboard data.
3366 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable); 3440 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable);
3367 3441
3368 if (m_mouseDownMayStartDrag) { 3442 if (m_mouseDownMayStartDrag) {
3369 // Dispatching the event could cause Page to go away. Make sure it's sti ll valid before trying to use DragController. 3443 // Dispatching the event could cause Page to go away. Make sure it's sti ll valid before trying to use DragController.
3370 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev ent.event(), m_mouseDownPos)) 3444 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev ent.event(), m_mouseDownPos))
3371 return true; 3445 return true;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
3547 m_lastScrollbarUnderMouse->mouseExited(); 3621 m_lastScrollbarUnderMouse->mouseExited();
3548 3622
3549 // Send mouse entered if we're setting a new scrollbar. 3623 // Send mouse entered if we're setting a new scrollbar.
3550 if (scrollbar && setLast) 3624 if (scrollbar && setLast)
3551 scrollbar->mouseEntered(); 3625 scrollbar->mouseEntered();
3552 3626
3553 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr; 3627 m_lastScrollbarUnderMouse = setLast ? scrollbar : nullptr;
3554 } 3628 }
3555 } 3629 }
3556 3630
3557 static const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint:: State state)
3558 {
3559 switch (state) {
3560 case PlatformTouchPoint::TouchReleased:
3561 return EventTypeNames::touchend;
3562 case PlatformTouchPoint::TouchCancelled:
3563 return EventTypeNames::touchcancel;
3564 case PlatformTouchPoint::TouchPressed:
3565 return EventTypeNames::touchstart;
3566 case PlatformTouchPoint::TouchMoved:
3567 return EventTypeNames::touchmove;
3568 case PlatformTouchPoint::TouchStationary:
3569 // Fall through to default
3570 default:
3571 ASSERT_NOT_REACHED();
3572 return emptyAtom;
3573 }
3574 }
3575
3576 static const AtomicString& pointerEventNameForTouchPointState(PlatformTouchPoint ::State state)
3577 {
3578 switch (state) {
3579 case PlatformTouchPoint::TouchReleased:
3580 return EventTypeNames::pointerup;
3581 case PlatformTouchPoint::TouchCancelled:
3582 return EventTypeNames::pointercancel;
3583 case PlatformTouchPoint::TouchPressed:
3584 return EventTypeNames::pointerdown;
3585 case PlatformTouchPoint::TouchMoved:
3586 return EventTypeNames::pointermove;
3587 case PlatformTouchPoint::TouchStationary:
3588 // Fall through to default
3589 default:
3590 ASSERT_NOT_REACHED();
3591 return emptyAtom;
3592 }
3593 }
3594
3595 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout Point& point, HitTestRequest::HitTestRequestType hitType) 3631 HitTestResult EventHandler::hitTestResultInFrame(LocalFrame* frame, const Layout Point& point, HitTestRequest::HitTestRequestType hitType)
3596 { 3632 {
3597 HitTestResult result(HitTestRequest(hitType), point); 3633 HitTestResult result(HitTestRequest(hitType), point);
3598 3634
3599 if (!frame || !frame->contentLayoutObject()) 3635 if (!frame || !frame->contentLayoutObject())
3600 return result; 3636 return result;
3601 if (frame->view()) { 3637 if (frame->view()) {
3602 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars); 3638 IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars);
3603 if (!rect.contains(roundedIntPoint(point))) 3639 if (!rect.contains(roundedIntPoint(point)))
3604 return result; 3640 return result;
3605 } 3641 }
3606 frame->contentLayoutObject()->hitTest(result); 3642 frame->contentLayoutObject()->hitTest(result);
3607 return result; 3643 return result;
3608 } 3644 }
3609 3645
3610 void EventHandler::dispatchPointerEventsForTouchEvent(const PlatformTouchEvent& event, 3646 void EventHandler::dispatchPointerEvents(const PlatformTouchEvent& event,
3611 WillBeHeapVector<TouchInfo>& touchInfos) 3647 WillBeHeapVector<TouchInfo>& touchInfos)
3612 { 3648 {
3649 if (!RuntimeEnabledFeatures::pointerEventEnabled())
3650 return;
3651
3613 // Iterate through the touch points, sending PointerEvents to the targets as required. 3652 // Iterate through the touch points, sending PointerEvents to the targets as required.
3614 for (unsigned i = 0; i < touchInfos.size(); ++i) { 3653 for (unsigned i = 0; i < touchInfos.size(); ++i) {
3615 TouchInfo& touchInfo = touchInfos[i]; 3654 TouchInfo& touchInfo = touchInfos[i];
3616 const PlatformTouchPoint& touchPoint = touchInfo.point; 3655 const PlatformTouchPoint& touchPoint = touchInfo.point;
3617 const unsigned& pointerId = touchPoint.id(); 3656 const unsigned& pointerId = touchPoint.id();
3618 const PlatformTouchPoint::State pointState = touchPoint.state(); 3657 const PlatformTouchPoint::State pointState = touchPoint.state();
3619 3658
3620 if (pointState == PlatformTouchPoint::TouchStationary || !touchInfo.know nTarget) 3659 if (pointState == PlatformTouchPoint::TouchStationary || !touchInfo.know nTarget)
3621 continue; 3660 continue;
3622 3661
(...skipping 15 matching lines...) Expand all
3638 touchInfo.consumed = pointerEvent->defaultPrevented() || pointerEvent->d efaultHandled(); 3677 touchInfo.consumed = pointerEvent->defaultPrevented() || pointerEvent->d efaultHandled();
3639 3678
3640 // Remove the released/cancelled id at the end to correctly determine pr imary id above. 3679 // Remove the released/cancelled id at the end to correctly determine pr imary id above.
3641 if (pointerReleasedOrCancelled) 3680 if (pointerReleasedOrCancelled)
3642 m_pointerIdManager.remove(pointerType, pointerId); 3681 m_pointerIdManager.remove(pointerType, pointerId);
3643 } 3682 }
3644 } 3683 }
3645 3684
3646 void EventHandler::sendPointerCancels(WillBeHeapVector<TouchInfo>& touchInfos) 3685 void EventHandler::sendPointerCancels(WillBeHeapVector<TouchInfo>& touchInfos)
3647 { 3686 {
3687 if (!RuntimeEnabledFeatures::pointerEventEnabled())
3688 return;
3689
3648 for (unsigned i = 0; i < touchInfos.size(); ++i) { 3690 for (unsigned i = 0; i < touchInfos.size(); ++i) {
3649 TouchInfo& touchInfo = touchInfos[i]; 3691 TouchInfo& touchInfo = touchInfos[i];
3650 const PlatformTouchPoint& point = touchInfo.point; 3692 const PlatformTouchPoint& point = touchInfo.point;
3651 const unsigned& pointerId = point.id(); 3693 const unsigned& pointerId = point.id();
3652 const PlatformTouchPoint::State pointState = point.state(); 3694 const PlatformTouchPoint::State pointState = point.state();
3653 3695
3654 if (pointState == PlatformTouchPoint::TouchReleased 3696 if (pointState == PlatformTouchPoint::TouchReleased
3655 || pointState == PlatformTouchPoint::TouchCancelled) 3697 || pointState == PlatformTouchPoint::TouchCancelled)
3656 continue; 3698 continue;
3657 3699
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3934 TouchInfo& touchInfo = touchInfos[i]; 3976 TouchInfo& touchInfo = touchInfos[i];
3935 touchInfo.point = point; 3977 touchInfo.point = point;
3936 touchInfo.touchTarget = touchTarget; 3978 touchInfo.touchTarget = touchTarget;
3937 touchInfo.targetFrame = targetFrame; 3979 touchInfo.targetFrame = targetFrame;
3938 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor); 3980 touchInfo.adjustedPagePoint = pagePoint.scaledBy(scaleFactor);
3939 touchInfo.adjustedRadius = point.radius().scaledBy(scaleFactor); 3981 touchInfo.adjustedRadius = point.radius().scaledBy(scaleFactor);
3940 touchInfo.knownTarget = knownTarget; 3982 touchInfo.knownTarget = knownTarget;
3941 touchInfo.consumed = false; 3983 touchInfo.consumed = false;
3942 } 3984 }
3943 3985
3944 if (RuntimeEnabledFeatures::pointerEventEnabled()) { 3986 if (!m_inPointerCanceledState) {
3945 if (!m_inPointerCanceledState) { 3987 dispatchPointerEvents(event, touchInfos);
3946 dispatchPointerEventsForTouchEvent(event, touchInfos); 3988 // Note that the disposition of any pointer events affects only the gene ration of touch
3947 // Note that the disposition of any pointer events affects only the generation of touch 3989 // events. If all pointer events were handled (and hence no touch events were fired), that
3948 // events. If all pointer events were handled (and hence no touch ev ents were fired), that 3990 // is still equivalent to the touch events going unhandled because point er event handler
3949 // is still equivalent to the touch events going unhandled because p ointer event handler 3991 // don't block scroll gesture generation.
3950 // don't block scroll gesture generation.
3951 }
3952 } 3992 }
3953 3993
3954 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after 3994 // TODO(crbug.com/507408): If PE handlers always call preventDefault, we won 't see TEs until after
3955 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE 3995 // scrolling starts because the scrolling would suppress upcoming PEs. This sudden "break" in TE
3956 // suppression can make the visible TEs inconsistent (e.g. touchmove without a touchstart). 3996 // suppression can make the visible TEs inconsistent (e.g. touchmove without a touchstart).
3957 3997
3958 bool swallowedTouchEvent = dispatchTouchEvents(event, touchInfos, freshTouch Events, 3998 bool swallowedTouchEvent = dispatchTouchEvents(event, touchInfos, freshTouch Events,
3959 allTouchReleased); 3999 allTouchReleased);
3960 4000
3961 if (RuntimeEnabledFeatures::pointerEventEnabled()) { 4001 if (!m_inPointerCanceledState) {
3962 if (!m_inPointerCanceledState) { 4002 // Check if we need to stop firing pointer events because of a touch act ion.
3963 // Check if we need to stop firing pointer events because of a touch action. 4003 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for-def ault-touch-behaviors
3964 // See: www.w3.org/TR/pointerevents/#declaring-candidate-regions-for -default-touch-behaviors 4004 if (event.causesScrollingIfUncanceled() && !swallowedTouchEvent) {
3965 if (event.causesScrollingIfUncanceled() && !swallowedTouchEvent) { 4005 m_inPointerCanceledState = true;
3966 m_inPointerCanceledState = true; 4006 sendPointerCancels(touchInfos);
3967 sendPointerCancels(touchInfos);
3968 }
3969 } else if (allTouchReleased) {
3970 m_inPointerCanceledState = false;
3971 } 4007 }
4008 } else if (allTouchReleased) {
4009 m_inPointerCanceledState = false;
3972 } 4010 }
3973 4011
3974 return swallowedTouchEvent; 4012 return swallowedTouchEvent;
3975 } 4013 }
3976 4014
3977 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) 4015 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event)
3978 { 4016 {
3979 m_mousePositionIsUnknown = false; 4017 m_mousePositionIsUnknown = false;
3980 m_lastKnownMousePosition = event.position(); 4018 m_lastKnownMousePosition = event.position();
3981 m_lastKnownMouseGlobalPosition = event.globalPosition(); 4019 m_lastKnownMouseGlobalPosition = event.globalPosition();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
4034 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4072 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4035 { 4073 {
4036 #if OS(MACOSX) 4074 #if OS(MACOSX)
4037 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4075 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4038 #else 4076 #else
4039 return PlatformEvent::AltKey; 4077 return PlatformEvent::AltKey;
4040 #endif 4078 #endif
4041 } 4079 }
4042 4080
4043 } // namespace blink 4081 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698