Title: [118890] trunk/Source/WebCore
Revision
118890
Author
[email protected]
Date
2012-05-29 21:20:02 -0700 (Tue, 29 May 2012)

Log Message

Introduces ComposedShadowTreeParentWalker, extracted from ComposedShadowTreeWalker.
https://bugs.webkit.org/show_bug.cgi?id=87004

Reviewed by Dimitri Glazkov.

Introduces a ComposedShadowTreeParentWalker, which is only used
for traversing a parent node (including shadow roots and insertion
points) and get rid of an equivalent function from
ComposedShadowTreeWalker.

Before this patch, there is an inconsistency inside of
ComposedShadowTreeWalker. The Walker uses 'Policy' to decide
whether it should visit shadow roots or not, but
parentIncludingInsertionPointAndShadowRoot() member function
ignores the policy.  We can not add an assertion in its
constructor due to this inconsistency.  To resolve it, we could
add yet another special policy, but that makes the implementation
complex and may add some overhead in runtime.  So separate the
functionality into another class as ComposedShadowTreeParentWalker.

No new tests, no new functionality except for assertion.

* dom/ComposedShadowTreeWalker.cpp:
(WebCore::ComposedShadowTreeWalker::ComposedShadowTreeWalker):
(WebCore::ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker):
(WebCore):
(WebCore::ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot):
(WebCore::ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot):
* dom/ComposedShadowTreeWalker.h:
(ComposedShadowTreeWalker):
(WebCore::ComposedShadowTreeWalker::assertPrecondition):
(WebCore):
(ComposedShadowTreeParentWalker):
(WebCore::ComposedShadowTreeParentWalker::get):
* dom/EventDispatcher.cpp:
(WebCore::EventRelatedTargetAdjuster::adjust):
(WebCore::EventDispatcher::ensureEventAncestors):
* page/EventHandler.cpp:
(WebCore::EventHandler::updateMouseEventTargetNode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118889 => 118890)


--- trunk/Source/WebCore/ChangeLog	2012-05-30 04:05:53 UTC (rev 118889)
+++ trunk/Source/WebCore/ChangeLog	2012-05-30 04:20:02 UTC (rev 118890)
@@ -1,5 +1,47 @@
 2012-05-29  Hayato Ito  <[email protected]>
 
+        Introduces ComposedShadowTreeParentWalker, extracted from ComposedShadowTreeWalker.
+        https://bugs.webkit.org/show_bug.cgi?id=87004
+
+        Reviewed by Dimitri Glazkov.
+
+        Introduces a ComposedShadowTreeParentWalker, which is only used
+        for traversing a parent node (including shadow roots and insertion
+        points) and get rid of an equivalent function from
+        ComposedShadowTreeWalker.
+
+        Before this patch, there is an inconsistency inside of
+        ComposedShadowTreeWalker. The Walker uses 'Policy' to decide
+        whether it should visit shadow roots or not, but
+        parentIncludingInsertionPointAndShadowRoot() member function
+        ignores the policy.  We can not add an assertion in its
+        constructor due to this inconsistency.  To resolve it, we could
+        add yet another special policy, but that makes the implementation
+        complex and may add some overhead in runtime.  So separate the
+        functionality into another class as ComposedShadowTreeParentWalker.
+
+        No new tests, no new functionality except for assertion.
+
+        * dom/ComposedShadowTreeWalker.cpp:
+        (WebCore::ComposedShadowTreeWalker::ComposedShadowTreeWalker):
+        (WebCore::ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker):
+        (WebCore):
+        (WebCore::ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot):
+        (WebCore::ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot):
+        * dom/ComposedShadowTreeWalker.h:
+        (ComposedShadowTreeWalker):
+        (WebCore::ComposedShadowTreeWalker::assertPrecondition):
+        (WebCore):
+        (ComposedShadowTreeParentWalker):
+        (WebCore::ComposedShadowTreeParentWalker::get):
+        * dom/EventDispatcher.cpp:
+        (WebCore::EventRelatedTargetAdjuster::adjust):
+        (WebCore::EventDispatcher::ensureEventAncestors):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::updateMouseEventTargetNode):
+
+2012-05-29  Hayato Ito  <[email protected]>
+
         Add assertions to make sure that event's target and relatedTarget are accessible.
         https://bugs.webkit.org/show_bug.cgi?id=87641
 

Modified: trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp (118889 => 118890)


--- trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2012-05-30 04:05:53 UTC (rev 118889)
+++ trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp	2012-05-30 04:20:02 UTC (rev 118890)
@@ -52,8 +52,10 @@
     : m_node(node)
     , m_policy(policy)
 {
-    // FIXME: Refactor ComposedShadowTreeWalker so that we can assert node here.
-    // https://bugs.webkit.org/show_bug.cgi?id=87004
+#ifndef NDEBUG
+    if (m_node)
+        assertPrecondition();
+#endif
 }
 
 ComposedShadowTreeWalker ComposedShadowTreeWalker::fromFirstChild(const Node* node, Policy policy)
@@ -198,28 +200,6 @@
     assertPostcondition();
 }
 
-void ComposedShadowTreeWalker::parentIncludingInsertionPointAndShadowRoot()
-{
-    ASSERT(m_node);
-    m_node = traverseParentIncludingInsertionPointAndShadowRoot(m_node);
-}
-
-Node* ComposedShadowTreeWalker::traverseParentIncludingInsertionPointAndShadowRoot(const Node* node) const
-{
-    if (ElementShadow* shadow = shadowOfParent(node)) {
-        if (InsertionPoint* insertionPoint = shadow->insertionPointFor(node))
-            return insertionPoint;
-    }
-    if (!node->isShadowRoot())
-        return node->parentNode();
-    const ShadowRoot* shadowRoot = toShadowRoot(node);
-    if (shadowRoot->isYoungest())
-        return shadowRoot->host();
-    InsertionPoint* assignedInsertionPoint = shadowRoot->assignedTo();
-    ASSERT(assignedInsertionPoint);
-    return assignedInsertionPoint;
-}
-
 Node* ComposedShadowTreeWalker::traverseParent(const Node* node) const
 {
     if (!canCrossUpperBoundary() && node->isShadowRoot()) {
@@ -293,4 +273,31 @@
     assertPostcondition();
 }
 
+ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker(const Node* node)
+    : m_node(node)
+{
+}
+
+void ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot()
+{
+    ASSERT(m_node);
+    m_node = traverseParentIncludingInsertionPointAndShadowRoot(m_node);
+}
+
+Node* ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot(const Node* node) const
+{
+    if (ElementShadow* shadow = shadowOfParent(node)) {
+        if (InsertionPoint* insertionPoint = shadow->insertionPointFor(node))
+            return insertionPoint;
+    }
+    if (!node->isShadowRoot())
+        return node->parentNode();
+    const ShadowRoot* shadowRoot = toShadowRoot(node);
+    if (shadowRoot->isYoungest())
+        return shadowRoot->host();
+    InsertionPoint* assignedInsertionPoint = shadowRoot->assignedTo();
+    ASSERT(assignedInsertionPoint);
+    return assignedInsertionPoint;
+}
+
 } // namespace

Modified: trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h (118889 => 118890)


--- trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h	2012-05-30 04:05:53 UTC (rev 118889)
+++ trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h	2012-05-30 04:20:02 UTC (rev 118890)
@@ -59,8 +59,6 @@
     void previousSibling();
 
     void parent();
-    // This function ignores policy and always crosses an upper boundary.
-    void parentIncludingInsertionPointAndShadowRoot();
 
     void next();
     void previous();
@@ -81,7 +79,7 @@
             ASSERT(!m_node->isShadowRoot());
         else
             ASSERT(!m_node->isShadowRoot() || toShadowRoot(m_node)->isYoungest());
-        ASSERT(!isInsertionPoint(m_node) || !toInsertionPoint(m_node)->isActive());
+        ASSERT(!isActiveInsertionPoint(m_node));
 #endif
     }
 
@@ -100,7 +98,6 @@
     Node* traverseLastChild(const Node*) const;
     Node* traverseChild(const Node*, TraversalDirection) const;
     Node* traverseParent(const Node*) const;
-    Node* traverseParentIncludingInsertionPointAndShadowRoot(const Node*) const;
 
     static Node* traverseNextSibling(const Node*);
     static Node* traversePreviousSibling(const Node*);
@@ -119,6 +116,18 @@
     Policy m_policy;
 };
 
+// A special walker class which is only used for traversing a parent node, including
+// insertion points and shadow roots.
+class ComposedShadowTreeParentWalker {
+public:
+    ComposedShadowTreeParentWalker(const Node*);
+    void parentIncludingInsertionPointAndShadowRoot();
+    Node* get() const { return const_cast<Node*>(m_node); }
+private:
+    Node* traverseParentIncludingInsertionPointAndShadowRoot(const Node*) const;
+    const Node* m_node;
+};
+
 } // namespace
 
 #endif

Modified: trunk/Source/WebCore/dom/EventDispatcher.cpp (118889 => 118890)


--- trunk/Source/WebCore/dom/EventDispatcher.cpp	2012-05-30 04:05:53 UTC (rev 118889)
+++ trunk/Source/WebCore/dom/EventDispatcher.cpp	2012-05-30 04:20:02 UTC (rev 118890)
@@ -62,7 +62,7 @@
 void EventRelatedTargetAdjuster::adjust(Vector<EventContext>& ancestors)
 {
     TreeScope* lastTreeScope = 0;
-    for (ComposedShadowTreeWalker walker(m_relatedTarget.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
+    for (ComposedShadowTreeParentWalker walker(m_relatedTarget.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
         TreeScope* scope = walker.get()->treeScope();
         // Skips adding a node to the map if treeScope does not change.
         if (scope != lastTreeScope)
@@ -203,7 +203,7 @@
     bool inDocument = m_node->inDocument();
     bool isSVGElement = m_node->isSVGElement();
     Vector<EventTarget*> targetStack;
-    for (ComposedShadowTreeWalker walker(m_node.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
+    for (ComposedShadowTreeParentWalker walker(m_node.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
         Node* node = walker.get();
         if (isActiveInsertionPoint(node) || targetStack.isEmpty())
             targetStack.append(eventTargetRespectingSVGTargetRules(node));

Modified: trunk/Source/WebCore/page/EventHandler.cpp (118889 => 118890)


--- trunk/Source/WebCore/page/EventHandler.cpp	2012-05-30 04:05:53 UTC (rev 118889)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2012-05-30 04:20:02 UTC (rev 118890)
@@ -2118,7 +2118,7 @@
     else {
         // If the target node is a text node, dispatch on the parent node - rdar://4196646
         if (result && result->isTextNode()) {
-            ComposedShadowTreeWalker walker(result);
+            ComposedShadowTreeParentWalker walker(result);
             walker.parentIncludingInsertionPointAndShadowRoot();
             result = walker.get();
         }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to