Changeset 137406 in webkit
- Timestamp:
- Dec 11, 2012 7:12:23 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r137400 r137406 1 2012-12-11 Antti Koivisto <antti@apple.com> 2 3 Add Element-specific traversal functions 4 https://bugs.webkit.org/show_bug.cgi?id=104685 5 6 Reviewed by Ryosuke Niwa. 7 8 In many cases where we use NodeTraversal we really only want Elements. By having 9 Element specific iteration functions we can tighten the code and make it faster too. 10 11 This patch adds ElementTraversal namespace, similar to NodeTraversal. It also switches 12 bunch of NodeTraversal call sites that obviously only care about elements to using 13 the new interface. 14 15 This should be a speedup too as we avoid number of branches by not having to look 16 for children of non-ContainerNodes and by allowing use of ContainerNode specific 17 accessors. 18 19 * accessibility/AccessibilityRenderObject.cpp: 20 (WebCore::AccessibilityRenderObject::addImageMapChildren): 21 * css/SelectorChecker.cpp: 22 (WebCore::linkAttribute): 23 (WebCore::SelectorChecker::allVisitedStateChanged): 24 (WebCore::SelectorChecker::visitedStateChanged): 25 * css/StyleInvalidationAnalysis.cpp: 26 (WebCore::elementMatchesSelectorScopes): 27 (WebCore::StyleInvalidationAnalysis::invalidateStyle): 28 * dom/ContainerNodeAlgorithms.h: 29 (WebCore::ChildFrameDisconnector::collectDescendant): 30 * dom/Document.cpp: 31 (WebCore::Document::buildAccessKeyMap): 32 (WebCore::Document::updateBaseURL): 33 (WebCore::Document::processBaseElement): 34 * dom/DocumentOrderedMap.cpp: 35 (WebCore::DocumentOrderedMap::get): 36 * dom/Element.cpp: 37 (WebCore::Element::firstElementChild): 38 * dom/Element.h: 39 (WebCore): 40 * dom/ElementShadow.cpp: 41 (WebCore::ElementShadow::collectSelectFeatureSetFrom): 42 * dom/NodeTraversal.h: 43 (ElementTraversal): 44 (WebCore): 45 (WebCore::ElementTraversal::traverseNextElementTemplate): 46 (WebCore::ElementTraversal::next): 47 (WebCore::ElementTraversal::firstWithin): 48 (WebCore::ElementTraversal::traverseNextElementSkippingChildrenTemplate): 49 (WebCore::ElementTraversal::nextSkippingChildren): 50 (NodeTraversal): 51 * dom/TreeScope.cpp: 52 (WebCore::TreeScope::labelElementForId): 53 (WebCore::TreeScope::findAnchor): 54 * editing/CompositeEditCommand.cpp: 55 (WebCore::CompositeEditCommand::cloneParagraphUnderNewElement): 56 * editing/DeleteSelectionCommand.cpp: 57 (WebCore::DeleteSelectionCommand::handleGeneralDelete): 58 * editing/FrameSelection.cpp: 59 (WebCore::scanForForm): 60 * editing/markup.cpp: 61 (WebCore::completeURLs): 62 * html/HTMLFieldSetElement.cpp: 63 (WebCore::HTMLFieldSetElement::invalidateDisabledStateUnder): 64 (WebCore::HTMLFieldSetElement::childrenChanged): 65 (WebCore::HTMLFieldSetElement::legend): 66 (WebCore::HTMLFieldSetElement::refreshElementsIfNeeded): 67 * html/HTMLFormElement.cpp: 68 (WebCore::HTMLFormElement::formElementIndex): 69 * html/HTMLLabelElement.cpp: 70 (WebCore::HTMLLabelElement::control): 71 * html/HTMLLegendElement.cpp: 72 (WebCore::HTMLLegendElement::associatedControl): 73 * html/HTMLMapElement.cpp: 74 (WebCore::HTMLMapElement::mapMouseEvent): 75 * html/HTMLNameCollection.cpp: 76 (WebCore::HTMLNameCollection::virtualItemAfter): 77 * html/HTMLObjectElement.cpp: 78 (WebCore::HTMLObjectElement::containsJavaApplet): 79 * html/HTMLSelectElement.cpp: 80 (WebCore::HTMLSelectElement::recalcListItems): 81 * html/shadow/ContentDistributor.cpp: 82 (WebCore::ShadowRootContentDistributionData::ensureInsertionPointList): 83 * page/FocusController.cpp: 84 (WebCore::FocusController::findFocusCandidateInContainer): 85 * rendering/RenderCounter.cpp: 86 (WebCore::nextInPreOrder): 87 * svg/SVGSVGElement.cpp: 88 (WebCore::SVGSVGElement::collectIntersectionOrEnclosureList): 89 * svg/SVGStyledElement.cpp: 90 (WebCore::SVGStyledElement::title): 91 * svg/SVGUseElement.cpp: 92 (WebCore::removeDisallowedElementsFromSubtree): 93 * svg/animation/SMILTimeContainer.cpp: 94 (WebCore::SMILTimeContainer::updateDocumentOrderIndexes): 95 1 96 2012-12-11 KyungTae Kim <ktf.kim@samsung.com> 2 97 -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r137221 r137406 2658 2658 return; 2659 2659 2660 for (Node* current = map->firstChild(); current; current = NodeTraversal::next(current, map)) { 2661 2660 for (Element* current = ElementTraversal::firstWithin(map); current; current = ElementTraversal::next(current, map)) { 2662 2661 // add an <area> element for this child if it has a link 2663 2662 if (current->hasTagName(areaTag) && current->isLink()) { -
trunk/Source/WebCore/css/SelectorChecker.cpp
r137284 r137406 208 208 } 209 209 210 static inline const AtomicString* linkAttribute( Node* node)211 { 212 if (! node->isLink())210 static inline const AtomicString* linkAttribute(Element* element) 211 { 212 if (!element->isLink()) 213 213 return 0; 214 215 ASSERT(node->isElementNode());216 Element* element = static_cast<Element*>(node);217 214 if (element->isHTMLElement()) 218 215 return &element->fastGetAttribute(hrefAttr); 219 216 if (element->isSVGElement()) 220 217 return &element->getAttribute(XLinkNames::hrefAttr); 221 222 218 return 0; 223 219 } … … 1226 1222 if (m_linksCheckedForVisitedState.isEmpty()) 1227 1223 return; 1228 for ( Node* node = m_document; node; node = NodeTraversal::next(node)) {1229 if ( node->isLink())1230 node->setNeedsStyleRecalc();1224 for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(element)) { 1225 if (element->isLink()) 1226 element->setNeedsStyleRecalc(); 1231 1227 } 1232 1228 } … … 1236 1232 if (!m_linksCheckedForVisitedState.contains(visitedHash)) 1237 1233 return; 1238 for ( Node* node = m_document; node; node = NodeTraversal::next(node)) {1234 for (Element* element = ElementTraversal::firstWithin(m_document); element; element = ElementTraversal::next(element)) { 1239 1235 LinkHash hash = 0; 1240 if ( node->hasTagName(aTag))1241 hash = static_cast<HTMLAnchorElement*>( node)->visitedLinkHash();1242 else if (const AtomicString* attr = linkAttribute( node))1236 if (element->hasTagName(aTag)) 1237 hash = static_cast<HTMLAnchorElement*>(element)->visitedLinkHash(); 1238 else if (const AtomicString* attr = linkAttribute(element)) 1243 1239 hash = visitedLinkHash(m_document->baseURL(), *attr); 1244 1240 if (hash == visitedHash) 1245 node->setNeedsStyleRecalc();1241 element->setNeedsStyleRecalc(); 1246 1242 } 1247 1243 } -
trunk/Source/WebCore/css/StyleInvalidationAnalysis.cpp
r137221 r137406 99 99 } 100 100 101 static bool elementMatchesSelectorScopes(const StyledElement* 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 103 if (!idScopes.isEmpty() && element->hasID() && idScopes.contains(element->idForStyleResolution().impl())) … … 118 118 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) 119 119 return; 120 Node* node = document->firstChild(); 121 while (node) { 122 if (!node->isStyledElement()) { 123 node = NodeTraversal::next(node); 124 continue; 125 } 126 StyledElement* element = static_cast<StyledElement*>(node); 120 Element* element = ElementTraversal::firstWithin(document); 121 while (element) { 127 122 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { 128 123 element->setNeedsStyleRecalc(); 129 124 // The whole subtree is now invalidated, we can skip to the next sibling. 130 node = NodeTraversal::nextSkippingChildren(node);125 element = ElementTraversal::nextSkippingChildren(element); 131 126 continue; 132 127 } 133 node = NodeTraversal::next(node);128 element = ElementTraversal::next(element); 134 129 } 135 130 } -
trunk/Source/WebCore/dom/ContainerNodeAlgorithms.h
r137221 r137406 317 317 inline void ChildFrameDisconnector::collectDescendant(Node* root, ShouldIncludeRoot shouldIncludeRoot) 318 318 { 319 for (Node* node = shouldIncludeRoot == IncludeRoot ? root : root->firstChild(); node; node = NodeTraversal::next(node, root)) { 320 if (!node->isElementNode()) 321 continue; 322 Element* element = toElement(node); 319 Element* element = (shouldIncludeRoot == IncludeRoot && root->isElementNode()) ? toElement(root) : ElementTraversal::firstWithin(root); 320 for (; element; element = ElementTraversal::next(element, root)) { 323 321 if (element->hasCustomCallbacks() && element->isFrameOwnerElement()) 324 322 m_list.append(toFrameOwnerElement(element)); -
trunk/Source/WebCore/dom/Document.cpp
r137318 r137406 751 751 ASSERT(scope); 752 752 Node* rootNode = scope->rootNode(); 753 for (Node* node = rootNode; node; node = NodeTraversal::next(node, rootNode)) { 754 if (!node->isElementNode()) 755 continue; 756 Element* element = static_cast<Element*>(node); 753 for (Element* element = ElementTraversal::firstWithin(rootNode); element; element = ElementTraversal::next(element, rootNode)) { 757 754 const AtomicString& accessKey = element->getAttribute(accesskeyAttr); 758 755 if (!accessKey.isEmpty()) 759 756 m_elementsByAccessKey.set(accessKey.impl(), element); 760 757 761 for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot())758 for (ShadowRoot* root = element->youngestShadowRoot(); root; root = root->olderShadowRoot()) 762 759 buildAccessKeyMap(root); 763 760 } … … 845 842 ContainerNode::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 846 843 847 Element* newDocumentElement = firstElementChild(this);844 Element* newDocumentElement = ElementTraversal::firstWithin(this); 848 845 if (newDocumentElement == m_documentElement) 849 846 return; … … 2668 2665 // Base URL change changes any relative visited links. 2669 2666 // FIXME: There are other URLs in the tree that would need to be re-evaluated on dynamic base URL change. Style should be invalidated too. 2670 for ( Node* node = firstChild(); node; node = NodeTraversal::next(node)) {2671 if ( node->hasTagName(aTag))2672 static_cast<HTMLAnchorElement*>( node)->invalidateCachedVisitedLinkHash();2667 for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element)) { 2668 if (element->hasTagName(aTag)) 2669 static_cast<HTMLAnchorElement*>(element)->invalidateCachedVisitedLinkHash(); 2673 2670 } 2674 2671 } … … 2686 2683 const AtomicString* href = 0; 2687 2684 const AtomicString* target = 0; 2688 for ( Node* node = document()->firstChild(); node && (!href || !target); node = NodeTraversal::next(node)) {2689 if ( node->hasTagName(baseTag)) {2685 for (Element* element = ElementTraversal::firstWithin(this); element && (!href || !target); element = ElementTraversal::next(element)) { 2686 if (element->hasTagName(baseTag)) { 2690 2687 if (!href) { 2691 const AtomicString& value = static_cast<Element*>(node)->fastGetAttribute(hrefAttr);2688 const AtomicString& value = element->fastGetAttribute(hrefAttr); 2692 2689 if (!value.isNull()) 2693 2690 href = &value; 2694 2691 } 2695 2692 if (!target) { 2696 const AtomicString& value = static_cast<Element*>(node)->fastGetAttribute(targetAttr);2693 const AtomicString& value = element->fastGetAttribute(targetAttr); 2697 2694 if (!value.isNull()) 2698 2695 target = &value; -
trunk/Source/WebCore/dom/DocumentOrderedMap.cpp
r137221 r137406 128 128 if (m_duplicateCounts.contains(key)) { 129 129 // We know there's at least one node that matches; iterate to find the first one. 130 for (Node* node = scope->rootNode()->firstChild(); node; node = NodeTraversal::next(node)) { 131 if (!node->isElementNode()) 132 continue; 133 element = static_cast<Element*>(node); 130 for (element = ElementTraversal::firstWithin(scope->rootNode()); element; element = ElementTraversal::next(element)) { 134 131 if (!keyMatches(key, element)) 135 132 continue; -
trunk/Source/WebCore/dom/Element.cpp
r137341 r137406 63 63 #include "NodeRenderStyle.h" 64 64 #include "NodeRenderingContext.h" 65 #include "NodeTraversal.h" 65 66 #include "Page.h" 66 67 #include "PointerLockController.h" … … 2146 2147 Element* Element::firstElementChild() const 2147 2148 { 2148 return WebCore::firstElementChild(this);2149 return ElementTraversal::firstWithin(this); 2149 2150 } 2150 2151 -
trunk/Source/WebCore/dom/Element.h
r137284 r137406 798 798 } 799 799 800 inline Element* firstElementChild(const ContainerNode* container)801 {802 ASSERT_ARG(container, container);803 Node* child = container->firstChild();804 while (child && !child->isElementNode())805 child = child->nextSibling();806 return static_cast<Element*>(child);807 }808 809 800 inline bool Element::hasID() const 810 801 { -
trunk/Source/WebCore/dom/ElementShadow.cpp
r137221 r137406 222 222 { 223 223 if (root->hasElementShadow()) { 224 for ( Node* node = root->firstChild(); node; node = NodeTraversal::next(node)) {225 if (ElementShadow* elementShadow = node->isElementNode() ? toElement(node)->shadow() : 0) {224 for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) { 225 if (ElementShadow* elementShadow = element->shadow()) { 226 226 elementShadow->ensureSelectFeatureSetCollected(); 227 227 m_selectFeatures.add(elementShadow->m_selectFeatures); … … 231 231 232 232 if (root->hasContentElement()) { 233 for ( Node* node = root->firstChild(); node; node = NodeTraversal::next(node)) {234 if (isHTMLContentElement( node)) {235 const CSSSelectorList& list = toHTMLContentElement( node)->selectorList();233 for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) { 234 if (isHTMLContentElement(element)) { 235 const CSSSelectorList& list = toHTMLContentElement(element)->selectorList(); 236 236 for (CSSSelector* selector = list.first(); selector; selector = list.next(selector)) 237 237 m_selectFeatures.collectFeaturesFromSelector(selector); -
trunk/Source/WebCore/dom/NodeTraversal.h
r137221 r137406 26 26 #define NodeTraversal_h 27 27 28 #include "Element.h" 29 28 30 namespace WebCore { 29 31 30 class Node; 31 class ContainerNode; 32 namespace ElementTraversal { 33 34 // First element child of the node. 35 Element* firstWithin(const Node*); 36 Element* firstWithin(const ContainerNode*); 37 // Pre-order traversal skipping non-element nodes. 38 Element* next(const Node*); 39 Element* next(const Node*, const Node* stayWithin); 40 Element* next(const ContainerNode*); 41 Element* next(const ContainerNode*, const Node* stayWithin); 42 // Like next, but skips children. 43 Element* nextSkippingChildren(const Node*); 44 Element* nextSkippingChildren(const Node*, const Node* stayWithin); 45 Element* nextSkippingChildren(const ContainerNode*); 46 Element* nextSkippingChildren(const ContainerNode*, const Node* stayWithin); 47 48 } 32 49 33 50 namespace NodeTraversal { … … 60 77 Node* previousPostOrder(const Node*, const Node* stayWithin = 0); 61 78 Node* previousSkippingChildrenPostOrder(const Node*, const Node* stayWithin = 0); 79 80 } 81 82 namespace ElementTraversal { 83 template <class NodeType> 84 inline Element* firstElementWithinTemplate(NodeType* current) 85 { 86 // Except for the root containers, only elements can have element children. 87 Node* node = current->firstChild(); 88 while (node && !node->isElementNode()) 89 node = node->nextSibling(); 90 return toElement(node); 91 } 92 inline Element* firstWithin(const ContainerNode* current) { return firstElementWithinTemplate(current); } 93 inline Element* firstWithin(const Node* current) { return firstElementWithinTemplate(current); } 94 95 template <class NodeType> 96 inline Element* traverseNextElementTemplate(NodeType* current) 97 { 98 Node* node = NodeTraversal::next(current); 99 while (node && !node->isElementNode()) 100 node = NodeTraversal::nextSkippingChildren(node); 101 return toElement(node); 102 } 103 inline Element* next(const ContainerNode* current) { return traverseNextElementTemplate(current); } 104 inline Element* next(const Node* current) { return traverseNextElementTemplate(current); } 105 106 template <class NodeType> 107 inline Element* traverseNextElementTemplate(NodeType* current, const Node* stayWithin) 108 { 109 Node* node = NodeTraversal::next(current, stayWithin); 110 while (node && !node->isElementNode()) 111 node = NodeTraversal::nextSkippingChildren(node, stayWithin); 112 return toElement(node); 113 } 114 inline Element* next(const ContainerNode* current, const Node* stayWithin) { return traverseNextElementTemplate(current, stayWithin); } 115 inline Element* next(const Node* current, const Node* stayWithin) { return traverseNextElementTemplate(current, stayWithin); } 116 117 template <class NodeType> 118 inline Element* traverseNextElementSkippingChildrenTemplate(NodeType* current) 119 { 120 Node* node = NodeTraversal::nextSkippingChildren(current); 121 while (node && !node->isElementNode()) 122 node = NodeTraversal::nextSkippingChildren(node); 123 return toElement(node); 124 } 125 inline Element* nextSkippingChildren(const ContainerNode* current) { return traverseNextElementSkippingChildrenTemplate(current); } 126 inline Element* nextSkippingChildren(const Node* current) { return traverseNextElementSkippingChildrenTemplate(current); } 127 128 template <class NodeType> 129 inline Element* traverseNextElementSkippingChildrenTemplate(NodeType* current, const Node* stayWithin) 130 { 131 Node* node = NodeTraversal::nextSkippingChildren(current, stayWithin); 132 while (node && !node->isElementNode()) 133 node = NodeTraversal::nextSkippingChildren(node, stayWithin); 134 return toElement(node); 135 } 136 inline Element* nextSkippingChildren(const ContainerNode* current, const Node* stayWithin) { return traverseNextElementSkippingChildrenTemplate(current, stayWithin); } 137 inline Element* nextSkippingChildren(const Node* current, const Node* stayWithin) { return traverseNextElementSkippingChildrenTemplate(current, stayWithin); } 138 } 139 140 namespace NodeTraversal { 62 141 63 142 Node* nextAncestorSibling(const Node*); -
trunk/Source/WebCore/dom/TreeScope.cpp
r137221 r137406 188 188 // Populate the map on first access. 189 189 m_labelsByForAttribute = adoptPtr(new DocumentOrderedMap); 190 for ( Node* node = rootNode(); node; node = NodeTraversal::next(node)) {191 if ( node->hasTagName(labelTag)) {192 HTMLLabelElement* label = static_cast<HTMLLabelElement*>( node);190 for (Element* element = ElementTraversal::firstWithin(rootNode()); element; element = ElementTraversal::next(element)) { 191 if (element->hasTagName(labelTag)) { 192 HTMLLabelElement* label = static_cast<HTMLLabelElement*>(element); 193 193 const AtomicString& forValue = label->fastGetAttribute(forAttr); 194 194 if (!forValue.isEmpty()) … … 232 232 if (Element* element = getElementById(name)) 233 233 return element; 234 for ( Node* node = rootNode(); node; node = NodeTraversal::next(node)) {235 if ( node->hasTagName(aTag)) {236 HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>( node);234 for (Element* element = ElementTraversal::firstWithin(rootNode()); element; element = ElementTraversal::next(element)) { 235 if (element->hasTagName(aTag)) { 236 HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(element); 237 237 if (rootNode()->document()->inQuirksMode()) { 238 238 // Quirks mode, case insensitive comparison of names. -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r137221 r137406 1026 1026 for (Node* node = NodeTraversal::nextSkippingChildren(startNode, outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(node, outerNode.get())) { 1027 1027 // Move lastNode up in the tree as much as node was moved up in the 1028 // tree by NodeTraversal::nextS ibling, so that the relative depth between1028 // tree by NodeTraversal::nextSkippingChildren, so that the relative depth between 1029 1029 // node and the original start node is maintained in the clone. 1030 1030 while (startNode->parentNode() != node->parentNode()) { -
trunk/Source/WebCore/editing/DeleteSelectionCommand.cpp
r137221 r137406 505 505 while (node && node != m_downstreamEnd.deprecatedNode()) { 506 506 if (comparePositions(firstPositionInOrBeforeNode(node.get()), m_downstreamEnd) >= 0) { 507 // NodeTraversal::nextS iblingjust blew past the end position, so stop deleting507 // NodeTraversal::nextSkippingChildren just blew past the end position, so stop deleting 508 508 node = 0; 509 509 } else if (!m_downstreamEnd.deprecatedNode()->isDescendantOf(node.get())) { -
trunk/Source/WebCore/editing/FrameSelection.cpp
r137221 r137406 1954 1954 static HTMLFormElement* scanForForm(Node* start) 1955 1955 { 1956 for (Node* node = start; node; node = NodeTraversal::next(node)) { 1957 if (node->hasTagName(formTag)) 1958 return static_cast<HTMLFormElement*>(node); 1959 if (node->isHTMLElement() && toHTMLElement(node)->isFormControlElement()) 1960 return static_cast<HTMLFormControlElement*>(node)->form(); 1961 if (node->hasTagName(frameTag) || node->hasTagName(iframeTag)) { 1962 Node* childDocument = static_cast<HTMLFrameElementBase*>(node)->contentDocument(); 1956 Element* element = start && start->isElementNode() ? toElement(start) : ElementTraversal::next(start); 1957 for (; element; element = ElementTraversal::next(element)) { 1958 if (element->hasTagName(formTag)) 1959 return static_cast<HTMLFormElement*>(element); 1960 if (element->isHTMLElement() && toHTMLElement(element)->isFormControlElement()) 1961 return static_cast<HTMLFormControlElement*>(element)->form(); 1962 if (element->hasTagName(frameTag) || element->hasTagName(iframeTag)) { 1963 Node* childDocument = static_cast<HTMLFrameElementBase*>(element)->contentDocument(); 1963 1964 if (HTMLFormElement* frameResult = scanForForm(childDocument)) 1964 1965 return frameResult; -
trunk/Source/WebCore/editing/markup.cpp
r137221 r137406 97 97 }; 98 98 99 static void completeURLs( Node* node, const String& baseURL)99 static void completeURLs(DocumentFragment* fragment, const String& baseURL) 100 100 { 101 101 Vector<AttributeChange> changes; … … 103 103 KURL parsedBaseURL(ParsedURLString, baseURL); 104 104 105 Node* end = NodeTraversal::nextSkippingChildren(node); 106 for (Node* n = node; n != end; n = NodeTraversal::next(n)) { 107 if (n->isElementNode()) { 108 Element* e = static_cast<Element*>(n); 109 if (!e->hasAttributes()) 110 continue; 111 unsigned length = e->attributeCount(); 112 for (unsigned i = 0; i < length; i++) { 113 const Attribute* attribute = e->attributeItem(i); 114 if (e->isURLAttribute(*attribute) && !attribute->value().isEmpty()) 115 changes.append(AttributeChange(e, attribute->name(), KURL(parsedBaseURL, attribute->value()).string())); 116 } 105 for (Element* element = ElementTraversal::firstWithin(fragment); element; element = ElementTraversal::next(element, fragment)) { 106 if (!element->hasAttributes()) 107 continue; 108 unsigned length = element->attributeCount(); 109 for (unsigned i = 0; i < length; i++) { 110 const Attribute* attribute = element->attributeItem(i); 111 if (element->isURLAttribute(*attribute) && !attribute->value().isEmpty()) 112 changes.append(AttributeChange(element, attribute->name(), KURL(parsedBaseURL, attribute->value()).string())); 117 113 } 118 114 } -
trunk/Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp
r137124 r137406 43 43 #include "KeyboardEvent.h" 44 44 #include "LocalizedStrings.h" 45 #include "NodeTraversal.h" 45 46 #include "Page.h" 46 47 #include "PickerIndicatorElement.h" … … 359 360 360 361 AtomicString direction = element()->locale().isRTL() ? AtomicString("rtl", AtomicString::ConstructFromLiteral) : AtomicString("ltr", AtomicString::ConstructFromLiteral); 361 if (Element* container = firstElementChild(element()->userAgentShadowRoot()))362 if (Element* container = ElementTraversal::firstWithin(element()->userAgentShadowRoot())) 362 363 container->setAttribute(HTMLNames::dirAttr, direction); 363 364 -
trunk/Source/WebCore/html/HTMLFieldSetElement.cpp
r137221 r137406 52 52 void HTMLFieldSetElement::invalidateDisabledStateUnder(Element* base) 53 53 { 54 for ( Node* node = base->firstChild(); node; node = NodeTraversal::next(node, base)) {55 if ( node->isElementNode() && toElement(node)->isFormControlElement())56 static_cast<HTMLFormControlElement*>( node)->ancestorDisabledStateWasChanged();54 for (Element* element = ElementTraversal::firstWithin(base); element; element = ElementTraversal::next(element, base)) { 55 if (element->isFormControlElement()) 56 static_cast<HTMLFormControlElement*>(element)->ancestorDisabledStateWasChanged(); 57 57 } 58 58 } … … 68 68 { 69 69 HTMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 70 for (Element* element = firstElementChild(); element; element = element->nextElementSibling()) {70 for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::nextSkippingChildren(element, this)) { 71 71 if (element->hasTagName(legendTag)) 72 72 invalidateDisabledStateUnder(element); … … 92 92 HTMLLegendElement* HTMLFieldSetElement::legend() const 93 93 { 94 for (Element* node = firstElementChild(); node; node = node->nextElementSibling()) {95 if ( node->hasTagName(legendTag))96 return static_cast<HTMLLegendElement*>( node);94 for (Element* child = ElementTraversal::firstWithin(this); child; child = ElementTraversal::nextSkippingChildren(child, this)) { 95 if (child->hasTagName(legendTag)) 96 return static_cast<HTMLLegendElement*>(child); 97 97 } 98 98 return 0; … … 114 114 m_associatedElements.clear(); 115 115 116 for (Node* node = firstChild(); node; node = NodeTraversal::next(node, this)) { 117 if (!node->isElementNode()) 118 continue; 119 120 if (node->hasTagName(objectTag)) { 121 m_associatedElements.append(static_cast<HTMLObjectElement*>(node)); 116 for (Element* element = ElementTraversal::firstWithin(this); element; element = ElementTraversal::next(element, this)) { 117 if (element->hasTagName(objectTag)) { 118 m_associatedElements.append(static_cast<HTMLObjectElement*>(element)); 122 119 continue; 123 120 } 124 121 125 if (! toElement(node)->isFormControlElement())122 if (!element->isFormControlElement()) 126 123 continue; 127 124 128 m_associatedElements.append(static_cast<HTMLFormControlElement*>( node));125 m_associatedElements.append(static_cast<HTMLFormControlElement*>(element)); 129 126 } 130 127 } -
trunk/Source/WebCore/html/HTMLFormElement.cpp
r137318 r137406 506 506 unsigned HTMLFormElement::formElementIndex(FormAssociatedElement* associatedElement) 507 507 { 508 HTMLElement* element = toHTMLElement(associatedElement);508 HTMLElement* associatedHTMLElement = toHTMLElement(associatedElement); 509 509 // Treats separately the case where this element has the form attribute 510 510 // for performance consideration. 511 if ( element->fastHasAttribute(formAttr)) {512 unsigned short position = compareDocumentPosition( element);511 if (associatedHTMLElement->fastHasAttribute(formAttr)) { 512 unsigned short position = compareDocumentPosition(associatedHTMLElement); 513 513 if (position & DOCUMENT_POSITION_PRECEDING) { 514 514 ++m_associatedElementsBeforeIndex; 515 515 ++m_associatedElementsAfterIndex; 516 return HTMLFormElement::formElementIndexWithFormAttribute( element, 0, m_associatedElementsBeforeIndex - 1);516 return HTMLFormElement::formElementIndexWithFormAttribute(associatedHTMLElement, 0, m_associatedElementsBeforeIndex - 1); 517 517 } 518 518 if (position & DOCUMENT_POSITION_FOLLOWING && !(position & DOCUMENT_POSITION_CONTAINED_BY)) 519 return HTMLFormElement::formElementIndexWithFormAttribute( element, m_associatedElementsAfterIndex, m_associatedElements.size());519 return HTMLFormElement::formElementIndexWithFormAttribute(associatedHTMLElement, m_associatedElementsAfterIndex, m_associatedElements.size()); 520 520 } 521 521 … … 524 524 // common case that occurs during parsing; instead we'll just return a value 525 525 // that says "add this form element to the end of the array". 526 if ( NodeTraversal::next(element, this)) {526 if (ElementTraversal::next(associatedHTMLElement, this)) { 527 527 unsigned i = m_associatedElementsBeforeIndex; 528 for ( Node* node = this; node; node = NodeTraversal::next(node, this)) {529 if ( node == element) {528 for (Element* element = this; element; element = ElementTraversal::next(element, this)) { 529 if (element == associatedHTMLElement) { 530 530 ++m_associatedElementsAfterIndex; 531 531 return i; 532 532 } 533 if ( node->isHTMLElement()534 && (static_cast<Element*>(node)->isFormControlElement()535 || node->hasTagName(objectTag))536 && toHTMLElement(node)->form() == this)537 533 if (!element->isFormControlElement() && !element->hasTagName(objectTag)) 534 continue; 535 if (!element->isHTMLElement() || toHTMLElement(element)->form() != this) 536 continue; 537 ++i; 538 538 } 539 539 } -
trunk/Source/WebCore/html/HTMLLabelElement.cpp
r137221 r137406 76 76 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element 77 77 // the form element must be "labelable form-associated element". 78 Node* node= this;79 while (( node = NodeTraversal::next(node, this))) {80 if (LabelableElement* element = nodeAsLabelableElement(node))81 return element;78 Element* element = this; 79 while ((element = ElementTraversal::next(element, this))) { 80 if (LabelableElement* labelableElement = nodeAsLabelableElement(element)) 81 return labelableElement; 82 82 } 83 83 return 0; -
trunk/Source/WebCore/html/HTMLLegendElement.cpp
r137221 r137406 51 51 { 52 52 // Check if there's a fieldset belonging to this legend. 53 ContainerNode* fieldset = parentNode();53 Element* fieldset = parentElement(); 54 54 while (fieldset && !fieldset->hasTagName(fieldsetTag)) 55 fieldset = fieldset->parent Node();55 fieldset = fieldset->parentElement(); 56 56 if (!fieldset) 57 57 return 0; … … 59 59 // Find first form element inside the fieldset that is not a legend element. 60 60 // FIXME: Should we consider tabindex? 61 Node* node = fieldset; 62 while ((node = NodeTraversal::next(node, fieldset))) { 63 if (node->isElementNode()) { 64 Element* element = static_cast<Element*>(node); 65 if (element->isFormControlElement()) 66 return static_cast<HTMLFormControlElement*>(element); 67 } 61 Element* element = fieldset; 62 while ((element = ElementTraversal::next(element, fieldset))) { 63 if (element->isFormControlElement()) 64 return static_cast<HTMLFormControlElement*>(element); 68 65 } 69 66 -
trunk/Source/WebCore/html/HTMLMapElement.cpp
r137221 r137406 63 63 { 64 64 HTMLAreaElement* defaultArea = 0; 65 Node *node= this;66 while (( node = NodeTraversal::next(node, this))) {67 if ( node->hasTagName(areaTag)) {68 HTMLAreaElement* areaElt = static_cast<HTMLAreaElement*>( node);65 Element* element = this; 66 while ((element = ElementTraversal::next(element, this))) { 67 if (element->hasTagName(areaTag)) { 68 HTMLAreaElement* areaElt = static_cast<HTMLAreaElement*>(element); 69 69 if (areaElt->isDefault()) { 70 70 if (!defaultArea) -
trunk/Source/WebCore/html/HTMLNameCollection.cpp
r137221 r137406 55 55 ASSERT(previous != ownerNode()); 56 56 57 Node* current;57 Element* current; 58 58 if (!previous) 59 current = ownerNode()->firstChild();59 current = ElementTraversal::firstWithin(ownerNode()); 60 60 else 61 current = NodeTraversal::next(previous, ownerNode());61 current = ElementTraversal::next(previous, ownerNode()); 62 62 63 for (; current; current = NodeTraversal::next(current, ownerNode())) { 64 if (!current->isElementNode()) 65 continue; 66 Element* e = static_cast<Element*>(current); 63 for (; current; current = ElementTraversal::next(current, ownerNode())) { 67 64 switch (type()) { 68 case WindowNamedItems: 69 // find only images, forms, applets, embeds and objects by name, 70 // but anything by id 71 if (e->hasTagName(imgTag) || 72 e->hasTagName(formTag) || 73 e->hasTagName(appletTag) || 74 e->hasTagName(embedTag) || 75 e->hasTagName(objectTag)) 76 if (e->getNameAttribute() == m_name) 77 return e; 78 if (e->getIdAttribute() == m_name) 79 return e; 80 break; 81 case DocumentNamedItems: 82 // find images, forms, applets, embeds, objects and iframes by name, 83 // applets and object by id, and images by id but only if they have 84 // a name attribute (this very strange rule matches IE) 85 if (e->hasTagName(formTag) || e->hasTagName(embedTag) || e->hasTagName(iframeTag)) { 86 if (e->getNameAttribute() == m_name) 87 return e; 88 } else if (e->hasTagName(appletTag)) { 89 if (e->getNameAttribute() == m_name || e->getIdAttribute() == m_name) 90 return e; 91 } else if (e->hasTagName(objectTag)) { 92 if ((e->getNameAttribute() == m_name || e->getIdAttribute() == m_name) 93 && static_cast<HTMLObjectElement*>(e)->isDocNamedItem()) 94 return e; 95 } else if (e->hasTagName(imgTag)) { 96 if (e->getNameAttribute() == m_name || (e->getIdAttribute() == m_name && e->hasName())) 97 return e; 98 } 99 break; 65 case WindowNamedItems: 66 // find only images, forms, applets, embeds and objects by name, 67 // but anything by id 68 if (current->hasTagName(imgTag) 69 || current->hasTagName(formTag) 70 || current->hasTagName(appletTag) 71 || current->hasTagName(embedTag) 72 || current->hasTagName(objectTag)) { 73 if (current->getNameAttribute() == m_name) 74 return current; 75 } 76 if (current->getIdAttribute() == m_name) 77 return current; 78 break; 79 case DocumentNamedItems: 80 // find images, forms, applets, embeds, objects and iframes by name, 81 // applets and object by id, and images by id but only if they have 82 // a name attribute (this very strange rule matches IE) 83 if (current->hasTagName(formTag) || current->hasTagName(embedTag) || current->hasTagName(iframeTag)) { 84 if (current->getNameAttribute() == m_name) 85 return current; 86 } else if (current->hasTagName(appletTag)) { 87 if (current->getNameAttribute() == m_name || current->getIdAttribute() == m_name) 88 return current; 89 } else if (current->hasTagName(objectTag)) { 90 if ((current->getNameAttribute() == m_name || current->getIdAttribute() == m_name) 91 && static_cast<HTMLObjectElement*>(current)->isDocNamedItem()) 92 return current; 93 } else if (current->hasTagName(imgTag)) { 94 if (current->getNameAttribute() == m_name || (current->getIdAttribute() == m_name && current->hasName())) 95 return current; 96 } 97 break; 100 98 default: 101 99 ASSERT_NOT_REACHED(); -
trunk/Source/WebCore/html/HTMLObjectElement.cpp
r135069 r137406 42 42 #include "MIMETypeRegistry.h" 43 43 #include "NodeList.h" 44 #include "NodeTraversal.h" 44 45 #include "Page.h" 45 46 #include "PluginViewBase.h" … … 458 459 return true; 459 460 460 for (Element* child = firstElementChild(); child; child = child->nextElementSibling()) {461 for (Element* child = ElementTraversal::firstWithin(this); child; child = ElementTraversal::nextSkippingChildren(child, this)) { 461 462 if (child->hasTagName(paramTag) 462 463 && equalIgnoringCase(child->getNameAttribute(), "type") -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r137221 r137406 736 736 HTMLOptionElement* foundSelected = 0; 737 737 HTMLOptionElement* firstOption = 0; 738 for ( Node* currentNode = this->firstChild(); currentNode;) {739 if (!current Node->isHTMLElement()) {740 current Node = NodeTraversal::nextSkippingChildren(currentNode, this);738 for (Element* currentElement = ElementTraversal::firstWithin(this); currentElement; ) { 739 if (!currentElement->isHTMLElement()) { 740 currentElement = ElementTraversal::nextSkippingChildren(currentElement, this); 741 741 continue; 742 742 } 743 744 HTMLElement* current = toHTMLElement(currentNode); 743 HTMLElement* current = toHTMLElement(currentElement); 745 744 746 745 // optgroup tags may not nest. However, both FireFox and IE will … … 750 749 m_listItems.append(current); 751 750 if (current->firstChild()) { 752 current Node = current->firstChild();751 currentElement = ElementTraversal::firstWithin(current); 753 752 continue; 754 753 } … … 777 776 778 777 // In conforming HTML code, only <optgroup> and <option> will be found 779 // within a <select>. We call NodeTraversal::nextS iblingso that we only step778 // within a <select>. We call NodeTraversal::nextSkippingChildren so that we only step 780 779 // into those tags that we choose to. For web-compat, we should cope 781 780 // with the case where odd tags like a <div> have been added but we 782 781 // handle this because such tags have already been removed from the 783 782 // <select>'s subtree at this point. 784 current Node = NodeTraversal::nextSkippingChildren(currentNode, this);783 currentElement = ElementTraversal::nextSkippingChildren(currentElement, this); 785 784 } 786 785 -
trunk/Source/WebCore/html/shadow/ContentDistributor.cpp
r137233 r137406 103 103 return m_insertionPointList; 104 104 105 for ( Node* node = shadowRoot; node; node = NodeTraversal::next(node, shadowRoot)) {106 if ( node->isInsertionPoint())107 m_insertionPointList.append(toInsertionPoint( node));105 for (Element* element = ElementTraversal::firstWithin(shadowRoot); element; element = ElementTraversal::next(element, shadowRoot)) { 106 if (element->isInsertionPoint()) 107 m_insertionPointList.append(toInsertionPoint(element)); 108 108 } 109 109 -
trunk/Source/WebCore/page/FocusController.cpp
r137221 r137406 771 771 Node* focusedNode = (focusedFrame() && focusedFrame()->document()) ? focusedFrame()->document()->focusedNode() : 0; 772 772 773 Node* node = container->firstChild();773 Element* element = ElementTraversal::firstWithin(container); 774 774 FocusCandidate current; 775 775 current.rect = startingRect; … … 777 777 current.visibleNode = focusedNode; 778 778 779 for (; node; node = (node->isFrameOwnerElement() || canScrollInDirection(node, direction)) ? NodeTraversal::nextSkippingChildren(node, container) : NodeTraversal::next(node, container)) { 780 if (node == focusedNode) 779 for (; element; element = (element->isFrameOwnerElement() || canScrollInDirection(element, direction)) 780 ? ElementTraversal::nextSkippingChildren(element, container) 781 : ElementTraversal::next(element, container)) { 782 if (element == focusedNode) 781 783 continue; 782 784 783 if (! node->isElementNode())785 if (!element->isKeyboardFocusable(event) && !element->isFrameOwnerElement() && !canScrollInDirection(element, direction)) 784 786 continue; 785 787 786 if (!node->isKeyboardFocusable(event) && !node->isFrameOwnerElement() && !canScrollInDirection(node, direction)) 787 continue; 788 789 FocusCandidate candidate = FocusCandidate(node, direction); 788 FocusCandidate candidate = FocusCandidate(element, direction); 790 789 if (candidate.isNull()) 791 790 continue; -
trunk/Source/WebCore/rendering/RenderCounter.cpp
r136744 r137406 28 28 #include "HTMLNames.h" 29 29 #include "HTMLOListElement.h" 30 #include "NodeTraversal.h" 30 31 #include "RenderListItem.h" 31 32 #include "RenderListMarker.h" … … 191 192 return 0; 192 193 } 193 child = self->firstElementChild();194 child = ElementTraversal::firstWithin(self); 194 195 while (true) { 195 196 while (child) { … … 197 198 if (result) 198 199 return result; 199 child = child->nextElementSibling();200 child = ElementTraversal::nextSkippingChildren(child, self); 200 201 } 201 202 result = rendererOfAfterPseudoElement(self->renderer()); … … 205 206 if (self == stayWithin) 206 207 return 0; 207 child = self->nextElementSibling();208 child = ElementTraversal::nextSkippingChildren(self); 208 209 self = self->parentElement(); 209 210 if (!self) { -
trunk/Source/WebCore/svg/SVGSVGElement.cpp
r137221 r137406 347 347 { 348 348 Vector<RefPtr<Node> > nodes; 349 Node* node = NodeTraversal::next(referenceElement ? referenceElement : this);350 while ( node) {351 if ( node->isSVGElement()) {349 Element* element = ElementTraversal::next(referenceElement ? referenceElement : this); 350 while (element) { 351 if (element->isSVGElement()) { 352 352 if (collect == CollectIntersectionList) { 353 if (checkIntersection(static_cast<SVGElement*>( node), rect))354 nodes.append( node);353 if (checkIntersection(static_cast<SVGElement*>(element), rect)) 354 nodes.append(element); 355 355 } else { 356 if (checkEnclosure(static_cast<SVGElement*>( node), rect))357 nodes.append( node);356 if (checkEnclosure(static_cast<SVGElement*>(element), rect)) 357 nodes.append(element); 358 358 } 359 359 } 360 360 361 node = NodeTraversal::next(node, referenceElement ? referenceElement : this);361 element = ElementTraversal::next(element, referenceElement ? referenceElement : this); 362 362 } 363 363 return StaticNodeList::adopt(nodes); -
trunk/Source/WebCore/svg/SVGStyledElement.cpp
r136975 r137406 29 29 #include "EventNames.h" 30 30 #include "HTMLNames.h" 31 #include "NodeTraversal.h" 31 32 #include "RenderObject.h" 32 33 #include "RenderSVGResource.h" … … 101 102 // If we aren't an instance in a <use> or the <use> title was not found, then find the first 102 103 // <title> child of this element. 103 Element* titleElement = firstElementChild();104 for (; titleElement; titleElement = titleElement->nextElementSibling()) {104 Element* titleElement = ElementTraversal::firstWithin(this); 105 for (; titleElement; titleElement = ElementTraversal::nextSkippingChildren(titleElement, this)) { 105 106 if (titleElement->hasTagName(SVGNames::titleTag) && titleElement->isSVGElement()) 106 107 break; -
trunk/Source/WebCore/svg/SVGUseElement.cpp
r137221 r137406 685 685 } 686 686 687 static inline void removeDisallowedElementsFromSubtree( Node* subtree)687 static inline void removeDisallowedElementsFromSubtree(Element* subtree) 688 688 { 689 689 ASSERT(!subtree->inDocument()); 690 Node* node = subtree->firstChild();691 while ( node) {692 if (isDisallowedElement( node)) {693 Node* next = NodeTraversal::nextSkippingChildren(node, subtree);690 Element* element = ElementTraversal::firstWithin(subtree); 691 while (element) { 692 if (isDisallowedElement(element)) { 693 Element* next = ElementTraversal::nextSkippingChildren(element, subtree); 694 694 // The subtree is not in document so this won't generate events that could mutate the tree. 695 node->parentNode()->removeChild(node);696 node= next;695 element->parentNode()->removeChild(element); 696 element = next; 697 697 } else 698 node = NodeTraversal::next(node, subtree);698 element = ElementTraversal::next(element, subtree); 699 699 } 700 700 } -
trunk/Source/WebCore/svg/animation/SMILTimeContainer.cpp
r137221 r137406 226 226 { 227 227 unsigned timingElementCount = 0; 228 for ( Node* node = m_ownerSVGElement; node; node = NodeTraversal::next(node, m_ownerSVGElement)) {229 if (SVGSMILElement::isSMILElement( node))230 static_cast<SVGSMILElement*>( node)->setDocumentOrderIndex(timingElementCount++);228 for (Element* element = m_ownerSVGElement; element; element = ElementTraversal::next(element, m_ownerSVGElement)) { 229 if (SVGSMILElement::isSMILElement(element)) 230 static_cast<SVGSMILElement*>(element)->setDocumentOrderIndex(timingElementCount++); 231 231 } 232 232 m_documentOrderIndexesDirty = false;
Note: See TracChangeset
for help on using the changeset viewer.