diff options
author | Adam Hodgen <ant1441@gmail.com> | 2021-05-02 17:43:42 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-09 18:38:34 +0200 |
commit | 0fa0367a394e89ea3419b3a5a4054d759bb975f9 (patch) | |
tree | 443b611df17b4dbd07d25c00a10da70c832885ac /Userland/Libraries | |
parent | 887fa18e32297290639f07fa12a7557f5ee33aa5 (diff) | |
download | serenity-0fa0367a394e89ea3419b3a5a4054d759bb975f9.zip |
LibWeb: Implement HTMLTableElement caption attributes
* caption - Getter and setter for the caption element
* createCaption - If necessary, creates a new caption element
and add it to the table
* deleteCaption - If a caption element exists in the table, delete it
Diffstat (limited to 'Userland/Libraries')
4 files changed, 46 insertions, 0 deletions
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 <LibWeb/Bindings/HTMLFormElementWrapper.h> #include <LibWeb/Bindings/HTMLHeadElementWrapper.h> #include <LibWeb/Bindings/HTMLImageElementWrapper.h> +#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h> #include <LibWeb/Bindings/ImageDataWrapper.h> #include <LibWeb/Bindings/NodeWrapperFactory.h> #include <LibWeb/Bindings/TextWrapper.h> @@ -1217,6 +1218,7 @@ void generate_prototype_implementation(const IDL::Interface& interface) #include <LibWeb/Bindings/HTMLFormElementWrapper.h> #include <LibWeb/Bindings/HTMLHeadElementWrapper.h> #include <LibWeb/Bindings/HTMLImageElementWrapper.h> +#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h> #include <LibWeb/Bindings/ImageDataWrapper.h> #include <LibWeb/Bindings/NodeWrapperFactory.h> #include <LibWeb/Bindings/PerformanceTimingWrapper.h> 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<HTMLTableCaptionElement> HTMLTableElement::caption() +{ + return first_child_of_type<HTMLTableCaptionElement>(); +} + +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<HTMLTableCaptionElement> 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<DOM::HTMLCollection> 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 <LibWeb/DOM/ExceptionOr.h> #include <LibWeb/HTML/HTMLElement.h> +#include <LibWeb/HTML/HTMLTableCaptionElement.h> #include <LibWeb/HTML/HTMLTableRowElement.h> namespace Web::HTML { @@ -19,6 +20,11 @@ public: HTMLTableElement(DOM::Document&, QualifiedName); virtual ~HTMLTableElement() override; + RefPtr<HTMLTableCaptionElement> caption(); + void set_caption(HTMLTableCaptionElement&); + NonnullRefPtr<HTMLTableCaptionElement> create_caption(); + void delete_caption(); + NonnullRefPtr<DOM::HTMLCollection> rows(); DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index); DOM::ExceptionOr<void> 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); |