Commit 39d6d4a6 authored by antti@apple.com's avatar antti@apple.com
Browse files

Switch some more code to element child/descendant iterators

https://bugs.webkit.org/show_bug.cgi?id=120355

Reviewed by Andreas Kling.

Move from Traversal<ElementType>::next() and Traversal<ElementType>::nextSibling() to iterators.

* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
* dom/Document.cpp:
(WebCore::Document::removeTitle):
(WebCore::Document::updateBaseURL):
(WebCore::Document::processBaseElement):
* dom/TreeScope.cpp:
(WebCore::TreeScope::labelElementForId):
(WebCore::TreeScope::findAnchor):
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::invalidateDisabledStateUnder):
(WebCore::HTMLFieldSetElement::childrenChanged):
* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::control):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::parametersForPlugin):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::buildReferenceFilter):
* svg/SVGFilterPrimitiveStandardAttributes.h:
(WebCore::isSVGFilterPrimitiveStandardAttributes):
(WebCore::SVGFilterPrimitiveStandardAttributes):
* svg/animation/SMILTimeContainer.cpp:
(WebCore::SMILTimeContainer::updateDocumentOrderIndexes):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::hasSingleSecurityOrigin):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154679 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ef7cefa6
2013-08-27 Antti Koivisto <antti@apple.com>
Switch some more code to element child/descendant iterators
https://bugs.webkit.org/show_bug.cgi?id=120355
Reviewed by Andreas Kling.
Move from Traversal<ElementType>::next() and Traversal<ElementType>::nextSibling() to iterators.
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
* dom/Document.cpp:
(WebCore::Document::removeTitle):
(WebCore::Document::updateBaseURL):
(WebCore::Document::processBaseElement):
* dom/TreeScope.cpp:
(WebCore::TreeScope::labelElementForId):
(WebCore::TreeScope::findAnchor):
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::invalidateDisabledStateUnder):
(WebCore::HTMLFieldSetElement::childrenChanged):
* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::control):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::cancelPendingEventsAndCallbacks):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::parametersForPlugin):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::buildReferenceFilter):
* svg/SVGFilterPrimitiveStandardAttributes.h:
(WebCore::isSVGFilterPrimitiveStandardAttributes):
(WebCore::SVGFilterPrimitiveStandardAttributes):
* svg/animation/SMILTimeContainer.cpp:
(WebCore::SMILTimeContainer::updateDocumentOrderIndexes):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::hasSingleSecurityOrigin):
2013-08-26 Andreas Kling <akling@apple.com>
 
FocusController::focusedOrMainFrame() should return a reference.
......@@ -26,12 +26,12 @@
#include "config.h"
#include "CSSFontFaceSource.h"
#include "CachedFont.h"
#include "CSSFontFace.h"
#include "CSSFontSelector.h"
#include "CachedFont.h"
#include "CachedResourceLoader.h"
#include "ChildIterator.h"
#include "Document.h"
#include "ElementTraversal.h"
#include "FontCache.h"
#include "FontDescription.h"
#include "SimpleFontData.h"
......@@ -139,14 +139,16 @@ PassRefPtr<SimpleFontData> CSSFontFaceSource::getFontData(const FontDescription&
if (!m_externalSVGFontElement)
return 0;
if (auto fontFaceElement = Traversal<SVGFontFaceElement>::firstChild(m_externalSVGFontElement.get())) {
auto fontFaceChildren = childrenOfType<SVGFontFaceElement>(m_externalSVGFontElement.get());
auto firstFontFace = fontFaceChildren.begin();
if (firstFontFace != fontFaceChildren.end()) {
if (!m_svgFontFaceElement) {
// We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
// Use the imported <font-face> tag as referencing font-face element for these cases.
m_svgFontFaceElement = fontFaceElement;
m_svgFontFaceElement = &*firstFontFace;
}
fontData = SimpleFontData::create(SVGFontData::create(fontFaceElement), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
fontData = SimpleFontData::create(SVGFontData::create(&*firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
}
} else
#endif
......
......@@ -1565,8 +1565,9 @@ void Document::removeTitle(Element* titleElement)
// Update title based on first title element in the head, if one exists.
if (HTMLElement* headElement = head()) {
if (HTMLTitleElement* titleElement = Traversal<HTMLTitleElement>::firstWithin(headElement))
setTitleElement(titleElement->textWithDirection(), titleElement);
auto firstTitle = childrenOfType<HTMLTitleElement>(headElement).begin();
if (firstTitle != childrenOfType<HTMLTitleElement>(headElement).end())
setTitleElement(firstTitle->textWithDirection(), &*firstTitle);
}
if (!m_titleElement)
......@@ -2654,7 +2655,8 @@ void Document::updateBaseURL()
if (!equalIgnoringFragmentIdentifier(oldBaseURL, m_baseURL)) {
// Base URL change changes any relative visited links.
// 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.
for (HTMLAnchorElement* anchor = Traversal<HTMLAnchorElement>::firstWithin(this); anchor; anchor = Traversal<HTMLAnchorElement>::next(anchor))
auto anchorDescendants = descendantsOfType<HTMLAnchorElement>(this);
for (auto anchor = anchorDescendants.begin(), end = anchorDescendants.end(); anchor != end; ++anchor)
anchor->invalidateCachedVisitedLinkHash();
}
}
......@@ -2670,7 +2672,8 @@ void Document::processBaseElement()
// Find the first href attribute in a base element and the first target attribute in a base element.
const AtomicString* href = 0;
const AtomicString* target = 0;
for (HTMLBaseElement* base = Traversal<HTMLBaseElement>::firstWithin(this); base && (!href || !target); base = Traversal<HTMLBaseElement>::next(base)) {
auto baseDescendants = descendantsOfType<HTMLBaseElement>(this);
for (auto base = baseDescendants.begin(), end = baseDescendants.end(); base != end && (!href || !target); ++base) {
if (!href) {
const AtomicString& value = base->fastGetAttribute(hrefAttr);
if (!value.isNull())
......
......@@ -30,9 +30,9 @@
#include "ContainerNode.h"
#include "DOMSelection.h"
#include "DOMWindow.h"
#include "DescendantIterator.h"
#include "Document.h"
#include "Element.h"
#include "ElementTraversal.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameView.h"
......@@ -298,10 +298,12 @@ HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeV
if (!m_labelsByForAttribute) {
// Populate the map on first access.
m_labelsByForAttribute = adoptPtr(new DocumentOrderedMap);
for (HTMLLabelElement* label = Traversal<HTMLLabelElement>::firstWithin(rootNode()); label; label = Traversal<HTMLLabelElement>::next(label)) {
auto labelDescendants = descendantsOfType<HTMLLabelElement>(rootNode());
for (auto label = labelDescendants.begin(), end = labelDescendants.end(); label != end; ++label) {
const AtomicString& forValue = label->fastGetAttribute(forAttr);
if (!forValue.isEmpty())
addLabel(forValue, label);
addLabel(forValue, &*label);
}
}
......@@ -339,15 +341,16 @@ Element* TreeScope::findAnchor(const String& name)
return 0;
if (Element* element = getElementById(name))
return element;
for (HTMLAnchorElement* anchor = Traversal<HTMLAnchorElement>::firstWithin(rootNode()); anchor; anchor = Traversal<HTMLAnchorElement>::next(anchor)) {
auto anchorDescendants = descendantsOfType<HTMLAnchorElement>(rootNode());
for (auto anchor = anchorDescendants.begin(), end = anchorDescendants.end(); anchor != end; ++anchor) {
if (rootNode()->document()->inQuirksMode()) {
// Quirks mode, case insensitive comparison of names.
if (equalIgnoringCase(anchor->name(), name))
return anchor;
return &*anchor;
} else {
// Strict mode, names need to match exactly.
if (anchor->name() == name)
return anchor;
return &*anchor;
}
}
return 0;
......
......@@ -25,7 +25,8 @@
#include "config.h"
#include "HTMLFieldSetElement.h"
#include "ElementTraversal.h"
#include "ChildIterator.h"
#include "DescendantIterator.h"
#include "HTMLCollection.h"
#include "HTMLLegendElement.h"
#include "HTMLNames.h"
......@@ -51,7 +52,8 @@ PassRefPtr<HTMLFieldSetElement> HTMLFieldSetElement::create(const QualifiedName&
void HTMLFieldSetElement::invalidateDisabledStateUnder(Element* base)
{
for (HTMLFormControlElement* control = Traversal<HTMLFormControlElement>::firstWithin(base); control; control = Traversal<HTMLFormControlElement>::next(control, base))
auto formControlDescendants = descendantsOfType<HTMLFormControlElement>(base);
for (auto control = formControlDescendants.begin(), end = formControlDescendants.end(); control != end; ++control)
control->ancestorDisabledStateWasChanged();
}
......@@ -65,8 +67,10 @@ void HTMLFieldSetElement::disabledAttributeChanged()
void HTMLFieldSetElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
for (HTMLLegendElement* legend = Traversal<HTMLLegendElement>::firstChild(this); legend; legend = Traversal<HTMLLegendElement>::nextSibling(legend))
invalidateDisabledStateUnder(legend);
auto legendChildren = childrenOfType<HTMLLegendElement>(this);
for (auto legend = legendChildren.begin(), end = legendChildren.end(); legend != end; ++legend)
invalidateDisabledStateUnder(&*legend);
}
bool HTMLFieldSetElement::supportsFocus() const
......
......@@ -25,8 +25,8 @@
#include "config.h"
#include "HTMLLabelElement.h"
#include "DescendantIterator.h"
#include "Document.h"
#include "ElementTraversal.h"
#include "Event.h"
#include "EventNames.h"
#include "FormAssociatedElement.h"
......@@ -69,11 +69,10 @@ LabelableElement* HTMLLabelElement::control()
// Search the children and descendants of the label element for a form element.
// per http://dev.w3.org/html5/spec/Overview.html#the-label-element
// the form element must be "labelable form-associated element".
LabelableElement* labelableElement = Traversal<LabelableElement>::firstWithin(this);
for (; labelableElement; labelableElement = Traversal<LabelableElement>::next(labelableElement, this)) {
auto labelableDescendants = descendantsOfType<LabelableElement>(this);
for (auto labelableElement = labelableDescendants.begin(), end = labelableDescendants.end(); labelableElement != end; ++labelableElement) {
if (labelableElement->supportLabels())
return labelableElement;
return &*labelableElement;
}
return 0;
}
......
......@@ -1651,7 +1651,8 @@ void HTMLMediaElement::cancelPendingEventsAndCallbacks()
LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks");
m_asyncEventQueue->cancelAllEvents();
for (auto source = Traversal<HTMLSourceElement>::firstChild(this); source; source = Traversal<HTMLSourceElement>::nextSibling(source))
auto sourceChildren = childrenOfType<HTMLSourceElement>(this);
for (auto source = sourceChildren.begin(), end = sourceChildren.end(); source != end; ++source)
source->cancelPendingErrorEvent();
}
......
......@@ -27,9 +27,9 @@
#include "Attribute.h"
#include "CSSValueKeywords.h"
#include "CachedImage.h"
#include "ChildIterator.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "ElementTraversal.h"
#include "EventNames.h"
#include "ExceptionCode.h"
#include "FormDataList.h"
......@@ -153,7 +153,8 @@ void HTMLObjectElement::parametersForPlugin(Vector<String>& paramNames, Vector<S
// Scan the PARAM children and store their name/value pairs.
// Get the URL and type from the params if we don't already have them.
for (auto param = Traversal<HTMLParamElement>::firstChild(this); param; param = Traversal<HTMLParamElement>::nextSibling(param)) {
auto paramChildren = childrenOfType<HTMLParamElement>(this);
for (auto param = paramChildren.begin(), end = paramChildren.end(); param != end; ++param) {
String name = param->name();
if (name.isEmpty())
continue;
......
......@@ -29,9 +29,9 @@
#include "FilterEffectRenderer.h"
#include "ChildIterator.h"
#include "ColorSpace.h"
#include "Document.h"
#include "ElementTraversal.h"
#include "FEColorMatrix.h"
#include "FEComponentTransfer.h"
#include "FEDropShadow.h"
......@@ -159,11 +159,9 @@ PassRefPtr<FilterEffect> FilterEffectRenderer::buildReferenceFilter(RenderObject
// This may need a spec clarification.
RefPtr<SVGFilterBuilder> builder = SVGFilterBuilder::create(previousEffect, SourceAlpha::create(this));
for (SVGElement* svgElement = Traversal<SVGElement>::firstChild(filter); svgElement; svgElement = Traversal<SVGElement>::nextSibling(svgElement)) {
if (!svgElement->isFilterEffect())
continue;
SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFilterPrimitiveStandardAttributes*>(svgElement);
auto attributesChildren = childrenOfType<SVGFilterPrimitiveStandardAttributes>(filter);
for (auto it = attributesChildren.begin(), end = attributesChildren.end(); it != end; ++it) {
SVGFilterPrimitiveStandardAttributes* effectElement = &*it;
effect = effectElement->build(builder.get(), this);
if (!effect)
continue;
......
......@@ -83,6 +83,14 @@ private:
void invalidateFilterPrimitiveParent(SVGElement*);
inline bool isSVGFilterPrimitiveStandardAttributes(const Node* node)
{
return node->isSVGElement() && toSVGElement(node)->isFilterEffect();
}
template <> inline bool isElementOfType<SVGFilterPrimitiveStandardAttributes>(const Element* element) { return isSVGFilterPrimitiveStandardAttributes(element); }
} // namespace WebCore
#endif // ENABLE(SVG)
......
......@@ -27,8 +27,8 @@
#include "SMILTimeContainer.h"
#if ENABLE(SVG)
#include "DescendantIterator.h"
#include "Document.h"
#include "ElementTraversal.h"
#include "SVGNames.h"
#include "SVGSMILElement.h"
#include "SVGSVGElement.h"
......@@ -222,9 +222,11 @@ void SMILTimeContainer::timerFired(Timer<SMILTimeContainer>*)
void SMILTimeContainer::updateDocumentOrderIndexes()
{
unsigned timingElementCount = 0;
SVGSMILElement* smilElement = Traversal<SVGSMILElement>::firstWithin(m_ownerSVGElement);
for (; smilElement; smilElement = Traversal<SVGSMILElement>::next(smilElement, m_ownerSVGElement))
auto smilDescendants = descendantsOfType<SVGSMILElement>(m_ownerSVGElement);
for (auto smilElement = smilDescendants.begin(), end = smilDescendants.end(); smilElement != end; ++smilElement)
smilElement->setDocumentOrderIndex(timingElementCount++);
m_documentOrderIndexesDirty = false;
}
......
......@@ -31,8 +31,8 @@
#include "SVGImage.h"
#include "Chrome.h"
#include "DescendantIterator.h"
#include "DocumentLoader.h"
#include "ElementTraversal.h"
#include "FrameView.h"
#include "ImageBuffer.h"
#include "ImageObserver.h"
......@@ -74,7 +74,8 @@ bool SVGImage::hasSingleSecurityOrigin() const
return true;
// Don't allow foreignObject elements since they can leak information with arbitrary HTML (like spellcheck or control theme).
if (Traversal<SVGForeignObjectElement>::firstWithin(rootElement))
auto foreignObjectDescendants = descendantsOfType<SVGForeignObjectElement>(rootElement);
if (foreignObjectDescendants.begin() != foreignObjectDescendants.end())
return false;
// Because SVG image rendering disallows external resources and links,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment