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

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

Issue 1479923002: Enumerate the return value of dispatchEvent so it is clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_passive_uma_add
Patch Set: sed -i s/DispatchEventResult/WebInputEventResult/g Created 5 years 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // is most significant. The enumeration is ordered with smaller specified 112 // is most significant. The enumeration is ordered with smaller specified
113 // numbers first. Examples of merged results are: 113 // numbers first. Examples of merged results are:
114 // (HandledApplication, HandledSystem) -> HandledSystem 114 // (HandledApplication, HandledSystem) -> HandledSystem
115 // (NotHandled, HandledApplication) -> HandledApplication 115 // (NotHandled, HandledApplication) -> HandledApplication
116 static_assert(static_cast<int>(WebInputEventResult::NotHandled) == 0, "WebIn putEventResult not ordered"); 116 static_assert(static_cast<int>(WebInputEventResult::NotHandled) == 0, "WebIn putEventResult not ordered");
117 static_assert(static_cast<int>(WebInputEventResult::HandledSuppressed) < sta tic_cast<int>(WebInputEventResult::HandledApplication), "WebInputEventResult not ordered"); 117 static_assert(static_cast<int>(WebInputEventResult::HandledSuppressed) < sta tic_cast<int>(WebInputEventResult::HandledApplication), "WebInputEventResult not ordered");
118 static_assert(static_cast<int>(WebInputEventResult::HandledApplication) < st atic_cast<int>(WebInputEventResult::HandledSystem), "WebInputEventResult not ord ered"); 118 static_assert(static_cast<int>(WebInputEventResult::HandledApplication) < st atic_cast<int>(WebInputEventResult::HandledSystem), "WebInputEventResult not ord ered");
119 return static_cast<WebInputEventResult>(max(static_cast<int>(responseA), sta tic_cast<int>(responseB))); 119 return static_cast<WebInputEventResult>(max(static_cast<int>(responseA), sta tic_cast<int>(responseB)));
120 } 120 }
121 121
122 WebInputEventResult eventToEventResult(PassRefPtrWillBeRawPtr<Event> event, bool res)
123 {
124 if (event->defaultPrevented())
125 return WebInputEventResult::HandledApplication;
126 if (event->defaultHandled())
127 return WebInputEventResult::HandledSystem;
128
129 // TODO(dtapuska): There are cases in the code where dispatchEvent
130 // returns false (indicated handled) but event is not marked
131 // as default handled or default prevented. crbug.com/560355
132 if (!res)
133 return WebInputEventResult::HandledSuppressed;
134 return WebInputEventResult::NotHandled;
135 }
136
137 bool isNodeInDocument(Node* n) 122 bool isNodeInDocument(Node* n)
138 { 123 {
139 return n && n->inDocument(); 124 return n && n->inDocument();
140 } 125 }
141 126
142 const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::State s tate) 127 const AtomicString& touchEventNameForTouchPointState(PlatformTouchPoint::State s tate)
143 { 128 {
144 switch (state) { 129 switch (state) {
145 case PlatformTouchPoint::TouchReleased: 130 case PlatformTouchPoint::TouchReleased:
146 return EventTypeNames::touchend; 131 return EventTypeNames::touchend;
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 // Both m_clickNode and mev.innerNode() don't need to be updated 1359 // Both m_clickNode and mev.innerNode() don't need to be updated
1375 // because commonAncestor() will exit early if their documents are diffe rent. 1360 // because commonAncestor() will exit early if their documents are diffe rent.
1376 m_clickNode->updateDistribution(); 1361 m_clickNode->updateDistribution();
1377 if (Node* clickTargetNode = mev.innerNode()->commonAncestor( 1362 if (Node* clickTargetNode = mev.innerNode()->commonAncestor(
1378 *m_clickNode, parentForClickEvent)) { 1363 *m_clickNode, parentForClickEvent)) {
1379 1364
1380 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode 1365 // Dispatch mouseup directly w/o calling updateMouseEventTargetNode
1381 // because the mouseup dispatch above has already updated it 1366 // because the mouseup dispatch above has already updated it
1382 // correctly. Moreover, clickTargetNode is different from 1367 // correctly. Moreover, clickTargetNode is different from
1383 // mev.innerNode at drag-release. 1368 // mev.innerNode at drag-release.
1384 if (clickTargetNode->dispatchMouseEvent(mouseEvent, 1369 clickEventResult = clickTargetNode->dispatchMouseEvent(mouseEvent,
1385 EventTypeNames::click, m_clickCount)) { 1370 EventTypeNames::click, m_clickCount);
1386 clickEventResult = WebInputEventResult::HandledApplication;
1387 }
1388 } 1371 }
1389 } 1372 }
1390 1373
1391 if (m_resizeScrollableArea) { 1374 if (m_resizeScrollableArea) {
1392 m_resizeScrollableArea->setInResizeMode(false); 1375 m_resizeScrollableArea->setInResizeMode(false);
1393 m_resizeScrollableArea = nullptr; 1376 m_resizeScrollableArea = nullptr;
1394 } 1377 }
1395 1378
1396 if (eventResult == WebInputEventResult::NotHandled) 1379 if (eventResult == WebInputEventResult::NotHandled)
1397 eventResult = handleMouseReleaseEvent(mev); 1380 eventResult = handleMouseReleaseEvent(mev);
(...skipping 11 matching lines...) Expand all
1409 if (!view) 1392 if (!view)
1410 return WebInputEventResult::NotHandled; 1393 return WebInputEventResult::NotHandled;
1411 1394
1412 RefPtrWillBeRawPtr<DragEvent> me = DragEvent::create(eventType, 1395 RefPtrWillBeRawPtr<DragEvent> me = DragEvent::create(eventType,
1413 true, true, m_frame->document()->domWindow(), 1396 true, true, m_frame->document()->domWindow(),
1414 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(), 1397 0, event.globalPosition().x(), event.globalPosition().y(), event.positio n().x(), event.position().y(),
1415 event.movementDelta().x(), event.movementDelta().y(), 1398 event.movementDelta().x(), event.movementDelta().y(),
1416 event.modifiers(), 1399 event.modifiers(),
1417 0, MouseEvent::platformModifiersToButtons(event.modifiers()), nullptr, e vent.timestamp(), dataTransfer, event.syntheticEventType()); 1400 0, MouseEvent::platformModifiersToButtons(event.modifiers()), nullptr, e vent.timestamp(), dataTransfer, event.syntheticEventType());
1418 1401
1419 bool dispatchResult = dragTarget->dispatchEvent(me.get()); 1402 return dragTarget->dispatchEvent(me.get());
1420 return eventToEventResult(me, dispatchResult);
1421 } 1403 }
1422 1404
1423 static bool targetIsFrame(Node* target, LocalFrame*& frame) 1405 static bool targetIsFrame(Node* target, LocalFrame*& frame)
1424 { 1406 {
1425 if (!isHTMLFrameElementBase(target)) 1407 if (!isHTMLFrameElementBase(target))
1426 return false; 1408 return false;
1427 1409
1428 // Cross-process drag and drop is not yet supported. 1410 // Cross-process drag and drop is not yet supported.
1429 if (toHTMLFrameElementBase(target)->contentFrame() && !toHTMLFrameElementBas e(target)->contentFrame()->isLocalFrame()) 1411 if (toHTMLFrameElementBase(target)->contentFrame() && !toHTMLFrameElementBas e(target)->contentFrame()->isLocalFrame())
1430 return false; 1412 return false;
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 1631
1650 WebInputEventResult EventHandler::dispatchPointerEvent(Node* target, const Atomi cString& eventType, 1632 WebInputEventResult EventHandler::dispatchPointerEvent(Node* target, const Atomi cString& eventType,
1651 const PlatformMouseEvent& mouseEvent, Node* relatedTarget) 1633 const PlatformMouseEvent& mouseEvent, Node* relatedTarget)
1652 { 1634 {
1653 if (!RuntimeEnabledFeatures::pointerEventEnabled()) 1635 if (!RuntimeEnabledFeatures::pointerEventEnabled())
1654 return WebInputEventResult::NotHandled; 1636 return WebInputEventResult::NotHandled;
1655 1637
1656 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true, 1638 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = PointerEvent::create(eventTy pe, true,
1657 mouseEvent, relatedTarget, m_frame->document()->domWindow()); 1639 mouseEvent, relatedTarget, m_frame->document()->domWindow());
1658 1640
1659 bool dispatchResult = target->dispatchEvent(pointerEvent.get()); 1641 return target->dispatchEvent(pointerEvent.get());
1660 return eventToEventResult(pointerEvent, dispatchResult);
1661 } 1642 }
1662 1643
1663 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode, 1644 void EventHandler::sendMouseEventsForNodeTransition(Node* exitedNode, Node* ente redNode,
1664 const PlatformMouseEvent& mouseEvent) 1645 const PlatformMouseEvent& mouseEvent)
1665 { 1646 {
1666 ASSERT(exitedNode != enteredNode); 1647 ASSERT(exitedNode != enteredNode);
1667 1648
1668 // Dispatch pointerout/mouseout events 1649 // Dispatch pointerout/mouseout events
1669 if (isNodeInDocument(exitedNode)) { 1650 if (isNodeInDocument(exitedNode)) {
1670 dispatchPointerEvent(exitedNode, EventTypeNames::pointerout, mouseEvent, enteredNode); 1651 dispatchPointerEvent(exitedNode, EventTypeNames::pointerout, mouseEvent, enteredNode);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1763 } 1744 }
1764 } 1745 }
1765 1746
1766 WebInputEventResult EventHandler::dispatchMouseEvent(const AtomicString& eventTy pe, Node* targetNode, int clickCount, const PlatformMouseEvent& mouseEvent) 1747 WebInputEventResult EventHandler::dispatchMouseEvent(const AtomicString& eventTy pe, Node* targetNode, int clickCount, const PlatformMouseEvent& mouseEvent)
1767 { 1748 {
1768 updateMouseEventTargetNode(targetNode, mouseEvent); 1749 updateMouseEventTargetNode(targetNode, mouseEvent);
1769 if (!m_nodeUnderMouse) 1750 if (!m_nodeUnderMouse)
1770 return WebInputEventResult::NotHandled; 1751 return WebInputEventResult::NotHandled;
1771 1752
1772 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(eventType, m_nodeU nderMouse->document().domWindow(), mouseEvent, clickCount, nullptr); 1753 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(eventType, m_nodeU nderMouse->document().domWindow(), mouseEvent, clickCount, nullptr);
1773 bool dispatchResult = m_nodeUnderMouse->dispatchEvent(event); 1754 return m_nodeUnderMouse->dispatchEvent(event);
1774 return eventToEventResult(event, dispatchResult);
1775 } 1755 }
1776 1756
1777 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler. 1757 // TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
1778 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent) 1758 WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato micString& mouseEventType, Node* targetNode, int clickCount, const PlatformMouse Event& mouseEvent)
1779 { 1759 {
1780 ASSERT(mouseEventType == EventTypeNames::mousedown 1760 ASSERT(mouseEventType == EventTypeNames::mousedown
1781 || mouseEventType == EventTypeNames::mousemove 1761 || mouseEventType == EventTypeNames::mousemove
1782 || mouseEventType == EventTypeNames::mouseup); 1762 || mouseEventType == EventTypeNames::mouseup);
1783 1763
1784 updateMouseEventTargetNode(targetNode, mouseEvent); 1764 updateMouseEventTargetNode(targetNode, mouseEvent);
1785 if (!m_nodeUnderMouse) 1765 if (!m_nodeUnderMouse)
1786 return WebInputEventResult::NotHandled; 1766 return WebInputEventResult::NotHandled;
1787 1767
1788 WebInputEventResult result = dispatchPointerEvent(m_nodeUnderMouse.get(), 1768 WebInputEventResult result = dispatchPointerEvent(m_nodeUnderMouse.get(),
1789 pointerEventNameForMouseEventName(mouseEventType), 1769 pointerEventNameForMouseEventName(mouseEventType),
1790 mouseEvent); 1770 mouseEvent);
1791 1771
1792 if (result != WebInputEventResult::NotHandled && mouseEventType == EventType Names::mousedown) { 1772 if (result != WebInputEventResult::NotHandled && mouseEventType == EventType Names::mousedown) {
1793 m_preventMouseEventForPointerTypeMouse = true; 1773 m_preventMouseEventForPointerTypeMouse = true;
1794 } 1774 }
1795 1775
1796 if (!m_preventMouseEventForPointerTypeMouse) { 1776 if (!m_preventMouseEventForPointerTypeMouse) {
1797 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(mouseEventType , m_nodeUnderMouse->document().domWindow(), mouseEvent, clickCount, nullptr); 1777 RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(mouseEventType , m_nodeUnderMouse->document().domWindow(), mouseEvent, clickCount, nullptr);
1798 bool dispatchResult = m_nodeUnderMouse->dispatchEvent(event); 1778 result = mergeEventResult(result, m_nodeUnderMouse->dispatchEvent(event) );
1799 result = mergeEventResult(result, eventToEventResult(event, dispatchResu lt));
1800 } 1779 }
1801 1780
1802 return result; 1781 return result;
1803 } 1782 }
1804 1783
1805 WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestRe sults& targetedEvent, InputDeviceCapabilities* sourceCapabilities) 1784 WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestRe sults& targetedEvent, InputDeviceCapabilities* sourceCapabilities)
1806 { 1785 {
1807 // If clicking on a frame scrollbar, do not mess up with content focus. 1786 // If clicking on a frame scrollbar, do not mess up with content focus.
1808 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) { 1787 if (targetedEvent.hitTestResult().scrollbar() && m_frame->contentLayoutObjec t()) {
1809 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea()) 1788 if (targetedEvent.hitTestResult().scrollbar()->scrollableArea() == m_fra me->contentLayoutObject()->scrollableArea())
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 if (Widget* widget = toLayoutPart(target)->widget()) { 1939 if (Widget* widget = toLayoutPart(target)->widget()) {
1961 WebInputEventResult result = passWheelEventToWidget(event, *widg et); 1940 WebInputEventResult result = passWheelEventToWidget(event, *widg et);
1962 if (result != WebInputEventResult::NotHandled) { 1941 if (result != WebInputEventResult::NotHandled) {
1963 setFrameWasScrolledByUser(); 1942 setFrameWasScrolledByUser();
1964 return result; 1943 return result;
1965 } 1944 }
1966 } 1945 }
1967 } 1946 }
1968 1947
1969 RefPtrWillBeRawPtr<Event> domEvent = WheelEvent::create(event, node->doc ument().domWindow()); 1948 RefPtrWillBeRawPtr<Event> domEvent = WheelEvent::create(event, node->doc ument().domWindow());
1970 if (!node->dispatchEvent(domEvent)) { 1949 WebInputEventResult domEventResult = node->dispatchEvent(domEvent);
1950 if (domEventResult != WebInputEventResult::NotHandled) {
1971 setFrameWasScrolledByUser(); 1951 setFrameWasScrolledByUser();
1972 return eventToEventResult(domEvent, false); 1952 return domEventResult;
1973 } 1953 }
1974 } 1954 }
1975 1955
1976 // We do another check on the frame view because the event handler can run 1956 // We do another check on the frame view because the event handler can run
1977 // JS which results in the frame getting destroyed. 1957 // JS which results in the frame getting destroyed.
1978 view = m_frame->view(); 1958 view = m_frame->view();
1979 if (!view) 1959 if (!view)
1980 return WebInputEventResult::NotHandled; 1960 return WebInputEventResult::NotHandled;
1981 1961
1982 // Wheel events which do not scroll are used to trigger zooming. 1962 // Wheel events which do not scroll are used to trigger zooming.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 if (scrollbar) { 2073 if (scrollbar) {
2094 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent); 2074 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent);
2095 if (gestureEvent.type() == PlatformEvent::GestureTapDown && eventSwallow ed) 2075 if (gestureEvent.type() == PlatformEvent::GestureTapDown && eventSwallow ed)
2096 m_scrollbarHandlingScrollGesture = scrollbar; 2076 m_scrollbarHandlingScrollGesture = scrollbar;
2097 if (eventSwallowed) 2077 if (eventSwallowed)
2098 return WebInputEventResult::HandledSuppressed; 2078 return WebInputEventResult::HandledSuppressed;
2099 } 2079 }
2100 2080
2101 if (eventTarget) { 2081 if (eventTarget) {
2102 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent); 2082 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent);
2103 // TODO(dtapuska): dispatchEvent is inverted for Gesture Events 2083 if (gestureDomEvent.get()) {
2104 // crbug.com/560357 2084 WebInputEventResult gestureDomEventResult = eventTarget->dispatchEve nt(gestureDomEvent);
2105 if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent) ) 2085 if (gestureDomEventResult != WebInputEventResult::NotHandled)
2106 return eventToEventResult(gestureDomEvent, false); 2086 return gestureDomEventResult;
2087 }
2107 } 2088 }
2108 2089
2109 switch (gestureEvent.type()) { 2090 switch (gestureEvent.type()) {
2110 case PlatformEvent::GestureTap: 2091 case PlatformEvent::GestureTap:
2111 return handleGestureTap(targetedEvent); 2092 return handleGestureTap(targetedEvent);
2112 case PlatformEvent::GestureShowPress: 2093 case PlatformEvent::GestureShowPress:
2113 return handleGestureShowPress(); 2094 return handleGestureShowPress();
2114 case PlatformEvent::GestureLongPress: 2095 case PlatformEvent::GestureLongPress:
2115 return handleGestureLongPress(targetedEvent); 2096 return handleGestureLongPress(targetedEvent);
2116 case PlatformEvent::GestureLongTap: 2097 case PlatformEvent::GestureLongTap:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 } 2153 }
2173 if (eventSwallowed) 2154 if (eventSwallowed)
2174 return WebInputEventResult::HandledSuppressed; 2155 return WebInputEventResult::HandledSuppressed;
2175 } 2156 }
2176 2157
2177 if (eventTarget) { 2158 if (eventTarget) {
2178 if (handleScrollGestureOnResizer(eventTarget.get(), gestureEvent)) 2159 if (handleScrollGestureOnResizer(eventTarget.get(), gestureEvent))
2179 return WebInputEventResult::HandledSuppressed; 2160 return WebInputEventResult::HandledSuppressed;
2180 2161
2181 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent); 2162 RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create( eventTarget->document().domWindow(), gestureEvent);
2182 // TODO(dtapuska): dispatchEvent is inverted for Gesture Events 2163 if (gestureDomEvent.get()) {
2183 // crbug.com/560357 2164 WebInputEventResult gestureDomEventResult = eventTarget->dispatchEve nt(gestureDomEvent);
2184 if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent) ) 2165 if (gestureDomEventResult != WebInputEventResult::NotHandled)
2185 return eventToEventResult(gestureDomEvent, false); 2166 return gestureDomEventResult;
2167 }
2186 } 2168 }
2187 2169
2188 switch (gestureEvent.type()) { 2170 switch (gestureEvent.type()) {
2189 case PlatformEvent::GestureScrollBegin: 2171 case PlatformEvent::GestureScrollBegin:
2190 return handleGestureScrollBegin(gestureEvent); 2172 return handleGestureScrollBegin(gestureEvent);
2191 case PlatformEvent::GestureScrollUpdate: 2173 case PlatformEvent::GestureScrollUpdate:
2192 return handleGestureScrollUpdate(gestureEvent); 2174 return handleGestureScrollUpdate(gestureEvent);
2193 case PlatformEvent::GestureScrollEnd: 2175 case PlatformEvent::GestureScrollEnd:
2194 return handleGestureScrollEnd(gestureEvent); 2176 return handleGestureScrollEnd(gestureEvent);
2195 case PlatformEvent::GestureFlingStart: 2177 case PlatformEvent::GestureFlingStart:
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
3232 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages. 3214 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch ing a keypress event for WM_SYSCHAR messages.
3233 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events. 3215 // Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events.
3234 bool matchedAnAccessKey = false; 3216 bool matchedAnAccessKey = false;
3235 if (initialKeyEvent.type() == PlatformEvent::KeyDown) 3217 if (initialKeyEvent.type() == PlatformEvent::KeyDown)
3236 matchedAnAccessKey = handleAccessKey(initialKeyEvent); 3218 matchedAnAccessKey = handleAccessKey(initialKeyEvent);
3237 3219
3238 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch. 3220 // FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
3239 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) { 3221 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) {
3240 RefPtrWillBeRawPtr<KeyboardEvent> domEvent = KeyboardEvent::create(initi alKeyEvent, m_frame->document()->domWindow()); 3222 RefPtrWillBeRawPtr<KeyboardEvent> domEvent = KeyboardEvent::create(initi alKeyEvent, m_frame->document()->domWindow());
3241 3223
3242 bool dispatchResult = node->dispatchEvent(domEvent); 3224 return node->dispatchEvent(domEvent);
3243 return eventToEventResult(domEvent, dispatchResult);
3244 } 3225 }
3245 3226
3246 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; 3227 PlatformKeyboardEvent keyDownEvent = initialKeyEvent;
3247 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) 3228 if (keyDownEvent.type() != PlatformEvent::RawKeyDown)
3248 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); 3229 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
3249 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow()); 3230 RefPtrWillBeRawPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEve nt, m_frame->document()->domWindow());
3250 if (matchedAnAccessKey) 3231 if (matchedAnAccessKey)
3251 keydown->setDefaultPrevented(true); 3232 keydown->setDefaultPrevented(true);
3252 keydown->setTarget(node); 3233 keydown->setTarget(node);
3253 3234
3254 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { 3235 WebInputEventResult dispatchResult = node->dispatchEvent(keydown);
3255 if (!node->dispatchEvent(keydown)) 3236 if (dispatchResult != WebInputEventResult::NotHandled)
3256 return eventToEventResult(keydown, false); 3237 return dispatchResult;
3257 // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
3258 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page() ->focusController().focusedOrMainFrame();
3259 if (changedFocusedFrame)
3260 return WebInputEventResult::HandledSystem;
3261 return WebInputEventResult::NotHandled;
3262 }
3263
3264 if (!node->dispatchEvent(keydown))
3265 return eventToEventResult(keydown, false);
3266 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame. 3238 // If frame changed as a result of keydown dispatch, then return early to av oid sending a subsequent keypress message to the new frame.
3267 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame(); 3239 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo cusController().focusedOrMainFrame();
3268 if (changedFocusedFrame) 3240 if (changedFocusedFrame)
3269 return WebInputEventResult::HandledSystem; 3241 return WebInputEventResult::HandledSystem;
3270 3242
3243 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown)
3244 return WebInputEventResult::NotHandled;
3245
3271 // Focus may have changed during keydown handling, so refetch node. 3246 // Focus may have changed during keydown handling, so refetch node.
3272 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node. 3247 // But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
3273 node = eventTargetNodeForDocument(m_frame->document()); 3248 node = eventTargetNodeForDocument(m_frame->document());
3274 if (!node) 3249 if (!node)
3275 return WebInputEventResult::NotHandled; 3250 return WebInputEventResult::NotHandled;
3276 3251
3277 PlatformKeyboardEvent keyPressEvent = initialKeyEvent; 3252 PlatformKeyboardEvent keyPressEvent = initialKeyEvent;
3278 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char); 3253 keyPressEvent.disambiguateKeyDownEvent(PlatformEvent::Char);
3279 if (keyPressEvent.text().isEmpty()) 3254 if (keyPressEvent.text().isEmpty())
3280 return WebInputEventResult::NotHandled; 3255 return WebInputEventResult::NotHandled;
3281 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE vent, m_frame->document()->domWindow()); 3256 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE vent, m_frame->document()->domWindow());
3282 keypress->setTarget(node); 3257 keypress->setTarget(node);
3283 bool dispatchResult = node->dispatchEvent(keypress); 3258 return node->dispatchEvent(keypress);
3284 return eventToEventResult(keypress, dispatchResult);
3285 } 3259 }
3286 3260
3287 static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier) 3261 static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier)
3288 { 3262 {
3289 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom Literal)); 3263 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom Literal));
3290 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite ral)); 3264 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite ral));
3291 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom Literal)); 3265 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom Literal));
3292 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr omLiteral)); 3266 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr omLiteral));
3293 3267
3294 WebFocusType retVal = WebFocusTypeNone; 3268 WebFocusType retVal = WebFocusTypeNone;
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
3870 continue; 3844 continue;
3871 3845
3872 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca st<PlatformTouchPoint::State>(state))); 3846 const AtomicString& eventName(touchEventNameForTouchPointState(static_ca st<PlatformTouchPoint::State>(state)));
3873 for (const auto& eventTarget : changedTouches[state].m_targets) { 3847 for (const auto& eventTarget : changedTouches[state].m_targets) {
3874 EventTarget* touchEventTarget = eventTarget.get(); 3848 EventTarget* touchEventTarget = eventTarget.get();
3875 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create( 3849 RefPtrWillBeRawPtr<TouchEvent> touchEvent = TouchEvent::create(
3876 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(), 3850 touches.get(), touchesByTarget.get(touchEventTarget), changedTou ches[state].m_touches.get(),
3877 eventName, touchEventTarget->toNode()->document().domWindow(), 3851 eventName, touchEventTarget->toNode()->document().domWindow(),
3878 event.modifiers(), event.cancelable(), event.causesScrollingIfUn canceled(), event.timestamp()); 3852 event.modifiers(), event.cancelable(), event.causesScrollingIfUn canceled(), event.timestamp());
3879 3853
3880 bool dispatchResult = touchEventTarget->dispatchEvent(touchEvent.get ()); 3854 eventResult = mergeEventResult(eventResult, touchEventTarget->dispat chEvent(touchEvent.get()));
3881 eventResult = mergeEventResult(eventResult, eventToEventResult(touch Event, dispatchResult));
3882 } 3855 }
3883 } 3856 }
3884 3857
3885 return eventResult; 3858 return eventResult;
3886 } 3859 }
3887 3860
3888 WebInputEventResult EventHandler::handleTouchEvent(const PlatformTouchEvent& eve nt) 3861 WebInputEventResult EventHandler::handleTouchEvent(const PlatformTouchEvent& eve nt)
3889 { 3862 {
3890 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent"); 3863 TRACE_EVENT0("blink", "EventHandler::handleTouchEvent");
3891 3864
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4149 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4122 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4150 { 4123 {
4151 #if OS(MACOSX) 4124 #if OS(MACOSX)
4152 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4125 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4153 #else 4126 #else
4154 return PlatformEvent::AltKey; 4127 return PlatformEvent::AltKey;
4155 #endif 4128 #endif
4156 } 4129 }
4157 4130
4158 } // namespace blink 4131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698