ladybird/Libraries/LibWeb/DOM/PseudoElement.cpp
Sam Atkins c1d4323cf7 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.
2025-06-19 12:35:31 +01:00

47 lines
1.1 KiB
C++

/*
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/CascadedProperties.h>
#include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/DOM/PseudoElement.h>
#include <LibWeb/Layout/Node.h>
namespace Web::DOM {
GC_DEFINE_ALLOCATOR(PseudoElement);
GC_DEFINE_ALLOCATOR(PseudoElementTreeNode);
void PseudoElement::visit_edges(JS::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_cascaded_properties);
visitor.visit(m_computed_properties);
visitor.visit(m_layout_node);
if (m_counters_set)
m_counters_set->visit_edges(visitor);
}
Optional<CSS::CountersSet const&> PseudoElement::counters_set() const
{
if (!m_counters_set)
return {};
return *m_counters_set;
}
CSS::CountersSet& PseudoElement::ensure_counters_set()
{
if (!m_counters_set)
m_counters_set = make<CSS::CountersSet>();
return *m_counters_set;
}
void PseudoElement::set_counters_set(OwnPtr<CSS::CountersSet>&& counters_set)
{
m_counters_set = move(counters_set);
}
}