diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp | 100 |
1 files changed, 43 insertions, 57 deletions
diff --git a/chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp b/chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp index 3037aff1c61..dbf5e04e827 100644 --- a/chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp +++ b/chromium/third_party/WebKit/Source/core/html/HTMLTableRowsCollection.cpp @@ -29,7 +29,8 @@ #include "config.h" #include "core/html/HTMLTableRowsCollection.h" -#include "HTMLNames.h" +#include "core/HTMLNames.h" +#include "core/dom/ElementTraversal.h" #include "core/html/HTMLTableElement.h" #include "core/html/HTMLTableRowElement.h" @@ -52,96 +53,81 @@ static bool isInFoot(Element* row) return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfootTag); } -HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement* table, HTMLTableRowElement* previous) +HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous) { - Node* child = 0; - // Start by looking for the next row in this section. // Continue only if there is none. if (previous && previous->parentNode() != table) { - for (child = previous->nextSibling(); child; child = child->nextSibling()) { - if (isHTMLTableRowElement(child)) - return toHTMLTableRowElement(child); - } + if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibling(*previous)) + return row; } // If still looking at head sections, find the first row in the next head section. + HTMLElement* child = 0; if (!previous) - child = table->firstChild(); + child = Traversal<HTMLElement>::firstChild(table); else if (isInHead(previous)) - child = previous->parentNode()->nextSibling(); - for (; child; child = child->nextSibling()) { - if (child->hasTagName(theadTag)) { - for (Node* grandchild = child->firstChild(); grandchild; grandchild = grandchild->nextSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); + for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { + if (child->hasLocalName(theadTag)) { + if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child)) + return row; } } // If still looking at top level and bodies, find the next row in top level or the first in the next body section. if (!previous || isInHead(previous)) - child = table->firstChild(); + child = Traversal<HTMLElement>::firstChild(table); else if (previous->parentNode() == table) - child = previous->nextSibling(); + child = Traversal<HTMLElement>::nextSibling(*previous); else if (isInBody(previous)) - child = previous->parentNode()->nextSibling(); - for (; child; child = child->nextSibling()) { + child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); + for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { if (isHTMLTableRowElement(child)) return toHTMLTableRowElement(child); - if (child->hasTagName(tbodyTag)) { - for (Node* grandchild = child->firstChild(); grandchild; grandchild = grandchild->nextSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + if (child->hasLocalName(tbodyTag)) { + if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child)) + return row; } } // Find the first row in the next foot section. if (!previous || !isInFoot(previous)) - child = table->firstChild(); + child = Traversal<HTMLElement>::firstChild(table); else - child = previous->parentNode()->nextSibling(); - for (; child; child = child->nextSibling()) { - if (child->hasTagName(tfootTag)) { - for (Node* grandchild = child->firstChild(); grandchild; grandchild = grandchild->nextSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + child = Traversal<HTMLElement>::nextSibling(*previous->parentNode()); + for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) { + if (child->hasLocalName(tfootTag)) { + if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child)) + return row; } } return 0; } -HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table) +HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement& table) { - for (Node* child = table->lastChild(); child; child = child->previousSibling()) { - if (child->hasTagName(tfootTag)) { - for (Node* grandchild = child->lastChild(); grandchild; grandchild = grandchild->previousSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) { + if (child->hasLocalName(tfootTag)) { + if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child)) + return lastRow; } } - for (Node* child = table->lastChild(); child; child = child->previousSibling()) { + for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) { if (isHTMLTableRowElement(child)) return toHTMLTableRowElement(child); - if (child->hasTagName(tbodyTag)) { - for (Node* grandchild = child->lastChild(); grandchild; grandchild = grandchild->previousSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + if (child->hasLocalName(tbodyTag)) { + if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child)) + return lastRow; } } - for (Node* child = table->lastChild(); child; child = child->previousSibling()) { - if (child->hasTagName(theadTag)) { - for (Node* grandchild = child->lastChild(); grandchild; grandchild = grandchild->previousSibling()) { - if (isHTMLTableRowElement(grandchild)) - return toHTMLTableRowElement(grandchild); - } + for (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) { + if (child->hasLocalName(theadTag)) { + if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child)) + return lastRow; } } @@ -151,20 +137,20 @@ HTMLTableRowElement* HTMLTableRowsCollection::lastRow(HTMLTableElement* table) // Must call get() on the table in case that argument is compiled before dereferencing the // table to get at the collection cache. Order of argument evaluation is undefined and can // differ between compilers. -HTMLTableRowsCollection::HTMLTableRowsCollection(Node* table) +HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table) : HTMLCollection(table, TableRows, OverridesItemAfter) { ASSERT(isHTMLTableElement(table)); } -PassRefPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(Node* table, CollectionType) +PassRefPtrWillBeRawPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(ContainerNode& table, CollectionType type) { - return adoptRef(new HTMLTableRowsCollection(table)); + ASSERT_UNUSED(type, type == TableRows); + return adoptRefWillBeNoop(new HTMLTableRowsCollection(table)); } -Element* HTMLTableRowsCollection::virtualItemAfter(unsigned& offsetInArray, Element* previous) const +Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const { - ASSERT_UNUSED(offsetInArray, !offsetInArray); return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previous)); } |