Changeset 198992 in webkit


Ignore:
Timestamp:
Apr 3, 2016, 3:00:20 PM (9 years ago)
Author:
Antti Koivisto
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r198990 r198992  
     12016-04-03  Antti Koivisto  <antti@apple.com>
     2
     3        Tighten ComposedTreeAncestorIterator to return Elements
     4        https://bugs.webkit.org/show_bug.cgi?id=150324
     5
     6        Reviewed by Andreas Kling.
     7
     8        Only other thing it could credibly return was Document. We can exclude it from the composed tree and avoid some casting.
     9
     10        * dom/ComposedTreeAncestorIterator.h:
     11        (WebCore::ComposedTreeAncestorIterator::operator*):
     12        (WebCore::ComposedTreeAncestorIterator::operator->):
     13        (WebCore::ComposedTreeAncestorIterator::operator==):
     14        (WebCore::ComposedTreeAncestorIterator::operator!=):
     15        (WebCore::ComposedTreeAncestorIterator::operator++):
     16        (WebCore::ComposedTreeAncestorIterator::get):
     17        (WebCore::ComposedTreeAncestorIterator::ComposedTreeAncestorIterator):
     18        (WebCore::ComposedTreeAncestorIterator::traverseParent):
     19        (WebCore::ComposedTreeAncestorAdapter::begin):
     20        (WebCore::ComposedTreeAncestorAdapter::end):
     21        (WebCore::ComposedTreeAncestorAdapter::first):
     22        * dom/Element.cpp:
     23        (WebCore::Element::resolveComputedStyle):
     24        * dom/Node.cpp:
     25        (WebCore::Node::updateAncestorsForStyleRecalc):
     26        (WebCore::Node::setNeedsStyleRecalc):
     27        * rendering/RenderNamedFlowThread.cpp:
     28        (WebCore::RenderNamedFlowThread::isChildAllowed):
     29        (WebCore::RenderNamedFlowThread::dispatchRegionOversetChangeEventIfNeeded):
     30        * style/RenderTreeUpdater.cpp:
     31        (WebCore::findRenderingRoot):
     32        (WebCore::RenderTreeUpdater::commit):
     33
    1342016-04-03  Antti Koivisto  <antti@apple.com>
    235
  • trunk/Source/WebCore/dom/ComposedTreeAncestorIterator.h

    r191127 r198992  
    3737class ComposedTreeAncestorIterator {
    3838public:
    39     ComposedTreeAncestorIterator(ContainerNode& root);
    40     ComposedTreeAncestorIterator(ContainerNode& root, Node& current);
     39    ComposedTreeAncestorIterator();
     40    ComposedTreeAncestorIterator(Node& current);
    4141
    42     ContainerNode& operator*() { return get(); }
    43     ContainerNode* operator->() { return &get(); }
     42    Element& operator*() { return get(); }
     43    Element* operator->() { return &get(); }
    4444
    4545    bool operator==(const ComposedTreeAncestorIterator& other) const { return m_current == other.m_current; }
     
    4848    ComposedTreeAncestorIterator& operator++() { return traverseParent(); }
    4949
    50     ContainerNode& get() { return downcast<ContainerNode>(*m_current); }
     50    Element& get() { return downcast<Element>(*m_current); }
    5151    ComposedTreeAncestorIterator& traverseParent();
    5252
     
    5454    void traverseParentInShadowTree();
    5555
    56     ContainerNode& m_root;
    5756    Node* m_current { 0 };
    5857};
    5958
    60 inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(ContainerNode& root)
    61     : m_root(root)
     59inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator()
    6260{
    63     ASSERT(!is<ShadowRoot>(m_root));
    6461}
    6562
    66 inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(ContainerNode& root, Node& current)
    67     : m_root(root)
    68     , m_current(&current)
     63inline ComposedTreeAncestorIterator::ComposedTreeAncestorIterator(Node& current)
     64    : m_current(&current)
    6965{
    70     ASSERT(!is<ShadowRoot>(m_root));
    7166    ASSERT(!is<ShadowRoot>(m_current));
    7267}
     
    7469inline ComposedTreeAncestorIterator& ComposedTreeAncestorIterator::traverseParent()
    7570{
    76     if (m_current == &m_root) {
    77         m_current = nullptr;
    78         return *this;
    79     }
    80 
    8171    auto* parent = m_current->parentNode();
    8272    if (!parent) {
     
    8878        return *this;
    8979    }
     80    if (!is<Element>(*parent)) {
     81        m_current = nullptr;
     82        return *this;
     83    };
    9084
    9185    if (auto* shadowRoot = parent->shadowRoot()) {
     
    114108    {
    115109        if (is<ShadowRoot>(m_node))
    116             return iterator(m_node.document(), *downcast<ShadowRoot>(m_node).host());
     110            return iterator(*downcast<ShadowRoot>(m_node).host());
    117111        if (is<PseudoElement>(m_node))
    118             return iterator(m_node.document(), *downcast<PseudoElement>(m_node).hostElement());
    119         return iterator(m_node.document(), m_node).traverseParent();
     112            return iterator(*downcast<PseudoElement>(m_node).hostElement());
     113        return iterator(m_node).traverseParent();
    120114    }
    121115    iterator end()
    122116    {
    123         return iterator(m_node.document());
     117        return iterator();
    124118    }
    125     ContainerNode* first()
     119    Element* first()
    126120    {
    127121        auto it = begin();
  • trunk/Source/WebCore/dom/Element.cpp

    r198943 r198992  
    24842484    auto composedAncestors = composedTreeAncestors(*this);
    24852485    for (auto& ancestor : composedAncestors) {
    2486         if (!is<Element>(ancestor))
    2487             break;
    2488         auto& ancestorElement = downcast<Element>(ancestor);
    2489         elementsRequiringComputedStyle.prepend(&ancestorElement);
    2490         if (auto* existingStyle = ancestorElement.existingComputedStyle()) {
     2486        elementsRequiringComputedStyle.prepend(&ancestor);
     2487        if (auto* existingStyle = ancestor.existingComputedStyle()) {
    24912488            computedStyle = existingStyle;
    24922489            break;
  • trunk/Source/WebCore/dom/Node.cpp

    r198943 r198992  
    747747        it->setDirectChildNeedsStyleRecalc();
    748748
    749         if (is<Element>(*it) && downcast<Element>(*it).childrenAffectedByPropertyBasedBackwardPositionalRules()) {
     749        if (it->childrenAffectedByPropertyBasedBackwardPositionalRules()) {
    750750            if (it->styleChangeType() < FullStyleChange)
    751751                it->setStyleChange(FullStyleChange);
     
    762762    }
    763763
    764     Document& document = this->document();
    765     if (document.childNeedsStyleRecalc())
    766         document.scheduleStyleRecalc();
     764    auto* documentElement = document().documentElement();
     765    if (!documentElement)
     766        return;
     767    if (!documentElement->childNeedsStyleRecalc() && !documentElement->needsStyleRecalc())
     768        return;
     769    document().setChildNeedsStyleRecalc();
     770    document().scheduleStyleRecalc();
    767771}
    768772
  • trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp

    r197716 r198992  
    549549
    550550    auto* originalParent = composedTreeAncestors(*child.node()).first();
    551     if (!is<Element>(originalParent) || !originalParent->renderer())
     551    if (!originalParent || !originalParent->renderer())
    552552        return true;
    553553
    554     return downcast<Element>(*originalParent).renderer()->isChildAllowed(child, style);
     554    return originalParent->renderer()->isChildAllowed(child, style);
    555555}
    556556
  • trunk/Source/WebCore/style/RenderTreeUpdater.cpp

    r198990 r198992  
    6464static ContainerNode& findRenderingRoot(ContainerNode& node)
    6565{
    66     auto& document = node.document();
    67     for (ComposedTreeAncestorIterator it(document, node), end(document); it != end; ++it) {
    68         if (it->renderer())
    69             return *it;
    70         ASSERT(hasImplicitDisplayContents(downcast<Element>(*it)));
     66    if (node.renderer())
     67        return node;
     68    for (auto& ancestor : composedTreeAncestors(node)) {
     69        if (ancestor.renderer())
     70            return ancestor;
     71        ASSERT(hasImplicitDisplayContents(ancestor));
    7172    }
    7273    ASSERT_NOT_REACHED();
    73     return document;
     74    return node.document();
    7475}
    7576
Note: See TracChangeset for help on using the changeset viewer.