diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/HTMLTableSectionElement.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/HTMLTableSectionElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLTableSectionElement.cpp | 131 |
1 files changed, 41 insertions, 90 deletions
diff --git a/Source/WebCore/html/HTMLTableSectionElement.cpp b/Source/WebCore/html/HTMLTableSectionElement.cpp index 32b8396f4..1861b03c4 100644 --- a/Source/WebCore/html/HTMLTableSectionElement.cpp +++ b/Source/WebCore/html/HTMLTableSectionElement.cpp @@ -26,11 +26,13 @@ #include "HTMLTableSectionElement.h" #include "ExceptionCode.h" +#include "GenericCachedHTMLCollection.h" #include "HTMLCollection.h" #include "HTMLNames.h" #include "HTMLTableRowElement.h" #include "HTMLTableElement.h" #include "NodeList.h" +#include "NodeRareData.h" #include "Text.h" namespace WebCore { @@ -42,112 +44,61 @@ inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tag { } -PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document& document) +Ref<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document& document) { - return adoptRef(new HTMLTableSectionElement(tagName, document)); + return adoptRef(*new HTMLTableSectionElement(tagName, document)); } -const StyleProperties* HTMLTableSectionElement::additionalPresentationAttributeStyle() +const StyleProperties* HTMLTableSectionElement::additionalPresentationAttributeStyle() const { - if (HTMLTableElement* table = findParentTable()) - return table->additionalGroupStyle(true); - return 0; + auto* table = findParentTable(); + if (!table) + return nullptr; + return table->additionalGroupStyle(true); } -// these functions are rather slow, since we need to get the row at -// the index... but they aren't used during usual HTML parsing anyway -PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec) +ExceptionOr<Ref<HTMLElement>> HTMLTableSectionElement::insertRow(int index) { - RefPtr<HTMLTableRowElement> row; - RefPtr<HTMLCollection> children = rows(); - int numRows = children ? (int)children->length() : 0; - if (index < -1 || index > numRows) - ec = INDEX_SIZE_ERR; // per the DOM - else { - row = HTMLTableRowElement::create(trTag, document()); - if (numRows == index || index == -1) - appendChild(row, ec); - else { - Node* n; - if (index < 1) - n = firstChild(); - else - n = children->item(index); - insertBefore(row, n, ec); - } - } - return row.release(); -} - -void HTMLTableSectionElement::deleteRow(int index, ExceptionCode& ec) + if (index < -1) + return Exception { INDEX_SIZE_ERR }; + auto children = rows(); + int numRows = children->length(); + if (index > numRows) + return Exception { INDEX_SIZE_ERR }; + auto row = HTMLTableRowElement::create(trTag, document()); + ExceptionOr<void> result; + if (numRows == index || index == -1) + result = appendChild(row); + else + result = insertBefore(row, index < 1 ? firstChild() : children->item(index)); + if (result.hasException()) + return result.releaseException(); + return Ref<HTMLElement> { WTFMove(row) }; +} + +ExceptionOr<void> HTMLTableSectionElement::deleteRow(int index) { - RefPtr<HTMLCollection> children = rows(); - int numRows = children ? (int)children->length() : 0; - if (index == -1) + auto children = rows(); + int numRows = children->length(); + if (index == -1) { + if (!numRows) + return { }; index = numRows - 1; - if (index >= 0 && index < numRows) { - RefPtr<Node> row = children->item(index); - HTMLElement::removeChild(row.get(), ec); - } else - ec = INDEX_SIZE_ERR; -} - -int HTMLTableSectionElement::numRows() const -{ - int rows = 0; - const Node *n = firstChild(); - while (n) { - if (n->hasTagName(trTag)) - rows++; - n = n->nextSibling(); } - - return rows; -} - -String HTMLTableSectionElement::align() const -{ - return getAttribute(alignAttr); -} - -void HTMLTableSectionElement::setAlign(const String &value) -{ - setAttribute(alignAttr, value); -} - -String HTMLTableSectionElement::ch() const -{ - return getAttribute(charAttr); -} - -void HTMLTableSectionElement::setCh(const String &value) -{ - setAttribute(charAttr, value); -} - -String HTMLTableSectionElement::chOff() const -{ - return getAttribute(charoffAttr); + if (index < 0 || index >= numRows) + return Exception { INDEX_SIZE_ERR }; + return removeChild(*children->item(index)); } -void HTMLTableSectionElement::setChOff(const String &value) -{ - setAttribute(charoffAttr, value); -} - -String HTMLTableSectionElement::vAlign() const -{ - return getAttribute(valignAttr); -} - -void HTMLTableSectionElement::setVAlign(const String &value) +int HTMLTableSectionElement::numRows() const { - setAttribute(valignAttr, value); + auto rows = childrenOfType<HTMLTableRowElement>(*this); + return std::distance(rows.begin(), rows.end()); } -PassRefPtr<HTMLCollection> HTMLTableSectionElement::rows() +Ref<HTMLCollection> HTMLTableSectionElement::rows() { - return ensureCachedHTMLCollection(TSectionRows); + return ensureRareData().ensureNodeLists().addCachedCollection<GenericCachedHTMLCollection<CollectionTypeTraits<TSectionRows>::traversalType>>(*this, TSectionRows); } } |