diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-03-12 23:50:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-12 23:49:50 +0100 |
commit | cc2e08d9e9eac7cb97e321e65d82b55eb141c2de (patch) | |
tree | 0f080f193451c8ad14bb2b6b135494abcfbc517b /Userland/Libraries | |
parent | 009588eb28a0ed86c2cc5140c36797cd789c059f (diff) | |
download | serenity-cc2e08d9e9eac7cb97e321e65d82b55eb141c2de.zip |
LibWeb: Implement HTMLTableSectionElement::deleteRow()
Diffstat (limited to 'Userland/Libraries')
3 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp index 187a40e521..7e0fa12378 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp @@ -59,4 +59,26 @@ DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> HTMLTableSectionElement::in return table_row; } +// https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-deleterow +DOM::ExceptionOr<void> HTMLTableSectionElement::delete_row(long index) +{ + auto rows_collection = rows(); + auto rows_collection_size = static_cast<long>(rows_collection->length()); + + // 1. If index is less than −1 or greater than or equal to the number of elements in the rows collection, then throw an "IndexSizeError" DOMException. + if (index < -1 || index >= rows_collection_size) + return DOM::IndexSizeError::create("Index is negative or greater than or equal to the number of rows"); + + // 2. If index is −1, then remove the last element in the rows collection from this element, or do nothing if the rows collection is empty. + if (index == -1) { + if (rows_collection_size > 0) + rows_collection->item(rows_collection_size - 1)->remove(); + } + // 3. Otherwise, remove the indexth element in the rows collection from this element. + else { + rows_collection->item(index)->remove(); + } + return {}; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h index d6db3c28e0..98642fdde3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h @@ -20,6 +20,7 @@ public: NonnullRefPtr<DOM::HTMLCollection> rows() const; DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index); + DOM::ExceptionOr<void> delete_row(long index); }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl index 2f74fa52b4..ee1025d819 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.idl @@ -11,5 +11,6 @@ interface HTMLTableSectionElement : HTMLElement { [SameObject] readonly attribute HTMLCollection rows; HTMLTableRowElement insertRow(optional long index = -1); + undefined deleteRow(long index); }; |