Changeset 161551 in webkit


Ignore:
Timestamp:
Jan 9, 2014, 2:20:39 AM (11 years ago)
Author:
Antti Koivisto
Message:

Switch HTMLTableRowsCollection from Traversal<> to iterators
https://bugs.webkit.org/show_bug.cgi?id=126684

Reviewed by Andreas Kling.

This is the last remaining client of Traversal<> outside the iterator implementation.

  • dom/ElementChildIterator.h:

(WebCore::ElementChildIteratorAdapter<ElementType>::find):
(WebCore::ElementChildConstIteratorAdapter<ElementType>::find):

Add find with the same semantics as ElementDescendantIterator::find.

  • html/HTMLTableRowsCollection.cpp:

(WebCore::HTMLTableRowsCollection::rowAfter):
(WebCore::HTMLTableRowsCollection::lastRow):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161549 r161551  
     12014-01-09  Antti Koivisto  <antti@apple.com>
     2
     3        Switch HTMLTableRowsCollection from Traversal<> to iterators
     4        https://bugs.webkit.org/show_bug.cgi?id=126684
     5
     6        Reviewed by Andreas Kling.
     7
     8        This is the last remaining client of Traversal<> outside the iterator implementation.
     9
     10        * dom/ElementChildIterator.h:
     11        (WebCore::ElementChildIteratorAdapter<ElementType>::find):
     12        (WebCore::ElementChildConstIteratorAdapter<ElementType>::find):
     13       
     14            Add find with the same semantics as ElementDescendantIterator::find.
     15
     16        * html/HTMLTableRowsCollection.cpp:
     17        (WebCore::HTMLTableRowsCollection::rowAfter):
     18        (WebCore::HTMLTableRowsCollection::lastRow):
     19
    1202014-01-08  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • trunk/Source/WebCore/dom/ElementChildIterator.h

    r161196 r161551  
    5151public:
    5252    ElementChildIteratorAdapter(ContainerNode& parent);
     53
    5354    ElementChildIterator<ElementType> begin();
    5455    ElementChildIterator<ElementType> end();
     56    ElementChildIterator<ElementType> find(Element&);
     57
    5558    ElementType* first();
    5659    ElementType* last();
     
    6467public:
    6568    ElementChildConstIteratorAdapter(const ContainerNode& parent);
     69
    6670    ElementChildConstIterator<ElementType> begin() const;
    6771    ElementChildConstIterator<ElementType> end() const;
     72    ElementChildConstIterator<ElementType> find(const Element&) const;
     73
    6874    const ElementType* first() const;
    6975    const ElementType* last() const;
     
    148154}
    149155
     156template <typename ElementType>
     157inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::find(Element& child)
     158{
     159    if (!isElementOfType<const ElementType>(child))
     160        return end();
     161    if (child.parentNode() != &m_parent)
     162        return end();
     163    return ElementChildIterator<ElementType>(m_parent, static_cast<ElementType*>(&child));
     164}
     165
    150166// ElementChildConstIteratorAdapter
    151167
     
    180196}
    181197
     198template <typename ElementType>
     199inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::find(const Element& child) const
     200{
     201    if (!isElementOfType<const ElementType>(child))
     202        return end();
     203    if (child.parentNode() != &m_parent)
     204        return end();
     205    return ElementChildConstIterator<ElementType>(m_parent, static_cast<const ElementType*>(&child));
     206}
     207
    182208// Standalone functions
    183209
  • trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp

    r158758 r161551  
    3030#include "HTMLTableRowsCollection.h"
    3131
    32 #include "ElementTraversal.h"
     32#include "ElementIterator.h"
    3333#include "HTMLNames.h"
    3434#include "HTMLTableElement.h"
     
    7171    // Start by looking for the next row in this section. Continue only if there is none.
    7272    if (previous && previous->parentNode() != table) {
    73         if (auto row = Traversal<HTMLTableRowElement>::nextSibling(previous))
    74             return row;
     73        auto rows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
     74        auto row = rows.find(*previous);
     75        if (++row != rows.end())
     76            return &*row;
    7577    }
    7678
    77     Element* child = 0;
     79    Element* child = nullptr;
    7880
    7981    // If still looking at head sections, find the first row in the next head section.
     
    8486    for (; child; child = ElementTraversal::nextSibling(child)) {
    8587        if (child->hasTagName(theadTag)) {
    86             if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
     88            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
    8789                return row;
    8890        }
     
    100102            return toHTMLTableRowElement(child);
    101103        if (child->hasTagName(tbodyTag)) {
    102             if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
     104            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
    103105                return row;
    104106        }
     
    112114    for (; child; child = ElementTraversal::nextSibling(child)) {
    113115        if (child->hasTagName(tfootTag)) {
    114             if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
     116            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
    115117                return row;
    116118        }
    117119    }
    118120
    119     return 0;
     121    return nullptr;
    120122}
    121123
     
    124126    for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
    125127        if (child->hasTagName(tfootTag)) {
    126             if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
     128            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
    127129                return row;
    128130        }
     
    133135            return toHTMLTableRowElement(child);
    134136        if (child->hasTagName(tbodyTag)) {
    135             if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
     137            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
    136138                return row;
    137139        }
     
    140142    for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
    141143        if (child->hasTagName(theadTag)) {
    142             if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
     144            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
    143145                return row;
    144146        }
    145147    }
    146148
    147     return 0;
     149    return nullptr;
    148150}
    149151
Note: See TracChangeset for help on using the changeset viewer.