From 87b8a36e561aa19b68e5931780274de317815218 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 18 Mar 2023 20:49:00 +0100 Subject: [PATCH] LibWeb: Parse and plumb the `accent-color` CSS property --- Userland/Libraries/LibWeb/CSS/ComputedValues.h | 3 +++ Userland/Libraries/LibWeb/CSS/Properties.json | 10 ++++++++++ Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 8 ++++++++ Userland/Libraries/LibWeb/CSS/StyleProperties.h | 1 + Userland/Libraries/LibWeb/Layout/Node.cpp | 4 ++++ 5 files changed, 26 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 9760a3f4d0..7b9859ef2b 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -168,6 +168,7 @@ public: float flex_grow() const { return m_noninherited.flex_grow; } float flex_shrink() const { return m_noninherited.flex_shrink; } int order() const { return m_noninherited.order; } + Optional accent_color() const { return m_inherited.accent_color; } CSS::AlignContent align_content() const { return m_noninherited.align_content; } CSS::AlignItems align_items() const { return m_noninherited.align_items; } CSS::AlignSelf align_self() const { return m_noninherited.align_self; } @@ -244,6 +245,7 @@ protected: int font_weight { InitialValues::font_weight() }; CSS::FontVariant font_variant { InitialValues::font_variant() }; Color color { InitialValues::color() }; + Optional accent_color {}; CSS::Cursor cursor { InitialValues::cursor() }; CSS::ImageRendering image_rendering { InitialValues::image_rendering() }; CSS::PointerEvents pointer_events { InitialValues::pointer_events() }; @@ -382,6 +384,7 @@ public: void set_flex_grow(float value) { m_noninherited.flex_grow = value; } void set_flex_shrink(float value) { m_noninherited.flex_shrink = value; } void set_order(int value) { m_noninherited.order = value; } + void set_accent_color(Color value) { m_inherited.accent_color = value; } void set_align_content(CSS::AlignContent value) { m_noninherited.align_content = value; } void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; } void set_align_self(CSS::AlignSelf value) { m_noninherited.align_self = value; } diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 6fca39a5d1..36ac8221c6 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -1,4 +1,14 @@ { + "accent-color": { + "inherited": true, + "initial": "auto", + "valid-types": [ + "color" + ], + "valid-identifiers": [ + "auto" + ] + }, "align-content": { "inherited": false, "initial": "stretch", diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 0621ee1935..4fcfeb819f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -375,6 +375,14 @@ CSS::TransformOrigin StyleProperties::transform_origin() const return { x_value.value(), y_value.value() }; } +Optional StyleProperties::accent_color(Layout::NodeWithStyle const& node) const +{ + auto value = property(CSS::PropertyID::AccentColor); + if (value->has_color()) + return value->to_color(node); + return {}; +} + Optional StyleProperties::align_content() const { auto value = property(CSS::PropertyID::AlignContent); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index 222f600e08..6e80c53406 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -68,6 +68,7 @@ public: float flex_grow() const; float flex_shrink() const; int order() const; + Optional accent_color(Layout::NodeWithStyle const&) const; Optional align_content() const; Optional align_items() const; Optional align_self() const; diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 317281516e..c93ede71f3 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -462,6 +462,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) if (justify_content.has_value()) computed_values.set_justify_content(justify_content.value()); + auto accent_color = computed_style.accent_color(*this); + if (accent_color.has_value()) + computed_values.set_accent_color(accent_color.value()); + auto align_content = computed_style.align_content(); if (align_content.has_value()) computed_values.set_align_content(align_content.value());