diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 5df28dbc7b..ab63c2bd43 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2021, Adam Hodgen * * SPDX-License-Identifier: BSD-2-Clause */ @@ -210,6 +211,37 @@ void HTMLTableElement::delete_t_foot() } } +NonnullRefPtr HTMLTableElement::t_bodies() +{ + return DOM::HTMLCollection::create(*this, [](DOM::Element const& element) { + return element.tag_name() == TagNames::tbody; + }); +} + +NonnullRefPtr HTMLTableElement::create_t_body() +{ + auto tbody = DOM::create_element(document(), TagNames::tbody, Namespace::HTML); + + // We insert the new tbody after the last element + DOM::Node* child_to_append_after = nullptr; + for (auto* child = last_child(); child; child = child->previous_sibling()) { + if (!is(*child)) + continue; + if (is(*child)) { + auto table_section_element = &downcast(*child); + if (table_section_element->tag_name() == TagNames::tbody) { + // We have found an element which is a we'll insert after this + child_to_append_after = child->next_sibling(); + break; + } + } + } + + pre_insert(tbody, child_to_append_after); + + return tbody; +} + NonnullRefPtr HTMLTableElement::rows() { HTMLTableElement* table_node = this; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h index 6827f30d81..6565017d2d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -36,6 +36,9 @@ public: NonnullRefPtr create_t_foot(); void delete_t_foot(); + NonnullRefPtr t_bodies(); + NonnullRefPtr create_t_body(); + NonnullRefPtr rows(); DOM::ExceptionOr> insert_row(long index); DOM::ExceptionOr delete_row(long index); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl index eb5084eed8..b0813555f4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl @@ -12,6 +12,9 @@ interface HTMLTableElement : HTMLElement { HTMLTableSectionElement createTFoot(); undefined deleteTFoot(); + readonly attribute HTMLCollection tBodies; + HTMLTableSectionElement createTBody(); + readonly attribute HTMLCollection rows; HTMLTableRowElement insertRow(optional long index = -1); undefined deleteRow(long index);