Changeset 157368 in webkit


Ignore:
Timestamp:
Oct 13, 2013 6:26:07 AM (11 years ago)
Author:
Antti Koivisto
Message:

Add traverseNextSkippingChildren to ElementIterators
https://bugs.webkit.org/show_bug.cgi?id=122727

Reviewed by Andreas Kling.

Also switch some code using ElementTraversal over to iterators.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r157367 r157368  
     12013-10-13  Antti Koivisto  <antti@apple.com>
     2
     3        Add traverseNextSkippingChildren to ElementIterators
     4        https://bugs.webkit.org/show_bug.cgi?id=122727
     5
     6        Reviewed by Andreas Kling.
     7
     8        Also switch some code using ElementTraversal over to iterators.
     9
    1102013-10-13  Antti Koivisto  <antti@apple.com>
    211
  • trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp

    r153939 r157368  
    2929#include "CSSSelectorList.h"
    3030#include "Document.h"
    31 #include "ElementTraversal.h"
     31#include "ElementIterator.h"
    3232#include "StyleRuleImport.h"
    3333#include "StyleSheetContents.h"
     
    9999}
    100100
    101 static bool elementMatchesSelectorScopes(const Element* element, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes)
     101static bool elementMatchesSelectorScopes(const Element& element, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes)
    102102{
    103     if (!idScopes.isEmpty() && element->hasID() && idScopes.contains(element->idForStyleResolution().impl()))
     103    if (!idScopes.isEmpty() && element.hasID() && idScopes.contains(element.idForStyleResolution().impl()))
    104104        return true;
    105     if (classScopes.isEmpty() || !element->hasClass())
     105    if (classScopes.isEmpty() || !element.hasClass())
    106106        return false;
    107     const SpaceSplitString& classNames = element->classNames();
     107    const SpaceSplitString& classNames = element.classNames();
    108108    for (unsigned i = 0; i < classNames.size(); ++i) {
    109109        if (classScopes.contains(classNames[i].impl()))
     
    118118    if (m_idScopes.isEmpty() && m_classScopes.isEmpty())
    119119        return;
    120     Element* element = ElementTraversal::firstWithin(document);
    121     while (element) {
    122         if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) {
    123             element->setNeedsStyleRecalc();
     120
     121    auto it = elementDescendants(document).begin();
     122    auto end = elementDescendants(document).end();
     123    while (it != end) {
     124        if (elementMatchesSelectorScopes(*it, m_idScopes, m_classScopes)) {
     125            it->setNeedsStyleRecalc();
    124126            // The whole subtree is now invalidated, we can skip to the next sibling.
    125             element = ElementTraversal::nextSkippingChildren(element);
     127            it.traverseNextSkippingChildren();
    126128            continue;
    127129        }
    128         element = ElementTraversal::next(element);
     130        ++it;
    129131    }
    130132}
  • trunk/Source/WebCore/dom/ElementIterator.h

    r154940 r157368  
    5151    ElementIterator& traverseNextSibling();
    5252    ElementIterator& traversePreviousSibling();
     53    ElementIterator& traverseNextSkippingChildren();
    5354    ElementIterator& traverseAncestor();
    5455
     
    7879    ElementConstIterator& traverseNextSibling();
    7980    ElementConstIterator& traversePreviousSibling();
     81    ElementConstIterator& traverseNextSkippingChildren();
    8082    ElementConstIterator& traverseAncestor();
    8183
     
    156158    ASSERT(!m_assertions.domTreeHasMutated());
    157159    m_current = Traversal<ElementType>::previousSibling(m_current);
     160#if !ASSERT_DISABLED
     161    // Drop the assertion when the iterator reaches the end.
     162    if (!m_current)
     163        m_assertions.dropEventDispatchAssertion();
     164#endif
     165    return *this;
     166}
     167
     168template <typename ElementType>
     169inline ElementIterator<ElementType>& ElementIterator<ElementType>::traverseNextSkippingChildren()
     170{
     171    ASSERT(m_current);
     172    ASSERT(!m_assertions.domTreeHasMutated());
     173    m_current = Traversal<ElementType>::nextSkippingChildren(m_current, m_root);
    158174#if !ASSERT_DISABLED
    159175    // Drop the assertion when the iterator reaches the end.
     
    301317
    302318template <typename ElementType>
     319inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::traverseNextSkippingChildren()
     320{
     321    ASSERT(m_current);
     322    ASSERT(!m_assertions.domTreeHasMutated());
     323    m_current = Traversal<ElementType>::nextSkippingChildren(m_current, m_root);
     324#if !ASSERT_DISABLED
     325    // Drop the assertion when the iterator reaches the end.
     326    if (!m_current)
     327        m_assertions.dropEventDispatchAssertion();
     328#endif
     329    return *this;
     330}
     331
     332template <typename ElementType>
    303333inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::traverseAncestor()
    304334{
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r157338 r157368  
    3737#include "DocumentFragment.h"
    3838#include "Element.h"
     39#include "ElementIterator.h"
    3940#include "EventNames.h"
    4041#include "ExceptionCodePlaceholder.h"
     
    7576public:
    7677    ReplacementFragment(Document&, DocumentFragment*, const VisibleSelection&);
     78
     79    DocumentFragment* fragment() { return m_fragment.get(); }
    7780
    7881    Node* firstChild() const;
     
    705708static void removeHeadContents(ReplacementFragment& fragment)
    706709{
    707     Node* next = 0;
    708     for (Node* node = fragment.firstChild(); node; node = next) {
    709         if (node->hasTagName(baseTag)
    710             || node->hasTagName(linkTag)
    711             || node->hasTagName(metaTag)
    712             || node->hasTagName(styleTag)
    713             || isHTMLTitleElement(node)) {
    714             next = NodeTraversal::nextSkippingChildren(node);
    715             fragment.removeNode(node);
    716         } else
    717             next = NodeTraversal::next(node);
    718     }
     710    if (fragment.isEmpty())
     711        return;
     712
     713    Vector<Element*> toRemove;
     714
     715    auto it = elementDescendants(fragment.fragment()).begin();
     716    auto end = elementDescendants(fragment.fragment()).end();
     717    while (it != end) {
     718        if (it->hasTagName(baseTag) || it->hasTagName(linkTag) || it->hasTagName(metaTag) || it->hasTagName(styleTag) || isHTMLTitleElement(*it)) {
     719            toRemove.append(&*it);
     720            it.traverseNextSkippingChildren();
     721            continue;
     722        }
     723        ++it;
     724    }
     725
     726    for (unsigned i = 0; i < toRemove.size(); ++i)
     727        fragment.removeNode(toRemove[i]);
    719728}
    720729
  • trunk/Source/WebCore/svg/SVGUseElement.cpp

    r157223 r157368  
    664664{
    665665    ASSERT(!subtree.inDocument());
    666     Element* element = ElementTraversal::firstWithin(&subtree);
    667     while (element) {
    668         if (isDisallowedElement(*element)) {
    669             Element* next = ElementTraversal::nextSkippingChildren(element, &subtree);
    670             // The subtree is not in document so this won't generate events that could mutate the tree.
    671             element->parentNode()->removeChild(element);
    672             element = next;
    673         } else
    674             element = ElementTraversal::next(element, &subtree);
    675     }
     666    Vector<Element*> toRemove;
     667    auto it = elementDescendants(&subtree).begin();
     668    auto end = elementDescendants(&subtree).end();
     669    while (it != end) {
     670        if (isDisallowedElement(*it)) {
     671            toRemove.append(&*it);
     672            it.traverseNextSkippingChildren();
     673            continue;
     674        }
     675        ++it;
     676    }
     677    // The subtree is not in document so this won't generate events that could mutate the tree.
     678    for (unsigned i = 0; i < toRemove.size(); ++i)
     679        toRemove[i]->parentNode()->removeChild(toRemove[i]);
    676680}
    677681
Note: See TracChangeset for help on using the changeset viewer.