summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-11-05 15:19:16 +0000
committerAndreas Kling <kling@serenityos.org>2022-11-07 14:10:41 +0100
commit009f04fa461479876f89b9d38b802ff7ab3777c5 (patch)
tree0220c1062d1101b9c8b4000a7e24f885a15126aa /Userland
parent6c9b3fb62eec92616578670eb460c9d353e5f26b (diff)
downloadserenity-009f04fa461479876f89b9d38b802ff7ab3777c5.zip
LibWeb: Implement HTMLTableRowElement.deleteCell
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp24
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h2
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl1
3 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
index 404ba84f14..e19956c553 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp
@@ -112,4 +112,28 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableCellElement>> HTMLTableRowElement:
return JS::NonnullGCPtr(table_cell);
}
+// https://html.spec.whatwg.org/multipage/tables.html#dom-tr-deletecell
+WebIDL::ExceptionOr<void> HTMLTableRowElement::delete_cell(i32 index)
+{
+ auto cells_collection = cells();
+ auto cells_collection_size = static_cast<i32>(cells_collection->length());
+
+ // 1. If index is less than −1 or greater than or equal to the number of elements in the cells collection, then throw an "IndexSizeError" DOMException.
+ if (index < -1 || index >= cells_collection_size)
+ return WebIDL::IndexSizeError::create(realm(), "Index is negative or greater than or equal to the number of cells");
+
+ // 2. If index is −1, then remove the last element in the cells collection from its parent, or do nothing if the cells collection is empty.
+ if (index == -1) {
+ if (cells_collection_size > 0)
+ cells_collection->item(cells_collection_size - 1)->remove();
+ }
+
+ // 3. Otherwise, remove the indexth element in the cells collection from its parent.
+ else {
+ cells_collection->item(index)->remove();
+ }
+
+ return {};
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
index bb879afa6f..64d386889b 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h
@@ -20,6 +20,8 @@ public:
int row_index() const;
int section_row_index() const;
+ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLTableCellElement>> insert_cell(i32 index);
+ WebIDL::ExceptionOr<void> delete_cell(i32 index);
private:
HTMLTableRowElement(DOM::Document&, DOM::QualifiedName);
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
index 0530647950..b2e205cf79 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.idl
@@ -18,4 +18,5 @@ interface HTMLTableRowElement : HTMLElement {
[SameObject] readonly attribute HTMLCollection cells;
HTMLTableCellElement insertCell(optional long index = -1);
+ [CEReactions] undefined deleteCell(long index);
};