mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibWeb: Implement HTMLTableElement thead attributes
* tHead - Getter for the thead element The setter is not currently implemented * createTHead - If necessary, creates a new thead element and add it to the table after any caption or colgroup elements, but before anything else * deleteTHead - If a thead element exists in the table, delete it
This commit is contained in:
parent
0fa0367a39
commit
b3f7ea9914
4 changed files with 97 additions and 0 deletions
|
@ -873,6 +873,7 @@ void generate_implementation(const IDL::Interface& interface)
|
||||||
#include <LibWeb/Bindings/HTMLHeadElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLHeadElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h>
|
||||||
|
#include <LibWeb/Bindings/HTMLTableSectionElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/ImageDataWrapper.h>
|
#include <LibWeb/Bindings/ImageDataWrapper.h>
|
||||||
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
||||||
#include <LibWeb/Bindings/TextWrapper.h>
|
#include <LibWeb/Bindings/TextWrapper.h>
|
||||||
|
@ -1219,6 +1220,7 @@ void generate_prototype_implementation(const IDL::Interface& interface)
|
||||||
#include <LibWeb/Bindings/HTMLHeadElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLHeadElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLImageElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h>
|
#include <LibWeb/Bindings/HTMLTableCaptionElementWrapper.h>
|
||||||
|
#include <LibWeb/Bindings/HTMLTableSectionElementWrapper.h>
|
||||||
#include <LibWeb/Bindings/ImageDataWrapper.h>
|
#include <LibWeb/Bindings/ImageDataWrapper.h>
|
||||||
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
#include <LibWeb/Bindings/NodeWrapperFactory.h>
|
||||||
#include <LibWeb/Bindings/PerformanceTimingWrapper.h>
|
#include <LibWeb/Bindings/PerformanceTimingWrapper.h>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||||
#include <LibWeb/DOM/ElementFactory.h>
|
#include <LibWeb/DOM/ElementFactory.h>
|
||||||
#include <LibWeb/DOM/HTMLCollection.h>
|
#include <LibWeb/DOM/HTMLCollection.h>
|
||||||
|
#include <LibWeb/HTML/HTMLTableColElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableElement.h>
|
#include <LibWeb/HTML/HTMLTableElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||||
#include <LibWeb/Namespace.h>
|
#include <LibWeb/Namespace.h>
|
||||||
|
@ -78,6 +79,90 @@ void HTMLTableElement::delete_caption()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
|
||||||
|
{
|
||||||
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
|
if (is<HTMLTableSectionElement>(*child)) {
|
||||||
|
auto table_section_element = &downcast<HTMLTableSectionElement>(*child);
|
||||||
|
if (table_section_element->tag_name() == TagNames::thead)
|
||||||
|
return table_section_element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DOM::ExceptionOr<void> 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 <caption> or <colgroup> elements
|
||||||
|
DOM::Node* child_to_append_after = nullptr;
|
||||||
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
|
if (!is<HTMLElement>(*child))
|
||||||
|
continue;
|
||||||
|
if (is<HTMLTableCaptionElement>(*child))
|
||||||
|
continue;
|
||||||
|
if (is<HTMLTableColElement>(*child)) {
|
||||||
|
auto table_col_element = &downcast<HTMLTableColElement>(*child);
|
||||||
|
if (table_col_element->tag_name() == TagNames::colgroup)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have found an element which is not a <caption> or <colgroup>, we'll insert before this
|
||||||
|
child_to_append_after = child;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre_insert(thead, child_to_append_after);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
NonnullRefPtr<HTMLTableSectionElement> 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 <caption> or <colgroup> elements
|
||||||
|
DOM::Node* child_to_append_after = nullptr;
|
||||||
|
for (auto* child = first_child(); child; child = child->next_sibling()) {
|
||||||
|
if (!is<HTMLElement>(*child))
|
||||||
|
continue;
|
||||||
|
if (is<HTMLTableCaptionElement>(*child))
|
||||||
|
continue;
|
||||||
|
if (is<HTMLTableColElement>(*child)) {
|
||||||
|
auto table_col_element = &downcast<HTMLTableColElement>(*child);
|
||||||
|
if (table_col_element->tag_name() == TagNames::colgroup)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have found an element which is not a <caption> or <colgroup>, 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<DOM::HTMLCollection> HTMLTableElement::rows()
|
NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows()
|
||||||
{
|
{
|
||||||
HTMLTableElement* table_node = this;
|
HTMLTableElement* table_node = this;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibWeb/HTML/HTMLElement.h>
|
#include <LibWeb/HTML/HTMLElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableCaptionElement.h>
|
#include <LibWeb/HTML/HTMLTableCaptionElement.h>
|
||||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -25,6 +26,11 @@ public:
|
||||||
NonnullRefPtr<HTMLTableCaptionElement> create_caption();
|
NonnullRefPtr<HTMLTableCaptionElement> create_caption();
|
||||||
void delete_caption();
|
void delete_caption();
|
||||||
|
|
||||||
|
RefPtr<HTMLTableSectionElement> t_head();
|
||||||
|
DOM::ExceptionOr<void> set_t_head(HTMLTableSectionElement& thead);
|
||||||
|
NonnullRefPtr<HTMLTableSectionElement> create_t_head();
|
||||||
|
void delete_t_head();
|
||||||
|
|
||||||
NonnullRefPtr<DOM::HTMLCollection> rows();
|
NonnullRefPtr<DOM::HTMLCollection> rows();
|
||||||
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index);
|
DOM::ExceptionOr<NonnullRefPtr<HTMLTableRowElement>> insert_row(long index);
|
||||||
DOM::ExceptionOr<void> delete_row(long index);
|
DOM::ExceptionOr<void> delete_row(long index);
|
||||||
|
|
|
@ -4,6 +4,10 @@ interface HTMLTableElement : HTMLElement {
|
||||||
HTMLTableCaptionElement createCaption();
|
HTMLTableCaptionElement createCaption();
|
||||||
undefined deleteCaption();
|
undefined deleteCaption();
|
||||||
|
|
||||||
|
attribute HTMLTableSectionElement? tHead;
|
||||||
|
HTMLTableSectionElement createTHead();
|
||||||
|
undefined deleteTHead();
|
||||||
|
|
||||||
readonly attribute HTMLCollection rows;
|
readonly attribute HTMLCollection rows;
|
||||||
HTMLTableRowElement insertRow(optional long index = -1);
|
HTMLTableRowElement insertRow(optional long index = -1);
|
||||||
undefined deleteRow(long index);
|
undefined deleteRow(long index);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue