diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 0c8cae019a6..3e90966b0fb 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -225,6 +225,7 @@ set(SOURCES CSS/StyleSheetIdentifier.cpp CSS/StyleSheetList.cpp CSS/StyleValues/AbstractImageStyleValue.cpp + CSS/StyleValues/AddFunctionStyleValue.cpp CSS/StyleValues/AnchorStyleValue.cpp CSS/StyleValues/AnchorSizeStyleValue.cpp CSS/StyleValues/AngleStyleValue.cpp @@ -265,7 +266,6 @@ set(SOURCES CSS/StyleValues/LengthStyleValue.cpp CSS/StyleValues/LightDarkStyleValue.cpp CSS/StyleValues/LinearGradientStyleValue.cpp - CSS/StyleValues/MathDepthStyleValue.cpp CSS/StyleValues/NumberStyleValue.cpp CSS/StyleValues/OpenTypeTaggedStyleValue.cpp CSS/StyleValues/PositionStyleValue.cpp diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index 69b89823155..3dd72e7f5a8 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -2543,7 +2542,7 @@ void ComputedProperties::set_math_depth(int math_depth) { m_math_depth = math_depth; // Make our children inherit our computed value, not our specified value. - set_property(PropertyID::MathDepth, MathDepthStyleValue::create_integer(IntegerStyleValue::create(math_depth))); + set_property(PropertyID::MathDepth, IntegerStyleValue::create(math_depth)); } QuotesData ComputedProperties::quotes() const diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 3d4de6d02f3..0cbf8a427dc 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -3712,10 +3712,9 @@ RefPtr Parser::parse_math_depth_value(TokenStream) @@ -3731,7 +3730,7 @@ RefPtr Parser::parse_math_depth_value(TokenStream Parser::parse_math_depth_value(TokenStream if (auto integer_value = parse_integer_value(tokens)) { transaction.commit(); - return MathDepthStyleValue::create_integer(integer_value.release_nonnull()); + return integer_value; } return nullptr; diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 908fd5c9b49..e4ec612e051 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,6 @@ #include #include #include -#include #include #include #include @@ -2773,26 +2773,7 @@ void StyleComputer::compute_math_depth(ComputedProperties& style, Optionalcomputed_properties()->math_depth(); }; - // NB: We always parse as a MathDepthStyleValue, but StylePropertyMap is able to set other StyleValues directly. - // So, extract the properties we care about from it or other StyleValue types we might have. - bool is_auto_add = false; - bool is_add = false; - bool is_integer = false; - RefPtr integer_value; - auto const& property_value = style.property(PropertyID::MathDepth); - if (property_value.to_keyword() == Keyword::AutoAdd) { - is_auto_add = true; - } else if (property_value.is_integer() || property_value.is_calculated()) { - integer_value = property_value; - } else { - auto const& math_depth = property_value.as_math_depth(); - is_auto_add = math_depth.is_auto_add(); - is_add = math_depth.is_add(); - is_integer = math_depth.is_integer(); - if (is_integer || is_add) - integer_value = math_depth.integer_value(); - } auto resolve_integer = [&](StyleValue const& integer_value) { if (integer_value.is_integer()) @@ -2814,20 +2795,20 @@ void StyleComputer::compute_math_depth(ComputedProperties& style, Optionalto_keyword() == Keyword::Compact) { + if (property_value.to_keyword() == Keyword::AutoAdd && inherited_math_style()->to_keyword() == Keyword::Compact) { style.set_math_depth(inherited_math_depth() + 1); return; } // - If the specified value of math-depth is of the form add() then the computed value of // math-depth of the element is its inherited value plus the specified integer. - if (is_add) { - style.set_math_depth(inherited_math_depth() + resolve_integer(*integer_value)); + if (property_value.is_add_function()) { + style.set_math_depth(inherited_math_depth() + resolve_integer(*property_value.as_add_function().value())); return; } // - If the specified value of math-depth is of the form then the computed value of math-depth // of the element is the specified integer. - if (is_integer) { - style.set_math_depth(resolve_integer(*integer_value)); + if (property_value.is_integer() || property_value.is_calculated()) { + style.set_math_depth(resolve_integer(property_value)); return; } // - Otherwise, the computed value of math-depth of the element is the inherited one. diff --git a/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.cpp new file mode 100644 index 00000000000..89a843e986f --- /dev/null +++ b/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023, Sam Atkins + * Copyright (c) 2026, Callum Law + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "AddFunctionStyleValue.h" + +namespace Web::CSS { + +void AddFunctionStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const +{ + builder.append("add("sv); + m_value->serialize(builder, mode); + builder.append(')'); +} + +} diff --git a/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.h new file mode 100644 index 00000000000..c279f232d74 --- /dev/null +++ b/Libraries/LibWeb/CSS/StyleValues/AddFunctionStyleValue.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2023, Sam Atkins + * Copyright (c) 2026, Callum Law + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::CSS { + +class AddFunctionStyleValue : public StyleValueWithDefaultOperators { +public: + static NonnullRefPtr create(NonnullRefPtr value) + { + return adopt_ref(*new AddFunctionStyleValue(move(value))); + } + + NonnullRefPtr value() const { return m_value; } + virtual void serialize(StringBuilder&, SerializationMode) const override; + + bool properties_equal(AddFunctionStyleValue const& other) const { return m_value == other.m_value; } + +private: + AddFunctionStyleValue(NonnullRefPtr value) + : StyleValueWithDefaultOperators(Type::AddFunction) + , m_value(move(value)) + { + } + + virtual ~AddFunctionStyleValue() override = default; + + ValueComparingNonnullRefPtr m_value; +}; + +} diff --git a/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.cpp deleted file mode 100644 index e3f48541ee9..00000000000 --- a/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2023, Sam Atkins - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "MathDepthStyleValue.h" - -namespace Web::CSS { - -ValueComparingNonnullRefPtr MathDepthStyleValue::create_auto_add() -{ - return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::AutoAdd)); -} - -ValueComparingNonnullRefPtr MathDepthStyleValue::create_add(ValueComparingNonnullRefPtr integer_value) -{ - return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::Add, move(integer_value))); -} - -ValueComparingNonnullRefPtr MathDepthStyleValue::create_integer(ValueComparingNonnullRefPtr integer_value) -{ - return adopt_ref(*new (nothrow) MathDepthStyleValue(MathDepthType::Integer, move(integer_value))); -} - -MathDepthStyleValue::MathDepthStyleValue(MathDepthType type, ValueComparingRefPtr integer_value) - : StyleValueWithDefaultOperators(Type::MathDepth) - , m_type(type) - , m_integer_value(move(integer_value)) -{ -} - -bool MathDepthStyleValue::properties_equal(MathDepthStyleValue const& other) const -{ - return m_type == other.m_type - && m_integer_value == other.m_integer_value; -} - -void MathDepthStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const -{ - switch (m_type) { - case MathDepthType::AutoAdd: - builder.append("auto-add"sv); - break; - case MathDepthType::Add: - builder.append("add("sv); - m_integer_value->serialize(builder, mode); - builder.append(')'); - break; - case MathDepthType::Integer: - m_integer_value->serialize(builder, mode); - break; - } -} - -} diff --git a/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.h b/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.h deleted file mode 100644 index f978d10f8ce..00000000000 --- a/Libraries/LibWeb/CSS/StyleValues/MathDepthStyleValue.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2023, Sam Atkins - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -namespace Web::CSS { - -class MathDepthStyleValue : public StyleValueWithDefaultOperators { -public: - static ValueComparingNonnullRefPtr create_auto_add(); - static ValueComparingNonnullRefPtr create_add(ValueComparingNonnullRefPtr integer_value); - static ValueComparingNonnullRefPtr create_integer(ValueComparingNonnullRefPtr integer_value); - virtual ~MathDepthStyleValue() override = default; - - bool is_auto_add() const { return m_type == MathDepthType::AutoAdd; } - bool is_add() const { return m_type == MathDepthType::Add; } - bool is_integer() const { return m_type == MathDepthType::Integer; } - auto integer_value() const - { - VERIFY(!m_integer_value.is_null()); - return m_integer_value; - } - virtual void serialize(StringBuilder&, SerializationMode) const override; - - bool properties_equal(MathDepthStyleValue const& other) const; - -private: - enum class MathDepthType { - AutoAdd, - Add, - Integer, - }; - - MathDepthStyleValue(MathDepthType type, ValueComparingRefPtr integer_value = nullptr); - - MathDepthType m_type; - ValueComparingRefPtr m_integer_value; -}; - -} diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp index 766f1a52c78..0a700f7f2f1 100644 --- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +51,6 @@ #include #include #include -#include #include #include #include diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h index 6a5a1fafe2a..7195382cd60 100644 --- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.h @@ -32,6 +32,7 @@ namespace Web::CSS { #define ENUMERATE_CSS_STYLE_VALUE_TYPES \ + __ENUMERATE_CSS_STYLE_VALUE_TYPE(AddFunction, add_function, AddFunctionStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(Anchor, anchor, AnchorStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(AnchorSize, anchor_size, AnchorSizeStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(Angle, angle, AngleStyleValue) \ @@ -68,7 +69,6 @@ namespace Web::CSS { __ENUMERATE_CSS_STYLE_VALUE_TYPE(Keyword, keyword, KeywordStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(Length, length, LengthStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(LinearGradient, linear_gradient, LinearGradientStyleValue) \ - __ENUMERATE_CSS_STYLE_VALUE_TYPE(MathDepth, math_depth, MathDepthStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(Number, number, NumberStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(OpenTypeTagged, open_type_tagged, OpenTypeTaggedStyleValue) \ __ENUMERATE_CSS_STYLE_VALUE_TYPE(PendingSubstitution, pending_substitution, PendingSubstitutionStyleValue) \ diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index e5e9e3e94fe..a3f4d832549 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -209,6 +209,7 @@ class SubtleCrypto; namespace Web::CSS { class AbstractImageStyleValue; +class AddFunctionStyleValue; class AnchorStyleValue; class AnchorSizeStyleValue; class Angle; @@ -334,7 +335,6 @@ class LengthPercentage; class LengthPercentageOrAuto; class LengthStyleValue; class LinearGradientStyleValue; -class MathDepthStyleValue; class MediaFeatureValue; class MediaList; class MediaQuery; diff --git a/Libraries/LibWeb/MathML/MathMLElement.cpp b/Libraries/LibWeb/MathML/MathMLElement.cpp index f4c0d8e495a..ac0a9fb869d 100644 --- a/Libraries/LibWeb/MathML/MathMLElement.cpp +++ b/Libraries/LibWeb/MathML/MathMLElement.cpp @@ -8,9 +8,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -122,8 +122,12 @@ void MathMLElement::apply_presentational_hints(GC::Ref if (Optional parsed_value = HTML::parse_integer_digits(value); parsed_value.has_value()) { auto string_value = parsed_value.value(); if (auto integer_value = parsed_value->to_number(TrimWhitespace::No); integer_value.has_value()) { - auto style_value = string_value[0] == '+' || string_value[0] == '-' ? CSS::MathDepthStyleValue::create_add(CSS::IntegerStyleValue::create(integer_value.release_value())) - : CSS::MathDepthStyleValue::create_integer(CSS::IntegerStyleValue::create(integer_value.release_value())); + auto style_value = [&]() -> NonnullRefPtr { + if (string_value[0] == '+' || string_value[0] == '-') + return CSS::AddFunctionStyleValue::create(CSS::IntegerStyleValue::create(integer_value.release_value())); + + return CSS::IntegerStyleValue::create(integer_value.release_value()); + }(); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MathDepth, style_value); } }