diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index f893d714bd..c62c1e6aa1 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -873,6 +873,7 @@ void generate_implementation(const IDL::Interface& interface) #include #include #include +#include #include #include #include @@ -1219,6 +1220,7 @@ void generate_prototype_implementation(const IDL::Interface& interface) #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index ba403bc906..8ac3ee4cde 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,90 @@ void HTMLTableElement::delete_caption() } } +RefPtr HTMLTableElement::t_head() +{ + 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::thead) + return table_section_element; + } + } + + return nullptr; +} + +DOM::ExceptionOr HTMLTableElement::set_t_head(HTMLTableSectionElement& thead) +{ + if (thead.tag_name() != TagNames::thead) + return DOM::HierarchyRequestError::create("Element is not thead"); + + // FIXME: The spec requires deleting the current thead if thead is null + // Currently the wrapper generator doesn't send us a nullable value + delete_t_head(); + + // We insert the new thead after any or elements + DOM::Node* child_to_append_after = nullptr; + for (auto* child = first_child(); child; child = child->next_sibling()) { + if (!is(*child)) + continue; + if (is(*child)) + continue; + if (is(*child)) { + auto table_col_element = &downcast(*child); + if (table_col_element->tag_name() == TagNames::colgroup) + continue; + } + + // We have found an element which is not a or , we'll insert before this + child_to_append_after = child; + break; + } + + pre_insert(thead, child_to_append_after); + + return {}; +} + +NonnullRefPtr HTMLTableElement::create_t_head() +{ + auto maybe_thead = t_head(); + if (maybe_thead) + return *maybe_thead; + + auto thead = DOM::create_element(document(), TagNames::thead, Namespace::HTML); + + // We insert the new thead after any or elements + DOM::Node* child_to_append_after = nullptr; + for (auto* child = first_child(); child; child = child->next_sibling()) { + if (!is(*child)) + continue; + if (is(*child)) + continue; + if (is(*child)) { + auto table_col_element = &downcast(*child); + if (table_col_element->tag_name() == TagNames::colgroup) + continue; + } + + // We have found an element which is not a or , we'll insert before this + child_to_append_after = child; + break; + } + + pre_insert(thead, child_to_append_after); + + return thead; +} + +void HTMLTableElement::delete_t_head() +{ + auto maybe_thead = t_head(); + if (maybe_thead) { + maybe_thead->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 0394c4e9a8..e8f2e47902 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace Web::HTML { @@ -25,6 +26,11 @@ public: NonnullRefPtr create_caption(); void delete_caption(); + RefPtr t_head(); + DOM::ExceptionOr set_t_head(HTMLTableSectionElement& thead); + NonnullRefPtr create_t_head(); + void delete_t_head(); + 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 32ce162235..b267bb08e9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl @@ -4,6 +4,10 @@ interface HTMLTableElement : HTMLElement { HTMLTableCaptionElement createCaption(); undefined deleteCaption(); + attribute HTMLTableSectionElement? tHead; + HTMLTableSectionElement createTHead(); + undefined deleteTHead(); + readonly attribute HTMLCollection rows; HTMLTableRowElement insertRow(optional long index = -1); undefined deleteRow(long index);