From c57975c9fdb98e03da0f8098c324577f8ecc753c Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 8 Aug 2025 10:11:51 +0100 Subject: [PATCH] LibWeb: Move and rename CSSStyleValue to StyleValues/StyleValue.{h,cpp} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts 0e3487b9ab455a7648185995363bb3b487551d40. Back when I made that change, I thought we could make our StyleValue classes match the typed-om definitions directly. However, they have different requirements. Typed-om types need to be mutable and GCed, whereas StyleValues are immutable and ideally wouldn't require a JS VM. While I was already making such a cataclysmic change, I've moved it into the StyleValues directory, because it *not* being there has bothered me for a long time. 😅 --- Documentation/CSSGeneratedFiles.md | 4 +- Documentation/CSSProperties.md | 4 +- Documentation/LibWebFromLoadingToPainting.md | 2 +- .../LibWeb/Animations/AnimationEffect.cpp | 6 +- Libraries/LibWeb/Animations/AnimationEffect.h | 4 +- .../LibWeb/Animations/KeyframeEffect.cpp | 8 +- Libraries/LibWeb/Animations/KeyframeEffect.h | 10 +- Libraries/LibWeb/CMakeLists.txt | 2 +- Libraries/LibWeb/CSS/CSS.cpp | 2 +- Libraries/LibWeb/CSS/CSSAnimation.h | 2 +- Libraries/LibWeb/CSS/CSSDescriptors.cpp | 10 +- Libraries/LibWeb/CSS/CSSDescriptors.h | 8 +- Libraries/LibWeb/CSS/CSSPropertyRule.cpp | 4 +- Libraries/LibWeb/CSS/CSSPropertyRule.h | 8 +- Libraries/LibWeb/CSS/CSSStyleDeclaration.h | 2 +- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 20 +- Libraries/LibWeb/CSS/CSSStyleProperties.h | 4 +- Libraries/LibWeb/CSS/CSSStyleRule.cpp | 2 +- Libraries/LibWeb/CSS/CSSTransition.cpp | 8 +- Libraries/LibWeb/CSS/CSSTransition.h | 22 +- Libraries/LibWeb/CSS/CalculatedOr.cpp | 18 +- Libraries/LibWeb/CSS/CalculatedOr.h | 22 +- Libraries/LibWeb/CSS/CascadedProperties.cpp | 8 +- Libraries/LibWeb/CSS/CascadedProperties.h | 8 +- Libraries/LibWeb/CSS/ComputedProperties.cpp | 18 +- Libraries/LibWeb/CSS/ComputedProperties.h | 18 +- Libraries/LibWeb/CSS/Descriptor.cpp | 2 +- Libraries/LibWeb/CSS/Descriptor.h | 2 +- Libraries/LibWeb/CSS/Filter.h | 2 +- Libraries/LibWeb/CSS/FontFace.cpp | 2 +- Libraries/LibWeb/CSS/Interpolation.cpp | 116 +++--- Libraries/LibWeb/CSS/Interpolation.h | 14 +- Libraries/LibWeb/CSS/LengthBox.h | 2 +- Libraries/LibWeb/CSS/ParsedFontFace.cpp | 6 +- Libraries/LibWeb/CSS/ParsedFontFace.h | 2 +- .../LibWeb/CSS/Parser/DescriptorParsing.cpp | 16 +- .../LibWeb/CSS/Parser/GradientParsing.cpp | 2 +- Libraries/LibWeb/CSS/Parser/Helpers.cpp | 4 +- Libraries/LibWeb/CSS/Parser/Parser.cpp | 6 +- Libraries/LibWeb/CSS/Parser/Parser.h | 258 ++++++------- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 360 +++++++++--------- Libraries/LibWeb/CSS/Parser/RuleParsing.cpp | 2 +- Libraries/LibWeb/CSS/Parser/SyntaxParsing.cpp | 6 +- Libraries/LibWeb/CSS/Parser/SyntaxParsing.h | 2 +- Libraries/LibWeb/CSS/Parser/ValueParsing.cpp | 146 +++---- Libraries/LibWeb/CSS/StyleComputer.cpp | 38 +- Libraries/LibWeb/CSS/StyleComputer.h | 10 +- Libraries/LibWeb/CSS/StyleInvalidation.cpp | 2 +- Libraries/LibWeb/CSS/StyleInvalidation.h | 2 +- Libraries/LibWeb/CSS/StyleProperty.cpp | 2 +- Libraries/LibWeb/CSS/StyleProperty.h | 2 +- .../CSS/StyleValues/AbstractImageStyleValue.h | 8 +- .../CSS/StyleValues/AnchorSizeStyleValue.cpp | 4 +- .../CSS/StyleValues/AnchorSizeStyleValue.h | 10 +- .../CSS/StyleValues/AnchorStyleValue.cpp | 8 +- .../LibWeb/CSS/StyleValues/AnchorStyleValue.h | 16 +- .../CSS/StyleValues/AngleStyleValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/AngleStyleValue.h | 2 +- .../StyleValues/BackgroundSizeStyleValue.cpp | 2 +- .../StyleValues/BackgroundSizeStyleValue.h | 4 +- .../CSS/StyleValues/BasicShapeStyleValue.h | 2 +- .../StyleValues/BorderImageSliceStyleValue.h | 22 +- .../StyleValues/BorderRadiusStyleValue.cpp | 2 +- .../CSS/StyleValues/BorderRadiusStyleValue.h | 4 +- .../LibWeb/CSS/StyleValues/CSSColorValue.cpp | 12 +- .../LibWeb/CSS/StyleValues/CSSColorValue.h | 18 +- Libraries/LibWeb/CSS/StyleValues/CSSHSL.cpp | 2 +- Libraries/LibWeb/CSS/StyleValues/CSSHSL.h | 22 +- Libraries/LibWeb/CSS/StyleValues/CSSHWB.cpp | 2 +- Libraries/LibWeb/CSS/StyleValues/CSSHWB.h | 22 +- .../LibWeb/CSS/StyleValues/CSSKeywordValue.h | 4 +- .../LibWeb/CSS/StyleValues/CSSLCHLike.cpp | 2 +- Libraries/LibWeb/CSS/StyleValues/CSSLCHLike.h | 26 +- .../LibWeb/CSS/StyleValues/CSSLabLike.cpp | 4 +- Libraries/LibWeb/CSS/StyleValues/CSSLabLike.h | 26 +- .../LibWeb/CSS/StyleValues/CSSLightDark.cpp | 2 +- .../LibWeb/CSS/StyleValues/CSSLightDark.h | 10 +- .../LibWeb/CSS/StyleValues/CSSNumericValue.h | 6 +- Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp | 6 +- Libraries/LibWeb/CSS/StyleValues/CSSRGB.h | 22 +- .../CSS/StyleValues/CalculatedStyleValue.cpp | 22 +- .../CSS/StyleValues/CalculatedStyleValue.h | 12 +- .../StyleValues/ColorFunctionStyleValue.cpp | 6 +- .../CSS/StyleValues/ColorFunctionStyleValue.h | 10 +- .../CSS/StyleValues/ColorMixStyleValue.cpp | 2 +- .../CSS/StyleValues/ColorMixStyleValue.h | 4 +- .../CSS/StyleValues/ColorSchemeStyleValue.h | 2 +- .../StyleValues/ConicGradientStyleValue.cpp | 2 +- .../CSS/StyleValues/ConicGradientStyleValue.h | 2 +- .../CSS/StyleValues/ContentStyleValue.h | 2 +- .../CounterDefinitionsStyleValue.h | 4 +- .../CSS/StyleValues/CounterStyleValue.cpp | 6 +- .../CSS/StyleValues/CounterStyleValue.h | 10 +- .../CSS/StyleValues/CursorStyleValue.cpp | 2 +- .../LibWeb/CSS/StyleValues/CursorStyleValue.h | 4 +- .../CSS/StyleValues/CustomIdentStyleValue.h | 2 +- .../CSS/StyleValues/DisplayStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/EasingStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/EdgeStyleValue.h | 2 +- .../CSS/StyleValues/FitContentStyleValue.h | 8 +- .../LibWeb/CSS/StyleValues/FlexStyleValue.h | 2 +- .../CSS/StyleValues/FontSourceStyleValue.h | 4 +- .../CSS/StyleValues/FontStyleStyleValue.cpp | 4 +- .../CSS/StyleValues/FontStyleStyleValue.h | 12 +- .../CSS/StyleValues/FrequencyStyleValue.h | 2 +- .../CSS/StyleValues/GridAutoFlowStyleValue.h | 2 +- .../StyleValues/GridTemplateAreaStyleValue.h | 2 +- .../GridTrackPlacementStyleValue.h | 2 +- .../StyleValues/GridTrackSizeListStyleValue.h | 2 +- .../StyleValues/GuaranteedInvalidStyleValue.h | 2 +- .../CSS/StyleValues/ImageStyleValue.cpp | 6 +- .../LibWeb/CSS/StyleValues/ImageStyleValue.h | 4 +- .../CSS/StyleValues/IntegerStyleValue.h | 2 +- .../CSS/StyleValues/LengthStyleValue.cpp | 4 +- .../LibWeb/CSS/StyleValues/LengthStyleValue.h | 4 +- .../StyleValues/LinearGradientStyleValue.cpp | 2 +- .../StyleValues/LinearGradientStyleValue.h | 2 +- .../CSS/StyleValues/MathDepthStyleValue.cpp | 6 +- .../CSS/StyleValues/MathDepthStyleValue.h | 10 +- .../LibWeb/CSS/StyleValues/NumberStyleValue.h | 2 +- .../StyleValues/OpenTypeTaggedStyleValue.h | 10 +- .../PendingSubstitutionStyleValue.h | 2 +- .../CSS/StyleValues/PercentageStyleValue.h | 2 +- .../CSS/StyleValues/PositionStyleValue.h | 2 +- .../StyleValues/RadialGradientStyleValue.cpp | 2 +- .../StyleValues/RadialGradientStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/RatioStyleValue.h | 2 +- .../LibWeb/CSS/StyleValues/RectStyleValue.h | 2 +- .../CSS/StyleValues/RepeatStyleStyleValue.h | 2 +- .../CSS/StyleValues/ResolutionStyleValue.h | 2 +- .../StyleValues/ScrollbarColorStyleValue.cpp | 2 +- .../StyleValues/ScrollbarColorStyleValue.h | 14 +- .../StyleValues/ScrollbarGutterStyleValue.h | 2 +- .../CSS/StyleValues/ShadowStyleValue.cpp | 10 +- .../LibWeb/CSS/StyleValues/ShadowStyleValue.h | 44 +-- .../CSS/StyleValues/ShorthandStyleValue.cpp | 20 +- .../CSS/StyleValues/ShorthandStyleValue.h | 12 +- .../LibWeb/CSS/StyleValues/StringStyleValue.h | 2 +- .../StyleValue.cpp} | 20 +- .../StyleValue.h} | 37 +- .../LibWeb/CSS/StyleValues/StyleValueList.cpp | 4 +- .../LibWeb/CSS/StyleValues/StyleValueList.h | 6 +- .../LibWeb/CSS/StyleValues/TimeStyleValue.h | 2 +- .../StyleValues/TransformationStyleValue.cpp | 6 +- .../StyleValues/TransformationStyleValue.h | 2 +- .../CSS/StyleValues/TransitionStyleValue.h | 4 +- .../LibWeb/CSS/StyleValues/URLStyleValue.h | 2 +- .../CSS/StyleValues/UnicodeRangeStyleValue.h | 2 +- .../CSS/StyleValues/UnresolvedStyleValue.cpp | 4 +- .../CSS/StyleValues/UnresolvedStyleValue.h | 6 +- Libraries/LibWeb/DOM/AbstractElement.cpp | 2 +- Libraries/LibWeb/DOM/AbstractElement.h | 2 +- Libraries/LibWeb/DOM/Document.cpp | 2 +- Libraries/LibWeb/DOM/Document.h | 2 +- Libraries/LibWeb/DOM/Element.cpp | 2 +- .../LibWeb/Editing/Internal/Algorithms.cpp | 8 +- .../LibWeb/Editing/Internal/Algorithms.h | 6 +- Libraries/LibWeb/Forward.h | 2 +- Libraries/LibWeb/HTML/Canvas/CanvasState.h | 2 +- Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 6 +- Libraries/LibWeb/HTML/Parser/HTMLParser.h | 4 +- Libraries/LibWeb/Layout/Node.cpp | 2 +- Libraries/LibWeb/SVG/SVGSVGElement.cpp | 4 +- Libraries/LibWeb/SVG/SVGSVGElement.h | 4 +- .../LibWeb/GenerateCSSDescriptors.cpp | 8 +- .../LibWeb/GenerateCSSPropertyID.cpp | 8 +- Services/WebContent/WebDriverConnection.cpp | 2 +- 167 files changed, 989 insertions(+), 990 deletions(-) rename Libraries/LibWeb/CSS/{CSSStyleValue.cpp => StyleValues/StyleValue.cpp} (93%) rename Libraries/LibWeb/CSS/{CSSStyleValue.h => StyleValues/StyleValue.h} (90%) diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.md index 0a74667199..d9af3ab9c7 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 | An object. See below. | `bool property_is_logical_alias(PropertyID);`
`PropertyID map_logical_alias_to_physical_property(PropertyID, LogicalAliasMappingContext const&)` | | `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)`
`Vector expanded_longhands_for_shorthand(PropertyID)`
`Vector shorthands_for_longhand(PropertyID)` | @@ -129,7 +129,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/Documentation/CSSProperties.md b/Documentation/CSSProperties.md index 772c3ae7f3..0d98ebd449 100644 --- a/Documentation/CSSProperties.md +++ b/Documentation/CSSProperties.md @@ -18,7 +18,7 @@ However, there are many CSS properties with more complicated grammar and so they Property-parsing code goes in `CSS/Parser/PropertyParsing.cpp`, and `CSS/Parser/Parser.h`. First, `Parser::parse_css_value()` is called, which has a switch for specific properties. Call your method from there. It -should return a `RefPtr` to a `CSSStyleValue` or one of its subclasses. +should return a `RefPtr` to a `StyleValue` or one of its subclasses. For shorthands, you should normally use `ShorthandStyleValue`, which automatically expands its longhand values. You might need to modify `ShorthandStyleValue::to_string` if your shorthand has special serialization rules. For example, @@ -29,7 +29,7 @@ If you need to do this, pester @AtkinsSJ until he gets around to documenting it. ## Computed style -After parsing and style computation, longhand properties are stored as `CSSStyleValue` pointers in +After parsing and style computation, longhand properties are stored as `StyleValue` pointers in `ComputedProperties`. Any shorthands have been expanded out, and so we do not need to store them directly. These longhands then need to be converted to a more usable form. To do this, add a getter to `ComputedProperties` with diff --git a/Documentation/LibWebFromLoadingToPainting.md b/Documentation/LibWebFromLoadingToPainting.md index c0c0f14089..0c582f45c3 100644 --- a/Documentation/LibWebFromLoadingToPainting.md +++ b/Documentation/LibWebFromLoadingToPainting.md @@ -80,7 +80,7 @@ The cascade origin determines the processing order for rules. The "user-agent" s Note: the user-agent style is a built-in CSS style sheet that lives in the LibWeb source code [here](https://github.com/LadybirdBrowser/ladybird/blob/master/Libraries/LibWeb/CSS/Default.css). -The end product of style computation is a fully populated StyleProperties object. It has a CSSStyleValue for each CSS::PropertyID. In spec parlance, these are the *computed* values. (Note that these are not the same as you get from `getComputedStyle()`, that API returns the *resolved* values.) +The end product of style computation is a fully populated StyleProperties object. It has a StyleValue for each CSS::PropertyID. In spec parlance, these are the *computed* values. (Note that these are not the same as you get from `getComputedStyle()`, that API returns the *resolved* values.) #### Resolving CSS custom properties ("variables") diff --git a/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Libraries/LibWeb/Animations/AnimationEffect.cpp index c5cb22deff..d135a33543 100644 --- a/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -158,7 +158,7 @@ WebIDL::ExceptionOr AnimationEffect::update_timing(OptionalEffectTiming ti // 4. If the easing member of input exists but cannot be parsed using the production // [CSS-EASING-1], throw a TypeError and abort this procedure. - RefPtr easing_value; + RefPtr easing_value; if (timing.easing.has_value()) { easing_value = parse_easing_string(timing.easing.value()); if (!easing_value) @@ -604,7 +604,7 @@ Optional AnimationEffect::transformed_progress() const return m_timing_function.evaluate_at(directed_progress.value(), before_flag); } -RefPtr AnimationEffect::parse_easing_string(StringView value) +RefPtr AnimationEffect::parse_easing_string(StringView value) { if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value, CSS::PropertyID::AnimationTimingFunction)) { if (style_value->is_easing()) @@ -631,7 +631,7 @@ void AnimationEffect::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(m_associated_animation); } -static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation_for_animated_properties(HashMap> const& old_properties, HashMap> const& new_properties) +static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation_for_animated_properties(HashMap> const& old_properties, HashMap> const& new_properties) { CSS::RequiredInvalidationAfterStyleChange invalidation; auto old_and_new_properties = MUST(Bitmap::create(to_underlying(CSS::last_property_id) + 1, 0)); diff --git a/Libraries/LibWeb/Animations/AnimationEffect.h b/Libraries/LibWeb/Animations/AnimationEffect.h index 4d78d78330..4212146412 100644 --- a/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Libraries/LibWeb/Animations/AnimationEffect.h @@ -62,7 +62,7 @@ Bindings::PlaybackDirection css_animation_direction_to_bindings_playback_directi // This object lives for the duration of an animation update, and is used to store per-element data about animated CSS properties. struct AnimationUpdateContext { struct ElementData { - using PropertyMap = HashMap>; + using PropertyMap = HashMap>; PropertyMap animated_properties_before_update; GC::Ptr target_style; }; @@ -79,7 +79,7 @@ class AnimationEffect : public Bindings::PlatformObject { GC_DECLARE_ALLOCATOR(AnimationEffect); public: - static RefPtr parse_easing_string(StringView value); + static RefPtr parse_easing_string(StringView value); EffectTiming get_timing() const; ComputedEffectTiming get_computed_timing() const; diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 742afbb7de..111b69f1f2 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -563,7 +563,7 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS if (!easing_value) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) }; - keyframe.easing.set(NonnullRefPtr { *easing_value }); + keyframe.easing.set(NonnullRefPtr { *easing_value }); } // 9. Parse each of the values in unused easings using the CSS syntax defined for easing member of the EffectTiming @@ -591,7 +591,7 @@ void KeyframeEffect::generate_initial_and_final_frames(RefPtr keyfr initial_keyframe = keyframe_set->keyframes_by_key.find(0); } - auto expanded_properties = [&](HashMap>>& properties) { + auto expanded_properties = [&](HashMap>>& properties) { HashTable result; for (auto property : properties) { @@ -827,7 +827,7 @@ WebIDL::ExceptionOr> KeyframeEffect::get_keyframes() auto object = JS::Object::create(realm, realm.intrinsics().object_prototype()); TRY(object->set(vm.names.offset, keyframe.offset.has_value() ? JS::Value(keyframe.offset.value()) : JS::js_null(), ShouldThrowExceptions::Yes)); TRY(object->set(vm.names.computedOffset, JS::Value(keyframe.computed_offset.value()), ShouldThrowExceptions::Yes)); - auto easing_value = keyframe.easing.get>(); + auto easing_value = keyframe.easing.get>(); TRY(object->set(vm.names.easing, JS::PrimitiveString::create(vm, easing_value->to_string(CSS::SerializationMode::Normal)), ShouldThrowExceptions::Yes)); if (keyframe.composite == Bindings::CompositeOperationOrAuto::Replace) { @@ -881,7 +881,7 @@ WebIDL::ExceptionOr KeyframeEffect::set_keyframes(Optionaldocument() }, *target, pseudo_element_type(), property_id, property_value->as_unresolved()); resolved_keyframe.properties.set(property_id, property_value); - CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, [&](CSS::PropertyID longhand_id, CSS::CSSStyleValue const&) { + CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, [&](CSS::PropertyID longhand_id, CSS::StyleValue const&) { m_target_properties.set(longhand_id); }); } diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.h b/Libraries/LibWeb/Animations/KeyframeEffect.h index 9b330cb55f..f00b8822c5 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.h +++ b/Libraries/LibWeb/Animations/KeyframeEffect.h @@ -11,13 +11,13 @@ #include #include #include -#include #include #include +#include namespace Web::Animations { -using EasingValue = Variant>; +using EasingValue = Variant>; // https://www.w3.org/TR/web-animations-1/#the-keyframeeffectoptions-dictionary struct KeyframeEffectOptions : public EffectTiming { @@ -39,7 +39,7 @@ struct BasePropertyIndexedKeyframe { // https://www.w3.org/TR/web-animations-1/#dictdef-basekeyframe struct BaseKeyframe { using UnparsedProperties = HashMap; - using ParsedProperties = HashMap>; + using ParsedProperties = HashMap>; Optional offset {}; EasingValue easing { "linear"_string }; @@ -64,9 +64,9 @@ public: struct KeyFrameSet : public RefCounted { struct UseInitial { }; struct ResolvedKeyFrame { - // These CSSStyleValue properties can be unresolved, as they may be generated from a @keyframes rule, well + // These StyleValue properties can be unresolved, as they may be generated from a @keyframes rule, well // before they are applied to an element - HashMap>> properties {}; + HashMap>> properties {}; }; RedBlackTree keyframes_by_key; }; diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 284eba123a..f2b40de20c 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -125,7 +125,6 @@ set(SOURCES CSS/CSSStyleProperties.cpp CSS/CSSStyleRule.cpp CSS/CSSStyleSheet.cpp - CSS/CSSStyleValue.cpp CSS/CSSSupportsRule.cpp CSS/CSSTransition.cpp CSS/Descriptor.cpp @@ -234,6 +233,7 @@ set(SOURCES CSS/StyleValues/ScrollbarColorStyleValue.cpp CSS/StyleValues/ShadowStyleValue.cpp CSS/StyleValues/ShorthandStyleValue.cpp + CSS/StyleValues/StyleValue.cpp CSS/StyleValues/StyleValueList.cpp CSS/StyleValues/TransformationStyleValue.cpp CSS/StyleValues/TransitionStyleValue.cpp diff --git a/Libraries/LibWeb/CSS/CSS.cpp b/Libraries/LibWeb/CSS/CSS.cpp index 6fb6d467d8..e9f55619b2 100644 --- a/Libraries/LibWeb/CSS/CSS.cpp +++ b/Libraries/LibWeb/CSS/CSS.cpp @@ -89,7 +89,7 @@ WebIDL::ExceptionOr register_property(JS::VM& vm, PropertyDefinition defin return WebIDL::SyntaxError::create(realm, "Invalid syntax definition"_string); } - RefPtr initial_value_maybe; + RefPtr initial_value_maybe; // 4. If syntax definition is the universal syntax definition, and initialValue is not present, if (maybe_syntax->type() == Parser::SyntaxNode::NodeType::Universal) { diff --git a/Libraries/LibWeb/CSS/CSSAnimation.h b/Libraries/LibWeb/CSS/CSSAnimation.h index a4fc1c5311..ebe374f40f 100644 --- a/Libraries/LibWeb/CSS/CSSAnimation.h +++ b/Libraries/LibWeb/CSS/CSSAnimation.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include namespace Web::CSS { diff --git a/Libraries/LibWeb/CSS/CSSDescriptors.cpp b/Libraries/LibWeb/CSS/CSSDescriptors.cpp index 3b965b9426..052f16163c 100644 --- a/Libraries/LibWeb/CSS/CSSDescriptors.cpp +++ b/Libraries/LibWeb/CSS/CSSDescriptors.cpp @@ -41,7 +41,7 @@ String CSSDescriptors::item(size_t index) const } // https://drafts.csswg.org/cssom/#set-a-css-declaration -bool CSSDescriptors::set_a_css_declaration(DescriptorID descriptor_id, NonnullRefPtr value, Important) +bool CSSDescriptors::set_a_css_declaration(DescriptorID descriptor_id, NonnullRefPtr value, Important) { VERIFY(!is_computed()); @@ -89,7 +89,7 @@ WebIDL::ExceptionOr CSSDescriptors::set_property(StringView property, Stri return {}; // 5. Let component value list be the result of parsing value for property property. - RefPtr component_value_list = parse_css_descriptor(Parser::ParsingParams {}, m_at_rule_id, *descriptor_id, value); + RefPtr component_value_list = parse_css_descriptor(Parser::ParsingParams {}, m_at_rule_id, *descriptor_id, value); // 6. If component value list is null, then return. if (!component_value_list) @@ -263,7 +263,7 @@ void CSSDescriptors::visit_edges(Visitor& visitor) } } -RefPtr CSSDescriptors::descriptor(DescriptorID descriptor_id) const +RefPtr CSSDescriptors::descriptor(DescriptorID descriptor_id) const { auto match = m_descriptors.first_matching([descriptor_id](Descriptor const& descriptor) { return descriptor.descriptor_id == descriptor_id; @@ -273,7 +273,7 @@ RefPtr CSSDescriptors::descriptor(DescriptorID descriptor_i return nullptr; } -RefPtr CSSDescriptors::descriptor_or_initial_value(DescriptorID descriptor_id) const +RefPtr CSSDescriptors::descriptor_or_initial_value(DescriptorID descriptor_id) const { if (auto value = descriptor(descriptor_id)) return value.release_nonnull(); @@ -289,7 +289,7 @@ bool is_shorthand(AtRuleID at_rule, DescriptorID descriptor) return false; } -void for_each_expanded_longhand(AtRuleID at_rule, DescriptorID descriptor, RefPtr value, Function)> callback) +void for_each_expanded_longhand(AtRuleID at_rule, DescriptorID descriptor, RefPtr value, Function)> callback) { if (at_rule == AtRuleID::Page && descriptor == DescriptorID::Margin) { if (!value) { diff --git a/Libraries/LibWeb/CSS/CSSDescriptors.h b/Libraries/LibWeb/CSS/CSSDescriptors.h index 64cb0fd7a8..3749465a9a 100644 --- a/Libraries/LibWeb/CSS/CSSDescriptors.h +++ b/Libraries/LibWeb/CSS/CSSDescriptors.h @@ -27,8 +27,8 @@ public: virtual StringView get_property_priority(StringView property) const override; Vector const& descriptors() const { return m_descriptors; } - RefPtr descriptor(DescriptorID) const; - RefPtr descriptor_or_initial_value(DescriptorID) const; + RefPtr descriptor(DescriptorID) const; + RefPtr descriptor_or_initial_value(DescriptorID) const; virtual String serialized() const override; virtual WebIDL::ExceptionOr set_css_text(StringView) override; @@ -37,7 +37,7 @@ protected: CSSDescriptors(JS::Realm&, AtRuleID, Vector); private: - bool set_a_css_declaration(DescriptorID, NonnullRefPtr, Important); + bool set_a_css_declaration(DescriptorID, NonnullRefPtr, Important); virtual void visit_edges(Visitor&) override; @@ -46,6 +46,6 @@ private: }; bool is_shorthand(AtRuleID, DescriptorID); -void for_each_expanded_longhand(AtRuleID, DescriptorID, RefPtr, Function)>); +void for_each_expanded_longhand(AtRuleID, DescriptorID, RefPtr, Function)>); } diff --git a/Libraries/LibWeb/CSS/CSSPropertyRule.cpp b/Libraries/LibWeb/CSS/CSSPropertyRule.cpp index ba17934504..7267c098af 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 a600f17e4b..e252b856ef 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; @@ -29,10 +29,10 @@ public: FlyString const& syntax() const { return m_syntax; } bool inherits() const { return m_inherits; } Optional initial_value() const; - RefPtr initial_style_value() const { return m_initial_value; } + RefPtr initial_style_value() const { return m_initial_value; } 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; @@ -40,7 +40,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/CSSStyleDeclaration.h b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index b3e69b3578..6bcb8ee322 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include namespace Web::CSS { diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index d8a9b36c03..74af148849 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -83,7 +83,7 @@ Vector CSSStyleProperties::convert_declarations_to_specified_orde Vector specified_order_declarations; for (auto declaration : declarations) { - StyleComputer::for_each_property_expanding_shorthands(declaration.property_id, declaration.value, [&](CSS::PropertyID longhand_id, CSS::CSSStyleValue const& longhand_property_value) { + StyleComputer::for_each_property_expanding_shorthands(declaration.property_id, declaration.value, [&](CSS::PropertyID longhand_id, CSS::StyleValue const& longhand_property_value) { auto existing_entry_index = specified_order_declarations.find_first_index_if([&](StyleProperty const& existing_declaration) { return existing_declaration.property_id == longhand_id; }); if (existing_entry_index.has_value()) { @@ -282,7 +282,7 @@ WebIDL::ExceptionOr CSSStyleProperties::set_property(StringView property_n // 8. If property is a shorthand property, if (property_is_shorthand(property_id)) { // then for each longhand property longhand that property maps to, in canonical order, follow these substeps: - StyleComputer::for_each_property_expanding_shorthands(property_id, *component_value_list, [this, &updated, priority](PropertyID longhand_property_id, CSSStyleValue const& longhand_value) { + StyleComputer::for_each_property_expanding_shorthands(property_id, *component_value_list, [this, &updated, priority](PropertyID longhand_property_id, StyleValue const& longhand_value) { // 1. Let longhand result be the result of set the CSS declaration longhand with the appropriate value(s) from component value list, // with the important flag set if priority is not the empty string, and unset otherwise, and with the list of declarations being the declarations. // 2. If longhand result is true, let updated be true. @@ -325,7 +325,7 @@ WebIDL::ExceptionOr CSSStyleProperties::set_property(PropertyID property_i return set_property(string_from_property_id(property_id), css_text, priority); } -static NonnullRefPtr style_value_for_length_percentage(LengthPercentage const& length_percentage) +static NonnullRefPtr style_value_for_length_percentage(LengthPercentage const& length_percentage) { if (length_percentage.is_auto()) return CSSKeywordValue::create(Keyword::Auto); @@ -336,7 +336,7 @@ static NonnullRefPtr style_value_for_length_percentage(Leng return length_percentage.calculated(); } -static NonnullRefPtr style_value_for_size(Size const& size) +static NonnullRefPtr style_value_for_size(Size const& size) { if (size.is_none()) return CSSKeywordValue::create(Keyword::None); @@ -357,7 +357,7 @@ static NonnullRefPtr style_value_for_size(Size const& size) TODO(); } -static RefPtr style_value_for_shadow(Vector const& shadow_data) +static RefPtr style_value_for_shadow(Vector const& shadow_data) { if (shadow_data.is_empty()) return CSSKeywordValue::create(Keyword::None); @@ -432,7 +432,7 @@ Optional CSSStyleProperties::get_property_internal(PropertyID pro // 2. If property is a shorthand property, then follow these substeps: if (property_is_shorthand(property_id)) { // 1. Let list be a new empty array. - Vector> list; + Vector> list; Optional last_important_flag; // 2. For each longhand property longhand that property maps to, in canonical order, follow these substeps: @@ -469,7 +469,7 @@ Optional CSSStyleProperties::get_property_internal(PropertyID pro return property(property_id); } -static RefPtr resolve_color_style_value(CSSStyleValue const& style_value, Color computed_color) +static RefPtr resolve_color_style_value(StyleValue const& style_value, Color computed_color) { if (style_value.is_color_function()) return style_value; @@ -482,7 +482,7 @@ static RefPtr resolve_color_style_value(CSSStyleValue const return CSSColorValue::create_from_color(computed_color, ColorSyntax::Modern); } -RefPtr CSSStyleProperties::style_value_for_computed_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const +RefPtr CSSStyleProperties::style_value_for_computed_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const { if (!owner_node().has_value()) { dbgln_if(LIBWEB_CSS_DEBUG, "Computed style for CSSStyleProperties without owner node was requested"); @@ -1189,7 +1189,7 @@ String CSSStyleProperties::serialize_a_css_value(Vector list) con // 3. Otherwise, serialize a CSS value from a hypothetical declaration of the property shorthand with its value representing the combined values of the declarations in list. Function(PropertyID)> make_shorthand_value = [&](PropertyID shorthand_id) { auto longhand_ids = longhands_for_shorthand(shorthand_id); - Vector> longhand_values; + Vector> longhand_values; for (auto longhand_id : longhand_ids) { if (property_is_shorthand(longhand_id)) @@ -1236,7 +1236,7 @@ void CSSStyleProperties::invalidate_owners(DOM::StyleInvalidationReason reason) } // https://drafts.csswg.org/cssom/#set-a-css-declaration -bool CSSStyleProperties::set_a_css_declaration(PropertyID property_id, NonnullRefPtr value, Important important) +bool CSSStyleProperties::set_a_css_declaration(PropertyID property_id, NonnullRefPtr value, Important important) { VERIFY(!is_computed()); diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.h b/Libraries/LibWeb/CSS/CSSStyleProperties.h index 5163a826c8..1d6c8050b3 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.h +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.h @@ -68,10 +68,10 @@ private: virtual void visit_edges(Cell::Visitor&) override; - RefPtr style_value_for_computed_property(Layout::NodeWithStyle const&, PropertyID) const; + RefPtr style_value_for_computed_property(Layout::NodeWithStyle const&, PropertyID) const; Optional get_property_internal(PropertyID) const; - bool set_a_css_declaration(PropertyID, NonnullRefPtr, Important); + bool set_a_css_declaration(PropertyID, NonnullRefPtr, Important); void empty_the_declarations(); void set_the_declarations(Vector properties, HashMap custom_properties); diff --git a/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Libraries/LibWeb/CSS/CSSStyleRule.cpp index 906d317490..eb9051ff63 100644 --- a/Libraries/LibWeb/CSS/CSSStyleRule.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleRule.cpp @@ -216,7 +216,7 @@ void CSSStyleRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet) // This is annoying: Style values that request resources need to know their CSSStyleSheet in order to fetch them. for (auto const& property : m_declaration->properties()) { - const_cast(*property.value).set_style_sheet(parent_style_sheet); + const_cast(*property.value).set_style_sheet(parent_style_sheet); } } diff --git a/Libraries/LibWeb/CSS/CSSTransition.cpp b/Libraries/LibWeb/CSS/CSSTransition.cpp index d3061615be..6842b3e50e 100644 --- a/Libraries/LibWeb/CSS/CSSTransition.cpp +++ b/Libraries/LibWeb/CSS/CSSTransition.cpp @@ -20,8 +20,8 @@ namespace Web::CSS { GC_DEFINE_ALLOCATOR(CSSTransition); GC::Ref CSSTransition::start_a_transition(DOM::Element& element, Optional pseudo_element, PropertyID property_id, - size_t transition_generation, double start_time, double end_time, NonnullRefPtr start_value, - NonnullRefPtr end_value, NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor) + size_t transition_generation, double start_time, double end_time, NonnullRefPtr start_value, + NonnullRefPtr end_value, NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor) { auto& realm = element.realm(); return realm.create(realm, element, pseudo_element, property_id, transition_generation, start_time, end_time, start_value, end_value, reversing_adjusted_start_value, reversing_shortening_factor); @@ -76,8 +76,8 @@ Optional CSSTransition::class_specific_composite_order(GC::Ref pseudo_element, PropertyID property_id, size_t transition_generation, - double start_time, double end_time, NonnullRefPtr start_value, NonnullRefPtr end_value, - NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor) + double start_time, double end_time, NonnullRefPtr start_value, NonnullRefPtr end_value, + NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor) : Animations::Animation(realm) , m_transition_property(property_id) , m_transition_generation(transition_generation) diff --git a/Libraries/LibWeb/CSS/CSSTransition.h b/Libraries/LibWeb/CSS/CSSTransition.h index 22cfc3e325..7f711893b3 100644 --- a/Libraries/LibWeb/CSS/CSSTransition.h +++ b/Libraries/LibWeb/CSS/CSSTransition.h @@ -8,11 +8,11 @@ #pragma once #include -#include #include #include #include #include +#include #include namespace Web::CSS { @@ -23,8 +23,8 @@ class CSSTransition : public Animations::Animation { public: static GC::Ref start_a_transition(DOM::Element&, Optional, PropertyID, - size_t transition_generation, double start_time, double end_time, NonnullRefPtr start_value, - NonnullRefPtr end_value, NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor); + size_t transition_generation, double start_time, double end_time, NonnullRefPtr start_value, + NonnullRefPtr end_value, NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor); StringView transition_property() const { return string_from_property_id(m_transition_property); } @@ -33,9 +33,9 @@ public: double transition_start_time() const { return m_start_time; } double transition_end_time() const { return m_end_time; } - NonnullRefPtr transition_start_value() const { return m_start_value; } - NonnullRefPtr transition_end_value() const { return m_end_value; } - NonnullRefPtr reversing_adjusted_start_value() const { return m_reversing_adjusted_start_value; } + NonnullRefPtr transition_start_value() const { return m_start_value; } + NonnullRefPtr transition_end_value() const { return m_end_value; } + NonnullRefPtr reversing_adjusted_start_value() const { return m_reversing_adjusted_start_value; } double reversing_shortening_factor() const { return m_reversing_shortening_factor; } double timing_function_output_at_time(double t) const; @@ -53,8 +53,8 @@ public: private: CSSTransition(JS::Realm&, DOM::Element&, Optional, PropertyID, size_t transition_generation, - double start_time, double end_time, NonnullRefPtr start_value, NonnullRefPtr end_value, - NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor); + double start_time, double end_time, NonnullRefPtr start_value, NonnullRefPtr end_value, + NonnullRefPtr reversing_adjusted_start_value, double reversing_shortening_factor); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; @@ -73,13 +73,13 @@ private: double m_end_time; // https://drafts.csswg.org/css-transitions/#transition-start-value - NonnullRefPtr m_start_value; + NonnullRefPtr m_start_value; // https://drafts.csswg.org/css-transitions/#transition-end-value - NonnullRefPtr m_end_value; + NonnullRefPtr m_end_value; // https://drafts.csswg.org/css-transitions/#transition-reversing-adjusted-start-value - NonnullRefPtr m_reversing_adjusted_start_value; + NonnullRefPtr m_reversing_adjusted_start_value; // https://drafts.csswg.org/css-transitions/#transition-reversing-shortening-factor double m_reversing_shortening_factor; diff --git a/Libraries/LibWeb/CSS/CalculatedOr.cpp b/Libraries/LibWeb/CSS/CalculatedOr.cpp index 99ce172162..f22d56f894 100644 --- a/Libraries/LibWeb/CSS/CalculatedOr.cpp +++ b/Libraries/LibWeb/CSS/CalculatedOr.cpp @@ -22,7 +22,7 @@ Optional AngleOrCalculated::resolve_calculated(NonnullRefPtrresolve_angle_deprecated(context); } -NonnullRefPtr AngleOrCalculated::create_style_value() const +NonnullRefPtr AngleOrCalculated::create_style_value() const { return AngleStyleValue::create(value()); } @@ -32,7 +32,7 @@ Optional FlexOrCalculated::resolve_calculated(NonnullRefPtrresolve_flex_deprecated(context); } -NonnullRefPtr FlexOrCalculated::create_style_value() const +NonnullRefPtr FlexOrCalculated::create_style_value() const { return FlexStyleValue::create(value()); } @@ -42,7 +42,7 @@ Optional FrequencyOrCalculated::resolve_calculated(NonnullRefPtrresolve_frequency_deprecated(context); } -NonnullRefPtr FrequencyOrCalculated::create_style_value() const +NonnullRefPtr FrequencyOrCalculated::create_style_value() const { return FrequencyStyleValue::create(value()); } @@ -52,7 +52,7 @@ Optional IntegerOrCalculated::resolve_calculated(NonnullRefPtrresolve_integer_deprecated(context); } -NonnullRefPtr IntegerOrCalculated::create_style_value() const +NonnullRefPtr IntegerOrCalculated::create_style_value() const { return IntegerStyleValue::create(value()); } @@ -62,7 +62,7 @@ Optional LengthOrCalculated::resolve_calculated(NonnullRefPtrresolve_length_deprecated(context); } -NonnullRefPtr LengthOrCalculated::create_style_value() const +NonnullRefPtr LengthOrCalculated::create_style_value() const { return LengthStyleValue::create(value()); } @@ -72,7 +72,7 @@ Optional NumberOrCalculated::resolve_calculated(NonnullRefPtrresolve_number_deprecated(context); } -NonnullRefPtr NumberOrCalculated::create_style_value() const +NonnullRefPtr NumberOrCalculated::create_style_value() const { return NumberStyleValue::create(value()); } @@ -82,7 +82,7 @@ Optional PercentageOrCalculated::resolve_calculated(NonnullRefPtrresolve_percentage_deprecated(context); } -NonnullRefPtr PercentageOrCalculated::create_style_value() const +NonnullRefPtr PercentageOrCalculated::create_style_value() const { return PercentageStyleValue::create(value()); } @@ -92,7 +92,7 @@ Optional ResolutionOrCalculated::resolve_calculated(NonnullRefPtrresolve_resolution_deprecated(context); } -NonnullRefPtr ResolutionOrCalculated::create_style_value() const +NonnullRefPtr ResolutionOrCalculated::create_style_value() const { return ResolutionStyleValue::create(value()); } @@ -102,7 +102,7 @@ Optional