Remove EventRetargeter.h/cpp
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Oct 2013 01:14:04 +0000 (01:14 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Oct 2013 01:14:04 +0000 (01:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122625

Reviewed by Anders Carlsson.

Merged the remaining contents of EventRetargeter.h and EventRetargter.cpp into EventDispatcher.cpp.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Modules/indieui/UIRequestEvent.cpp:
* WebCore.xcodeproj/project.pbxproj:
* dom/DOMAllInOne.cpp:
* dom/Event.cpp:
* dom/Event.h:
* dom/EventDispatcher.cpp:
(WebCore::eventTargetRespectingTargetRules):
(WebCore::shouldEventCrossShadowBoundary):
(WebCore::nodeOrHostIfPseudoElement):
(WebCore::EventPath::EventPath):
(WebCore::buildRelatedNodeMap):
(WebCore::addRelatedNodeForUnmapedTreeScopes):
(WebCore::calculateAdjustedNodes):
(WebCore::updateTouchListsInEventPath):
(WebCore::EventPath::updateTouchLists):
(WebCore::EventPath::setRelatedTarget):
* dom/EventRetargeter.cpp: Removed.
* dom/EventRetargeter.h: Removed.
* dom/FocusEvent.cpp:
* dom/GestureEvent.h:
* dom/KeyboardEvent.h:
* dom/MouseEvent.cpp:
* dom/MouseEvent.h:
* dom/TouchEvent.cpp:
* dom/UIEvent.cpp:
* dom/WheelEvent.cpp:

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

19 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/indieui/UIRequestEvent.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/DOMAllInOne.cpp
Source/WebCore/dom/Event.cpp
Source/WebCore/dom/Event.h
Source/WebCore/dom/EventDispatcher.cpp
Source/WebCore/dom/EventRetargeter.cpp [deleted file]
Source/WebCore/dom/EventRetargeter.h [deleted file]
Source/WebCore/dom/FocusEvent.cpp
Source/WebCore/dom/GestureEvent.h
Source/WebCore/dom/KeyboardEvent.h
Source/WebCore/dom/MouseEvent.cpp
Source/WebCore/dom/MouseEvent.h
Source/WebCore/dom/TouchEvent.cpp
Source/WebCore/dom/UIEvent.cpp
Source/WebCore/dom/WheelEvent.cpp

index eaea22d..ce1a830 100644 (file)
@@ -1132,7 +1132,6 @@ set(WebCore_SOURCES
     dom/EventException.cpp
     dom/EventListenerMap.cpp
     dom/EventNames.cpp
-    dom/EventRetargeter.cpp
     dom/EventTarget.cpp
     dom/ExceptionBase.cpp
     dom/ExceptionCodePlaceholder.cpp
index d24f2bc..91ecb36 100644 (file)
@@ -1,3 +1,41 @@
+2013-10-10  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Remove EventRetargeter.h/cpp
+        https://bugs.webkit.org/show_bug.cgi?id=122625
+
+        Reviewed by Anders Carlsson.
+
+        Merged the remaining contents of EventRetargeter.h and EventRetargter.cpp into EventDispatcher.cpp.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Modules/indieui/UIRequestEvent.cpp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/DOMAllInOne.cpp:
+        * dom/Event.cpp:
+        * dom/Event.h:
+        * dom/EventDispatcher.cpp:
+        (WebCore::eventTargetRespectingTargetRules):
+        (WebCore::shouldEventCrossShadowBoundary):
+        (WebCore::nodeOrHostIfPseudoElement):
+        (WebCore::EventPath::EventPath):
+        (WebCore::buildRelatedNodeMap):
+        (WebCore::addRelatedNodeForUnmapedTreeScopes):
+        (WebCore::calculateAdjustedNodes):
+        (WebCore::updateTouchListsInEventPath):
+        (WebCore::EventPath::updateTouchLists):
+        (WebCore::EventPath::setRelatedTarget):
+        * dom/EventRetargeter.cpp: Removed.
+        * dom/EventRetargeter.h: Removed.
+        * dom/FocusEvent.cpp:
+        * dom/GestureEvent.h:
+        * dom/KeyboardEvent.h:
+        * dom/MouseEvent.cpp:
+        * dom/MouseEvent.h:
+        * dom/TouchEvent.cpp:
+        * dom/UIEvent.cpp:
+        * dom/WheelEvent.cpp:
+
 2013-10-10  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
 
         Making the base implementation of isAudioStreamSource, in MediaStreamSource, return the correct value
index 3384360..9591dae 100644 (file)
@@ -2833,8 +2833,6 @@ webcore_sources += \
        Source/WebCore/dom/EventListenerMap.h \
        Source/WebCore/dom/EventNames.cpp \
        Source/WebCore/dom/EventNames.h \
-       Source/WebCore/dom/EventRetargeter.cpp \
-       Source/WebCore/dom/EventRetargeter.h \
        Source/WebCore/dom/EventTarget.cpp \
        Source/WebCore/dom/EventTarget.h \
        Source/WebCore/dom/EventQueue.h \
index 5809ac3..c19feb0 100644 (file)
@@ -26,8 +26,6 @@
 #include "config.h"
 #include "UIRequestEvent.h"
 
-#include "EventDispatcher.h"
-
 #if ENABLE(INDIE_UI)
 
 namespace WebCore {
index 98781f8..c1dfb03 100644 (file)
                4A4F48AA16B0DFC000EDBB29 /* DocumentRuleSets.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A4F48A816B0DFC000EDBB29 /* DocumentRuleSets.h */; };
                4A5A2ADB161E7E00005889DD /* WebSocketExtensionParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A5A2AD9161E7E00005889DD /* WebSocketExtensionParser.cpp */; };
                4A5A2ADC161E7E00005889DD /* WebSocketExtensionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A5A2ADA161E7E00005889DD /* WebSocketExtensionParser.h */; };
-               4A5CB1C516C3A5FD00AB2886 /* EventRetargeter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A5CB1C316C3A5FD00AB2886 /* EventRetargeter.cpp */; };
-               4A5CB1C616C3A5FD00AB2886 /* EventRetargeter.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A5CB1C416C3A5FD00AB2886 /* EventRetargeter.h */; };
                4A6E9FC313C17D1D0046A7F8 /* CSSFontFeatureValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A6E9FC113C17D1D0046A7F8 /* CSSFontFeatureValue.cpp */; };
                4A6E9FC413C17D1D0046A7F8 /* CSSFontFeatureValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 4A6E9FC213C17D1D0046A7F8 /* CSSFontFeatureValue.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4A6E9FC713C17D570046A7F8 /* FontFeatureSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A6E9FC513C17D570046A7F8 /* FontFeatureSettings.cpp */; };
                4A4F48A816B0DFC000EDBB29 /* DocumentRuleSets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentRuleSets.h; sourceTree = "<group>"; };
                4A5A2AD9161E7E00005889DD /* WebSocketExtensionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebSocketExtensionParser.cpp; path = Modules/websockets/WebSocketExtensionParser.cpp; sourceTree = "<group>"; };
                4A5A2ADA161E7E00005889DD /* WebSocketExtensionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebSocketExtensionParser.h; path = Modules/websockets/WebSocketExtensionParser.h; sourceTree = "<group>"; };
-               4A5CB1C316C3A5FD00AB2886 /* EventRetargeter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventRetargeter.cpp; sourceTree = "<group>"; };
-               4A5CB1C416C3A5FD00AB2886 /* EventRetargeter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventRetargeter.h; sourceTree = "<group>"; };
                4A6E9FC113C17D1D0046A7F8 /* CSSFontFeatureValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFeatureValue.cpp; sourceTree = "<group>"; };
                4A6E9FC213C17D1D0046A7F8 /* CSSFontFeatureValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFeatureValue.h; sourceTree = "<group>"; };
                4A6E9FC513C17D570046A7F8 /* FontFeatureSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFeatureSettings.cpp; sourceTree = "<group>"; };
                                939885C208B7E3D100E707C4 /* EventNames.h */,
                                BC9A6142146859D9006057FD /* EventNames.in */,
                                8F6756191288B17B0047ACA3 /* EventQueue.h */,
-                               4A5CB1C316C3A5FD00AB2886 /* EventRetargeter.cpp */,
-                               4A5CB1C416C3A5FD00AB2886 /* EventRetargeter.h */,
                                CE5CB1B314EDAB6F00BB2795 /* EventSender.h */,
                                E12EDBE90B308E0B002704B6 /* EventTarget.cpp */,
                                E12EDB7A0B308A78002704B6 /* EventTarget.h */,
                                1CA19E160DC255CA0065A994 /* EventLoop.h in Headers */,
                                939885C408B7E3D100E707C4 /* EventNames.h in Headers */,
                                8F67561B1288B17B0047ACA3 /* EventQueue.h in Headers */,
-                               4A5CB1C616C3A5FD00AB2886 /* EventRetargeter.h in Headers */,
                                E0FEF372B17C53EAC1C1FBEE /* EventSource.h in Headers */,
                                E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */,
                                97AA3CA5145237CC003E1DA6 /* EventTargetHeaders.h in Headers */,
                                1CA19E050DC255950065A994 /* EventLoopMac.mm in Sources */,
                                939885C308B7E3D100E707C4 /* EventNames.cpp in Sources */,
                                07969DB917D14151007FF842 /* JSRTCPeerConnection.cpp in Sources */,
-                               4A5CB1C516C3A5FD00AB2886 /* EventRetargeter.cpp in Sources */,
                                E0FEF372B27C53EAC1C1FBEE /* EventSource.cpp in Sources */,
                                E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */,
                                BC60D8F20D2A11E000B9918F /* ExceptionBase.cpp in Sources */,
index f6e71a0..ae273bc 100644 (file)
@@ -76,7 +76,6 @@
 #include "EventException.cpp"
 #include "EventListenerMap.cpp"
 #include "EventNames.cpp"
-#include "EventRetargeter.cpp"
 #include "EventTarget.cpp"
 #include "ExceptionBase.cpp"
 #include "ExceptionCodePlaceholder.cpp"
index 0ec3d2a..df17f08 100644 (file)
@@ -23,7 +23,6 @@
 #include "config.h"
 #include "Event.h"
 
-#include "EventDispatcher.h"
 #include "EventNames.h"
 #include "EventTarget.h"
 #include "UserGestureIndicator.h"
index 536a92a..9cd6dcd 100644 (file)
@@ -36,7 +36,6 @@ namespace WebCore {
 
 class Clipboard;
 class EventTarget;
-class EventDispatcher;
 class HTMLIFrameElement;
 
 struct EventInit {
index a904c85..b40eb78 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2011, 2012, 2013 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -28,7 +28,6 @@
 
 #include "ContainerNode.h"
 #include "EventContext.h"
-#include "EventRetargeter.h"
 #include "FocusEvent.h"
 #include "FrameView.h"
 #include "HTMLInputElement.h"
 #include "InsertionPoint.h"
 #include "InspectorInstrumentation.h"
 #include "MouseEvent.h"
+#include "PseudoElement.h"
 #include "ScopedEventQueue.h"
 #include "ShadowRoot.h"
 #include "TouchEvent.h"
 #include "WindowEventContext.h"
 #include <wtf/RefPtr.h>
 
+#if ENABLE(SVG)
+#include "SVGElementInstance.h"
+#include "SVGNames.h"
+#include "SVGUseElement.h"
+#endif
+
 namespace WebCore {
 
+inline EventTarget& eventTargetRespectingTargetRules(Node& referenceNode)
+{
+    if (referenceNode.isPseudoElement()) {
+        EventTarget* hostElement = toPseudoElement(referenceNode).hostElement();
+        ASSERT(hostElement);
+        return *hostElement;
+    }
+
+#if ENABLE(SVG)
+    if (!referenceNode.isSVGElement() || !referenceNode.isInShadowTree())
+        return referenceNode;
+
+    // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
+    // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
+    Node* rootNode = referenceNode.treeScope().rootNode();
+    Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
+    // At this time, SVG nodes are not supported in non-<use> shadow trees.
+    if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
+        return referenceNode;
+    SVGUseElement* useElement = toSVGUseElement(shadowHostElement);
+    if (SVGElementInstance* instance = useElement->instanceForShadowTreeElement(&referenceNode))
+        return *instance;
+#endif
+
+    return referenceNode;
+}
+
 void EventDispatcher::dispatchScopedEvent(Node& node, PassRefPtr<Event> event)
 {
     // We need to set the target here because it can go away by the time we actually fire the event.
@@ -192,6 +225,207 @@ bool EventDispatcher::dispatchEvent(Node* origin, PassRefPtr<Event> prpEvent)
     return !event->defaultPrevented();
 }
 
+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 (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;
+        }
+    }
+#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();
+    bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
+    return !targetIsInShadowRoot
+        || !(eventType == eventNames().abortEvent
+            || eventType == eventNames().changeEvent
+            || eventType == eventNames().errorEvent
+            || eventType == eventNames().loadEvent
+            || eventType == eventNames().resetEvent
+            || eventType == eventNames().resizeEvent
+            || eventType == eventNames().scrollEvent
+            || eventType == eventNames().selectEvent
+            || eventType == eventNames().selectstartEvent);
+}
+
+static Node* nodeOrHostIfPseudoElement(Node* node)
+{
+    return node->isPseudoElement() ? toPseudoElement(node)->hostElement() : node;
+}
+
+EventPath::EventPath(Node& targetNode, Event& event)
+    : m_origin(&targetNode)
+{
+    bool inDocument = targetNode.inDocument();
+    bool isSVGElement = targetNode.isSVGElement();
+    bool isMouseOrFocusEvent = event.isMouseEvent() || event.isFocusEvent();
+#if ENABLE(TOUCH_EVENTS)
+    bool isTouchEvent = event.isTouchEvent();
+#endif
+    EventTarget* target = 0;
+
+    Node* node = nodeOrHostIfPseudoElement(&targetNode);
+    while (node) {
+        if (!target || !isSVGElement) // FIXME: This code doesn't make sense once we've climbed out of the SVG subtree in a HTML document.
+            target = &eventTargetRespectingTargetRules(*node);
+        for (; node; node = node->parentNode()) {
+            EventTarget& currentTarget = eventTargetRespectingTargetRules(*node);
+            if (isMouseOrFocusEvent)
+                m_path.append(std::make_unique<MouseOrFocusEventContext>(node, &currentTarget, target));
+#if ENABLE(TOUCH_EVENTS)
+            else if (isTouchEvent)
+                m_path.append(std::make_unique<TouchEventContext>(node, &currentTarget, target));
+#endif
+            else
+                m_path.append(std::make_unique<EventContext>(node, &currentTarget, target));
+            if (!inDocument)
+                return;
+            if (node->isShadowRoot())
+                break;
+        }
+        if (!node || !shouldEventCrossShadowBoundary(event, *toShadowRoot(node), *target))
+            return;
+        node = toShadowRoot(node)->hostElement();
+    }
+}
+
+static void buildRelatedNodeMap(const Node* relatedNode, HashMap<TreeScope*, Node*>& relatedNodeMap)
+{
+    Node* relatedNodeInCurrentTree = 0;
+    TreeScope* lastTreeScope = 0;
+    for (Node* node = nodeOrHostIfPseudoElement(const_cast<Node*>(relatedNode)); node; node = node->parentOrShadowHostNode()) {
+        if (!relatedNodeInCurrentTree)
+            relatedNodeInCurrentTree = node;
+        TreeScope* scope = &node->treeScope();
+        // Skips adding a node to the map if treeScope does not change. Just for the performance optimization.
+        if (scope != lastTreeScope)
+            relatedNodeMap.add(scope, relatedNodeInCurrentTree);
+        lastTreeScope = scope;
+        if (node->isShadowRoot()) {
+            ASSERT(relatedNodeInCurrentTree);
+            relatedNodeInCurrentTree = 0;
+        }
+    }
+}
+
+static Node* addRelatedNodeForUnmapedTreeScopes(TreeScope* scope, HashMap<TreeScope*, Node*>& relatedNodeMap)
+{
+    Node* relatedNode = 0;
+    TreeScope* endScope = 0;
+    for (TreeScope* currentScope = scope; currentScope; currentScope = currentScope->parentTreeScope()) {
+        auto result = relatedNodeMap.find(currentScope);
+        if (result != relatedNodeMap.end()) {
+            relatedNode = result->value;
+            endScope = currentScope;
+            break;
+        }
+    }
+    for (TreeScope* currentScope = scope; currentScope != endScope; currentScope = currentScope->parentTreeScope())
+        relatedNodeMap.add(currentScope, relatedNode);
+    return relatedNode;
+}
+
+enum EventWithRelatedTargetDispatchBehavior {
+    StopAtBoundaryIfNeeded,
+    DoesNotStopAtBoundary
+};
+static size_t calculateAdjustedNodes(const Node* node, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior eventWithRelatedTargetDispatchBehavior, const EventPath& eventPath, Vector<RefPtr<Node>>& adjustedNodes)
+{
+    HashMap<TreeScope*, Node*> relatedNodeMap;
+    buildRelatedNodeMap(relatedNode, relatedNodeMap);
+
+    // Synthetic mouse events can have a relatedTarget which is identical to the target.
+    bool targetIsIdenticalToToRelatedTarget = (node == relatedNode);
+
+    TreeScope* lastTreeScope = 0;
+    Node* adjustedNode = 0;
+    size_t eventPathSize = eventPath.size();
+    for (size_t i = 0; i < eventPathSize; i++) {
+        const EventContext& context = eventPath.contextAt(i);
+        TreeScope* scope = &context.node()->treeScope();
+
+        // Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
+        if (scope != lastTreeScope)
+            adjustedNode = addRelatedNodeForUnmapedTreeScopes(scope, relatedNodeMap);
+        adjustedNodes.append(adjustedNode);
+
+        lastTreeScope = scope;
+        if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
+            continue;
+        if (targetIsIdenticalToToRelatedTarget) {
+            if (node->treeScope().rootNode() == context.node())
+                return i + 1;
+        } else if (context.target() == adjustedNode) {
+            // Event dispatching should be stopped here.
+            adjustedNodes.shrink(adjustedNodes.size() - 1);
+            return i;
+        }
+    }
+    return eventPathSize;
+}
+
+#if ENABLE(TOUCH_EVENTS)
+static void updateTouchListsInEventPath(Vector<RefPtr<TouchList>>& touchListsInEventPath, const Node* node, const TouchList* touchList, const EventPath& eventPath)
+{
+    if (!touchList)
+        return;
+    size_t eventPathSize = eventPath.size();
+    ASSERT(touchListsInEventPath.size() == eventPathSize);
+    for (size_t i = 0; i < touchList->length(); ++i) {
+        const Touch& touch = *touchList->item(i);
+
+        Vector<RefPtr<Node>> adjustedNodes;
+        calculateAdjustedNodes(node, touch.target()->toNode(), DoesNotStopAtBoundary, eventPath, adjustedNodes);
+
+        ASSERT(adjustedNodes.size() == eventPathSize);
+        for (size_t j = 0; j < eventPathSize; ++j)
+            touchListsInEventPath[j]->append(touch.cloneWithNewTarget(adjustedNodes[j].get()));
+    }
+}
+
+void EventPath::updateTouchLists(const TouchEvent& touchEvent)
+{
+    size_t eventPathSize = m_path.size();
+
+    Vector<RefPtr<TouchList>> touchesInEventPath(eventPathSize);
+    Vector<RefPtr<TouchList>> targetTouchesInEventPath(eventPathSize);
+    Vector<RefPtr<TouchList>> changedTouchesInEventPath(eventPathSize);
+
+    for (size_t i = 0; i < eventPathSize; ++i) {
+        TouchEventContext& context = *toTouchEventContext(m_path[i].get());
+        touchesInEventPath[i] = context.touches();
+        targetTouchesInEventPath[i] = context.targetTouches();
+        changedTouchesInEventPath[i] = context.changedTouches();
+    }
+
+    updateTouchListsInEventPath(touchesInEventPath, m_origin.get(), touchEvent.touches(), *this);
+    updateTouchListsInEventPath(targetTouchesInEventPath, m_origin.get(), touchEvent.targetTouches(), *this);
+    updateTouchListsInEventPath(changedTouchesInEventPath, m_origin.get(), touchEvent.changedTouches(), *this);
+}
+#endif
+
+void EventPath::setRelatedTarget(EventTarget& relatedTarget)
+{
+    Node* relatedNode = relatedTarget.toNode();
+    if (!relatedNode)
+        return;
+    Vector<RefPtr<Node>> adjustedNodes;
+    m_path.shrink(calculateAdjustedNodes(m_origin.get(), relatedNode, StopAtBoundaryIfNeeded, *this, adjustedNodes));
+    ASSERT(adjustedNodes.size() <= m_path.size());
+    for (size_t i = 0; i < adjustedNodes.size(); ++i)
+        toMouseOrFocusEventContext(*m_path[i]).setRelatedTarget(adjustedNodes[i]);
+}
+
 bool EventPath::hasEventListeners(const AtomicString& eventType) const
 {
     for (size_t i = 0; i < m_path.size(); i++) {
diff --git a/Source/WebCore/dom/EventRetargeter.cpp b/Source/WebCore/dom/EventRetargeter.cpp
deleted file mode 100644 (file)
index 3eb304b..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "EventRetargeter.h"
-
-#include "ContainerNode.h"
-#include "EventContext.h"
-#include "EventDispatcher.h"
-#include "FocusEvent.h"
-#include "MouseEvent.h"
-#include "ShadowRoot.h"
-#include "Touch.h"
-#include "TouchEvent.h"
-#include "TouchList.h"
-#include "TreeScope.h"
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-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 (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;
-        }
-    }
-#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();
-    bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
-    return !targetIsInShadowRoot
-        || !(eventType == eventNames().abortEvent
-            || eventType == eventNames().changeEvent
-            || eventType == eventNames().errorEvent
-            || eventType == eventNames().loadEvent
-            || eventType == eventNames().resetEvent
-            || eventType == eventNames().resizeEvent
-            || eventType == eventNames().scrollEvent
-            || eventType == eventNames().selectEvent
-            || eventType == eventNames().selectstartEvent);
-}
-
-static Node* nodeOrHostIfPseudoElement(Node* node)
-{
-    return node->isPseudoElement() ? toPseudoElement(node)->hostElement() : node;
-}
-
-EventPath::EventPath(Node& targetNode, Event& event)
-    : m_origin(&targetNode)
-{
-    bool inDocument = targetNode.inDocument();
-    bool isSVGElement = targetNode.isSVGElement();
-    bool isMouseOrFocusEvent = event.isMouseEvent() || event.isFocusEvent();
-#if ENABLE(TOUCH_EVENTS)
-    bool isTouchEvent = event.isTouchEvent();
-#endif
-    EventTarget* target = 0;
-
-    Node* node = nodeOrHostIfPseudoElement(&targetNode);
-    while (node) {
-        if (!target || !isSVGElement) // FIXME: This code doesn't make sense once we've climbed out of the SVG subtree in a HTML document.
-            target = &eventTargetRespectingTargetRules(*node);
-        for (; node; node = node->parentNode()) {
-            EventTarget& currentTarget = eventTargetRespectingTargetRules(*node);
-            if (isMouseOrFocusEvent)
-                m_path.append(std::make_unique<MouseOrFocusEventContext>(node, &currentTarget, target));
-#if ENABLE(TOUCH_EVENTS)
-            else if (isTouchEvent)
-                m_path.append(std::make_unique<TouchEventContext>(node, &currentTarget, target));
-#endif
-            else
-                m_path.append(std::make_unique<EventContext>(node, &currentTarget, target));
-            if (!inDocument)
-                return;
-            if (node->isShadowRoot())
-                break;
-        }
-        if (!node || !shouldEventCrossShadowBoundary(event, *toShadowRoot(node), *target))
-            return;
-        node = toShadowRoot(node)->hostElement();
-    }
-}
-
-static void buildRelatedNodeMap(const Node* relatedNode, HashMap<TreeScope*, Node*>& relatedNodeMap)
-{
-    Node* relatedNodeInCurrentTree = 0;
-    TreeScope* lastTreeScope = 0;
-    for (Node* node = nodeOrHostIfPseudoElement(const_cast<Node*>(relatedNode)); node; node = node->parentOrShadowHostNode()) {
-        if (!relatedNodeInCurrentTree)
-            relatedNodeInCurrentTree = node;
-        TreeScope* scope = &node->treeScope();
-        // Skips adding a node to the map if treeScope does not change. Just for the performance optimization.
-        if (scope != lastTreeScope)
-            relatedNodeMap.add(scope, relatedNodeInCurrentTree);
-        lastTreeScope = scope;
-        if (node->isShadowRoot()) {
-            ASSERT(relatedNodeInCurrentTree);
-            relatedNodeInCurrentTree = 0;
-        }
-    }
-}
-
-static Node* addRelatedNodeForUnmapedTreeScopes(TreeScope* scope, HashMap<TreeScope*, Node*>& relatedNodeMap)
-{
-    Node* relatedNode = 0;
-    TreeScope* endScope = 0;
-    for (TreeScope* currentScope = scope; currentScope; currentScope = currentScope->parentTreeScope()) {
-        auto result = relatedNodeMap.find(currentScope);
-        if (result != relatedNodeMap.end()) {
-            relatedNode = result->value;
-            endScope = currentScope;
-            break;
-        }
-    }
-    for (TreeScope* currentScope = scope; currentScope != endScope; currentScope = currentScope->parentTreeScope())
-        relatedNodeMap.add(currentScope, relatedNode);
-    return relatedNode;
-}
-
-enum EventWithRelatedTargetDispatchBehavior {
-    StopAtBoundaryIfNeeded,
-    DoesNotStopAtBoundary
-};
-static size_t calculateAdjustedNodes(const Node* node, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior eventWithRelatedTargetDispatchBehavior, const EventPath& eventPath, Vector<RefPtr<Node>>& adjustedNodes)
-{
-    HashMap<TreeScope*, Node*> relatedNodeMap;
-    buildRelatedNodeMap(relatedNode, relatedNodeMap);
-
-    // Synthetic mouse events can have a relatedTarget which is identical to the target.
-    bool targetIsIdenticalToToRelatedTarget = (node == relatedNode);
-
-    TreeScope* lastTreeScope = 0;
-    Node* adjustedNode = 0;
-    size_t eventPathSize = eventPath.size();
-    for (size_t i = 0; i < eventPathSize; i++) {
-        const EventContext& context = eventPath.contextAt(i);
-        TreeScope* scope = &context.node()->treeScope();
-
-        // Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
-        if (scope != lastTreeScope)
-            adjustedNode = addRelatedNodeForUnmapedTreeScopes(scope, relatedNodeMap);
-        adjustedNodes.append(adjustedNode);
-
-        lastTreeScope = scope;
-        if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
-            continue;
-        if (targetIsIdenticalToToRelatedTarget) {
-            if (node->treeScope().rootNode() == context.node())
-                return i + 1;
-        } else if (context.target() == adjustedNode) {
-            // Event dispatching should be stopped here.
-            adjustedNodes.shrink(adjustedNodes.size() - 1);
-            return i;
-        }
-    }
-    return eventPathSize;
-}
-
-#if ENABLE(TOUCH_EVENTS)
-static void updateTouchListsInEventPath(Vector<RefPtr<TouchList>>& touchListsInEventPath, const Node* node, const TouchList* touchList, const EventPath& eventPath)
-{
-    if (!touchList)
-        return;
-    size_t eventPathSize = eventPath.size();
-    ASSERT(touchListsInEventPath.size() == eventPathSize);
-    for (size_t i = 0; i < touchList->length(); ++i) {
-        const Touch& touch = *touchList->item(i);
-
-        Vector<RefPtr<Node>> adjustedNodes;
-        calculateAdjustedNodes(node, touch.target()->toNode(), DoesNotStopAtBoundary, eventPath, adjustedNodes);
-
-        ASSERT(adjustedNodes.size() == eventPathSize);
-        for (size_t j = 0; j < eventPathSize; ++j)
-            touchListsInEventPath[j]->append(touch.cloneWithNewTarget(adjustedNodes[j].get()));
-    }
-}
-
-void EventPath::updateTouchLists(const TouchEvent& touchEvent)
-{
-    size_t eventPathSize = m_path.size();
-
-    Vector<RefPtr<TouchList>> touchesInEventPath(eventPathSize);
-    Vector<RefPtr<TouchList>> targetTouchesInEventPath(eventPathSize);
-    Vector<RefPtr<TouchList>> changedTouchesInEventPath(eventPathSize);
-
-    for (size_t i = 0; i < eventPathSize; ++i) {
-        TouchEventContext& context = *toTouchEventContext(m_path[i].get());
-        touchesInEventPath[i] = context.touches();
-        targetTouchesInEventPath[i] = context.targetTouches();
-        changedTouchesInEventPath[i] = context.changedTouches();
-    }
-
-    updateTouchListsInEventPath(touchesInEventPath, m_origin.get(), touchEvent.touches(), *this);
-    updateTouchListsInEventPath(targetTouchesInEventPath, m_origin.get(), touchEvent.targetTouches(), *this);
-    updateTouchListsInEventPath(changedTouchesInEventPath, m_origin.get(), touchEvent.changedTouches(), *this);
-}
-#endif
-
-void EventPath::setRelatedTarget(EventTarget& relatedTarget)
-{
-    Node* relatedNode = relatedTarget.toNode();
-    if (!relatedNode)
-        return;
-    Vector<RefPtr<Node>> adjustedNodes;
-    m_path.shrink(calculateAdjustedNodes(m_origin.get(), relatedNode, StopAtBoundaryIfNeeded, *this, adjustedNodes));
-    ASSERT(adjustedNodes.size() <= m_path.size());
-    for (size_t i = 0; i < adjustedNodes.size(); ++i)
-        toMouseOrFocusEventContext(*m_path[i]).setRelatedTarget(adjustedNodes[i]);
-}
-
-}
diff --git a/Source/WebCore/dom/EventRetargeter.h b/Source/WebCore/dom/EventRetargeter.h
deleted file mode 100644 (file)
index a5338f4..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2013 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef EventRetargeter_h
-#define EventRetargeter_h
-
-#include "ContainerNode.h"
-#include "EventContext.h"
-#include "PseudoElement.h"
-#include "ShadowRoot.h"
-#include <wtf/HashMap.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-
-#if ENABLE(SVG)
-#include "SVGElementInstance.h"
-#include "SVGNames.h"
-#include "SVGUseElement.h"
-#endif
-
-namespace WebCore {
-
-class EventPath;
-class EventTarget;
-class FocusEvent;
-class MouseEvent;
-class Node;
-#if ENABLE(TOUCH_EVENTS)
-class TouchEvent;
-#endif
-class TreeScope;
-
-inline EventTarget& eventTargetRespectingTargetRules(Node& referenceNode)
-{
-    if (referenceNode.isPseudoElement()) {
-        EventTarget* hostElement = toPseudoElement(referenceNode).hostElement();
-        ASSERT(hostElement);
-        return *hostElement;
-    }
-
-#if ENABLE(SVG)
-    if (!referenceNode.isSVGElement() || !referenceNode.isInShadowTree())
-        return referenceNode;
-
-    // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
-    // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
-    Node* rootNode = referenceNode.treeScope().rootNode();
-    Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
-    // At this time, SVG nodes are not supported in non-<use> shadow trees.
-    if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
-        return referenceNode;
-    SVGUseElement* useElement = toSVGUseElement(shadowHostElement);
-    if (SVGElementInstance* instance = useElement->instanceForShadowTreeElement(&referenceNode))
-        return *instance;
-#endif
-
-    return referenceNode;
-}
-
-}
-
-#endif // EventRetargeter_h
index 26ccf33..68c8362 100644 (file)
@@ -27,9 +27,7 @@
 #include "FocusEvent.h"
 
 #include "Event.h"
-#include "EventDispatcher.h"
 #include "EventNames.h"
-#include "EventRetargeter.h"
 #include "Node.h"
 
 namespace WebCore {
index e34e74e..be3f2d5 100644 (file)
@@ -29,7 +29,6 @@
 
 #if ENABLE(GESTURE_EVENTS)
 
-#include "EventDispatcher.h"
 #include "EventNames.h"
 #include "Frame.h"
 #include "FrameView.h"
index be44505..d22694b 100644 (file)
@@ -29,7 +29,6 @@
 
 namespace WebCore {
 
-class EventDispatcher;
 class Node;
 class PlatformKeyboardEvent;
 
index 52e9fd4..bf476c5 100644 (file)
@@ -24,9 +24,7 @@
 #include "MouseEvent.h"
 
 #include "Clipboard.h"
-#include "EventDispatcher.h"
 #include "EventNames.h"
-#include "EventRetargeter.h"
 #include "Frame.h"
 #include "FrameView.h"
 #include "HTMLIFrameElement.h"
index bb9a627..1568972 100644 (file)
@@ -29,7 +29,6 @@
 namespace WebCore {
 
 class Clipboard;
-class EventDispatcher;
 class PlatformMouseEvent;
 
 struct MouseEventInit : public UIEventInit {
index 0cab8e7..649de2a 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "EventDispatcher.h"
 #include "EventNames.h"
-#include "EventRetargeter.h"
 #include "TouchList.h"
 #include <wtf/CurrentTime.h>
 
index f43c378..f06bb00 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "Console.h"
 #include "DOMWindow.h"
-#include "EventDispatcher.h"
 #include "Node.h"
 
 namespace WebCore {
index a9acbb7..ee672cb 100644 (file)
@@ -25,7 +25,6 @@
 #include "WheelEvent.h"
 
 #include "Clipboard.h"
-#include "EventDispatcher.h"
 #include "EventNames.h"
 #include "PlatformWheelEvent.h"