2011-03-24 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Mar 2011 22:20:17 +0000 (22:20 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Mar 2011 22:20:17 +0000 (22:20 +0000)
        Reviewed by Darin Adler.

        Untangle dependency between event ancestor chain computation and InspectorDOMAgent.
        https://bugs.webkit.org/show_bug.cgi?id=57050

        Inspector's list of event listeners does not need to invoke Node::getEventListeners,
        because it simply wants to collect all ancestors and never uses EventContext bits.

        No functional change, covered by existing tests.

        * dom/Node.cpp:
        (WebCore::getEventAncestors): Converted into a static function.
        (WebCore::Node::dispatchGenericEvent): Changed to pass node to getEventAncestors.
        * dom/Node.h: Removed decl, moved EventDispatchBehavior enum inside.
        * inspector/InspectorDOMAgent.cpp:
        (WebCore::InspectorDOMAgent::getEventListenersForNode): Replaced the call
            to getEventAncestors with a simple ancestor traversal loop.

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

Source/WebCore/ChangeLog
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/inspector/InspectorDOMAgent.cpp

index 574da9b..965b58c 100644 (file)
@@ -1,3 +1,23 @@
+2011-03-24  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Untangle dependency between event ancestor chain computation and InspectorDOMAgent.
+        https://bugs.webkit.org/show_bug.cgi?id=57050
+
+        Inspector's list of event listeners does not need to invoke Node::getEventListeners,
+        because it simply wants to collect all ancestors and never uses EventContext bits.
+
+        No functional change, covered by existing tests.
+
+        * dom/Node.cpp:
+        (WebCore::getEventAncestors): Converted into a static function.
+        (WebCore::Node::dispatchGenericEvent): Changed to pass node to getEventAncestors.
+        * dom/Node.h: Removed decl, moved EventDispatchBehavior enum inside.
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::getEventListenersForNode): Replaced the call
+            to getEventAncestors with a simple ancestor traversal loop.
+
 2011-03-24  Adam Klein  <adamk@chromium.org>
 
         Reviewed by David Levin.
index bde174d..e264a26 100644 (file)
@@ -2627,13 +2627,18 @@ static inline EventTarget* eventTargetRespectingSVGTargetRules(Node* referenceNo
     return referenceNode;
 }
 
-void Node::getEventAncestors(Vector<EventContext>& ancestors, EventTarget* originalTarget, EventDispatchBehavior behavior)
+enum EventDispatchBehavior {
+    RetargetEvent,
+    StayInsideShadowDOM
+};
+
+static void getEventAncestors(Node* node, Vector<EventContext>& ancestors, EventTarget* originalTarget, EventDispatchBehavior behavior)
 {
-    if (!inDocument())
+    if (!node->inDocument())
         return;
 
     EventTarget* target = originalTarget;
-    Node* ancestor = this;
+    Node* ancestor = node;
     bool shouldSkipNextAncestor = false;
     while (true) {
         if (ancestor->isShadowRoot()) {
@@ -2714,7 +2719,7 @@ bool Node::dispatchGenericEvent(PassRefPtr<Event> prpEvent)
     RefPtr<Node> thisNode(this);
     RefPtr<EventTarget> originalTarget = event->target();
     Vector<EventContext> ancestors;
-    getEventAncestors(ancestors, originalTarget.get(), determineDispatchBehavior(event.get()));
+    getEventAncestors(this, ancestors, originalTarget.get(), determineDispatchBehavior(event.get()));
 
     WindowEventContext windowContext(event.get(), this, topEventContext(ancestors));
 
index e3895a6..28eebb2 100644 (file)
@@ -87,11 +87,6 @@ enum StyleChangeType {
     SyntheticStyleChange = 3 << nodeStyleChangeShift
 };
 
-enum EventDispatchBehavior {
-    RetargetEvent,
-    StayInsideShadowDOM
-};
-
 class Node : public EventTarget, public TreeShared<ContainerNode>, public ScriptWrappable {
     friend class Document;
 public:
@@ -225,9 +220,6 @@ public:
     // Returns the enclosing event parent node (or self) that, when clicked, would trigger a navigation.
     Node* enclosingLinkEventParentOrSelf();
 
-    // Node ancestors when concerned about event flow.
-    void getEventAncestors(Vector<EventContext>& ancestors, EventTarget*, EventDispatchBehavior = RetargetEvent);
-
     bool isBlockFlow() const;
     bool isBlockFlowOrBlockTable() const;
     
index 6572005..5b32d9b 100644 (file)
@@ -745,18 +745,19 @@ void InspectorDOMAgent::getEventListenersForNode(ErrorString*, int nodeId, RefPt
     if (!eventTypesLength)
         return;
 
-    // The Node's Event Ancestors (not including self)
-    Vector<EventContext> ancestors;
-    node->getEventAncestors(ancestors, node);
+    // The Node's Ancestors (not including self)
+    Vector<ContainerNode*> ancestors;
+    for (ContainerNode* ancestor = node->parentOrHostNode(); ancestor; ancestor = ancestor->parentOrHostNode())
+        ancestors.append(ancestor);
 
     // Nodes and their Listeners for the concerned event types (order is top to bottom)
     Vector<EventListenerInfo> eventInformation;
     for (size_t i = ancestors.size(); i; --i) {
-        Node* ancestor = ancestors[i - 1].node();
+        ContainerNode* ancestor = ancestors[i - 1];
         for (size_t j = 0; j < eventTypesLength; ++j) {
             AtomicString& type = eventTypes[j];
             if (ancestor->hasEventListeners(type))
-                eventInformation.append(EventListenerInfo(static_cast<Node*>(ancestor), type, ancestor->getEventListeners(type)));
+                eventInformation.append(EventListenerInfo(ancestor, type, ancestor->getEventListeners(type)));
         }
     }