From d2e3e98b6b64a3af23e886c51dd0c317fe70e701 Mon Sep 17 00:00:00 2001 From: Adam Hodgen Date: Sun, 2 May 2021 18:07:45 +0100 Subject: [PATCH] LibWeb: Implement HTMLTableElement tfoot attributes * tFoot - Getter for the tfoot element The setter is not currently implemented * createTFoot - If necessary, creates a new tfoot element and add it to the table after any tbody elements * deleteTFoot - If a tfoot element exists in the table, delete it --- .../LibWeb/HTML/HTMLTableElement.cpp | 47 +++++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLTableElement.h | 5 ++ .../LibWeb/HTML/HTMLTableElement.idl | 4 ++ 3 files changed, 56 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 8ac3ee4cde..5df28dbc7b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -163,6 +163,53 @@ void HTMLTableElement::delete_t_head() } } +RefPtr HTMLTableElement::t_foot() +{ + for (auto* child = first_child(); child; child = child->next_sibling()) { + if (is(*child)) { + auto table_section_element = &downcast(*child); + if (table_section_element->tag_name() == TagNames::tfoot) + return table_section_element; + } + } + + return nullptr; +} + +DOM::ExceptionOr HTMLTableElement::set_t_foot(HTMLTableSectionElement& tfoot) +{ + if (tfoot.tag_name() != TagNames::tfoot) + return DOM::HierarchyRequestError::create("Element is not tfoot"); + + // FIXME: The spec requires deleting the current tfoot if tfoot is null + // Currently the wrapper generator doesn't send us a nullable value + delete_t_foot(); + + // We insert the new tfoot at the end of the table + append_child(tfoot); + + return {}; +} + +NonnullRefPtr HTMLTableElement::create_t_foot() +{ + auto maybe_tfoot = t_foot(); + if (maybe_tfoot) + return *maybe_tfoot; + + auto tfoot = DOM::create_element(document(), TagNames::tfoot, Namespace::HTML); + append_child(tfoot); + return tfoot; +} + +void HTMLTableElement::delete_t_foot() +{ + auto maybe_tfoot = t_foot(); + if (maybe_tfoot) { + maybe_tfoot->remove(false); + } +} + NonnullRefPtr HTMLTableElement::rows() { HTMLTableElement* table_node = this; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h index e8f2e47902..6827f30d81 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -31,6 +31,11 @@ public: NonnullRefPtr create_t_head(); void delete_t_head(); + RefPtr t_foot(); + DOM::ExceptionOr set_t_foot(HTMLTableSectionElement& thead); + NonnullRefPtr create_t_foot(); + void delete_t_foot(); + 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 b267bb08e9..eb5084eed8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl @@ -8,6 +8,10 @@ interface HTMLTableElement : HTMLElement { HTMLTableSectionElement createTHead(); undefined deleteTHead(); + attribute HTMLTableSectionElement? tFoot; + HTMLTableSectionElement createTFoot(); + undefined deleteTFoot(); + readonly attribute HTMLCollection rows; HTMLTableRowElement insertRow(optional long index = -1); undefined deleteRow(long index);