From 3296fd70b315c85b2cae8577f0170dfe3271a341 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 20 Aug 2021 12:48:17 +0100 Subject: [PATCH] LibWeb: Intercept CSS `initial`/`inherit` values in StyleProperties When property() previously would have returned an InitialStyleValue, we now look up what the initial value would be, and return that instead. We also intercep 'inherit', but inheritance is not implemented yet so we just return nothing. This does cause a regression on Acid2: The eyes no longer appear, and I am not sure why. :^( --- .../Libraries/LibWeb/CSS/StyleProperties.cpp | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 6ad47dee85..c6067abe68 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -45,10 +45,34 @@ void StyleProperties::set_property(CSS::PropertyID id, const StringView& value) Optional> StyleProperties::property(CSS::PropertyID id) const { - auto it = m_property_values.find((unsigned)id); - if (it == m_property_values.end()) + auto fetch_initial = [](CSS::PropertyID id) -> Optional> { + auto initial_value = property_initial_value(id); + if (initial_value) + return initial_value.release_nonnull(); return {}; - return it->value; + }; + auto fetch_inherited = [](CSS::PropertyID) -> Optional> { + // FIXME: Implement inheritance + return {}; + }; + + auto it = m_property_values.find((unsigned)id); + if (it == m_property_values.end()) { + if (is_inherited_property(id)) { + return fetch_inherited(id); + } else { + // FIXME: This causes the Acid2 eyes to disappear for some reason + return fetch_initial(id); + } + } + + auto& value = it->value; + if (value->is_initial()) + return fetch_initial(id); + if (value->is_inherit()) + return fetch_inherited(id); + + return value; } Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fallback) const