mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 23:39:02 +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
Notes:
sideshowbarker
2024-07-18 18:25:26 +09:00
Author: https://github.com/ant1441
Commit: b3f7ea9914
Pull-request: https://github.com/SerenityOS/serenity/pull/6823
Reviewed-by: https://github.com/awesomekling
4 changed files with 97 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibWeb/CSS/Parser/DeprecatedCSSParser.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/HTML/HTMLTableColElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableRowElement.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()
|
||||
{
|
||||
HTMLTableElement* table_node = this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue