1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 09:08:10 +00:00

LibWeb: Start implementing the CSS cascade

The 'C' in "CSS" is for Cascade, so let's actually implement the cascade
in LibWeb. :^)

StyleResolver::resolve_style() now begins by collecting all the matching
CSS rules for the given DOM::Element. Rules are then processed in the
spec's cascade order (instead of in the order we encounter them.)

With this, "!important" is now honored on CSS properties.

After performing the cascade, we do another pass of what the spec calls
"defaulting" where we resolve "inherit" and "initial" values.
I've left a FIXME about supporting correct "initial" values for every
property, since we're currently lacking some coverage there.

Note that this mechanism now resolves every known CSS property. This is
*not* space-efficient and we'll eventually need to come up with some
strategies to reduce memory usage around this. However, this will do
fine until we have more of the engine working correctly. :^)
This commit is contained in:
Andreas Kling 2021-09-21 11:38:18 +02:00
parent c55909f175
commit d965a9552f
4 changed files with 150 additions and 77 deletions

View file

@ -82,7 +82,9 @@ public:
Optional<int> z_index() const;
private:
HashMap<unsigned, NonnullRefPtr<StyleValue>> m_property_values;
friend class StyleResolver;
HashMap<CSS::PropertyID, NonnullRefPtr<StyleValue>> m_property_values;
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
void load_font(Layout::Node const&) const;