This source file includes following definitions.
- create
- additionalPresentationAttributeStyle
- insertRow
- deleteRow
- numRows
- rows
#include "config.h"
#include "core/html/HTMLTableSectionElement.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/ExceptionCode.h"
#include "core/html/HTMLCollection.h"
#include "core/html/HTMLTableElement.h"
#include "core/html/HTMLTableRowElement.h"
namespace WebCore {
using namespace HTMLNames;
inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document& document)
: HTMLTablePartElement(tagName, document)
{
ScriptWrappable::init(this);
}
PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(new HTMLTableSectionElement(tagName, document));
}
const StylePropertySet* HTMLTableSectionElement::additionalPresentationAttributeStyle()
{
if (HTMLTableElement* table = findParentTable())
return table->additionalGroupStyle(true);
return 0;
}
PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionState& exceptionState)
{
RefPtr<HTMLTableRowElement> row;
RefPtr<HTMLCollection> children = rows();
int numRows = children ? (int)children->length() : 0;
if (index < -1 || index > numRows) {
exceptionState.throwDOMException(IndexSizeError, "The provided index (" + String::number(index) + " is outside the range [-1, " + String::number(numRows) + "].");
} else {
row = HTMLTableRowElement::create(document());
if (numRows == index || index == -1)
appendChild(row, exceptionState);
else {
Node* n;
if (index < 1)
n = firstChild();
else
n = children->item(index);
insertBefore(row, n, exceptionState);
}
}
return row.release();
}
void HTMLTableSectionElement::deleteRow(int index, ExceptionState& exceptionState)
{
RefPtr<HTMLCollection> children = rows();
int numRows = children ? (int)children->length() : 0;
if (index == -1)
index = numRows - 1;
if (index >= 0 && index < numRows) {
RefPtr<Element> row = children->item(index);
HTMLElement::removeChild(row.get(), exceptionState);
} else {
exceptionState.throwDOMException(IndexSizeError, "The provided index (" + String::number(index) + " is outside the range [-1, " + String::number(numRows) + "].");
}
}
int HTMLTableSectionElement::numRows() const
{
int rowCount = 0;
for (const HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*this); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row))
++rowCount;
return rowCount;
}
PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
{
return ensureCachedHTMLCollection(TSectionRows);
}
}