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 "bindings/core/v8/ExceptionState.h" 29 #include "core/HTMLNames.h" 30 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ExceptionCode.h" 32 #include "core/dom/NodeListsNodeData.h" 33 #include "core/html/HTMLCollection.h" 34 #include "core/html/HTMLTableElement.h" 35 #include "core/html/HTMLTableRowElement.h" 36 37 namespace blink { 38 39 using namespace HTMLNames; 40 41 inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document& document) 42 : HTMLTablePartElement(tagName, document) 43 { 44 } 45 46 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLTableSectionElement) 47 48 const StylePropertySet* HTMLTableSectionElement::additionalPresentationAttributeStyle() 49 { 50 if (HTMLTableElement* table = findParentTable()) 51 return table->additionalGroupStyle(true); 52 return 0; 53 } 54 55 // these functions are rather slow, since we need to get the row at 56 // the index... but they aren't used during usual HTML parsing anyway 57 PassRefPtrWillBeRawPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionState& exceptionState) 58 { 59 RefPtrWillBeRawPtr<HTMLCollection> children = rows(); 60 int numRows = children ? static_cast<int>(children->length()) : 0; 61 if (index < -1 || index > numRows) { 62 exceptionState.throwDOMException(IndexSizeError, "The provided index (" + String::number(index) + " is outside the range [-1, " + String::number(numRows) + "]."); 63 return nullptr; 64 } 65 66 RefPtrWillBeRawPtr<HTMLTableRowElement> row = HTMLTableRowElement::create(document()); 67 if (numRows == index || index == -1) 68 appendChild(row, exceptionState); 69 else 70 insertBefore(row, children->item(index), exceptionState); 71 return row.release(); 72 } 73 74 void HTMLTableSectionElement::deleteRow(int index, ExceptionState& exceptionState) 75 { 76 RefPtrWillBeRawPtr<HTMLCollection> children = rows(); 77 int numRows = children ? (int)children->length() : 0; 78 if (index == -1) 79 index = numRows - 1; 80 if (index >= 0 && index < numRows) { 81 RefPtrWillBeRawPtr<Element> row = children->item(index); 82 HTMLElement::removeChild(row.get(), exceptionState); 83 } else { 84 exceptionState.throwDOMException(IndexSizeError, "The provided index (" + String::number(index) + " is outside the range [-1, " + String::number(numRows) + "]."); 85 } 86 } 87 88 int HTMLTableSectionElement::numRows() const 89 { 90 int rowCount = 0; 91 for (const HTMLTableRowElement* row = Traversal<HTMLTableRowElement>::firstChild(*this); row; row = Traversal<HTMLTableRowElement>::nextSibling(*row)) 92 ++rowCount; 93 return rowCount; 94 } 95 96 PassRefPtrWillBeRawPtr<HTMLCollection> HTMLTableSectionElement::rows() 97 { 98 return ensureCachedCollection<HTMLCollection>(TSectionRows); 99 } 100 101 } 102