diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index e56e56edc8..f893d714bd 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -872,6 +872,7 @@ void generate_implementation(const IDL::Interface& interface) #include #include #include +#include #include #include #include @@ -1217,6 +1218,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 67a6bf43b3..ba403bc906 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -44,6 +44,40 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c }); } +RefPtr HTMLTableElement::caption() +{ + return first_child_of_type(); +} + +void HTMLTableElement::set_caption(HTMLTableCaptionElement& caption) +{ + // FIXME: The spec requires deleting the current caption if caption is null + // Currently the wrapper generator doesn't send us a nullable value + delete_caption(); + + pre_insert(caption, first_child()); +} + +NonnullRefPtr HTMLTableElement::create_caption() +{ + auto maybe_caption = caption(); + if (maybe_caption) { + return *maybe_caption; + } + + auto caption = DOM::create_element(document(), TagNames::caption, Namespace::HTML); + pre_insert(caption, first_child()); + return caption; +} + +void HTMLTableElement::delete_caption() +{ + auto maybe_caption = caption(); + if (maybe_caption) { + maybe_caption->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 5df428a0aa..0394c4e9a8 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -8,6 +8,7 @@ #include #include +#include #include namespace Web::HTML { @@ -19,6 +20,11 @@ public: HTMLTableElement(DOM::Document&, QualifiedName); virtual ~HTMLTableElement() override; + RefPtr caption(); + void set_caption(HTMLTableCaptionElement&); + NonnullRefPtr create_caption(); + void delete_caption(); + 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 e007d88585..32ce162235 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.idl @@ -1,5 +1,9 @@ interface HTMLTableElement : HTMLElement { + attribute HTMLTableCaptionElement? caption; + HTMLTableCaptionElement createCaption(); + undefined deleteCaption(); + readonly attribute HTMLCollection rows; HTMLTableRowElement insertRow(optional long index = -1); undefined deleteRow(long index);