Title: [198992] trunk/Source/WebCore
Revision
198992
Author
[email protected]
Date
2016-04-03 15:00:20 -0700 (Sun, 03 Apr 2016)

Log Message

Tighten ComposedTreeAncestorIterator to return Elements
https://bugs.webkit.org/show_bug.cgi?id=150324

Reviewed by Andreas Kling.

Only other thing it could credibly return was Document. We can exclude it from the composed tree and avoid some casting.

* dom/ComposedTreeAncestorIterator.h:
(WebCore::ComposedTreeAncestorIterator::operator*):
(WebCore::ComposedTreeAncestorIterator::operator->):
(WebCore::ComposedTreeAncestorIterator::operator==):
(WebCore::ComposedTreeAncestorIterator::operator!=):
(WebCore::ComposedTreeAncestorIterator::operator++):
(WebCore::ComposedTreeAncestorIterator::get):
(WebCore::ComposedTreeAncestorIterator::ComposedTreeAncestorIterator):
(WebCore::ComposedTreeAncestorIterator::traverseParent):
(WebCore::ComposedTreeAncestorAdapter::begin):
(WebCore::ComposedTreeAncestorAdapter::end):
(WebCore::ComposedTreeAncestorAdapter::first):
* dom/Element.cpp:
(WebCore::Element::resolveComputedStyle):
* dom/Node.cpp:
(WebCore::Node::updateAncestorsForStyleRecalc):
(WebCore::Node::setNeedsStyleRecalc):
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::isChildAllowed):
(WebCore::RenderNamedFlowThread::dispatchRegionOversetChangeEventIfNeeded):
* style/RenderTreeUpdater.cpp:
(WebCore::findRenderingRoot):
(WebCore::RenderTreeUpdater::commit):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (198991 => 198992)


--- trunk/Source/WebCore/ChangeLog	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/ChangeLog	2016-04-03 22:00:20 UTC (rev 198992)
@@ -1,5 +1,38 @@
 2016-04-03  Antti Koivisto  <[email protected]>
 
+        Tighten ComposedTreeAncestorIterator to return Elements
+        https://bugs.webkit.org/show_bug.cgi?id=150324
+
+        Reviewed by Andreas Kling.
+
+        Only other thing it could credibly return was Document. We can exclude it from the composed tree and avoid some casting.
+
+        * dom/ComposedTreeAncestorIterator.h:
+        (WebCore::ComposedTreeAncestorIterator::operator*):
+        (WebCore::ComposedTreeAncestorIterator::operator->):
+        (WebCore::ComposedTreeAncestorIterator::operator==):
+        (WebCore::ComposedTreeAncestorIterator::operator!=):
+        (WebCore::ComposedTreeAncestorIterator::operator++):
+        (WebCore::ComposedTreeAncestorIterator::get):
+        (WebCore::ComposedTreeAncestorIterator::ComposedTreeAncestorIterator):
+        (WebCore::ComposedTreeAncestorIterator::traverseParent):
+        (WebCore::ComposedTreeAncestorAdapter::begin):
+        (WebCore::ComposedTreeAncestorAdapter::end):
+        (WebCore::ComposedTreeAncestorAdapter::first):
+        * dom/Element.cpp:
+        (WebCore::Element::resolveComputedStyle):
+        * dom/Node.cpp:
+        (WebCore::Node::updateAncestorsForStyleRecalc):
+        (WebCore::Node::setNeedsStyleRecalc):
+        * rendering/RenderNamedFlowThread.cpp:
+        (WebCore::RenderNamedFlowThread::isChildAllowed):
+        (WebCore::RenderNamedFlowThread::dispatchRegionOversetChangeEventIfNeeded):
+        * style/RenderTreeUpdater.cpp:
+        (WebCore::findRenderingRoot):
+        (WebCore::RenderTreeUpdater::commit):
+
+2016-04-03  Antti Koivisto  <[email protected]>
+
         Shadow DOM: Slot style is not computed
         https://bugs.webkit.org/show_bug.cgi?id=156144
 

Modified: trunk/Source/WebCore/dom/ComposedTreeAncestorIterator.h (198991 => 198992)


--- trunk/Source/WebCore/dom/ComposedTreeAncestorIterator.h	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/dom/ComposedTreeAncestorIterator.h	2016-04-03 22:00:20 UTC (rev 198992)
@@ -36,48 +36,38 @@
 
 class ComposedTreeAncestorIterator {
 public:
-    ComposedTreeAncestorIterator(ContainerNode& root);
-    ComposedTreeAncestorIterator(ContainerNode& root, Node& current);
+    ComposedTreeAncestorIterator();
+    ComposedTreeAncestorIterator(Node& current);
 
-    ContainerNode& operator*() { return get(); }
-    ContainerNode* operator->() { return &get(); }
+    Element& operator*() { return get(); }
+    Element* operator->() { return &get(); }
 
     bool operator==(const ComposedTreeAncestorIterator& other) const { return m_current == other.m_current; }
     bool operator!=(const ComposedTreeAncestorIterator& other) const { return m_current != other.m_current; }
 
     ComposedTreeAncestorIterator& operator++() { return traverseParent(); }
 
-    ContainerNode& get() { return downcast<ContainerNode>(*m_current); }
+    Element& get() { return downcast<Element>(*m_current); }
     ComposedTreeAncestorIterator& traverseParent();
 
 private:
     void traverseParentInShadowTree();
 
-    ContainerNode& m_root;
     Node* m_current { 0 };
 };
 
-inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(ContainerNode& root)
-    : m_root(root)
+inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator()
 {
-    ASSERT(!is<ShadowRoot>(m_root));
 }
 
-inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(ContainerNode& root, Node& current)
-    : m_root(root)
-    , m_current(&current)
+inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(Node& current)
+    : m_current(&current)
 {
-    ASSERT(!is<ShadowRoot>(m_root));
     ASSERT(!is<ShadowRoot>(m_current));
 }
 
 inline ComposedTreeAncestorIterator& ComposedTreeAncestorIterator::traverseParent()
 {
-    if (m_current == &m_root) {
-        m_current = nullptr;
-        return *this;
-    }
-
     auto* parent = m_current->parentNode();
     if (!parent) {
         m_current = nullptr;
@@ -87,6 +77,10 @@
         m_current = downcast<ShadowRoot>(*parent).host();
         return *this;
     }
+    if (!is<Element>(*parent)) {
+        m_current = nullptr;
+        return *this;
+    };
 
     if (auto* shadowRoot = parent->shadowRoot()) {
 #if ENABLE(SHADOW_DOM) || ENABLE(DETAILS_ELEMENT)
@@ -113,16 +107,16 @@
     iterator begin()
     {
         if (is<ShadowRoot>(m_node))
-            return iterator(m_node.document(), *downcast<ShadowRoot>(m_node).host());
+            return iterator(*downcast<ShadowRoot>(m_node).host());
         if (is<PseudoElement>(m_node))
-            return iterator(m_node.document(), *downcast<PseudoElement>(m_node).hostElement());
-        return iterator(m_node.document(), m_node).traverseParent();
+            return iterator(*downcast<PseudoElement>(m_node).hostElement());
+        return iterator(m_node).traverseParent();
     }
     iterator end()
     {
-        return iterator(m_node.document());
+        return iterator();
     }
-    ContainerNode* first()
+    Element* first()
     {
         auto it = begin();
         if (it == end())

Modified: trunk/Source/WebCore/dom/Element.cpp (198991 => 198992)


--- trunk/Source/WebCore/dom/Element.cpp	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-04-03 22:00:20 UTC (rev 198992)
@@ -2483,11 +2483,8 @@
     // Collect ancestors until we find one that has style.
     auto composedAncestors = composedTreeAncestors(*this);
     for (auto& ancestor : composedAncestors) {
-        if (!is<Element>(ancestor))
-            break;
-        auto& ancestorElement = downcast<Element>(ancestor);
-        elementsRequiringComputedStyle.prepend(&ancestorElement);
-        if (auto* existingStyle = ancestorElement.existingComputedStyle()) {
+        elementsRequiringComputedStyle.prepend(&ancestor);
+        if (auto* existingStyle = ancestor.existingComputedStyle()) {
             computedStyle = existingStyle;
             break;
         }

Modified: trunk/Source/WebCore/dom/Node.cpp (198991 => 198992)


--- trunk/Source/WebCore/dom/Node.cpp	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/dom/Node.cpp	2016-04-03 22:00:20 UTC (rev 198992)
@@ -746,7 +746,7 @@
     if (it != end) {
         it->setDirectChildNeedsStyleRecalc();
 
-        if (is<Element>(*it) && downcast<Element>(*it).childrenAffectedByPropertyBasedBackwardPositionalRules()) {
+        if (it->childrenAffectedByPropertyBasedBackwardPositionalRules()) {
             if (it->styleChangeType() < FullStyleChange)
                 it->setStyleChange(FullStyleChange);
         }
@@ -761,9 +761,13 @@
         }
     }
 
-    Document& document = this->document();
-    if (document.childNeedsStyleRecalc())
-        document.scheduleStyleRecalc();
+    auto* documentElement = document().documentElement();
+    if (!documentElement)
+        return;
+    if (!documentElement->childNeedsStyleRecalc() && !documentElement->needsStyleRecalc())
+        return;
+    document().setChildNeedsStyleRecalc();
+    document().scheduleStyleRecalc();
 }
 
 void Node::setNeedsStyleRecalc(StyleChangeType changeType)

Modified: trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp (198991 => 198992)


--- trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2016-04-03 22:00:20 UTC (rev 198992)
@@ -548,10 +548,10 @@
     ASSERT(is<Element>(*child.node()));
 
     auto* originalParent = composedTreeAncestors(*child.node()).first();
-    if (!is<Element>(originalParent) || !originalParent->renderer())
+    if (!originalParent || !originalParent->renderer())
         return true;
 
-    return downcast<Element>(*originalParent).renderer()->isChildAllowed(child, style);
+    return originalParent->renderer()->isChildAllowed(child, style);
 }
 
 void RenderNamedFlowThread::dispatchRegionOversetChangeEventIfNeeded()

Modified: trunk/Source/WebCore/style/RenderTreeUpdater.cpp (198991 => 198992)


--- trunk/Source/WebCore/style/RenderTreeUpdater.cpp	2016-04-03 21:19:58 UTC (rev 198991)
+++ trunk/Source/WebCore/style/RenderTreeUpdater.cpp	2016-04-03 22:00:20 UTC (rev 198992)
@@ -63,14 +63,15 @@
 
 static ContainerNode& findRenderingRoot(ContainerNode& node)
 {
-    auto& document = node.document();
-    for (ComposedTreeAncestorIterator it(document, node), end(document); it != end; ++it) {
-        if (it->renderer())
-            return *it;
-        ASSERT(hasImplicitDisplayContents(downcast<Element>(*it)));
+    if (node.renderer())
+        return node;
+    for (auto& ancestor : composedTreeAncestors(node)) {
+        if (ancestor.renderer())
+            return ancestor;
+        ASSERT(hasImplicitDisplayContents(ancestor));
     }
     ASSERT_NOT_REACHED();
-    return document;
+    return node.document();
 }
 
 void RenderTreeUpdater::commit(std::unique_ptr<const Style::Update> styleUpdate)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to