2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include "HTMLTableSectionElement.h"
28 #include "ExceptionCode.h"
29 #include "HTMLCollection.h"
30 #include "HTMLNames.h"
31 #include "HTMLTableRowElement.h"
32 #include "HTMLTableElement.h"
38 using namespace HTMLNames;
40 inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document)
41 : HTMLTablePartElement(tagName, document)
45 PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document* document)
47 return adoptRef(new HTMLTableSectionElement(tagName, document));
50 // used by table row groups to share style decls created by the enclosing table.
51 void HTMLTableSectionElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
53 ContainerNode* p = parentNode();
54 while (p && !p->hasTagName(tableTag))
58 static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(true, results);
61 // these functions are rather slow, since we need to get the row at
62 // the index... but they aren't used during usual HTML parsing anyway
63 PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec)
65 RefPtr<HTMLTableRowElement> row;
66 RefPtr<HTMLCollection> children = rows();
67 int numRows = children ? (int)children->length() : 0;
68 if (index < -1 || index > numRows)
69 ec = INDEX_SIZE_ERR; // per the DOM
71 row = HTMLTableRowElement::create(trTag, document());
72 if (numRows == index || index == -1)
79 n = children->item(index);
80 insertBefore(row, n, ec);
86 void HTMLTableSectionElement::deleteRow(int index, ExceptionCode& ec)
88 RefPtr<HTMLCollection> children = rows();
89 int numRows = children ? (int)children->length() : 0;
92 if (index >= 0 && index < numRows) {
93 RefPtr<Node> row = children->item(index);
94 HTMLElement::removeChild(row.get(), ec);
99 int HTMLTableSectionElement::numRows() const
102 const Node *n = firstChild();
104 if (n->hasTagName(trTag))
106 n = n->nextSibling();
112 String HTMLTableSectionElement::align() const
114 return getAttribute(alignAttr);
117 void HTMLTableSectionElement::setAlign(const String &value)
119 setAttribute(alignAttr, value);
122 String HTMLTableSectionElement::ch() const
124 return getAttribute(charAttr);
127 void HTMLTableSectionElement::setCh(const String &value)
129 setAttribute(charAttr, value);
132 String HTMLTableSectionElement::chOff() const
134 return getAttribute(charoffAttr);
137 void HTMLTableSectionElement::setChOff(const String &value)
139 setAttribute(charoffAttr, value);
142 String HTMLTableSectionElement::vAlign() const
144 return getAttribute(valignAttr);
147 void HTMLTableSectionElement::setVAlign(const String &value)
149 setAttribute(valignAttr, value);
152 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
154 return HTMLCollection::create(this, TSectionRows);