diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-08-20 12:48:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-25 12:14:34 +0200 |
commit | 3296fd70b315c85b2cae8577f0170dfe3271a341 (patch) | |
tree | abcaccdd84db3f72ae531d5c8cada47adfaecf9c | |
parent | 160f434769d86a26e8c709cd7eba9eeaa9005b57 (diff) | |
download | serenity-3296fd70b315c85b2cae8577f0170dfe3271a341.zip |
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. :^(
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 30 |
1 files 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<NonnullRefPtr<StyleValue>> 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<NonnullRefPtr<StyleValue>> { + auto initial_value = property_initial_value(id); + if (initial_value) + return initial_value.release_nonnull(); + return {}; + }; + auto fetch_inherited = [](CSS::PropertyID) -> Optional<NonnullRefPtr<StyleValue>> { + // FIXME: Implement inheritance return {}; - return it->value; + }; + + 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 |