From 6d114149572f5e4824737b9a233d12cb40110ca4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 15 Apr 2025 15:18:27 -0600 Subject: [PATCH] LibWeb: Make storage of CSS::StyleValues const-correct Now we consistently use `RefPtr` for all StyleValues. --- Documentation/CSSGeneratedFiles.md | 4 +- Libraries/LibWeb/CSS/Angle.cpp | 2 +- Libraries/LibWeb/CSS/Angle.h | 2 +- .../LibWeb/CSS/CSSFontFaceDescriptors.cpp | 2 +- Libraries/LibWeb/CSS/CSSPropertyRule.cpp | 4 +- Libraries/LibWeb/CSS/CSSPropertyRule.h | 6 +- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 8 +- Libraries/LibWeb/CSS/CalculatedOr.cpp | 36 +-- Libraries/LibWeb/CSS/CalculatedOr.h | 56 ++-- Libraries/LibWeb/CSS/ComputedValues.h | 4 +- Libraries/LibWeb/CSS/FontFace.cpp | 2 +- Libraries/LibWeb/CSS/Frequency.cpp | 2 +- Libraries/LibWeb/CSS/Frequency.h | 2 +- Libraries/LibWeb/CSS/Interpolation.cpp | 2 +- Libraries/LibWeb/CSS/Length.cpp | 4 +- Libraries/LibWeb/CSS/Length.h | 4 +- Libraries/LibWeb/CSS/LengthBox.h | 2 +- .../LibWeb/CSS/Parser/DescriptorParsing.cpp | 8 +- .../LibWeb/CSS/Parser/GradientParsing.cpp | 12 +- Libraries/LibWeb/CSS/Parser/Helpers.cpp | 4 +- Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 +- Libraries/LibWeb/CSS/Parser/Parser.h | 248 ++++++++--------- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 262 +++++++++--------- Libraries/LibWeb/CSS/Parser/RuleParsing.cpp | 2 +- Libraries/LibWeb/CSS/Parser/ValueParsing.cpp | 164 +++++------ Libraries/LibWeb/CSS/PercentageOr.h | 20 +- Libraries/LibWeb/CSS/Size.cpp | 2 +- Libraries/LibWeb/CSS/Size.h | 2 +- Libraries/LibWeb/CSS/StyleComputer.cpp | 6 +- Libraries/LibWeb/CSS/StyleComputer.h | 2 +- .../CSS/StyleValues/AbstractImageStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/AngleStyleValue.h | 2 +- .../StyleValues/BackgroundRepeatStyleValue.h | 2 +- .../StyleValues/BackgroundSizeStyleValue.h | 2 +- .../CSS/StyleValues/BasicShapeStyleValue.h | 6 +- .../CSS/StyleValues/BorderRadiusStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/CSSColorValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/CSSColorValue.h | 2 +- Libraries/LibWeb/CSS/StyleValues/CSSHSL.h | 12 +- Libraries/LibWeb/CSS/StyleValues/CSSHWB.h | 12 +- .../LibWeb/CSS/StyleValues/CSSKeywordValue.h | 12 +- Libraries/LibWeb/CSS/StyleValues/CSSLCHLike.h | 16 +- Libraries/LibWeb/CSS/StyleValues/CSSLabLike.h | 16 +- .../LibWeb/CSS/StyleValues/CSSLightDark.h | 8 +- Libraries/LibWeb/CSS/StyleValues/CSSRGB.h | 12 +- .../CSS/StyleValues/CalculatedStyleValue.cpp | 18 +- .../CSS/StyleValues/CalculatedStyleValue.h | 4 +- .../StyleValues/ColorFunctionStyleValue.cpp | 4 +- .../CSS/StyleValues/ColorFunctionStyleValue.h | 8 +- .../CSS/StyleValues/ColorSchemeStyleValue.h | 4 +- .../CSS/StyleValues/ConicGradientStyleValue.h | 6 +- .../CSS/StyleValues/ContentStyleValue.h | 8 +- .../CounterDefinitionsStyleValue.h | 2 +- .../CSS/StyleValues/CounterStyleValue.h | 4 +- .../LibWeb/CSS/StyleValues/CursorStyleValue.h | 8 +- .../CSS/StyleValues/CustomIdentStyleValue.h | 2 +- .../CSS/StyleValues/DisplayStyleValue.cpp | 2 +- .../CSS/StyleValues/DisplayStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/EasingStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/EdgeStyleValue.h | 2 +- .../StyleValues/FilterValueListStyleValue.h | 2 +- .../CSS/StyleValues/FitContentStyleValue.h | 4 +- .../LibWeb/CSS/StyleValues/FlexStyleValue.h | 2 +- .../CSS/StyleValues/FontSourceStyleValue.h | 4 +- .../CSS/StyleValues/FrequencyStyleValue.h | 2 +- .../StyleValues/GridAutoFlowStyleValue.cpp | 2 +- .../CSS/StyleValues/GridAutoFlowStyleValue.h | 2 +- .../GridTemplateAreaStyleValue.cpp | 2 +- .../StyleValues/GridTemplateAreaStyleValue.h | 2 +- .../GridTrackPlacementStyleValue.cpp | 2 +- .../GridTrackPlacementStyleValue.h | 2 +- .../GridTrackSizeListStyleValue.cpp | 6 +- .../StyleValues/GridTrackSizeListStyleValue.h | 6 +- .../CSS/StyleValues/ImageStyleValue.cpp | 4 +- .../LibWeb/CSS/StyleValues/ImageStyleValue.h | 7 +- .../CSS/StyleValues/IntegerStyleValue.h | 2 +- .../CSS/StyleValues/LengthStyleValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/LengthStyleValue.h | 2 +- .../StyleValues/LinearGradientStyleValue.h | 2 +- .../CSS/StyleValues/MathDepthStyleValue.cpp | 6 +- .../CSS/StyleValues/MathDepthStyleValue.h | 6 +- .../LibWeb/CSS/StyleValues/NumberStyleValue.h | 2 +- .../StyleValues/OpenTypeTaggedStyleValue.h | 8 +- .../CSS/StyleValues/PercentageStyleValue.h | 2 +- .../CSS/StyleValues/PositionStyleValue.h | 16 +- .../StyleValues/RadialGradientStyleValue.h | 6 +- .../LibWeb/CSS/StyleValues/RatioStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/RectStyleValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/RectStyleValue.h | 2 +- .../CSS/StyleValues/ResolutionStyleValue.h | 2 +- .../StyleValues/ScrollbarGutterStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/ShadowStyleValue.h | 2 +- .../CSS/StyleValues/ShorthandStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/StringStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/TimeStyleValue.h | 2 +- .../StyleValues/TransformationStyleValue.h | 2 +- .../CSS/StyleValues/TransitionStyleValue.h | 6 +- .../LibWeb/CSS/StyleValues/URLStyleValue.h | 2 +- .../CSS/StyleValues/UnicodeRangeStyleValue.h | 2 +- .../CSS/StyleValues/UnresolvedStyleValue.h | 2 +- Libraries/LibWeb/CSS/Time.cpp | 2 +- Libraries/LibWeb/CSS/Time.h | 2 +- Libraries/LibWeb/HTML/Canvas/CanvasState.h | 2 +- Libraries/LibWeb/HTML/HTMLBodyElement.h | 2 +- Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 6 +- Libraries/LibWeb/HTML/Parser/HTMLParser.h | 4 +- Libraries/LibWeb/Layout/LayoutState.h | 8 +- Libraries/LibWeb/Page/EventHandler.cpp | 2 +- Libraries/LibWeb/Painting/PaintableBox.h | 12 +- Libraries/LibWeb/SVG/SVGSVGElement.cpp | 4 +- Libraries/LibWeb/SVG/SVGSVGElement.h | 4 +- .../LibWeb/GenerateCSSDescriptors.cpp | 6 +- .../LibWeb/GenerateCSSPropertyID.cpp | 6 +- 113 files changed, 628 insertions(+), 629 deletions(-) diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.md index 2d43ce20564..f6cfa808ab3 100644 --- a/Documentation/CSSGeneratedFiles.md +++ b/Documentation/CSSGeneratedFiles.md @@ -25,7 +25,7 @@ Each property will have some set of these fields on it: | `affects-stacking-context` | No | `false` | Boolean. Whether this property can cause a new stacking context for the element. | `bool property_affects_stacking_context(PropertyID)` | | `animation-type` | Yes | | String. How the property should be animated. Defined by the spec. See below. | `AnimationType animation_type_from_longhand_property(PropertyID)` | | `inherited` | Yes | | Boolean. Whether the property is inherited by its child elements. | `bool is_inherited_property(PropertyID)` | -| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr property_initial_value(PropertyID)` | +| `initial` | Yes | | String. The property's initial value if it is not specified. | `NonnullRefPtr property_initial_value(PropertyID)` | | `legacy-alias-for` | No | Nothing | String. The name of a property this is an alias for. See below. | | | `logical-alias-for` | No | Nothing | Array of strings. The name of a property this is an alias for. See below. | | | `longhands` | No | `[]` | Array of strings. If this is a shorthand, these are the property names that it expands out into. | `Vector longhands_for_shorthand(PropertyID)` | @@ -89,7 +89,7 @@ The generated code provides: it exists in that at-rule. - `FlyString to_string(DescriptorID)` for serializing descriptor names. - `bool at_rule_supports_descriptor(AtRuleID, DescriptorID)` to query if the given at-rule allows the descriptor. -- `RefPtr descriptor_initial_value(AtRuleID, DescriptorID)` for getting a descriptor's initial value. +- `RefPtr descriptor_initial_value(AtRuleID, DescriptorID)` for getting a descriptor's initial value. - `DescriptorMetadata get_descriptor_metadata(AtRuleID, DescriptorID)` returns data used for parsing the descriptor. ### At-rule fields diff --git a/Libraries/LibWeb/CSS/Angle.cpp b/Libraries/LibWeb/CSS/Angle.cpp index 44fa016ba03..68eb0023201 100644 --- a/Libraries/LibWeb/CSS/Angle.cpp +++ b/Libraries/LibWeb/CSS/Angle.cpp @@ -84,7 +84,7 @@ Optional Angle::unit_from_name(StringView name) return {}; } -Angle Angle::resolve_calculated(NonnullRefPtr const& calculated, Layout::Node const& layout_node, Angle const& reference_value) +Angle Angle::resolve_calculated(NonnullRefPtr const& calculated, Layout::Node const& layout_node, Angle const& reference_value) { return calculated->resolve_angle( { diff --git a/Libraries/LibWeb/CSS/Angle.h b/Libraries/LibWeb/CSS/Angle.h index 533de18f08e..5972b2d6935 100644 --- a/Libraries/LibWeb/CSS/Angle.h +++ b/Libraries/LibWeb/CSS/Angle.h @@ -52,7 +52,7 @@ public: return 0; } - static Angle resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Angle const& reference_value); + static Angle resolve_calculated(NonnullRefPtr const&, Layout::Node const&, Angle const& reference_value); private: Type m_type; diff --git a/Libraries/LibWeb/CSS/CSSFontFaceDescriptors.cpp b/Libraries/LibWeb/CSS/CSSFontFaceDescriptors.cpp index 3e9ec1982bc..55df18b5f55 100644 --- a/Libraries/LibWeb/CSS/CSSFontFaceDescriptors.cpp +++ b/Libraries/LibWeb/CSS/CSSFontFaceDescriptors.cpp @@ -100,7 +100,7 @@ WebIDL::ExceptionOr CSSFontFaceDescriptors::set_property(StringView proper return {}; // 5. Let component value list be the result of parsing value for property property. - RefPtr component_value_list = parse_css_descriptor(Parser::ParsingParams {}, AtRuleID::FontFace, *descriptor_id, value); + RefPtr component_value_list = parse_css_descriptor(Parser::ParsingParams {}, AtRuleID::FontFace, *descriptor_id, value); // 6. If component value list is null, then return. if (!component_value_list) diff --git a/Libraries/LibWeb/CSS/CSSPropertyRule.cpp b/Libraries/LibWeb/CSS/CSSPropertyRule.cpp index e6443cb0c79..47b12afffa9 100644 --- a/Libraries/LibWeb/CSS/CSSPropertyRule.cpp +++ b/Libraries/LibWeb/CSS/CSSPropertyRule.cpp @@ -13,12 +13,12 @@ namespace Web::CSS { GC_DEFINE_ALLOCATOR(CSSPropertyRule); -GC::Ref CSSPropertyRule::create(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value) +GC::Ref CSSPropertyRule::create(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value) { return realm.create(realm, move(name), move(syntax), inherits, move(initial_value)); } -CSSPropertyRule::CSSPropertyRule(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value) +CSSPropertyRule::CSSPropertyRule(JS::Realm& realm, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value) : CSSRule(realm, Type::Property) , m_name(move(name)) , m_syntax(move(syntax)) diff --git a/Libraries/LibWeb/CSS/CSSPropertyRule.h b/Libraries/LibWeb/CSS/CSSPropertyRule.h index 159361fc92a..49745ea0aed 100644 --- a/Libraries/LibWeb/CSS/CSSPropertyRule.h +++ b/Libraries/LibWeb/CSS/CSSPropertyRule.h @@ -21,7 +21,7 @@ class CSSPropertyRule final : public CSSRule { GC_DECLARE_ALLOCATOR(CSSPropertyRule); public: - static GC::Ref create(JS::Realm&, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value); + static GC::Ref create(JS::Realm&, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value); virtual ~CSSPropertyRule() = default; @@ -31,7 +31,7 @@ public: Optional initial_value() const; private: - CSSPropertyRule(JS::Realm&, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value); + CSSPropertyRule(JS::Realm&, FlyString name, FlyString syntax, bool inherits, RefPtr initial_value); virtual void initialize(JS::Realm&) override; virtual String serialized() const override; @@ -39,7 +39,7 @@ private: FlyString m_name; FlyString m_syntax; bool m_inherits; - RefPtr m_initial_value; + RefPtr m_initial_value; }; template<> diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 3af27b22b93..eaab16c50b4 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -428,10 +428,10 @@ static Optional style_property_for_sided_shorthand(PropertyID pro if (top->important != right->important || top->important != bottom->important || top->important != left->important) return {}; - ValueComparingNonnullRefPtr const top_value { top->value }; - ValueComparingNonnullRefPtr const right_value { right->value }; - ValueComparingNonnullRefPtr const bottom_value { bottom->value }; - ValueComparingNonnullRefPtr const left_value { left->value }; + ValueComparingNonnullRefPtr const top_value { top->value }; + ValueComparingNonnullRefPtr const right_value { right->value }; + ValueComparingNonnullRefPtr const bottom_value { bottom->value }; + ValueComparingNonnullRefPtr const left_value { left->value }; bool const top_and_bottom_same = top_value == bottom_value; bool const left_and_right_same = left_value == right_value; diff --git a/Libraries/LibWeb/CSS/CalculatedOr.cpp b/Libraries/LibWeb/CSS/CalculatedOr.cpp index 470d5996df7..ec21a2bb467 100644 --- a/Libraries/LibWeb/CSS/CalculatedOr.cpp +++ b/Libraries/LibWeb/CSS/CalculatedOr.cpp @@ -17,92 +17,92 @@ namespace Web::CSS { -Optional AngleOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional AngleOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_angle(context); } -NonnullRefPtr AngleOrCalculated::create_style_value() const +NonnullRefPtr AngleOrCalculated::create_style_value() const { return AngleStyleValue::create(value()); } -Optional FlexOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional FlexOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_flex(context); } -NonnullRefPtr FlexOrCalculated::create_style_value() const +NonnullRefPtr FlexOrCalculated::create_style_value() const { return FlexStyleValue::create(value()); } -Optional FrequencyOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional FrequencyOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_frequency(context); } -NonnullRefPtr FrequencyOrCalculated::create_style_value() const +NonnullRefPtr FrequencyOrCalculated::create_style_value() const { return FrequencyStyleValue::create(value()); } -Optional IntegerOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional IntegerOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_integer(context); } -NonnullRefPtr IntegerOrCalculated::create_style_value() const +NonnullRefPtr IntegerOrCalculated::create_style_value() const { return IntegerStyleValue::create(value()); } -Optional LengthOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional LengthOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_length(context); } -NonnullRefPtr LengthOrCalculated::create_style_value() const +NonnullRefPtr LengthOrCalculated::create_style_value() const { return LengthStyleValue::create(value()); } -Optional NumberOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional NumberOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_number(context); } -NonnullRefPtr NumberOrCalculated::create_style_value() const +NonnullRefPtr NumberOrCalculated::create_style_value() const { return NumberStyleValue::create(value()); } -Optional PercentageOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional PercentageOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_percentage(context); } -NonnullRefPtr PercentageOrCalculated::create_style_value() const +NonnullRefPtr PercentageOrCalculated::create_style_value() const { return PercentageStyleValue::create(value()); } -Optional ResolutionOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const +Optional ResolutionOrCalculated::resolve_calculated(NonnullRefPtr const& calculated, CalculationResolutionContext const& context) const { return calculated->resolve_resolution(context); } -NonnullRefPtr ResolutionOrCalculated::create_style_value() const +NonnullRefPtr ResolutionOrCalculated::create_style_value() const { return ResolutionStyleValue::create(value()); } -Optional