Commit 607d2e5a authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Use new Traversal<> API more in the code base

Use new Traversal<> API more in the code base to simplify code a bit and
increase readability.

R=esprehn@chromium.org, adamk@chromium.org

Review URL: https://codereview.chromium.org/420193007

git-svn-id: svn://svn.chromium.org/blink/trunk@179067 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b174c4c8
...@@ -59,16 +59,16 @@ void AffectedByFocusTest::setHtmlInnerHTML(const char* htmlContent) ...@@ -59,16 +59,16 @@ void AffectedByFocusTest::setHtmlInnerHTML(const char* htmlContent)
void AffectedByFocusTest::checkElements(ElementResult expected[], unsigned expectedCount) const void AffectedByFocusTest::checkElements(ElementResult expected[], unsigned expectedCount) const
{ {
unsigned i = 0; unsigned i = 0;
Element* elm = document().body(); HTMLElement* element = document().body();
for (; elm && i < expectedCount; elm = ElementTraversal::next(*elm), ++i) { for (; element && i < expectedCount; element = Traversal<HTMLElement>::next(*element), ++i) {
ASSERT_TRUE(elm->hasTagName(expected[i].tag)); ASSERT_TRUE(element->hasTagName(expected[i].tag));
ASSERT(elm->renderStyle()); ASSERT(element->renderStyle());
ASSERT_EQ(expected[i].affectedBy, elm->renderStyle()->affectedByFocus()); ASSERT_EQ(expected[i].affectedBy, element->renderStyle()->affectedByFocus());
ASSERT_EQ(expected[i].childrenOrSiblingsAffectedBy, elm->childrenOrSiblingsAffectedByFocus()); ASSERT_EQ(expected[i].childrenOrSiblingsAffectedBy, element->childrenOrSiblingsAffectedByFocus());
} }
ASSERT(!elm && i == expectedCount); ASSERT(!element && i == expectedCount);
} }
// A global :focus rule in html.css currently causes every single element to be // A global :focus rule in html.css currently causes every single element to be
......
...@@ -316,10 +316,8 @@ const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> >& ShadowRoot::descend ...@@ -316,10 +316,8 @@ const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> >& ShadowRoot::descend
return emptyList; return emptyList;
WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> > insertionPoints; WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> > insertionPoints;
for (Element* element = ElementTraversal::firstWithin(*this); element; element = ElementTraversal::next(*element, this)) { for (InsertionPoint* insertionPoint = Traversal<InsertionPoint>::firstWithin(*this); insertionPoint; insertionPoint = Traversal<InsertionPoint>::next(*insertionPoint, this))
if (element->isInsertionPoint()) insertionPoints.append(insertionPoint);
insertionPoints.append(toInsertionPoint(element));
}
ensureShadowRootRareData()->setDescendantInsertionPoints(insertionPoints); ensureShadowRootRareData()->setDescendantInsertionPoints(insertionPoints);
......
...@@ -60,10 +60,8 @@ void HTMLFieldSetElement::trace(Visitor* visitor) ...@@ -60,10 +60,8 @@ void HTMLFieldSetElement::trace(Visitor* visitor)
void HTMLFieldSetElement::invalidateDisabledStateUnder(Element& base) void HTMLFieldSetElement::invalidateDisabledStateUnder(Element& base)
{ {
for (Element* element = ElementTraversal::firstWithin(base); element; element = ElementTraversal::next(*element, &base)) { for (HTMLFormControlElement* element = Traversal<HTMLFormControlElement>::firstWithin(base); element; element = Traversal<HTMLFormControlElement>::next(*element, &base))
if (element->isFormControlElement()) element->ancestorDisabledStateWasChanged();
toHTMLFormControlElement(element)->ancestorDisabledStateWasChanged();
}
} }
void HTMLFieldSetElement::disabledAttributeChanged() void HTMLFieldSetElement::disabledAttributeChanged()
......
...@@ -37,15 +37,6 @@ namespace blink { ...@@ -37,15 +37,6 @@ namespace blink {
using namespace HTMLNames; using namespace HTMLNames;
static bool supportsLabels(const Element& element)
{
if (!element.isHTMLElement())
return false;
if (!toHTMLElement(element).isLabelable())
return false;
return toLabelableElement(element).supportLabels();
}
inline HTMLLabelElement::HTMLLabelElement(Document& document) inline HTMLLabelElement::HTMLLabelElement(Document& document)
: HTMLElement(labelTag, document) : HTMLElement(labelTag, document)
{ {
...@@ -67,16 +58,15 @@ LabelableElement* HTMLLabelElement::control() const ...@@ -67,16 +58,15 @@ LabelableElement* HTMLLabelElement::control() const
// Search the children and descendants of the label element for a form element. // 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 // per http://dev.w3.org/html5/spec/Overview.html#the-label-element
// the form element must be "labelable form-associated element". // the form element must be "labelable form-associated element".
for (Element* element = ElementTraversal::next(*this, this); element; element = ElementTraversal::next(*element, this)) { for (LabelableElement* element = Traversal<LabelableElement>::next(*this, this); element; element = Traversal<LabelableElement>::next(*element, this)) {
if (!supportsLabels(*element)) if (element->supportLabels())
continue; return element;
return toLabelableElement(element);
} }
return 0; return 0;
} }
if (Element* element = treeScope().getElementById(controlId)) { if (Element* element = treeScope().getElementById(controlId)) {
if (supportsLabels(*element)) if (isLabelableElement(*element) && toLabelableElement(*element).supportLabels())
return toLabelableElement(element); return toLabelableElement(element);
} }
......
...@@ -374,8 +374,9 @@ void VTTRegion::displayLastVTTCueBox() ...@@ -374,8 +374,9 @@ void VTTRegion::displayLastVTTCueBox()
// Find first cue that is not entirely displayed and scroll it upwards. // Find first cue that is not entirely displayed and scroll it upwards.
for (Element* child = ElementTraversal::firstChild(*m_cueContainer); child && !m_scrollTimer.isActive(); child = ElementTraversal::nextSibling(*child)) { for (Element* child = ElementTraversal::firstChild(*m_cueContainer); child && !m_scrollTimer.isActive(); child = ElementTraversal::nextSibling(*child)) {
float childTop = toHTMLDivElement(child)->getBoundingClientRect()->top(); RefPtrWillBeRawPtr<ClientRect> clientRect = child->getBoundingClientRect();
float childBottom = toHTMLDivElement(child)->getBoundingClientRect()->bottom(); float childTop = clientRect->top();
float childBottom = clientRect->bottom();
if (regionBottom >= childBottom) if (regionBottom >= childBottom)
continue; continue;
......
...@@ -91,14 +91,14 @@ bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context, ...@@ -91,14 +91,14 @@ bool RenderSVGResourceClipper::tryPathOnlyClipping(GraphicsContext* context,
WindRule clipRule = RULE_NONZERO; WindRule clipRule = RULE_NONZERO;
Path clipPath = Path(); Path clipPath = Path();
for (Element* childElement = ElementTraversal::firstChild(*element()); childElement; childElement = ElementTraversal::nextSibling(*childElement)) { for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement)) {
RenderObject* renderer = childElement->renderer(); RenderObject* renderer = childElement->renderer();
if (!renderer) if (!renderer)
continue; continue;
// Only shapes or paths are supported for direct clipping. We need to fallback to masking for texts. // Only shapes or paths are supported for direct clipping. We need to fallback to masking for texts.
if (renderer->isSVGText()) if (renderer->isSVGText())
return false; return false;
if (!childElement->isSVGElement() || !toSVGElement(childElement)->isSVGGraphicsElement()) if (!childElement->isSVGGraphicsElement())
continue; continue;
SVGGraphicsElement* styled = toSVGGraphicsElement(childElement); SVGGraphicsElement* styled = toSVGGraphicsElement(childElement);
RenderStyle* style = renderer->style(); RenderStyle* style = renderer->style();
......
...@@ -137,9 +137,9 @@ PassRefPtr<DisplayList> RenderSVGResourceMasker::asDisplayList(GraphicsContext* ...@@ -137,9 +137,9 @@ PassRefPtr<DisplayList> RenderSVGResourceMasker::asDisplayList(GraphicsContext*
// with local clips/mask, which may yield incorrect results when mixing objectBoundingBox and // with local clips/mask, which may yield incorrect results when mixing objectBoundingBox and
// userSpaceOnUse units (http://crbug.com/294900). // userSpaceOnUse units (http://crbug.com/294900).
context->beginRecording(strokeBoundingBox()); context->beginRecording(strokeBoundingBox());
for (Element* childElement = ElementTraversal::firstChild(*element()); childElement; childElement = ElementTraversal::nextSibling(*childElement)) { for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement)) {
RenderObject* renderer = childElement->renderer(); RenderObject* renderer = childElement->renderer();
if (!childElement->isSVGElement() || !renderer) if (!renderer)
continue; continue;
RenderStyle* style = renderer->style(); RenderStyle* style = renderer->style();
if (!style || style->display() == NONE || style->visibility() != VISIBLE) if (!style || style->display() == NONE || style->visibility() != VISIBLE)
......
...@@ -258,8 +258,8 @@ PassOwnPtr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const PatternA ...@@ -258,8 +258,8 @@ PassOwnPtr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const PatternA
contentTransformation = tileImageTransform; contentTransformation = tileImageTransform;
// Draw the content into the ImageBuffer. // Draw the content into the ImageBuffer.
for (Element* element = ElementTraversal::firstChild(*attributes.patternContentElement()); element; element = ElementTraversal::nextSibling(*element)) { for (SVGElement* element = Traversal<SVGElement>::firstChild(*attributes.patternContentElement()); element; element = Traversal<SVGElement>::nextSibling(*element)) {
if (!element->isSVGElement() || !element->renderer()) if (!element->renderer())
continue; continue;
if (element->renderer()->needsLayout()) if (element->renderer()->needsLayout())
return nullptr; return nullptr;
......
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