LibWeb: Implement the color-scheme meta tag name

This commit is contained in:
Gingeh 2025-01-04 09:59:57 +11:00 committed by Sam Atkins
parent ce5cd012b9
commit df70455d3f
Notes: github-actions[bot] 2025-01-08 11:19:34 +00:00
7 changed files with 97 additions and 3 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/CSS/Parser/ParsingContext.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLMetaElement.h>
#include <LibWeb/Infra/CharacterTypes.h>
@ -47,6 +48,23 @@ Optional<HTMLMetaElement::HttpEquivAttributeState> HTMLMetaElement::http_equiv_s
return OptionalNone {};
}
void HTMLMetaElement::update_metadata(Optional<String> const& old_name)
{
if (name().has_value()) {
if (name()->equals_ignoring_ascii_case("color-scheme"sv)) {
document().obtain_supported_color_schemes();
return;
}
}
if (old_name.has_value()) {
if (old_name->equals_ignoring_ascii_case("color-scheme"sv)) {
document().obtain_supported_color_schemes();
return;
}
}
}
void HTMLMetaElement::inserted()
{
Base::inserted();
@ -84,6 +102,8 @@ void HTMLMetaElement::inserted()
return;
}
update_metadata();
// https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives
// When a meta element is inserted into the document, if its http-equiv attribute is present and represents one of
// the above states, then the user agent must run the algorithm appropriate for that state, as described in the
@ -160,4 +180,20 @@ void HTMLMetaElement::inserted()
}
}
void HTMLMetaElement::removed_from(Node* parent)
{
Base::removed_from(parent);
update_metadata();
}
void HTMLMetaElement::attribute_changed(FlyString const& local_name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)
{
Base::attribute_changed(local_name, old_value, value, namespace_);
if (local_name == HTML::AttributeNames::name) {
update_metadata(old_value);
} else {
update_metadata();
}
}
}