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

Unified 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: Add back the EventDispatchResult enum Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/input/EventHandler.cpp
diff --git a/third_party/WebKit/Source/core/input/EventHandler.cpp b/third_party/WebKit/Source/core/input/EventHandler.cpp
index e1d4146cdb060c8b8a0a80448b5588659728c0cf..33220c8d48fd59b5a6fbfc0878b3305428fba467 100644
--- a/third_party/WebKit/Source/core/input/EventHandler.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandler.cpp
@@ -367,20 +367,14 @@ WebInputEventResult EventHandler::mergeEventResult(
return static_cast<WebInputEventResult>(max(static_cast<int>(resultA), static_cast<int>(resultB)));
}
-WebInputEventResult EventHandler::eventToEventResult(
- PassRefPtrWillBeRawPtr<Event> event, bool result)
+WebInputEventResult EventHandler::eventDispatchResultToWebInputEventResult(
+ EventTarget::DispatchEventResult result)
{
- if (event->defaultPrevented())
- return WebInputEventResult::HandledApplication;
- if (event->defaultHandled())
- return WebInputEventResult::HandledSystem;
-
- // TODO(dtapuska): There are cases in the code where dispatchEvent
- // returns false (indicated handled) but event is not marked
- // as default handled or default prevented. crbug.com/560355
- if (!result)
- return WebInputEventResult::HandledSuppressed;
- return WebInputEventResult::NotHandled;
+ static_assert(static_cast<int>(WebInputEventResult::NotHandled) == static_cast<int>(EventTarget::DispatchEventResult::NotHandled), "WebInputEventResult does not match EventTarget::DispatchEventResult");
+ static_assert(static_cast<int>(WebInputEventResult::HandledApplication) == static_cast<int>(EventTarget::DispatchEventResult::HandledApplication), "WebInput EventResult does not match EventTarget::DispatchEventResult");
+ static_assert(static_cast<int>(WebInputEventResult::HandledSystem) == static_cast<int>(EventTarget::DispatchEventResult::HandledSystem), "WebInputEventResult does not match EventTarget::DispatchEventResult");
+ static_assert(static_cast<int>(WebInputEventResult::HandledSuppressed) == static_cast<int>(EventTarget::DispatchEventResult::HandledSuppressed), "WebInputEventResult does not match EventTarget::DispatchEventResult");
+ return static_cast<WebInputEventResult>(static_cast<int>(result));
}
void EventHandler::nodeWillBeRemoved(Node& nodeToBeRemoved)
@@ -1346,10 +1340,8 @@ WebInputEventResult EventHandler::handleMouseReleaseEvent(const PlatformMouseEve
// because the mouseup dispatch above has already updated it
// correctly. Moreover, clickTargetNode is different from
// mev.innerNode at drag-release.
- if (clickTargetNode->dispatchMouseEvent(mouseEvent,
- EventTypeNames::click, m_clickCount)) {
- clickEventResult = WebInputEventResult::HandledApplication;
- }
+ clickEventResult = eventDispatchResultToWebInputEventResult(clickTargetNode->dispatchMouseEvent(mouseEvent,
+ EventTypeNames::click, m_clickCount));
}
}
@@ -1381,8 +1373,7 @@ WebInputEventResult EventHandler::dispatchDragEvent(const AtomicString& eventTyp
event.modifiers(),
0, MouseEvent::platformModifiersToButtons(event.modifiers()), nullptr, event.timestamp(), dataTransfer, event.syntheticEventType());
- bool dispatchResult = dragTarget->dispatchEvent(me.get());
- return eventToEventResult(me, dispatchResult);
+ return eventDispatchResultToWebInputEventResult(dragTarget->dispatchEvent(me.get()));
}
static bool targetIsFrame(Node* target, LocalFrame*& frame)
@@ -1619,8 +1610,7 @@ WebInputEventResult EventHandler::dispatchMouseEvent(const AtomicString& eventTy
return WebInputEventResult::NotHandled;
RefPtrWillBeRawPtr<MouseEvent> event = MouseEvent::create(eventType, m_nodeUnderMouse->document().domWindow(), mouseEvent, clickCount, nullptr);
- bool dispatchResult = m_nodeUnderMouse->dispatchEvent(event);
- return eventToEventResult(event, dispatchResult);
+ return eventDispatchResultToWebInputEventResult(m_nodeUnderMouse->dispatchEvent(event));
}
// TODO(mustaq): Make PE drive ME dispatch & bookkeeping in EventHandler.
@@ -1634,11 +1624,9 @@ WebInputEventResult EventHandler::updatePointerTargetAndDispatchEvents(const Ato
if (!m_nodeUnderMouse)
return WebInputEventResult::NotHandled;
- WebInputEventResult result = m_pointerEventManager.sendMousePointerEvent(
+ return m_pointerEventManager.sendMousePointerEvent(
m_nodeUnderMouse, mouseEventType, clickCount, mouseEvent, nullptr,
m_frame->document()->domWindow());
-
- return result;
}
WebInputEventResult EventHandler::handleMouseFocus(const MouseEventWithHitTestResults& targetedEvent, InputDeviceCapabilities* sourceCapabilities)
@@ -1806,9 +1794,10 @@ WebInputEventResult EventHandler::handleWheelEvent(const PlatformWheelEvent& eve
}
RefPtrWillBeRawPtr<Event> domEvent = WheelEvent::create(event, node->document().domWindow());
- if (!node->dispatchEvent(domEvent)) {
+ EventTarget::DispatchEventResult domEventResult = node->dispatchEvent(domEvent);
+ if (domEventResult != EventTarget::DispatchEventResult::NotHandled) {
setFrameWasScrolledByUser();
- return eventToEventResult(domEvent, false);
+ return eventDispatchResultToWebInputEventResult(domEventResult);
}
}
@@ -1938,10 +1927,11 @@ WebInputEventResult EventHandler::handleGestureEventInFrame(const GestureEventWi
if (eventTarget) {
RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create(eventTarget->document().domWindow(), gestureEvent);
- // TODO(dtapuska): dispatchEvent is inverted for Gesture Events
- // crbug.com/560357
- if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent))
- return eventToEventResult(gestureDomEvent, false);
+ if (gestureDomEvent.get()) {
+ EventTarget::DispatchEventResult gestureDomEventResult = eventTarget->dispatchEvent(gestureDomEvent);
Rick Byers 2016/02/22 15:16:14 There used to be an ASSERT in the GestureEventDisp
dtapuska 2016/02/23 19:14:40 Done; I rolled this into a method.
+ if (gestureDomEventResult != EventTarget::DispatchEventResult::NotHandled)
+ return eventDispatchResultToWebInputEventResult(gestureDomEventResult);
+ }
}
switch (gestureEvent.type()) {
@@ -2017,10 +2007,11 @@ WebInputEventResult EventHandler::handleGestureScrollEvent(const PlatformGesture
return WebInputEventResult::HandledSuppressed;
RefPtrWillBeRawPtr<GestureEvent> gestureDomEvent = GestureEvent::create(eventTarget->document().domWindow(), gestureEvent);
- // TODO(dtapuska): dispatchEvent is inverted for Gesture Events
- // crbug.com/560357
- if (gestureDomEvent.get() && eventTarget->dispatchEvent(gestureDomEvent))
- return eventToEventResult(gestureDomEvent, false);
+ if (gestureDomEvent.get()) {
+ EventTarget::DispatchEventResult gestureDomEventResult = eventTarget->dispatchEvent(gestureDomEvent);
+ if (gestureDomEventResult != EventTarget::DispatchEventResult::NotHandled)
+ return eventDispatchResultToWebInputEventResult(gestureDomEventResult);
+ }
}
switch (gestureEvent.type()) {
@@ -3092,8 +3083,7 @@ WebInputEventResult EventHandler::keyEvent(const PlatformKeyboardEvent& initialK
if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type() == PlatformEvent::Char) {
RefPtrWillBeRawPtr<KeyboardEvent> domEvent = KeyboardEvent::create(initialKeyEvent, m_frame->document()->domWindow());
- bool dispatchResult = node->dispatchEvent(domEvent);
- return eventToEventResult(domEvent, dispatchResult);
+ return eventDispatchResultToWebInputEventResult(node->dispatchEvent(domEvent));
}
PlatformKeyboardEvent keyDownEvent = initialKeyEvent;
@@ -3104,23 +3094,17 @@ WebInputEventResult EventHandler::keyEvent(const PlatformKeyboardEvent& initialK
keydown->setDefaultPrevented(true);
keydown->setTarget(node);
- if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) {
- if (!node->dispatchEvent(keydown))
- return eventToEventResult(keydown, false);
- // If frame changed as a result of keydown dispatch, then return true to avoid sending a subsequent keypress message to the new frame.
- bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame();
- if (changedFocusedFrame)
- return WebInputEventResult::HandledSystem;
- return WebInputEventResult::NotHandled;
- }
-
- if (!node->dispatchEvent(keydown))
- return eventToEventResult(keydown, false);
+ EventTarget::DispatchEventResult dispatchResult = node->dispatchEvent(keydown);
+ if (dispatchResult != EventTarget::DispatchEventResult::NotHandled)
+ return eventDispatchResultToWebInputEventResult(dispatchResult);
// If frame changed as a result of keydown dispatch, then return early to avoid sending a subsequent keypress message to the new frame.
bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->focusController().focusedOrMainFrame();
if (changedFocusedFrame)
return WebInputEventResult::HandledSystem;
+ if (initialKeyEvent.type() == PlatformEvent::RawKeyDown)
+ return WebInputEventResult::NotHandled;
+
// Focus may have changed during keydown handling, so refetch node.
// But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
node = eventTargetNodeForDocument(m_frame->document());
@@ -3133,8 +3117,7 @@ WebInputEventResult EventHandler::keyEvent(const PlatformKeyboardEvent& initialK
return WebInputEventResult::NotHandled;
RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame->document()->domWindow());
keypress->setTarget(node);
- bool dispatchResult = node->dispatchEvent(keypress);
- return eventToEventResult(keypress, dispatchResult);
+ return eventDispatchResultToWebInputEventResult(node->dispatchEvent(keypress));
}
static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier)
@@ -3708,8 +3691,7 @@ WebInputEventResult EventHandler::dispatchTouchEvents(const PlatformTouchEvent&
eventName, touchEventTarget->toNode()->document().domWindow(),
event.modifiers(), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp());
- bool dispatchResult = touchEventTarget->dispatchEvent(touchEvent.get());
- eventResult = mergeEventResult(eventResult, eventToEventResult(touchEvent, dispatchResult));
+ eventResult = mergeEventResult(eventResult, eventDispatchResultToWebInputEventResult(touchEventTarget->dispatchEvent(touchEvent.get())));
}
}

Powered by Google App Engine
This is Rietveld 408576698