mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01:00
LibWeb/CSS: Support inherit custom properties on :root
Make sure we have a parent element before trying to look at it! I've also pulled out a stub function for getting a custom property's initial value, so that there's only one place to change once we support `@property` more.
This commit is contained in:
parent
edca2ab666
commit
b3abbeab89
|
|
@ -3105,6 +3105,15 @@ void StyleComputer::unload_fonts_from_sheet(CSSStyleSheet& sheet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NonnullRefPtr<CSSStyleValue const> custom_property_initial_value(FlyString const& name)
|
||||||
|
{
|
||||||
|
// FIXME: Look-up initial value for registered properties. (@property)
|
||||||
|
(void)name;
|
||||||
|
|
||||||
|
// For non-registered properties, the initial value is the guaranteed-invalid value.
|
||||||
|
return GuaranteedInvalidStyleValue::create();
|
||||||
|
}
|
||||||
|
|
||||||
NonnullRefPtr<CSSStyleValue const> StyleComputer::compute_value_of_custom_property(DOM::AbstractElement abstract_element, FlyString const& name, Optional<Parser::GuardedSubstitutionContexts&> guarded_contexts)
|
NonnullRefPtr<CSSStyleValue const> StyleComputer::compute_value_of_custom_property(DOM::AbstractElement abstract_element, FlyString const& name, Optional<Parser::GuardedSubstitutionContexts&> guarded_contexts)
|
||||||
{
|
{
|
||||||
// https://drafts.csswg.org/css-variables/#propdef-
|
// https://drafts.csswg.org/css-variables/#propdef-
|
||||||
|
|
@ -3112,19 +3121,17 @@ NonnullRefPtr<CSSStyleValue const> StyleComputer::compute_value_of_custom_proper
|
||||||
// FIXME: These should probably be part of ComputedProperties.
|
// FIXME: These should probably be part of ComputedProperties.
|
||||||
|
|
||||||
auto value = abstract_element.get_custom_property(name);
|
auto value = abstract_element.get_custom_property(name);
|
||||||
if (!value)
|
if (!value || value->is_initial())
|
||||||
return GuaranteedInvalidStyleValue::create();
|
return custom_property_initial_value(name);
|
||||||
|
|
||||||
// Initial value is the guaranteed-invalid value.
|
|
||||||
if (value->is_initial())
|
|
||||||
return GuaranteedInvalidStyleValue::create();
|
|
||||||
|
|
||||||
// Unset is the same as inherit for inherited properties, and by default all custom properties are inherited.
|
// Unset is the same as inherit for inherited properties, and by default all custom properties are inherited.
|
||||||
// FIXME: Update handling of css-wide keywords once we support @property properly.
|
// FIXME: Support non-inherited registered custom properties.
|
||||||
if (value->is_inherit() || value->is_unset()) {
|
if (value->is_inherit() || value->is_unset()) {
|
||||||
|
if (!abstract_element.parent_element())
|
||||||
|
return custom_property_initial_value(name);
|
||||||
auto inherited_value = DOM::AbstractElement { const_cast<DOM::Element&>(*abstract_element.parent_element()) }.get_custom_property(name);
|
auto inherited_value = DOM::AbstractElement { const_cast<DOM::Element&>(*abstract_element.parent_element()) }.get_custom_property(name);
|
||||||
if (!inherited_value)
|
if (!inherited_value)
|
||||||
return GuaranteedInvalidStyleValue::create();
|
return custom_property_initial_value(name);
|
||||||
return inherited_value.release_nonnull();
|
return inherited_value.release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
PASS! (Didn't crash)
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--example: unset;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
println("PASS! (Didn't crash)");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user