mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-01 14:42:05 +00:00
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.
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGC/Cell.h>
|
|
#include <LibWeb/CSS/Selector.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::DOM {
|
|
|
|
// Either an Element or a PseudoElement
|
|
class AbstractElement {
|
|
public:
|
|
AbstractElement(GC::Ref<Element>, Optional<CSS::PseudoElement> = {});
|
|
|
|
Element& element() { return m_element; }
|
|
Element const& element() const { return m_element; }
|
|
Optional<CSS::PseudoElement> pseudo_element() const { return m_pseudo_element; }
|
|
|
|
GC::Ptr<Layout::NodeWithStyle> layout_node();
|
|
GC::Ptr<Layout::NodeWithStyle const> layout_node() const { return const_cast<AbstractElement*>(this)->layout_node(); }
|
|
|
|
GC::Ptr<Element const> parent_element() const;
|
|
Optional<AbstractElement> previous_in_tree_order() { return walk_layout_tree(WalkMethod::Previous); }
|
|
Optional<AbstractElement> previous_sibling_in_tree_order() { return walk_layout_tree(WalkMethod::PreviousSibling); }
|
|
bool is_before(AbstractElement const&) const;
|
|
|
|
GC::Ptr<CSS::ComputedProperties const> computed_properties() const;
|
|
|
|
bool has_non_empty_counters_set() const;
|
|
Optional<CSS::CountersSet const&> counters_set() const;
|
|
CSS::CountersSet& ensure_counters_set();
|
|
void set_counters_set(OwnPtr<CSS::CountersSet>&&);
|
|
|
|
void visit(GC::Cell::Visitor& visitor) const;
|
|
|
|
String debug_description() const;
|
|
bool operator==(AbstractElement const&) const = default;
|
|
|
|
private:
|
|
enum class WalkMethod : u8 {
|
|
Previous,
|
|
PreviousSibling,
|
|
};
|
|
Optional<AbstractElement> walk_layout_tree(WalkMethod);
|
|
|
|
GC::Ref<Element> m_element;
|
|
Optional<CSS::PseudoElement> m_pseudo_element;
|
|
};
|
|
|
|
}
|