mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 08:31:51 +00:00
LibWeb/CSS: Use PendingSubstitutionValue for unresolved shorthands
Previously, we would just assign the UnresolvedStyleValue to each
longhand, which was completely wrong but happened to work if it was a
ShorthandStyleValue (because that's basically a list of "set property X
to Y", and doesn't care which property it's the value of).
For example, the included `var-in-margin-shorthand.html` test would:
1. Set `margin-top` to `var(--a) 10px`
2. Resolve it to `margin-top: 5px 10px`
3. Reject that as invalid
What now happens is:
1. Set `margin-top` to a PendingSubstitutionValue
2. Resolve `margin` to `5px 10px`
3. Expand that out into its longhands
4. `margin-top` is `5px` 🎉
In order to support this, `for_each_property_expanding_shorthands()` now
runs the callback for the shorthand too if it's an unresolved or
pending-substitution value. This is so that we can store those in the
CascadedProperties until they can be resolved - otherwise, by the time
we want to resolve them, we don't have them any more.
`cascade_declarations()` has an unfortunate hack: it tracks, for each
declaration, which properties have already been given values, so that
it can avoid overwriting an actual value with a pending one. This is
necessary because of the unfortunate way that CSSStyleProperties holds
expanded longhands, and not just the original declarations. The spec
disagrees with itself about this, but we do need to do that expansion
for `element.style` to work correctly. This HashTable is unfortunate
but it does solve the problem until a better solution can be found.
This commit is contained in:
parent
398d2f9981
commit
4edafb35cd
Notes:
github-actions[bot]
2025-05-14 10:47:57 +00:00
Author: https://github.com/AtkinsSJ
Commit: 4edafb35cd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4209
Reviewed-by: https://github.com/awesomekling
6 changed files with 164 additions and 41 deletions
|
@ -45,6 +45,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
|
@ -3941,8 +3942,6 @@ NonnullRefPtr<CSSStyleValue const> Parser::resolve_unresolved_style_value(Parsin
|
|||
// to produce a different CSSStyleValue from it.
|
||||
VERIFY(unresolved.contains_var_or_attr());
|
||||
|
||||
// If the value is invalid, we fall back to `unset`: https://www.w3.org/TR/css-variables-1/#invalid-at-computed-value-time
|
||||
|
||||
auto parser = Parser::create(context, ""sv);
|
||||
return parser.resolve_unresolved_style_value(element, pseudo_element, property_id, unresolved);
|
||||
}
|
||||
|
@ -4005,18 +4004,18 @@ NonnullRefPtr<CSSStyleValue const> Parser::resolve_unresolved_style_value(DOM::E
|
|||
}
|
||||
};
|
||||
if (!expand_variables(element, pseudo_element, string_from_property_id(property_id), dependencies, unresolved_values_without_variables_expanded, values_with_variables_expanded))
|
||||
return CSSKeywordValue::create(Keyword::Unset);
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
|
||||
TokenStream unresolved_values_with_variables_expanded { values_with_variables_expanded };
|
||||
Vector<ComponentValue> expanded_values;
|
||||
if (!expand_unresolved_values(element, string_from_property_id(property_id), unresolved_values_with_variables_expanded, expanded_values))
|
||||
return CSSKeywordValue::create(Keyword::Unset);
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
|
||||
auto expanded_value_tokens = TokenStream { expanded_values };
|
||||
if (auto parsed_value = parse_css_value(property_id, expanded_value_tokens); !parsed_value.is_error())
|
||||
return parsed_value.release_value();
|
||||
|
||||
return CSSKeywordValue::create(Keyword::Unset);
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
}
|
||||
|
||||
static RefPtr<CSSStyleValue const> get_custom_property(DOM::Element const& element, Optional<CSS::PseudoElement> pseudo_element, FlyString const& custom_property_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue