mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 23:59:49 +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
|
@ -1,15 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
||||
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "CounterStyleValue.h"
|
||||
#include <LibWeb/CSS/CountersSet.h>
|
||||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/Keyword.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/CounterStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
|
@ -94,13 +95,13 @@ static String generate_a_counter_representation(CSSStyleValue const& counter_sty
|
|||
return MUST(String::formatted("{}", value));
|
||||
}
|
||||
|
||||
String CounterStyleValue::resolve(DOM::Element& element) const
|
||||
String CounterStyleValue::resolve(DOM::AbstractElement& element_reference) const
|
||||
{
|
||||
// "If no counter named <counter-name> exists on an element where counter() or counters() is used,
|
||||
// one is first instantiated with a starting value of 0."
|
||||
auto& counters_set = element.ensure_counters_set();
|
||||
auto& counters_set = element_reference.ensure_counters_set();
|
||||
if (!counters_set.last_counter_with_name(m_properties.counter_name).has_value())
|
||||
counters_set.instantiate_a_counter(m_properties.counter_name, element.unique_id(), false, 0);
|
||||
counters_set.instantiate_a_counter(m_properties.counter_name, element_reference, false, 0);
|
||||
|
||||
// counter( <counter-name>, <counter-style>? )
|
||||
// "Represents the value of the innermost counter in the element’s CSS counters set named <counter-name>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue