Changeset 155264 in webkit


Ignore:
Timestamp:
Sep 7, 2013, 3:30:41 PM (11 years ago)
Author:
Antti Koivisto
Message:

Simplify ComposedShadowTreeWalker parent traversal
https://bugs.webkit.org/show_bug.cgi?id=120971

Reviewed by Andreas Kling.

Combine a bunch of parent traversal functions into one.

  • dom/ComposedShadowTreeWalker.cpp:

(WebCore::ComposedShadowTreeWalker::traverseParent):
(WebCore::ComposedShadowTreeWalker::previous):

  • dom/ComposedShadowTreeWalker.h:


Remove unused fromFirstChild.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155262 r155264  
     12013-09-07  Antti Koivisto  <antti@apple.com>
     2
     3        Simplify ComposedShadowTreeWalker parent traversal
     4        https://bugs.webkit.org/show_bug.cgi?id=120971
     5
     6        Reviewed by Andreas Kling.
     7
     8        Combine a bunch of parent traversal functions into one.
     9
     10        * dom/ComposedShadowTreeWalker.cpp:
     11        (WebCore::ComposedShadowTreeWalker::traverseParent):
     12        (WebCore::ComposedShadowTreeWalker::previous):
     13        * dom/ComposedShadowTreeWalker.h:
     14       
     15            Remove unused fromFirstChild.
     16
    1172013-09-07  Anders Carlsson  <andersca@apple.com>
    218
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp

    r154327 r155264  
    5353}
    5454
    55 ComposedShadowTreeWalker ComposedShadowTreeWalker::fromFirstChild(const Node* node, Policy policy)
    56 {
    57     ComposedShadowTreeWalker walker(node, policy);
    58     walker.firstChild();
    59     return walker;
    60 }
    61 
    6255void ComposedShadowTreeWalker::firstChild()
    6356{
     
    179172}
    180173
    181 inline Node* ComposedShadowTreeWalker::traverseNodeEscapingFallbackContents(const Node* node) const
    182 {
    183     ASSERT(node);
    184     if (!node->isInsertionPoint())
    185         return const_cast<Node*>(node);
    186     const InsertionPoint* insertionPoint = toInsertionPoint(node);
    187     return insertionPoint->hasDistribution() ? 0 :
    188         insertionPoint->isActive() ? traverseParent(node) : const_cast<Node*>(node);
    189 }
    190 
    191174void ComposedShadowTreeWalker::parent()
    192175{
     
    196179}
    197180
    198 // FIXME: Use an iterative algorithm so that it can be inlined.
    199 // https://bugs.webkit.org/show_bug.cgi?id=90415
    200181Node* ComposedShadowTreeWalker::traverseParent(const Node* node) const
    201182{
     
    209190        if (InsertionPoint* insertionPoint = findInsertionPointOf(node))
    210191            return traverseParent(insertionPoint);
    211         return 0;
    212     }
    213     return traverseParentInCurrentTree(node);
    214 }
    215 
    216 inline Node* ComposedShadowTreeWalker::traverseParentInCurrentTree(const Node* node) const
    217 {
    218     if (Node* parent = node->parentNode())
    219         return parent->isShadowRoot() ? traverseParentBackToShadowRootOrHost(toShadowRoot(parent)) : traverseNodeEscapingFallbackContents(parent);
    220     return 0;
    221 }
    222 
    223 Node* ComposedShadowTreeWalker::traverseParentBackToShadowRootOrHost(const ShadowRoot* shadowRoot) const
    224 {
    225     ASSERT(shadowRoot);
    226 
    227     if (canCrossUpperBoundary())
    228         return shadowRoot->hostElement();
    229 
    230     return const_cast<ShadowRoot*>(shadowRoot);
     192        return nullptr;
     193    }
     194    ContainerNode* parent = node->parentNode();
     195    if (!parent)
     196        return nullptr;
     197
     198    if (parent->isShadowRoot())
     199        return canCrossUpperBoundary() ? toShadowRoot(parent)->hostElement() : parent;
     200
     201    if (parent->isInsertionPoint()) {
     202        const InsertionPoint* insertionPoint = toInsertionPoint(parent);
     203        if (insertionPoint->hasDistribution())
     204            return nullptr;
     205        if (insertionPoint->isActive())
     206            return traverseParent(parent);
     207    }
     208    return parent;
    231209}
    232210
     
    267245        m_node = n;
    268246    } else
    269         parent();
     247        m_node = traverseParent(m_node);
    270248    assertPostcondition();
    271249}
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h

    r154327 r155264  
    5252
    5353    ComposedShadowTreeWalker(const Node*, Policy = CrossUpperBoundary, StartPolicy = CannotStartFromShadowBoundary);
    54 
    55     // For a common use case such as:
    56     // for (ComposedShadowTreeWalker walker = ComposedShadowTreeWalker::fromFirstChild(node); walker.get(); walker.nextSibling())
    57     static ComposedShadowTreeWalker fromFirstChild(const Node*, Policy = CrossUpperBoundary);
    5854
    5955    Node* get() const { return const_cast<Node*>(m_node); }
     
    116112    static Node* escapeFallbackContentElement(const Node*, TraversalDirection);
    117113
    118     Node* traverseNodeEscapingFallbackContents(const Node*) const;
    119     Node* traverseParentInCurrentTree(const Node*) const;
    120     Node* traverseParentBackToShadowRootOrHost(const ShadowRoot*) const;
    121 
    122114    const Node* m_node;
    123115    Policy m_policy;
Note: See TracChangeset for help on using the changeset viewer.