This source file includes following definitions.
- isInHead
- isInBody
- isInFoot
- rowAfter
- lastRow
- create
- virtualItemAfter
#include "config.h"
#include "core/html/HTMLTableRowsCollection.h"
#include "HTMLNames.h"
#include "core/dom/ElementTraversal.h"
#include "core/html/HTMLTableElement.h"
#include "core/html/HTMLTableRowElement.h"
namespace WebCore {
using namespace HTMLNames;
static bool isInHead(Element* row)
{
return row->parentNode() && toElement(row->parentNode())->hasLocalName(theadTag);
}
static bool isInBody(Element* row)
{
return row->parentNode() && toElement(row->parentNode())->hasLocalName(tbodyTag);
}
static bool isInFoot(Element* row)
{
return row->parentNode() && toElement(row->parentNode())->hasLocalName(tfootTag);
}
HTMLTableRowElement* HTMLTableRowsCollection::rowAfter(HTMLTableElement& table, HTMLTableRowElement* previous)
{
if (previous && previous->parentNode() != table) {
if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::nextSibling(*previous))
return row;
}
HTMLElement* child = 0;
if (!previous)
child = Traversal<HTMLElement>::firstChild(table);
else if (isInHead(previous))
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 (!previous || isInHead(previous))
child = Traversal<HTMLElement>::firstChild(table);
else if (previous->parentNode() == table)
child = Traversal<HTMLElement>::nextSibling(*previous);
else if (isInBody(previous))
child = Traversal<HTMLElement>::nextSibling(*previous->parentNode());
for (; child; child = Traversal<HTMLElement>::nextSibling(*child)) {
if (isHTMLTableRowElement(child))
return toHTMLTableRowElement(child);
if (child->hasLocalName(tbodyTag)) {
if (HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*child))
return row;
}
}
if (!previous || !isInFoot(previous))
child = Traversal<HTMLElement>::firstChild(table);
else
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)
{
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 (HTMLElement* child = Traversal<HTMLElement>::lastChild(table); child; child = Traversal<HTMLElement>::previousSibling(*child)) {
if (isHTMLTableRowElement(child))
return toHTMLTableRowElement(child);
if (child->hasLocalName(tbodyTag)) {
if (HTMLTableRowElement* lastRow = Traversal<HTMLTableRowElement>::lastChild(*child))
return lastRow;
}
}
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;
}
}
return 0;
}
HTMLTableRowsCollection::HTMLTableRowsCollection(ContainerNode& table)
: HTMLCollection(table, TableRows, OverridesItemAfter)
{
ASSERT(isHTMLTableElement(table));
}
PassRefPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(ContainerNode& table, CollectionType)
{
return adoptRef(new HTMLTableRowsCollection(table));
}
Element* HTMLTableRowsCollection::virtualItemAfter(Element* previous) const
{
return rowAfter(toHTMLTableElement(ownerNode()), toHTMLTableRowElement(previous));
}
}