Changeset 156612 in webkit


Ignore:
Timestamp:
Sep 28, 2013 1:20:56 PM (11 years ago)
Author:
Antti Koivisto
Message:

Add first()/last() to ElementIteratorAdapters
https://bugs.webkit.org/show_bug.cgi?id=122067

Reviewed by Darin Adler.

Add a convenient way for getting the first and last element if it exists.

Use it in some places.

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::canvasHasFallbackContent):

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::getFontData):

  • dom/Document.cpp:

(WebCore::Document::childrenChanged):
(WebCore::Document::removeTitle):

  • dom/ElementChildIterator.h:

(WebCore::::first):
(WebCore::::last):

  • dom/ElementDescendantIterator.h:

(WebCore::::first):
(WebCore::::last):

  • html/HTMLFieldSetElement.cpp:

(WebCore::HTMLFieldSetElement::legend):

  • html/HTMLLegendElement.cpp:

(WebCore::HTMLLegendElement::associatedControl):

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::finishParsingChildren):
(WebCore::HTMLMediaElement::selectMediaResource):

  • svg/SVGElement.cpp:

(WebCore::SVGElement::title):

  • svg/SVGFontFaceElement.cpp:

(WebCore::SVGFontFaceElement::rebuildFontFace):

  • svg/graphics/SVGImage.cpp:

(WebCore::SVGImage::hasSingleSecurityOrigin):

Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156611 r156612  
     12013-09-28  Antti Koivisto  <antti@apple.com>
     2
     3        Add first()/last() to ElementIteratorAdapters
     4        https://bugs.webkit.org/show_bug.cgi?id=122067
     5
     6        Reviewed by Darin Adler.
     7
     8        Add a convenient way for getting the first and last element if it exists.
     9       
     10        Use it in some places.
     11
     12        * accessibility/AccessibilityNodeObject.cpp:
     13        (WebCore::AccessibilityNodeObject::canvasHasFallbackContent):
     14        * css/CSSFontFaceSource.cpp:
     15        (WebCore::CSSFontFaceSource::getFontData):
     16        * dom/Document.cpp:
     17        (WebCore::Document::childrenChanged):
     18        (WebCore::Document::removeTitle):
     19        * dom/ElementChildIterator.h:
     20        (WebCore::::first):
     21        (WebCore::::last):
     22        * dom/ElementDescendantIterator.h:
     23        (WebCore::::first):
     24        (WebCore::::last):
     25        * html/HTMLFieldSetElement.cpp:
     26        (WebCore::HTMLFieldSetElement::legend):
     27        * html/HTMLLegendElement.cpp:
     28        (WebCore::HTMLLegendElement::associatedControl):
     29        * html/HTMLMediaElement.cpp:
     30        (WebCore::HTMLMediaElement::finishParsingChildren):
     31        (WebCore::HTMLMediaElement::selectMediaResource):
     32        * svg/SVGElement.cpp:
     33        (WebCore::SVGElement::title):
     34        * svg/SVGFontFaceElement.cpp:
     35        (WebCore::SVGFontFaceElement::rebuildFontFace):
     36        * svg/graphics/SVGImage.cpp:
     37        (WebCore::SVGImage::hasSingleSecurityOrigin):
     38
    1392013-09-28  Mark Rowe  <mrowe@apple.com>
    240
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r156532 r156612  
    424424    // content. If it has no children or its only children are not elements
    425425    // (e.g. just text nodes), it doesn't have fallback content.
    426     return elementChildren(canvasElement).begin() != elementChildren(canvasElement).end();
     426    return elementChildren(canvasElement).first();
    427427}
    428428
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r155729 r156612  
    140140                    return 0;
    141141
    142                 auto fontFaceChildren = childrenOfType<SVGFontFaceElement>(m_externalSVGFontElement.get());
    143                 auto firstFontFace = fontFaceChildren.begin();
    144                 if (firstFontFace != fontFaceChildren.end()) {
     142                if (auto firstFontFace = childrenOfType<SVGFontFaceElement>(m_externalSVGFontElement.get()).first()) {
    145143                    if (!m_svgFontFaceElement) {
    146144                        // We're created using a CSS @font-face rule, that means we're not associated with a SVGFontFaceElement.
    147145                        // Use the imported <font-face> tag as referencing font-face element for these cases.
    148                         m_svgFontFaceElement = &*firstFontFace;
     146                        m_svgFontFaceElement = firstFontFace;
    149147                    }
    150148
    151                     fontData = SimpleFontData::create(SVGFontData::create(&*firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
     149                    fontData = SimpleFontData::create(SVGFontData::create(firstFontFace), fontDescription.computedPixelSize(), syntheticBold, syntheticItalic);
    152150                }
    153151            } else
  • trunk/Source/WebCore/dom/Document.cpp

    r156609 r156612  
    795795#endif
    796796
    797     Element* newDocumentElement = 0;
    798     auto firstElementChild = elementChildren(this).begin();
    799     if (firstElementChild != elementChildren(this).end())
    800         newDocumentElement = &*firstElementChild;
     797    Element* newDocumentElement = elementChildren(this).first();
    801798
    802799    if (newDocumentElement == m_documentElement)
     
    15871584    // Update title based on first title element in the head, if one exists.
    15881585    if (HTMLElement* headElement = head()) {
    1589         auto firstTitle = childrenOfType<HTMLTitleElement>(headElement).begin();
    1590         if (firstTitle != childrenOfType<HTMLTitleElement>(headElement).end())
    1591             setTitleElement(firstTitle->textWithDirection(), &*firstTitle);
     1586        if (auto firstTitle = childrenOfType<HTMLTitleElement>(headElement).first())
     1587            setTitleElement(firstTitle->textWithDirection(), firstTitle);
    15921588    }
    15931589
  • trunk/Source/WebCore/dom/ElementChildIterator.h

    r154928 r156612  
    5353    ElementChildIterator<ElementType> begin();
    5454    ElementChildIterator<ElementType> end();
     55    ElementType* first();
     56    ElementType* last();
    5557
    5658private:
     
    6466    ElementChildConstIterator<ElementType> begin() const;
    6567    ElementChildConstIterator<ElementType> end() const;
     68    const ElementType* first() const;
     69    const ElementType* last() const;
    6670
    6771private:
     
    134138}
    135139
     140template <typename ElementType>
     141inline ElementType* ElementChildIteratorAdapter<ElementType>::first()
     142{
     143    return Traversal<ElementType>::firstChild(m_root);
     144}
     145
     146template <typename ElementType>
     147inline ElementType* ElementChildIteratorAdapter<ElementType>::last()
     148{
     149    return Traversal<ElementType>::lastChild(m_root);
     150}
     151
    136152// ElementChildConstIteratorAdapter
    137153
     
    154170}
    155171
     172template <typename ElementType>
     173inline const ElementType* ElementChildConstIteratorAdapter<ElementType>::first() const
     174{
     175    return Traversal<ElementType>::firstChild(m_root);
     176}
     177
     178template <typename ElementType>
     179inline const ElementType* ElementChildConstIteratorAdapter<ElementType>::last() const
     180{
     181    return Traversal<ElementType>::lastChild(m_root);
     182}
     183
    156184// Standalone functions
    157185
  • trunk/Source/WebCore/dom/ElementDescendantIterator.h

    r154928 r156612  
    5353    ElementDescendantIterator<ElementType> begin();
    5454    ElementDescendantIterator<ElementType> end();
     55    ElementType* first();
     56    ElementType* last();
    5557
    5658private:
     
    6466    ElementDescendantConstIterator<ElementType> begin() const;
    6567    ElementDescendantConstIterator<ElementType> end() const;
     68    const ElementType* first() const;
     69    const ElementType* last() const;
    6670
    6771private:
     
    135139}
    136140
     141template <typename ElementType>
     142inline ElementType* ElementDescendantIteratorAdapter<ElementType>::first()
     143{
     144    return Traversal<ElementType>::firstWithin(m_root);
     145}
     146
     147template <typename ElementType>
     148inline ElementType* ElementDescendantIteratorAdapter<ElementType>::last()
     149{
     150    return Traversal<ElementType>::lastWithin(m_root);
     151}
     152
    137153// ElementDescendantConstIteratorAdapter
    138154
     
    155171}
    156172
     173template <typename ElementType>
     174inline const ElementType* ElementDescendantConstIteratorAdapter<ElementType>::first() const
     175{
     176    return Traversal<ElementType>::firstWithin(m_root);
     177}
     178
     179template <typename ElementType>
     180inline const ElementType* ElementDescendantConstIteratorAdapter<ElementType>::last() const
     181{
     182    return Traversal<ElementType>::lastWithin(m_root);
     183}
     184
    157185// Standalone functions
    158186
  • trunk/Source/WebCore/html/HTMLFieldSetElement.cpp

    r156147 r156612  
    9191const HTMLLegendElement* HTMLFieldSetElement::legend() const
    9292{
    93     auto legendDescendants = descendantsOfType<HTMLLegendElement>(this);
    94     auto firstLegend = legendDescendants.begin();
    95     if (firstLegend != legendDescendants.end())
    96         return &*firstLegend;
    97     return nullptr;
     93    return descendantsOfType<HTMLLegendElement>(this).first();
    9894}
    9995
  • trunk/Source/WebCore/html/HTMLLegendElement.cpp

    r155795 r156612  
    5757    // Find first form element inside the fieldset that is not a legend element.
    5858    // FIXME: Should we consider tabindex?
    59     auto fieldsetFormControlDescendants = descendantsOfType<HTMLFormControlElement>(&*enclosingFieldset);
    60     auto firstFormControl = fieldsetFormControlDescendants.begin();
    61     return firstFormControl != fieldsetFormControlDescendants.end() ? &*firstFormControl : nullptr;
     59    return descendantsOfType<HTMLFormControlElement>(&*enclosingFieldset).first();
    6260}
    6361
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r156550 r156612  
    549549        return;
    550550
    551     auto trackDescendants = descendantsOfType<HTMLTrackElement>(this);
    552     if (trackDescendants.begin() != trackDescendants.end())
     551    if (descendantsOfType<HTMLTrackElement>(this).first())
    553552        scheduleDelayedAction(ConfigureTextTracks);
    554553#endif
     
    940939        // element child, then let mode be children and let candidate be the first such
    941940        // source element child in tree order.
    942         auto source = childrenOfType<HTMLSourceElement>(this).begin();
    943         if (source != childrenOfType<HTMLSourceElement>(this).end()) {
     941        if (auto firstSource = childrenOfType<HTMLSourceElement>(this).first()) {
    944942            mode = children;
    945             m_nextChildNodeToConsider = &*source;
     943            m_nextChildNodeToConsider = firstSource;
    946944            m_currentSourceNode = 0;
    947945        } else {
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r156231 r156612  
    954954    // If we aren't an instance in a <use> or the <use> title was not found, then find the first
    955955    // <title> child of this element.
    956     // If a title child was found, return the text contents.
    957     auto titleDescendants = descendantsOfType<SVGTitleElement>(this);
    958     auto firstTitle = titleDescendants.begin();
    959     if (firstTitle != titleDescendants.end())
    960         return const_cast<SVGTitleElement&>(*firstTitle).innerText();
    961 
    962     // Otherwise return a null/empty string.
    963     return String();
     956    auto firstTitle = descendantsOfType<SVGTitleElement>(this).first();
     957    return firstTitle ? const_cast<SVGTitleElement*>(firstTitle)->innerText() : String();
    964958}
    965959
  • trunk/Source/WebCore/svg/SVGFontFaceElement.cpp

    r155815 r156612  
    229229
    230230    // we currently ignore all but the first src element, alternatively we could concat them
    231     SVGFontFaceSrcElement* srcElement = 0;
    232     auto firstFontFaceSrcElementChild = childrenOfType<SVGFontFaceSrcElement>(this).begin();
    233     if (firstFontFaceSrcElementChild != childrenOfType<SVGFontFaceSrcElement>(this).end())
    234         srcElement = &*firstFontFaceSrcElementChild;
     231    auto srcElement = childrenOfType<SVGFontFaceSrcElement>(this).first();
    235232
    236233    bool describesParentFont = isSVGFontElement(parentNode());
  • trunk/Source/WebCore/svg/graphics/SVGImage.cpp

    r156550 r156612  
    7676
    7777    // Don't allow foreignObject elements since they can leak information with arbitrary HTML (like spellcheck or control theme).
    78     auto foreignObjectDescendants = descendantsOfType<SVGForeignObjectElement>(rootElement);
    79     if (foreignObjectDescendants.begin() != foreignObjectDescendants.end())
     78    if (descendantsOfType<SVGForeignObjectElement>(rootElement).first())
    8079        return false;
    8180
Note: See TracChangeset for help on using the changeset viewer.