From 6045143d39380330c5caaa868bedad339a53e954 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 5 Sep 2023 20:23:15 +0100 Subject: [PATCH] LibWeb: Parse the `math-shift` and `math-style` CSS properties Currently these have no effect, but they're simple, and `math-style` influences `math-depth` which is coming next. --- Userland/Libraries/LibWeb/CSS/ComputedValues.h | 12 ++++++++++++ Userland/Libraries/LibWeb/CSS/Enums.json | 8 ++++++++ Userland/Libraries/LibWeb/CSS/Identifiers.json | 1 + Userland/Libraries/LibWeb/CSS/Properties.json | 14 ++++++++++++++ Userland/Libraries/LibWeb/Layout/Node.cpp | 8 ++++++++ 5 files changed, 43 insertions(+) diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 61fb280fa8..415cf1c80b 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -120,6 +120,9 @@ public: static CSS::OutlineStyle outline_style() { return CSS::OutlineStyle::None; } static CSS::Length outline_width() { return CSS::Length::make_px(3); } static CSS::TableLayout table_layout() { return CSS::TableLayout::Auto; } + + static CSS::MathShift math_shift() { return CSS::MathShift::Normal; } + static CSS::MathStyle math_style() { return CSS::MathStyle::Normal; } }; enum class BackgroundSize { @@ -346,6 +349,9 @@ public: CSS::TableLayout table_layout() const { return m_noninherited.table_layout; } + CSS::MathShift math_shift() const { return m_inherited.math_shift; } + CSS::MathStyle math_style() const { return m_inherited.math_style; } + ComputedValues clone_inherited_values() const { ComputedValues clone; @@ -385,6 +391,9 @@ protected: CSS::TextAnchor text_anchor { InitialValues::text_anchor() }; Vector text_shadow; + + CSS::MathShift math_shift { InitialValues::math_shift() }; + CSS::MathStyle math_style { InitialValues::math_style() }; } m_inherited; struct { @@ -579,6 +588,9 @@ public: void set_outline_offset(CSS::Length value) { m_noninherited.outline_offset = value; } void set_outline_style(CSS::OutlineStyle value) { m_noninherited.outline_style = value; } void set_outline_width(CSS::Length value) { m_noninherited.outline_width = value; } + + void set_math_shift(CSS::MathShift value) { m_inherited.math_shift = value; } + void set_math_style(CSS::MathStyle value) { m_inherited.math_style = value; } }; } diff --git a/Userland/Libraries/LibWeb/CSS/Enums.json b/Userland/Libraries/LibWeb/CSS/Enums.json index 3b48c16f05..7cf8fa939d 100644 --- a/Userland/Libraries/LibWeb/CSS/Enums.json +++ b/Userland/Libraries/LibWeb/CSS/Enums.json @@ -276,6 +276,14 @@ "inside", "outside" ], + "math-shift": [ + "normal", + "compact" + ], + "math-style": [ + "normal", + "compact" + ], "object-fit": [ "fill", "contain", diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index 7fddd4e6df..c62c31410b 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -105,6 +105,7 @@ "collapse", "column", "column-reverse", + "compact", "condensed", "contain", "content", diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index c06a7917aa..9ec266edd4 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -1479,6 +1479,20 @@ "unitless-length" ] }, + "math-shift": { + "inherited": true, + "initial": "normal", + "valid-types": [ + "math-shift" + ] + }, + "math-style": { + "inherited": true, + "initial": "normal", + "valid-types": [ + "math-style" + ] + }, "max-height": { "inherited": false, "initial": "none", diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index ba60ab7362..c7d231508a 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -789,6 +789,14 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) transfer_table_box_computed_values_to_wrapper_computed_values(wrapper_computed_values); } + auto math_shift_value = computed_style.property(CSS::PropertyID::MathShift); + if (auto math_shift = value_id_to_math_shift(math_shift_value->to_identifier()); math_shift.has_value()) + computed_values.set_math_shift(math_shift.value()); + + auto math_style_value = computed_style.property(CSS::PropertyID::MathStyle); + if (auto math_style = value_id_to_math_style(math_style_value->to_identifier()); math_style.has_value()) + computed_values.set_math_style(math_style.value()); + // Update any anonymous children that inherit from this node. // FIXME: This is pretty hackish. It would be nicer if they shared the inherited style // data structure somehow, so this wasn't necessary.