mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Support counter-* properties on pseudo-elements
There are multiple things happening here which are interconnected: - We now use AbstractElement to refer to the source of a counter, which means we also need to pass that around to compute `content`. - Give AbstractElement new helper methods that are needed by CountersSet, so it doesn't have to care whether it's dealing with a true Element or PseudoElement. - The CountersSet algorithms now walk the layout tree instead of DOM tree, so TreeBuilder needs to wait until the layout node exists before it resolves counters for it. - Resolve counters when creating a pseudo-element's layout node. We awkwardly compute the `content` value up to twice: Once to figure out what kind of node we need to make, and then if it's a string, we do so again after counters are resolved so we can get the true value of any `counter()` functions. This will need adjusting in the future but it works for now.
This commit is contained in:
parent
a6df9e1bac
commit
c1d4323cf7
Notes:
github-actions[bot]
2025-06-19 11:36:57 +00:00
Author: https://github.com/AtkinsSJ
Commit: c1d4323cf7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5132
Reviewed-by: https://github.com/tcl3
14 changed files with 247 additions and 60 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Checked.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <LibWeb/DOM/AbstractElement.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -22,7 +23,7 @@ using CounterValue = Checked<i32>;
|
|||
// https://drafts.csswg.org/css-lists-3/#counter
|
||||
struct Counter {
|
||||
FlyString name;
|
||||
UniqueNodeID originating_element_id; // "creator"
|
||||
DOM::AbstractElement originating_element; // "creator"
|
||||
bool reversed { false };
|
||||
Optional<CounterValue> value;
|
||||
};
|
||||
|
@ -33,17 +34,21 @@ public:
|
|||
CountersSet() = default;
|
||||
~CountersSet() = default;
|
||||
|
||||
Counter& instantiate_a_counter(FlyString name, UniqueNodeID originating_element_id, bool reversed, Optional<CounterValue>);
|
||||
void set_a_counter(FlyString name, UniqueNodeID originating_element_id, CounterValue value);
|
||||
void increment_a_counter(FlyString name, UniqueNodeID originating_element_id, CounterValue amount);
|
||||
Counter& instantiate_a_counter(FlyString name, DOM::AbstractElement const&, bool reversed, Optional<CounterValue>);
|
||||
void set_a_counter(FlyString name, DOM::AbstractElement const&, CounterValue value);
|
||||
void increment_a_counter(FlyString name, DOM::AbstractElement const&, CounterValue amount);
|
||||
void append_copy(Counter const&);
|
||||
|
||||
Optional<Counter&> last_counter_with_name(FlyString const& name);
|
||||
Optional<Counter&> counter_with_same_name_and_creator(FlyString const& name, UniqueNodeID originating_element_id);
|
||||
Optional<Counter&> counter_with_same_name_and_creator(FlyString const& name, DOM::AbstractElement const&);
|
||||
|
||||
Vector<Counter> const& counters() const { return m_counters; }
|
||||
bool is_empty() const { return m_counters.is_empty(); }
|
||||
|
||||
void visit_edges(GC::Cell::Visitor&);
|
||||
|
||||
String dump() const;
|
||||
|
||||
private:
|
||||
Vector<Counter> m_counters;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue