mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 01:42:17 +00: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
Notes:
github-actions[bot]
2025-07-15 08:37:17 +00:00
Author: https://github.com/AtkinsSJ
Commit: b3abbeab89
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5438
Reviewed-by: https://github.com/gmta ✅
3 changed files with 28 additions and 8 deletions
|
@ -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)
|
||||
{
|
||||
// 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.
|
||||
|
||||
auto value = abstract_element.get_custom_property(name);
|
||||
if (!value)
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
|
||||
// Initial value is the guaranteed-invalid value.
|
||||
if (value->is_initial())
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
if (!value || value->is_initial())
|
||||
return custom_property_initial_value(name);
|
||||
|
||||
// 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 (!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);
|
||||
if (!inherited_value)
|
||||
return GuaranteedInvalidStyleValue::create();
|
||||
return custom_property_initial_value(name);
|
||||
return inherited_value.release_nonnull();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue