1 /* 2 * Copyright (C) 1997 Martin Jones (mjones (at) kde.org) 3 * (C) 1997 Torben Weis (weis (at) kde.org) 4 * (C) 1998 Waldo Bastian (bastian (at) kde.org) 5 * (C) 1999 Lars Knoll (knoll (at) kde.org) 6 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 7 * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. 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 25 #include "config.h" 26 #include "core/html/HTMLTableSectionElement.h" 27 28 #include "HTMLNames.h" 29 #include "bindings/v8/ExceptionState.h" 30 #include "core/dom/ExceptionCode.h" 31 #include "core/html/HTMLCollection.h" 32 #include "core/html/HTMLTableElement.h" 33 #include "core/html/HTMLTableRowElement.h" 34 35 namespace WebCore { 36 37 using namespace HTMLNames; 38 39 inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document) 40 : HTMLTablePartElement(tagName, document) 41 { 42 ScriptWrappable::init(this); 43 } 44 45 PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document* document) 46 { 47 return adoptRef(new HTMLTableSectionElement(tagName, document)); 48 } 49 50 const StylePropertySet* HTMLTableSectionElement::additionalPresentationAttributeStyle() 51 { 52 if (HTMLTableElement* table = findParentTable()) 53 return table->additionalGroupStyle(true); 54 return 0; 55 } 56 57 // these functions are rather slow, since we need to get the row at 58 // the index... but they aren't used during usual HTML parsing anyway 59 PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionState& es) 60 { 61 RefPtr<HTMLTableRowElement> row; 62 RefPtr<HTMLCollection> children = rows(); 63 int numRows = children ? (int)children->length() : 0; 64 if (index < -1 || index > numRows) 65 es.throwDOMException(IndexSizeError); // per the DOM 66 else { 67 row = HTMLTableRowElement::create(trTag, document()); 68 if (numRows == index || index == -1) 69 appendChild(row, es, AttachLazily); 70 else { 71 Node* n; 72 if (index < 1) 73 n = firstChild(); 74 else 75 n = children->item(index); 76 insertBefore(row, n, es, AttachLazily); 77 } 78 } 79 return row.release(); 80 } 81 82 void HTMLTableSectionElement::deleteRow(int index, ExceptionState& es) 83 { 84 RefPtr<HTMLCollection> children = rows(); 85 int numRows = children ? (int)children->length() : 0; 86 if (index == -1) 87 index = numRows - 1; 88 if (index >= 0 && index < numRows) { 89 RefPtr<Node> row = children->item(index); 90 HTMLElement::removeChild(row.get(), es); 91 } else { 92 es.throwDOMException(IndexSizeError); 93 } 94 } 95 96 int HTMLTableSectionElement::numRows() const 97 { 98 int rows = 0; 99 const Node *n = firstChild(); 100 while (n) { 101 if (n->hasTagName(trTag)) 102 rows++; 103 n = n->nextSibling(); 104 } 105 106 return rows; 107 } 108 109 String HTMLTableSectionElement::align() const 110 { 111 return getAttribute(alignAttr); 112 } 113 114 void HTMLTableSectionElement::setAlign(const String &value) 115 { 116 setAttribute(alignAttr, value); 117 } 118 119 String HTMLTableSectionElement::ch() const 120 { 121 return getAttribute(charAttr); 122 } 123 124 void HTMLTableSectionElement::setCh(const String &value) 125 { 126 setAttribute(charAttr, value); 127 } 128 129 String HTMLTableSectionElement::chOff() const 130 { 131 return getAttribute(charoffAttr); 132 } 133 134 void HTMLTableSectionElement::setChOff(const String &value) 135 { 136 setAttribute(charoffAttr, value); 137 } 138 139 String HTMLTableSectionElement::vAlign() const 140 { 141 return getAttribute(valignAttr); 142 } 143 144 void HTMLTableSectionElement::setVAlign(const String &value) 145 { 146 setAttribute(valignAttr, value); 147 } 148 149 PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows() 150 { 151 return ensureCachedHTMLCollection(TSectionRows); 152 } 153 154 } 155