EventDispatchBehavior is unnecessary
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Oct 2013 04:44:14 +0000 (04:44 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Oct 2013 04:44:14 +0000 (04:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122483

Reviewed by Andreas Kling.

Removed EventDispatchBehavior and changed the return type of determineDispatchBehavior to bool.
Also renamed it to shouldEventCrossShadowBoundary to reflect the semantics more clear.

* dom/EventRetargeter.cpp:
(WebCore::shouldEventCrossShadowBoundary):
(WebCore::EventRetargeter::calculateEventPath):
* dom/EventRetargeter.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@157085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/EventRetargeter.cpp
Source/WebCore/dom/EventRetargeter.h

index 473c454..87989d7 100644 (file)
@@ -1,5 +1,20 @@
 2013-10-07  Ryosuke Niwa  <rniwa@webkit.org>
 
+        EventDispatchBehavior is unnecessary
+        https://bugs.webkit.org/show_bug.cgi?id=122483
+
+        Reviewed by Andreas Kling.
+
+        Removed EventDispatchBehavior and changed the return type of determineDispatchBehavior to bool.
+        Also renamed it to shouldEventCrossShadowBoundary to reflect the semantics more clear.
+
+        * dom/EventRetargeter.cpp:
+        (WebCore::shouldEventCrossShadowBoundary):
+        (WebCore::EventRetargeter::calculateEventPath):
+        * dom/EventRetargeter.h:
+
+2013-10-07  Ryosuke Niwa  <rniwa@webkit.org>
+
         Make buildRelatedNodeMap and findRelatedNode static to EventRetargeter.cpp
         https://bugs.webkit.org/show_bug.cgi?id=122477
 
index 38f6447..05d88ab 100644 (file)
 
 namespace WebCore {
 
-static inline bool inTheSameScope(ShadowRoot* shadowRoot, EventTarget* target)
-{
-    return target->toNode() && target->toNode()->treeScope().rootNode() == shadowRoot;
-}
-
-static inline EventDispatchBehavior determineDispatchBehavior(Event* event, ShadowRoot* shadowRoot, EventTarget* target)
+static inline bool shouldEventCrossShadowBoundary(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
 {
+    Node* targetNode = target.toNode();
 #if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
     // Video-only full screen is a mode where we use the shadow DOM as an implementation
     // detail that should not be detectable by the web content.
-    if (Element* element = target->toNode()->document().webkitCurrentFullScreenElement()) {
-        // FIXME: We assume that if the full screen element is a media element that it's
-        // the video-only full screen. Both here and elsewhere. But that is probably wrong.
-        if (element->isMediaElement() && shadowRoot && shadowRoot->hostElement() == element)
-            return StayInsideShadowDOM;
+    if (targetNode) {
+        if (Element* element = targetNode->document().webkitCurrentFullScreenElement()) {
+            // FIXME: We assume that if the full screen element is a media element that it's
+            // the video-only full screen. Both here and elsewhere. But that is probably wrong.
+            if (element->isMediaElement() && shadowRoot.hostElement() == element)
+                return false;
+        }
     }
-#else
-    UNUSED_PARAM(shadowRoot);
 #endif
 
     // WebKit never allowed selectstart event to cross the the shadow DOM boundary.
     // Changing this breaks existing sites.
     // See https://bugs.webkit.org/show_bug.cgi?id=52195 for details.
-    const AtomicString eventType = event->type();
-    if (inTheSameScope(shadowRoot, target)
-        && (eventType == eventNames().abortEvent
+    const AtomicString& eventType = event.type();
+    bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
+    return !targetIsInShadowRoot
+        || !(eventType == eventNames().abortEvent
             || eventType == eventNames().changeEvent
             || eventType == eventNames().errorEvent
             || eventType == eventNames().loadEvent
@@ -68,10 +65,7 @@ static inline EventDispatchBehavior determineDispatchBehavior(Event* event, Shad
             || eventType == eventNames().resizeEvent
             || eventType == eventNames().scrollEvent
             || eventType == eventNames().selectEvent
-            || eventType == eventNames().selectstartEvent))
-        return StayInsideShadowDOM;
-
-    return RetargetEvent;
+            || eventType == eventNames().selectstartEvent);
 }
 
 static Node* nodeOrHostIfPseudoElement(Node* node)
@@ -81,6 +75,7 @@ static Node* nodeOrHostIfPseudoElement(Node* node)
 
 void EventRetargeter::calculateEventPath(Node* targetNode, Event* event, EventPath& eventPath)
 {
+    ASSERT(event);
     bool inDocument = targetNode->inDocument();
     bool isSVGElement = targetNode->isSVGElement();
     bool isMouseOrFocusEvent = event->isMouseEvent() || event->isFocusEvent();
@@ -104,7 +99,8 @@ void EventRetargeter::calculateEventPath(Node* targetNode, Event* event, EventPa
             return;
         if (!node->isShadowRoot())
             continue;
-        if (determineDispatchBehavior(event, toShadowRoot(node), targetStack.last()) == StayInsideShadowDOM)
+        ASSERT(!targetStack.isEmpty());
+        if (!shouldEventCrossShadowBoundary(*event, *toShadowRoot(node), *targetStack.last()))
             return;
         if (!isSVGElement) {
             ASSERT(!targetStack.isEmpty());
index 3e21420..ac7555c 100644 (file)
@@ -45,11 +45,6 @@ class TouchEvent;
 #endif
 class TreeScope;
 
-enum EventDispatchBehavior {
-    RetargetEvent,
-    StayInsideShadowDOM
-};
-
 class EventRetargeter {
 public:
     static void calculateEventPath(Node*, Event*, EventPath&);