Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / HTMLTableRowElement.cpp
blob8c071d6bd51cc45d003a11296db76f363406d296
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, 2007, 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.
25 #include "config.h"
26 #include "core/html/HTMLTableRowElement.h"
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/HTMLTableCellElement.h"
35 #include "core/html/HTMLTableElement.h"
36 #include "core/html/HTMLTableRowsCollection.h"
37 #include "core/html/HTMLTableSectionElement.h"
39 namespace blink {
41 using namespace HTMLNames;
43 inline HTMLTableRowElement::HTMLTableRowElement(Document& document)
44 : HTMLTablePartElement(trTag, document)
48 DEFINE_NODE_FACTORY(HTMLTableRowElement)
50 bool HTMLTableRowElement::hasLegalLinkAttribute(const QualifiedName& name) const
52 return name == backgroundAttr || HTMLTablePartElement::hasLegalLinkAttribute(name);
55 const QualifiedName& HTMLTableRowElement::subResourceAttributeName() const
57 return backgroundAttr;
60 int HTMLTableRowElement::rowIndex() const
62 ContainerNode* maybeTable = parentNode();
63 if (maybeTable && isHTMLTableSectionElement(maybeTable)) {
64 // Skip THEAD, TBODY and TFOOT.
65 maybeTable = maybeTable->parentNode();
67 if (!(maybeTable && isHTMLTableElement(maybeTable)))
68 return -1;
70 RefPtrWillBeRawPtr<HTMLTableRowsCollection> rows =
71 toHTMLTableElement(maybeTable)->rows();
72 HTMLTableRowElement* candidate = rows->item(0);
73 for (int i = 0; candidate; i++, candidate = rows->item(i)) {
74 if (this == candidate)
75 return i;
78 return -1;
81 int HTMLTableRowElement::sectionRowIndex() const
83 int rIndex = 0;
84 const Node* n = this;
85 do {
86 n = n->previousSibling();
87 if (n && isHTMLTableRowElement(*n))
88 ++rIndex;
89 } while (n);
91 return rIndex;
94 PassRefPtrWillBeRawPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionState& exceptionState)
96 RefPtrWillBeRawPtr<HTMLCollection> children = cells();
97 int numCells = children ? children->length() : 0;
98 if (index < -1 || index > numCells) {
99 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [-1, " + String::number(numCells) + "].");
100 return nullptr;
103 RefPtrWillBeRawPtr<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, document());
104 if (numCells == index || index == -1)
105 appendChild(cell, exceptionState);
106 else
107 insertBefore(cell, children->item(index), exceptionState);
108 return cell.release();
111 void HTMLTableRowElement::deleteCell(int index, ExceptionState& exceptionState)
113 RefPtrWillBeRawPtr<HTMLCollection> children = cells();
114 int numCells = children ? children->length() : 0;
115 if (index == -1)
116 index = numCells-1;
117 if (index >= 0 && index < numCells) {
118 RefPtrWillBeRawPtr<Element> cell = children->item(index);
119 HTMLElement::removeChild(cell.get(), exceptionState);
120 } else {
121 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(index) + ") is outside the range [0, " + String::number(numCells) + ").");
125 PassRefPtrWillBeRawPtr<HTMLCollection> HTMLTableRowElement::cells()
127 return ensureCachedCollection<HTMLCollection>(TRCells);