mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-23 02:31:55 +00:00
LibWeb: Obtain theme-color on meta element removal and modification
This commit is contained in:
parent
df70455d3f
commit
4a0ac312cc
Notes:
github-actions[bot]
2025-01-08 11:19:28 +00:00
Author: https://github.com/Gingeh
Commit: 4a0ac312cc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3146
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 55 additions and 35 deletions
|
@ -51,14 +51,18 @@ Optional<HTMLMetaElement::HttpEquivAttributeState> HTMLMetaElement::http_equiv_s
|
|||
void HTMLMetaElement::update_metadata(Optional<String> const& old_name)
|
||||
{
|
||||
if (name().has_value()) {
|
||||
if (name()->equals_ignoring_ascii_case("color-scheme"sv)) {
|
||||
if (name()->equals_ignoring_ascii_case("theme-color"sv)) {
|
||||
document().obtain_theme_color();
|
||||
} else 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)) {
|
||||
if (old_name->equals_ignoring_ascii_case("theme-color"sv)) {
|
||||
document().obtain_theme_color();
|
||||
} else if (old_name->equals_ignoring_ascii_case("color-scheme"sv)) {
|
||||
document().obtain_supported_color_schemes();
|
||||
return;
|
||||
}
|
||||
|
@ -69,39 +73,6 @@ void HTMLMetaElement::inserted()
|
|||
{
|
||||
Base::inserted();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#meta-theme-color
|
||||
// 1. To obtain a page's theme color, user agents must run the following steps:
|
||||
// * The element is in a document tree
|
||||
// * The element has a name attribute, whose value is an ASCII case-insensitive match for theme-color
|
||||
// * The element has a content attribute
|
||||
auto content = attribute(AttributeNames::content);
|
||||
if (name().has_value() && name()->equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) {
|
||||
auto context = CSS::Parser::ParsingContext { document() };
|
||||
|
||||
// 2. For each element in candidate elements:
|
||||
|
||||
// 1. If element has a media attribute and the value of element's media attribute does not match the environment, then continue.
|
||||
auto media = attribute(AttributeNames::media);
|
||||
if (media.has_value()) {
|
||||
auto query = parse_media_query(context, media.value());
|
||||
if (document().window() && !query->evaluate(*document().window()))
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Let value be the result of stripping leading and trailing ASCII whitespace from the value of element's content attribute.
|
||||
auto value = content->bytes_as_string_view().trim(Infra::ASCII_WHITESPACE);
|
||||
|
||||
// 3. Let color be the result of parsing value.
|
||||
auto css_value = parse_css_value(context, value, CSS::PropertyID::Color);
|
||||
if (css_value.is_null() || !css_value->is_color())
|
||||
return;
|
||||
auto color = css_value->to_color({}); // TODO: Pass a layout node?
|
||||
|
||||
// 4. If color is not failure, then return color.
|
||||
document().page().client().page_did_change_theme_color(color);
|
||||
return;
|
||||
}
|
||||
|
||||
update_metadata();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#pragma-directives
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue