From 8d9e20cb03f28d481a376d34b4477673e24c7540 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 27 Feb 2024 09:37:18 +0100 Subject: [PATCH] LibWeb: Parse the CSS scrollbar-width property --- .../Text/expected/css/getComputedStyle-print-all.txt | 1 + Userland/Libraries/LibWeb/CSS/ComputedValues.h | 8 ++++++++ Userland/Libraries/LibWeb/CSS/Enums.json | 5 +++++ Userland/Libraries/LibWeb/CSS/Properties.json | 12 ++++++++++++ Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 6 ++++++ Userland/Libraries/LibWeb/CSS/StyleProperties.h | 2 ++ Userland/Libraries/LibWeb/Layout/Node.cpp | 3 +++ 7 files changed, 37 insertions(+) diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt index 8e52e2d6b5d..9e190cdb11e 100644 --- a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt +++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt @@ -138,6 +138,7 @@ position: static quotes: auto right: auto row-gap: auto +scrollbar-width: auto stop-color: rgb(0, 0, 0) stop-opacity: 1 stroke: none diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 0c7ccf6780b..98fcc68789e 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -177,6 +177,8 @@ public: static CSS::MathShift math_shift() { return CSS::MathShift::Normal; } static CSS::MathStyle math_style() { return CSS::MathStyle::Normal; } static int math_depth() { return 0; } + + static CSS::ScrollbarWidth scrollbar_width() { return CSS::ScrollbarWidth::Auto; } }; enum class BackgroundSize { @@ -432,6 +434,8 @@ public: CSS::MathStyle math_style() const { return m_inherited.math_style; } int math_depth() const { return m_inherited.math_depth; } + CSS::ScrollbarWidth scrollbar_width() const { return m_noninherited.scrollbar_width; } + NonnullOwnPtr clone_inherited_values() const { auto clone = make(); @@ -564,6 +568,8 @@ protected: CSS::MaskType mask_type { InitialValues::mask_type() }; LengthPercentage x { InitialValues::x() }; LengthPercentage y { InitialValues::x() }; + + CSS::ScrollbarWidth scrollbar_width { InitialValues::scrollbar_width() }; } m_noninherited; }; @@ -694,6 +700,8 @@ public: void set_math_shift(CSS::MathShift value) { m_inherited.math_shift = value; } void set_math_style(CSS::MathStyle value) { m_inherited.math_style = value; } void set_math_depth(int value) { m_inherited.math_depth = value; } + + void set_scrollbar_width(CSS::ScrollbarWidth value) { m_noninherited.scrollbar_width = value; } }; } diff --git a/Userland/Libraries/LibWeb/CSS/Enums.json b/Userland/Libraries/LibWeb/CSS/Enums.json index 377fe4575bb..fc1f143e7e4 100644 --- a/Userland/Libraries/LibWeb/CSS/Enums.json +++ b/Userland/Libraries/LibWeb/CSS/Enums.json @@ -361,6 +361,11 @@ "middle", "end" ], + "scrollbar-width": [ + "auto", + "thin", + "none" + ], "text-align": [ "center", "justify", diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 11d46f9a1b7..d480f186a47 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -2034,6 +2034,18 @@ ], "percentages-resolve-to": "length" }, + "scrollbar-width": { + "affects-layout": false, + "animation-type": "by-computed-value", + "inherited": false, + "initial": "auto", + "valid-types": [ "scrollbar-width" ], + "valid-identifiers": [ + "auto", + "thin", + "none" + ] + }, "stop-color": { "affects-layout": false, "animation-type": "by-computed-value", diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index a64ca77e53a..794365752e0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -1110,4 +1110,10 @@ QuotesData StyleProperties::quotes() const return InitialValues::quotes(); } +Optional StyleProperties::scrollbar_width() const +{ + auto value = property(CSS::PropertyID::ScrollbarWidth); + return value_id_to_scrollbar_width(value->to_identifier()); +} + } diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index f6fee7d702e..7518f6fa894 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -158,6 +158,8 @@ public: QuotesData quotes() const; + Optional scrollbar_width() const; + static NonnullRefPtr font_fallback(bool monospace, bool bold); private: diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 4d638dfa01d..a3f55a6dbee 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -835,6 +835,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) computed_values.set_object_position(computed_style.object_position()); + if (auto scrollbar_width = computed_style.scrollbar_width(); scrollbar_width.has_value()) + computed_values.set_scrollbar_width(scrollbar_width.value()); + propagate_style_to_anonymous_wrappers(); }