LibWeb: Give DOM Elements a CountersSet

This represents each element's set of CSS counters.
https://drafts.csswg.org/css-lists-3/#css-counters-set

Counters are resolved while building the tree. Most elements will not
have any counters to keep track of, so as an optimization, we don't
create a CountersSet object until the element actually needs one.

In order to properly support counters on pseudo-elements, the
CountersSet needs to go somewhere else. However, my experiments with
placing it on the Layout::Node kept hitting a wall. For now, this is
fairly simple at least.
This commit is contained in:
Sam Atkins 2024-07-17 11:46:08 +01:00
commit 708f49d906
Notes: github-actions[bot] 2024-07-26 10:06:00 +00:00
6 changed files with 253 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include <LibWeb/Bindings/ElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/ShadowRootPrototype.h>
#include <LibWeb/CSS/CountersSet.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleInvalidation.h>
#include <LibWeb/CSS/StyleProperty.h>
@ -399,6 +400,12 @@ public:
void set_in_top_layer(bool in_top_layer) { m_in_top_layer = in_top_layer; }
bool in_top_layer() const { return m_in_top_layer; }
bool has_non_empty_counters_set() const { return m_counters_set; }
Optional<CSS::CountersSet const&> counters_set();
CSS::CountersSet& ensure_counters_set();
void resolve_counters(CSS::StyleProperties&);
void inherit_counters();
protected:
Element(Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
@ -476,6 +483,8 @@ private:
Array<CSSPixelPoint, 3> m_scroll_offset;
bool m_in_top_layer { false };
OwnPtr<CSS::CountersSet> m_counters_set;
};
template<>