Move the rest of EventRetargeter functions to EventPath
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 19:49:24 +0000 (19:49 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 19:49:24 +0000 (19:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122586

Reviewed by Andreas Kling.

Moved the rest of EventRetargeter functiosn either static local or EventPath member functions.

* dom/EventDispatcher.cpp:
(WebCore::EventDispatcher::dispatchScopedEvent):
(WebCore::EventDispatcher::dispatch):
(WebCore::EventDispatcher::dispatchEventPostProcess):
* dom/EventDispatcher.h:
* dom/EventRetargeter.cpp:
(WebCore::EventPath::EventPath):
(WebCore::calculateAdjustedNodes): Made static local. Also takes const EventPath and returns the size
to which EventPath should be shrunk; this allows us to remove EventPath::shrink.
(WebCore::updateTouchListsInEventPath): Moved and renamed from EventRetargeter::adjustTouchList.
(WebCore::EventPath::updateTouchLists): Moved and renamed from EventRetargeter::adjustForTouchEvent.
(WebCore::EventPath::setRelatedTarget): Moved.
* dom/EventRetargeter.h:
(WebCore::eventTargetRespectingTargetRules): Renamed from EventRetargeter::eventTargetRespectingTargetRules.

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

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

index c89fe63..3b1844d 100644 (file)
@@ -1,3 +1,27 @@
+2013-10-10  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Move the rest of EventRetargeter functions to EventPath
+        https://bugs.webkit.org/show_bug.cgi?id=122586
+
+        Reviewed by Andreas Kling.
+
+        Moved the rest of EventRetargeter functiosn either static local or EventPath member functions.
+
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventDispatcher::dispatchScopedEvent):
+        (WebCore::EventDispatcher::dispatch):
+        (WebCore::EventDispatcher::dispatchEventPostProcess):
+        * dom/EventDispatcher.h:
+        * dom/EventRetargeter.cpp:
+        (WebCore::EventPath::EventPath):
+        (WebCore::calculateAdjustedNodes): Made static local. Also takes const EventPath and returns the size
+        to which EventPath should be shrunk; this allows us to remove EventPath::shrink.
+        (WebCore::updateTouchListsInEventPath): Moved and renamed from EventRetargeter::adjustTouchList.
+        (WebCore::EventPath::updateTouchLists): Moved and renamed from EventRetargeter::adjustForTouchEvent.
+        (WebCore::EventPath::setRelatedTarget): Moved.
+        * dom/EventRetargeter.h:
+        (WebCore::eventTargetRespectingTargetRules): Renamed from EventRetargeter::eventTargetRespectingTargetRules.
+
 2013-10-10  Mark Rowe  <mrowe@apple.com>
 
         <rdar://problem/13341666> WebKit should always build against an SDK.
index 4bc55a8..eac2eba 100644 (file)
@@ -70,7 +70,7 @@ EventDispatcher::EventDispatcher(Node* node, PassRefPtr<Event> event)
 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.
-    event->setTarget(&EventRetargeter::eventTargetRespectingTargetRules(node));
+    event->setTarget(&eventTargetRespectingTargetRules(node));
     ScopedEventQueue::instance()->enqueueEvent(event);
 }
 
@@ -165,7 +165,7 @@ bool EventDispatcher::dispatch()
         m_eventPath.setRelatedTarget(*relatedTarget);
 #if ENABLE(TOUCH_EVENTS)
     if (m_event->isTouchEvent())
-        EventRetargeter::adjustForTouchEvent(m_node.get(), *toTouchEvent(m_event.get()), m_eventPath); 
+        m_eventPath.updateTouchLists(*toTouchEvent(m_event.get())); 
 #endif
 
 #ifndef NDEBUG
@@ -175,7 +175,7 @@ bool EventDispatcher::dispatch()
     ChildNodesLazySnapshot::takeChildNodesLazySnapshot();
 
     ASSERT(m_node);
-    m_event->setTarget(&EventRetargeter::eventTargetRespectingTargetRules(*m_node));
+    m_event->setTarget(&eventTargetRespectingTargetRules(*m_node));
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
     ASSERT(m_event->target());
     WindowEventContext windowEventContext(m_event.get(), m_node.get(), topEventContext());
@@ -188,7 +188,7 @@ bool EventDispatcher::dispatch()
     if (!m_event->propagationStopped() && !m_eventPath.isEmpty())
         dispatchEventInDOM(*m_event, m_eventPath, windowEventContext);
 
-    m_event->setTarget(&EventRetargeter::eventTargetRespectingTargetRules(*m_node));
+    m_event->setTarget(&eventTargetRespectingTargetRules(*m_node));
     m_event->setCurrentTarget(0);
     m_event->setEventPhase(0);
 
index c1f4883..9f9a307 100644 (file)
@@ -59,14 +59,14 @@ public:
     size_t size() const { return m_path.size(); }
     const EventContext& contextAt(size_t i) const { return *m_path[i]; }
     EventContext& contextAt(size_t i) { return *m_path[i]; }
-    
+
+#if ENABLE(TOUCH_EVENTS)
+    void updateTouchLists(const TouchEvent&);
+#endif
     void setRelatedTarget(EventTarget&);
 
     bool hasEventListeners(const AtomicString& eventType) const;
 
-    // FIXME: We shouldn't expose this function.
-    void shrink(size_t newSize) { m_path.shrink(newSize); }
-
     EventContext* lastContextIfExists() { return m_path.isEmpty() ? 0 : m_path.last().get(); }
 
 private:
index ced8bd2..3eb304b 100644 (file)
@@ -88,9 +88,9 @@ EventPath::EventPath(Node& targetNode, Event& event)
     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 = &EventRetargeter::eventTargetRespectingTargetRules(*node);
+            target = &eventTargetRespectingTargetRules(*node);
         for (; node; node = node->parentNode()) {
-            EventTarget& currentTarget = EventRetargeter::eventTargetRespectingTargetRules(*node);
+            EventTarget& currentTarget = eventTargetRespectingTargetRules(*node);
             if (isMouseOrFocusEvent)
                 m_path.append(std::make_unique<MouseOrFocusEventContext>(node, &currentTarget, target));
 #if ENABLE(TOUCH_EVENTS)
@@ -110,56 +110,6 @@ EventPath::EventPath(Node& targetNode, Event& event)
     }
 }
 
-#if ENABLE(TOUCH_EVENTS)
-void EventRetargeter::adjustForTouchEvent(Node* node, const TouchEvent& touchEvent, EventPath& eventPath)
-{
-    size_t eventPathSize = eventPath.size();
-
-    EventPathTouchLists eventPathTouches(eventPathSize);
-    EventPathTouchLists eventPathTargetTouches(eventPathSize);
-    EventPathTouchLists eventPathChangedTouches(eventPathSize);
-
-    for (size_t i = 0; i < eventPathSize; ++i) {
-        TouchEventContext& context = toTouchEventContext(eventPath.contextAt(i));
-        eventPathTouches[i] = context.touches();
-        eventPathTargetTouches[i] = context.targetTouches();
-        eventPathChangedTouches[i] = context.changedTouches();
-    }
-
-    adjustTouchList(node, touchEvent.touches(), eventPath, eventPathTouches);
-    adjustTouchList(node, touchEvent.targetTouches(), eventPath, eventPathTargetTouches);
-    adjustTouchList(node, touchEvent.changedTouches(), eventPath, eventPathChangedTouches);
-}
-
-void EventRetargeter::adjustTouchList(const Node* node, const TouchList* touchList, const EventPath& eventPath, EventPathTouchLists& eventPathTouchLists)
-{
-    if (!touchList)
-        return;
-    size_t eventPathSize = eventPath.size();
-    ASSERT(eventPathTouchLists.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, const_cast<EventPath&>(eventPath), adjustedNodes);
-        ASSERT(adjustedNodes.size() == eventPathSize);
-        for (size_t j = 0; j < eventPathSize; ++j)
-            eventPathTouchLists[j]->append(touch.cloneWithNewTarget(adjustedNodes[j].get()));
-    }
-}
-#endif
-
-void EventPath::setRelatedTarget(EventTarget& relatedTarget)
-{
-    Node* relatedNode = relatedTarget.toNode();
-    if (!relatedNode)
-        return;
-    Vector<RefPtr<Node>> adjustedNodes;
-    EventRetargeter::calculateAdjustedNodes(m_origin.get(), relatedNode, EventRetargeter::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]);
-}
-
 static void buildRelatedNodeMap(const Node* relatedNode, HashMap<TreeScope*, Node*>& relatedNodeMap)
 {
     Node* relatedNodeInCurrentTree = 0;
@@ -196,7 +146,11 @@ static Node* addRelatedNodeForUnmapedTreeScopes(TreeScope* scope, HashMap<TreeSc
     return relatedNode;
 }
 
-void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior eventWithRelatedTargetDispatchBehavior, EventPath& eventPath, Vector<RefPtr<Node>>& adjustedNodes)
+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);
@@ -208,7 +162,7 @@ void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relat
     Node* adjustedNode = 0;
     size_t eventPathSize = eventPath.size();
     for (size_t i = 0; i < eventPathSize; i++) {
-        EventContext& context = eventPath.contextAt(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.
@@ -220,17 +174,67 @@ void EventRetargeter::calculateAdjustedNodes(const Node* node, const Node* relat
         if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
             continue;
         if (targetIsIdenticalToToRelatedTarget) {
-            if (node->treeScope().rootNode() == context.node()) {
-                eventPath.shrink(i + 1);
-                break;
-            }
+            if (node->treeScope().rootNode() == context.node())
+                return i + 1;
         } else if (context.target() == adjustedNode) {
             // Event dispatching should be stopped here.
-            eventPath.shrink(i);
             adjustedNodes.shrink(adjustedNodes.size() - 1);
-            break;
+            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]);
 }
 
 }
index dc7b609..a5338f4 100644 (file)
@@ -46,28 +46,7 @@ class TouchEvent;
 #endif
 class TreeScope;
 
-class EventRetargeter {
-public:
-#if ENABLE(TOUCH_EVENTS)
-    typedef Vector<RefPtr<TouchList> > EventPathTouchLists;
-    static void adjustForTouchEvent(Node*, const TouchEvent&, EventPath&);
-#endif
-    static EventTarget& eventTargetRespectingTargetRules(Node& referenceNode);
-
-private:
-    enum EventWithRelatedTargetDispatchBehavior {
-        StopAtBoundaryIfNeeded,
-        DoesNotStopAtBoundary
-    };
-    static void adjustForRelatedTarget(const Node*, EventTarget* relatedTarget, EventPath&);
-    static void calculateAdjustedNodes(const Node*, const Node* relatedNode, EventWithRelatedTargetDispatchBehavior, EventPath&, Vector<RefPtr<Node>>& adjustedNodes);
-#if ENABLE(TOUCH_EVENTS)
-    static void adjustTouchList(const Node*, const TouchList*, const EventPath&, EventPathTouchLists&);
-#endif
-    friend class EventPath;
-};
-
-inline EventTarget& EventRetargeter::eventTargetRespectingTargetRules(Node& referenceNode)
+inline EventTarget& eventTargetRespectingTargetRules(Node& referenceNode)
 {
     if (referenceNode.isPseudoElement()) {
         EventTarget* hostElement = toPseudoElement(referenceNode).hostElement();