Changeset 157368 in webkit
- Timestamp:
- Oct 13, 2013, 6:26:07 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r157367 r157368 1 2013-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 1 10 2013-10-13 Antti Koivisto <antti@apple.com> 2 11 -
trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp
r153939 r157368 29 29 #include "CSSSelectorList.h" 30 30 #include "Document.h" 31 #include "Element Traversal.h"31 #include "ElementIterator.h" 32 32 #include "StyleRuleImport.h" 33 33 #include "StyleSheetContents.h" … … 99 99 } 100 100 101 static bool elementMatchesSelectorScopes(const Element *element, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes)101 static bool elementMatchesSelectorScopes(const Element& element, const HashSet<AtomicStringImpl*>& idScopes, const HashSet<AtomicStringImpl*>& classScopes) 102 102 { 103 if (!idScopes.isEmpty() && element ->hasID() && idScopes.contains(element->idForStyleResolution().impl()))103 if (!idScopes.isEmpty() && element.hasID() && idScopes.contains(element.idForStyleResolution().impl())) 104 104 return true; 105 if (classScopes.isEmpty() || !element ->hasClass())105 if (classScopes.isEmpty() || !element.hasClass()) 106 106 return false; 107 const SpaceSplitString& classNames = element ->classNames();107 const SpaceSplitString& classNames = element.classNames(); 108 108 for (unsigned i = 0; i < classNames.size(); ++i) { 109 109 if (classScopes.contains(classNames[i].impl())) … … 118 118 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) 119 119 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(); 124 126 // The whole subtree is now invalidated, we can skip to the next sibling. 125 element = ElementTraversal::nextSkippingChildren(element);127 it.traverseNextSkippingChildren(); 126 128 continue; 127 129 } 128 element = ElementTraversal::next(element);130 ++it; 129 131 } 130 132 } -
trunk/Source/WebCore/dom/ElementIterator.h
r154940 r157368 51 51 ElementIterator& traverseNextSibling(); 52 52 ElementIterator& traversePreviousSibling(); 53 ElementIterator& traverseNextSkippingChildren(); 53 54 ElementIterator& traverseAncestor(); 54 55 … … 78 79 ElementConstIterator& traverseNextSibling(); 79 80 ElementConstIterator& traversePreviousSibling(); 81 ElementConstIterator& traverseNextSkippingChildren(); 80 82 ElementConstIterator& traverseAncestor(); 81 83 … … 156 158 ASSERT(!m_assertions.domTreeHasMutated()); 157 159 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 168 template <typename ElementType> 169 inline 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); 158 174 #if !ASSERT_DISABLED 159 175 // Drop the assertion when the iterator reaches the end. … … 301 317 302 318 template <typename ElementType> 319 inline 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 332 template <typename ElementType> 303 333 inline ElementConstIterator<ElementType>& ElementConstIterator<ElementType>::traverseAncestor() 304 334 { -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r157338 r157368 37 37 #include "DocumentFragment.h" 38 38 #include "Element.h" 39 #include "ElementIterator.h" 39 40 #include "EventNames.h" 40 41 #include "ExceptionCodePlaceholder.h" … … 75 76 public: 76 77 ReplacementFragment(Document&, DocumentFragment*, const VisibleSelection&); 78 79 DocumentFragment* fragment() { return m_fragment.get(); } 77 80 78 81 Node* firstChild() const; … … 705 708 static void removeHeadContents(ReplacementFragment& fragment) 706 709 { 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]); 719 728 } 720 729 -
trunk/Source/WebCore/svg/SVGUseElement.cpp
r157223 r157368 664 664 { 665 665 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]); 676 680 } 677 681
Note:
See TracChangeset
for help on using the changeset viewer.