Title: [161551] trunk/Source/WebCore
Revision
161551
Author
[email protected]
Date
2014-01-09 02:20:39 -0800 (Thu, 09 Jan 2014)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161550 => 161551)


--- trunk/Source/WebCore/ChangeLog	2014-01-09 08:44:48 UTC (rev 161550)
+++ trunk/Source/WebCore/ChangeLog	2014-01-09 10:20:39 UTC (rev 161551)
@@ -1,3 +1,22 @@
+2014-01-09  Antti Koivisto  <[email protected]>
+
+        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):
+
 2014-01-08  Carlos Garcia Campos  <[email protected]>
 
         REGRESSION(r161176): http/tests/misc/authentication-redirect-3/authentication-sent-to-redirect-same-origin-with-location-credentials.html is failing on GTK

Modified: trunk/Source/WebCore/dom/ElementChildIterator.h (161550 => 161551)


--- trunk/Source/WebCore/dom/ElementChildIterator.h	2014-01-09 08:44:48 UTC (rev 161550)
+++ trunk/Source/WebCore/dom/ElementChildIterator.h	2014-01-09 10:20:39 UTC (rev 161551)
@@ -50,8 +50,11 @@
 class ElementChildIteratorAdapter {
 public:
     ElementChildIteratorAdapter(ContainerNode& parent);
+
     ElementChildIterator<ElementType> begin();
     ElementChildIterator<ElementType> end();
+    ElementChildIterator<ElementType> find(Element&);
+
     ElementType* first();
     ElementType* last();
 
@@ -63,8 +66,11 @@
 class ElementChildConstIteratorAdapter {
 public:
     ElementChildConstIteratorAdapter(const ContainerNode& parent);
+
     ElementChildConstIterator<ElementType> begin() const;
     ElementChildConstIterator<ElementType> end() const;
+    ElementChildConstIterator<ElementType> find(const Element&) const;
+
     const ElementType* first() const;
     const ElementType* last() const;
 
@@ -147,6 +153,16 @@
     return Traversal<ElementType>::lastChild(&m_parent);
 }
 
+template <typename ElementType>
+inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::find(Element& child)
+{
+    if (!isElementOfType<const ElementType>(child))
+        return end();
+    if (child.parentNode() != &m_parent)
+        return end();
+    return ElementChildIterator<ElementType>(m_parent, static_cast<ElementType*>(&child));
+}
+
 // ElementChildConstIteratorAdapter
 
 template <typename ElementType>
@@ -179,6 +195,16 @@
     return Traversal<ElementType>::lastChild(&m_parent);
 }
 
+template <typename ElementType>
+inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::find(const Element& child) const
+{
+    if (!isElementOfType<const ElementType>(child))
+        return end();
+    if (child.parentNode() != &m_parent)
+        return end();
+    return ElementChildConstIterator<ElementType>(m_parent, static_cast<const ElementType*>(&child));
+}
+
 // Standalone functions
 
 template <typename ElementType>

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp (161550 => 161551)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2014-01-09 08:44:48 UTC (rev 161550)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2014-01-09 10:20:39 UTC (rev 161551)
@@ -29,7 +29,7 @@
 #include "config.h"
 #include "HTMLTableRowsCollection.h"
 
-#include "ElementTraversal.h"
+#include "ElementIterator.h"
 #include "HTMLNames.h"
 #include "HTMLTableElement.h"
 #include "HTMLTableRowElement.h"
@@ -70,11 +70,13 @@
 
     // Start by looking for the next row in this section. Continue only if there is none.
     if (previous && previous->parentNode() != table) {
-        if (auto row = Traversal<HTMLTableRowElement>::nextSibling(previous))
-            return row;
+        auto rows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
+        auto row = rows.find(*previous);
+        if (++row != rows.end())
+            return &*row;
     }
 
-    Element* child = 0;
+    Element* child = nullptr;
 
     // If still looking at head sections, find the first row in the next head section.
     if (!previous)
@@ -83,7 +85,7 @@
         child = ElementTraversal::nextSibling(previous->parentNode());
     for (; child; child = ElementTraversal::nextSibling(child)) {
         if (child->hasTagName(theadTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
                 return row;
         }
     }
@@ -99,7 +101,7 @@
         if (isHTMLTableRowElement(child))
             return toHTMLTableRowElement(child);
         if (child->hasTagName(tbodyTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
                 return row;
         }
     }
@@ -111,19 +113,19 @@
         child = ElementTraversal::nextSibling(previous->parentNode());
     for (; child; child = ElementTraversal::nextSibling(child)) {
         if (child->hasTagName(tfootTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::firstChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).first())
                 return row;
         }
     }
 
-    return 0;
+    return nullptr;
 }
 
 HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table)
 {
     for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
         if (child->hasTagName(tfootTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
                 return row;
         }
     }
@@ -132,19 +134,19 @@
         if (isHTMLTableRowElement(child))
             return toHTMLTableRowElement(child);
         if (child->hasTagName(tbodyTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
                 return row;
         }
     }
 
     for (auto child = ElementTraversal::lastChild(table); child; child = ElementTraversal::previousSibling(child)) {
         if (child->hasTagName(theadTag)) {
-            if (auto row = Traversal<HTMLTableRowElement>::lastChild(child))
+            if (auto row = childrenOfType<HTMLTableRowElement>(*child).last())
                 return row;
         }
     }
 
-    return 0;
+    return nullptr;
 }
 
 HTMLTableRowsCollection::HTMLTableRowsCollection(HTMLTableElement& table)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to