HTMLTableSectionElement.cpp [plain text]
#include "config.h"
#include "HTMLTableSectionElement.h"
#include "ExceptionCode.h"
#include "HTMLCollection.h"
#include "HTMLNames.h"
#include "HTMLTableRowElement.h"
#include "HTMLTableElement.h"
#include "NodeList.h"
#include "Text.h"
namespace WebCore {
using namespace HTMLNames;
HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document)
: HTMLTablePartElement(tagName, document)
{
}
bool HTMLTableSectionElement::checkDTD(const Node* newChild)
{
if (newChild->isTextNode())
return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
return newChild->hasTagName(trTag) || newChild->hasTagName(formTag) ||
newChild->hasTagName(scriptTag);
}
ContainerNode* HTMLTableSectionElement::addChild(PassRefPtr<Node> child)
{
if (child->hasTagName(formTag)) {
HTMLTablePartElement::addChild(child);
return this;
}
return HTMLTablePartElement::addChild(child);
}
CSSMutableStyleDeclaration* HTMLTableSectionElement::additionalAttributeStyleDecl()
{
Node* p = parentNode();
while (p && !p->hasTagName(tableTag))
p = p->parentNode();
return p ? static_cast<HTMLTableElement*>(p)->getSharedGroupDecl(true) : 0;
}
PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec)
{
RefPtr<HTMLTableRowElement> r;
RefPtr<HTMLCollection> children = rows();
int numRows = children ? (int)children->length() : 0;
if (index < -1 || index > numRows)
ec = INDEX_SIZE_ERR; else {
r = new HTMLTableRowElement(document());
if (numRows == index || index == -1)
appendChild(r, ec);
else {
Node* n;
if (index < 1)
n = firstChild();
else
n = children->item(index);
insertBefore(r, n, ec);
}
}
return r.release();
}
void HTMLTableSectionElement::deleteRow( int index, ExceptionCode& ec)
{
RefPtr<HTMLCollection> children = rows();
int numRows = children ? (int)children->length() : 0;
if (index == -1)
index = numRows - 1;
if (index >= 0 && index < numRows) {
RefPtr<Node> row = children->item(index);
HTMLElement::removeChild(row.get(), ec);
} else
ec = INDEX_SIZE_ERR;
}
int HTMLTableSectionElement::numRows() const
{
int rows = 0;
const Node *n = firstChild();
while (n) {
if (n->hasTagName(trTag))
rows++;
n = n->nextSibling();
}
return rows;
}
String HTMLTableSectionElement::align() const
{
return getAttribute(alignAttr);
}
void HTMLTableSectionElement::setAlign(const String &value)
{
setAttribute(alignAttr, value);
}
String HTMLTableSectionElement::ch() const
{
return getAttribute(charAttr);
}
void HTMLTableSectionElement::setCh(const String &value)
{
setAttribute(charAttr, value);
}
String HTMLTableSectionElement::chOff() const
{
return getAttribute(charoffAttr);
}
void HTMLTableSectionElement::setChOff(const String &value)
{
setAttribute(charoffAttr, value);
}
String HTMLTableSectionElement::vAlign() const
{
return getAttribute(valignAttr);
}
void HTMLTableSectionElement::setVAlign(const String &value)
{
setAttribute(valignAttr, value);
}
PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
{
return new HTMLCollection(this, HTMLCollection::TableRows);
}
}