• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
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 Apple Computer, Inc.
8  *
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.
13  *
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.
18  *
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.
23  */
24 #include "config.h"
25 #include "HTMLTableSectionElement.h"
26 
27 #include "ExceptionCode.h"
28 #include "HTMLCollection.h"
29 #include "HTMLNames.h"
30 #include "HTMLTableRowElement.h"
31 #include "HTMLTableElement.h"
32 #include "NodeList.h"
33 #include "Text.h"
34 
35 namespace WebCore {
36 
37 using namespace HTMLNames;
38 
HTMLTableSectionElement(const QualifiedName & tagName,Document * document)39 HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document)
40     : HTMLTablePartElement(tagName, document)
41 {
42 }
43 
checkDTD(const Node * newChild)44 bool HTMLTableSectionElement::checkDTD(const Node* newChild)
45 {
46     if (newChild->isTextNode())
47         return static_cast<const Text*>(newChild)->containsOnlyWhitespace();
48     return newChild->hasTagName(trTag) || newChild->hasTagName(formTag) ||
49            newChild->hasTagName(scriptTag);
50 }
51 
addChild(PassRefPtr<Node> child)52 ContainerNode* HTMLTableSectionElement::addChild(PassRefPtr<Node> child)
53 {
54     if (child->hasTagName(formTag)) {
55         // First add the child.
56         HTMLTablePartElement::addChild(child);
57 
58         // Now simply return ourselves as the container to insert into.
59         // This has the effect of demoting the form to a leaf and moving it safely out of the way.
60         return this;
61     }
62 
63     return HTMLTablePartElement::addChild(child);
64 }
65 
66 // used by table row groups to share style decls created by the enclosing table.
additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration * > & results)67 void HTMLTableSectionElement::additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>& results)
68 {
69     Node* p = parentNode();
70     while (p && !p->hasTagName(tableTag))
71         p = p->parentNode();
72     if (!p)
73         return;
74     static_cast<HTMLTableElement*>(p)->addSharedGroupDecls(true, results);
75 }
76 
77 // these functions are rather slow, since we need to get the row at
78 // the index... but they aren't used during usual HTML parsing anyway
insertRow(int index,ExceptionCode & ec)79 PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec)
80 {
81     RefPtr<HTMLTableRowElement> r;
82     RefPtr<HTMLCollection> children = rows();
83     int numRows = children ? (int)children->length() : 0;
84     if (index < -1 || index > numRows)
85         ec = INDEX_SIZE_ERR; // per the DOM
86     else {
87         r = new HTMLTableRowElement(trTag, document());
88         if (numRows == index || index == -1)
89             appendChild(r, ec);
90         else {
91             Node* n;
92             if (index < 1)
93                 n = firstChild();
94             else
95                 n = children->item(index);
96             insertBefore(r, n, ec);
97         }
98     }
99     return r.release();
100 }
101 
deleteRow(int index,ExceptionCode & ec)102 void HTMLTableSectionElement::deleteRow( int index, ExceptionCode& ec)
103 {
104     RefPtr<HTMLCollection> children = rows();
105     int numRows = children ? (int)children->length() : 0;
106     if (index == -1)
107         index = numRows - 1;
108     if (index >= 0 && index < numRows) {
109         RefPtr<Node> row = children->item(index);
110         HTMLElement::removeChild(row.get(), ec);
111     } else
112         ec = INDEX_SIZE_ERR;
113 }
114 
numRows() const115 int HTMLTableSectionElement::numRows() const
116 {
117     int rows = 0;
118     const Node *n = firstChild();
119     while (n) {
120         if (n->hasTagName(trTag))
121             rows++;
122         n = n->nextSibling();
123     }
124 
125     return rows;
126 }
127 
align() const128 String HTMLTableSectionElement::align() const
129 {
130     return getAttribute(alignAttr);
131 }
132 
setAlign(const String & value)133 void HTMLTableSectionElement::setAlign(const String &value)
134 {
135     setAttribute(alignAttr, value);
136 }
137 
ch() const138 String HTMLTableSectionElement::ch() const
139 {
140     return getAttribute(charAttr);
141 }
142 
setCh(const String & value)143 void HTMLTableSectionElement::setCh(const String &value)
144 {
145     setAttribute(charAttr, value);
146 }
147 
chOff() const148 String HTMLTableSectionElement::chOff() const
149 {
150     return getAttribute(charoffAttr);
151 }
152 
setChOff(const String & value)153 void HTMLTableSectionElement::setChOff(const String &value)
154 {
155     setAttribute(charoffAttr, value);
156 }
157 
vAlign() const158 String HTMLTableSectionElement::vAlign() const
159 {
160     return getAttribute(valignAttr);
161 }
162 
setVAlign(const String & value)163 void HTMLTableSectionElement::setVAlign(const String &value)
164 {
165     setAttribute(valignAttr, value);
166 }
167 
rows()168 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows()
169 {
170     return HTMLCollection::create(this, HTMLCollection::TSectionRows);
171 }
172 
173 }
174