mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-11-03 23:00:58 +00:00 
			
		
		
		
	LibWeb/DOM: Rename ElementReference to AbstractElement
This isn't some kind of identifier, it's a handle on an actual Element or PseudoElement.
This commit is contained in:
		
							parent
							
								
									e7c2f0dd52
								
							
						
					
					
						commit
						ce380a59c7
					
				
				
				Notes:
				
					github-actions[bot]
				
				2025-06-19 11:37:42 +00:00 
				
			
			Author: https://github.com/AtkinsSJ
Commit: ce380a59c7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5132
Reviewed-by: https://github.com/tcl3
			
					 10 changed files with 73 additions and 23 deletions
				
			
		| 
						 | 
					@ -211,6 +211,7 @@ set(SOURCES
 | 
				
			||||||
    CSS/VisualViewport.cpp
 | 
					    CSS/VisualViewport.cpp
 | 
				
			||||||
    DOM/AbortController.cpp
 | 
					    DOM/AbortController.cpp
 | 
				
			||||||
    DOM/AbortSignal.cpp
 | 
					    DOM/AbortSignal.cpp
 | 
				
			||||||
 | 
					    DOM/AbstractElement.cpp
 | 
				
			||||||
    DOM/AbstractRange.cpp
 | 
					    DOM/AbstractRange.cpp
 | 
				
			||||||
    DOM/AccessibilityTreeNode.cpp
 | 
					    DOM/AccessibilityTreeNode.cpp
 | 
				
			||||||
    DOM/AdoptedStyleSheets.cpp
 | 
					    DOM/AdoptedStyleSheets.cpp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@
 | 
				
			||||||
#include <LibWeb/Bindings/PlatformObject.h>
 | 
					#include <LibWeb/Bindings/PlatformObject.h>
 | 
				
			||||||
#include <LibWeb/CSS/CSSStyleValue.h>
 | 
					#include <LibWeb/CSS/CSSStyleValue.h>
 | 
				
			||||||
#include <LibWeb/CSS/StyleProperty.h>
 | 
					#include <LibWeb/CSS/StyleProperty.h>
 | 
				
			||||||
#include <LibWeb/DOM/ElementReference.h>
 | 
					#include <LibWeb/DOM/AbstractElement.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Web::CSS {
 | 
					namespace Web::CSS {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,8 +50,8 @@ public:
 | 
				
			||||||
    void set_parent_rule(GC::Ptr<CSSRule> parent) { m_parent_rule = parent; }
 | 
					    void set_parent_rule(GC::Ptr<CSSRule> parent) { m_parent_rule = parent; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
 | 
					    // https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
 | 
				
			||||||
    Optional<DOM::ElementReference> owner_node() const { return m_owner_node; }
 | 
					    Optional<DOM::AbstractElement> owner_node() const { return m_owner_node; }
 | 
				
			||||||
    void set_owner_node(Optional<DOM::ElementReference> owner_node) { m_owner_node = move(owner_node); }
 | 
					    void set_owner_node(Optional<DOM::AbstractElement> owner_node) { m_owner_node = move(owner_node); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
 | 
					    // https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
 | 
				
			||||||
    [[nodiscard]] bool is_updating() const { return m_updating; }
 | 
					    [[nodiscard]] bool is_updating() const { return m_updating; }
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,7 @@ private:
 | 
				
			||||||
    GC::Ptr<CSSRule> m_parent_rule { nullptr };
 | 
					    GC::Ptr<CSSRule> m_parent_rule { nullptr };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
 | 
					    // https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
 | 
				
			||||||
    Optional<DOM::ElementReference> m_owner_node {};
 | 
					    Optional<DOM::AbstractElement> m_owner_node {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag
 | 
					    // https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag
 | 
				
			||||||
    bool m_computed { false };
 | 
					    bool m_computed { false };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ GC::Ref<CSSStyleProperties> CSSStyleProperties::create(JS::Realm& realm, Vector<
 | 
				
			||||||
    return realm.create<CSSStyleProperties>(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), OptionalNone {});
 | 
					    return realm.create<CSSStyleProperties>(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), OptionalNone {});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GC::Ref<CSSStyleProperties> CSSStyleProperties::create_resolved_style(JS::Realm& realm, Optional<DOM::ElementReference> element_reference)
 | 
					GC::Ref<CSSStyleProperties> CSSStyleProperties::create_resolved_style(JS::Realm& realm, Optional<DOM::AbstractElement> element_reference)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle
 | 
					    // https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle
 | 
				
			||||||
    // 6.  Return a live CSSStyleProperties object with the following properties:
 | 
					    // 6.  Return a live CSSStyleProperties object with the following properties:
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ GC::Ref<CSSStyleProperties> CSSStyleProperties::create_resolved_style(JS::Realm&
 | 
				
			||||||
    return realm.create<CSSStyleProperties>(realm, Computed::Yes, Readonly::Yes, Vector<StyleProperty> {}, HashMap<FlyString, StyleProperty> {}, move(element_reference));
 | 
					    return realm.create<CSSStyleProperties>(realm, Computed::Yes, Readonly::Yes, Vector<StyleProperty> {}, HashMap<FlyString, StyleProperty> {}, move(element_reference));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GC::Ref<CSSStyleProperties> CSSStyleProperties::create_element_inline_style(DOM::ElementReference element_reference, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
 | 
					GC::Ref<CSSStyleProperties> CSSStyleProperties::create_element_inline_style(DOM::AbstractElement element_reference, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // https://drafts.csswg.org/cssom/#dom-elementcssinlinestyle-style
 | 
					    // https://drafts.csswg.org/cssom/#dom-elementcssinlinestyle-style
 | 
				
			||||||
    // The style attribute must return a CSS declaration block object whose readonly flag is unset, whose parent CSS
 | 
					    // The style attribute must return a CSS declaration block object whose readonly flag is unset, whose parent CSS
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ GC::Ref<CSSStyleProperties> CSSStyleProperties::create_element_inline_style(DOM:
 | 
				
			||||||
    return realm.create<CSSStyleProperties>(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), move(element_reference));
 | 
					    return realm.create<CSSStyleProperties>(realm, Computed::No, Readonly::No, convert_declarations_to_specified_order(properties), move(custom_properties), move(element_reference));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CSSStyleProperties::CSSStyleProperties(JS::Realm& realm, Computed computed, Readonly readonly, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties, Optional<DOM::ElementReference> owner_node)
 | 
					CSSStyleProperties::CSSStyleProperties(JS::Realm& realm, Computed computed, Readonly readonly, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties, Optional<DOM::AbstractElement> owner_node)
 | 
				
			||||||
    : CSSStyleDeclaration(realm, computed, readonly)
 | 
					    : CSSStyleDeclaration(realm, computed, readonly)
 | 
				
			||||||
    , m_properties(move(properties))
 | 
					    , m_properties(move(properties))
 | 
				
			||||||
    , m_custom_properties(move(custom_properties))
 | 
					    , m_custom_properties(move(custom_properties))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,8 +22,8 @@ class CSSStyleProperties
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    [[nodiscard]] static GC::Ref<CSSStyleProperties> create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
 | 
					    [[nodiscard]] static GC::Ref<CSSStyleProperties> create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [[nodiscard]] static GC::Ref<CSSStyleProperties> create_resolved_style(JS::Realm&, Optional<DOM::ElementReference>);
 | 
					    [[nodiscard]] static GC::Ref<CSSStyleProperties> create_resolved_style(JS::Realm&, Optional<DOM::AbstractElement>);
 | 
				
			||||||
    [[nodiscard]] static GC::Ref<CSSStyleProperties> create_element_inline_style(DOM::ElementReference, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
 | 
					    [[nodiscard]] static GC::Ref<CSSStyleProperties> create_element_inline_style(DOM::AbstractElement, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual ~CSSStyleProperties() override = default;
 | 
					    virtual ~CSSStyleProperties() override = default;
 | 
				
			||||||
    virtual void initialize(JS::Realm&) override;
 | 
					    virtual void initialize(JS::Realm&) override;
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,7 @@ public:
 | 
				
			||||||
    virtual CSSStyleProperties& generated_style_properties_to_css_style_properties() override { return *this; }
 | 
					    virtual CSSStyleProperties& generated_style_properties_to_css_style_properties() override { return *this; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    CSSStyleProperties(JS::Realm&, Computed, Readonly, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties, Optional<DOM::ElementReference>);
 | 
					    CSSStyleProperties(JS::Realm&, Computed, Readonly, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties, Optional<DOM::AbstractElement>);
 | 
				
			||||||
    static Vector<StyleProperty> convert_declarations_to_specified_order(Vector<StyleProperty>&);
 | 
					    static Vector<StyleProperty> convert_declarations_to_specified_order(Vector<StyleProperty>&);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void visit_edges(Cell::Visitor&) override;
 | 
					    virtual void visit_edges(Cell::Visitor&) override;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										48
									
								
								Libraries/LibWeb/DOM/AbstractElement.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								Libraries/LibWeb/DOM/AbstractElement.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,48 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: BSD-2-Clause
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <LibWeb/DOM/AbstractElement.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Web::DOM {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AbstractElement::AbstractElement(GC::Ref<Element> element, Optional<CSS::PseudoElement> pseudo_element)
 | 
				
			||||||
 | 
					    : m_element(element)
 | 
				
			||||||
 | 
					    , m_pseudo_element(move(pseudo_element))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AbstractElement::visit(GC::Cell::Visitor& visitor) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    visitor.visit(m_element);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GC::Ptr<Element const> AbstractElement::parent_element() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_pseudo_element.has_value())
 | 
				
			||||||
 | 
					        return m_element;
 | 
				
			||||||
 | 
					    return m_element->parent_element();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GC::Ptr<CSS::ComputedProperties const> AbstractElement::computed_properties() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_pseudo_element.has_value())
 | 
				
			||||||
 | 
					        return m_element->pseudo_element_computed_properties(*m_pseudo_element);
 | 
				
			||||||
 | 
					    return m_element->computed_properties();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CSS::CountersSet& AbstractElement::ensure_counters_set()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // FIXME: Handle pseudo-elements
 | 
				
			||||||
 | 
					    return m_element->ensure_counters_set();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AbstractElement::set_counters_set(OwnPtr<CSS::CountersSet>&& counters_set)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // FIXME: Handle pseudo-elements
 | 
				
			||||||
 | 
					    m_element->set_counters_set(move(counters_set));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -12,22 +12,22 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Web::DOM {
 | 
					namespace Web::DOM {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ElementReference {
 | 
					// Either an Element or a PseudoElement
 | 
				
			||||||
 | 
					class AbstractElement {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    ElementReference(GC::Ref<Element> element, Optional<CSS::PseudoElement> pseudo_element = {})
 | 
					    AbstractElement(GC::Ref<Element>, Optional<CSS::PseudoElement> = {});
 | 
				
			||||||
        : m_element(element)
 | 
					 | 
				
			||||||
        , m_pseudo_element(move(pseudo_element))
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Element& element() { return m_element; }
 | 
					    Element& element() { return m_element; }
 | 
				
			||||||
    Element const& element() const { return m_element; }
 | 
					    Element const& element() const { return m_element; }
 | 
				
			||||||
    Optional<CSS::PseudoElement> pseudo_element() const { return m_pseudo_element; }
 | 
					    Optional<CSS::PseudoElement> pseudo_element() const { return m_pseudo_element; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void visit(GC::Cell::Visitor& visitor) const
 | 
					    GC::Ptr<Element const> parent_element() const;
 | 
				
			||||||
    {
 | 
					    GC::Ptr<CSS::ComputedProperties const> computed_properties() const;
 | 
				
			||||||
        visitor.visit(m_element);
 | 
					
 | 
				
			||||||
    }
 | 
					    CSS::CountersSet& ensure_counters_set();
 | 
				
			||||||
 | 
					    void set_counters_set(OwnPtr<CSS::CountersSet>&&);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void visit(GC::Cell::Visitor& visitor) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    GC::Ref<Element> m_element;
 | 
					    GC::Ref<Element> m_element;
 | 
				
			||||||
| 
						 | 
					@ -832,7 +832,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GC::Ref<CSS::ComputedProperties> Element::resolved_css_values(Optional<CSS::PseudoElement> type)
 | 
					GC::Ref<CSS::ComputedProperties> Element::resolved_css_values(Optional<CSS::PseudoElement> type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    auto element_computed_style = CSS::CSSStyleProperties::create_resolved_style(realm(), ElementReference { *this, type });
 | 
					    auto element_computed_style = CSS::CSSStyleProperties::create_resolved_style(realm(), AbstractElement { *this, type });
 | 
				
			||||||
    auto properties = heap().allocate<CSS::ComputedProperties>();
 | 
					    auto properties = heap().allocate<CSS::ComputedProperties>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
 | 
					    for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4741,7 +4741,7 @@ Optional<NonnullRefPtr<CSS::CSSStyleValue const>> resolved_value(GC::Ref<DOM::No
 | 
				
			||||||
        return {};
 | 
					        return {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Retrieve resolved style value
 | 
					    // Retrieve resolved style value
 | 
				
			||||||
    auto resolved_css_style_declaration = CSS::CSSStyleProperties::create_resolved_style(element->realm(), DOM::ElementReference { static_cast<DOM::Element&>(*element) });
 | 
					    auto resolved_css_style_declaration = CSS::CSSStyleProperties::create_resolved_style(element->realm(), DOM::AbstractElement { static_cast<DOM::Element&>(*element) });
 | 
				
			||||||
    auto optional_style_property = resolved_css_style_declaration->property(property_id);
 | 
					    auto optional_style_property = resolved_css_style_declaration->property(property_id);
 | 
				
			||||||
    if (!optional_style_property.has_value())
 | 
					    if (!optional_style_property.has_value())
 | 
				
			||||||
        return {};
 | 
					        return {};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -339,6 +339,7 @@ namespace Web::DOM {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AbortController;
 | 
					class AbortController;
 | 
				
			||||||
class AbortSignal;
 | 
					class AbortSignal;
 | 
				
			||||||
 | 
					class AbstractElement;
 | 
				
			||||||
class AbstractRange;
 | 
					class AbstractRange;
 | 
				
			||||||
class AccessibilityTreeNode;
 | 
					class AccessibilityTreeNode;
 | 
				
			||||||
class Attr;
 | 
					class Attr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1278,7 +1278,7 @@ GC::Ref<CSS::CSSStyleDeclaration> Window::get_computed_style(DOM::Element& eleme
 | 
				
			||||||
    // 1. Let doc be elt’s node document.
 | 
					    // 1. Let doc be elt’s node document.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 2. Let obj be elt.
 | 
					    // 2. Let obj be elt.
 | 
				
			||||||
    Optional<DOM::ElementReference> object { element };
 | 
					    Optional<DOM::AbstractElement> object { element };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 3. If pseudoElt is provided, is not the empty string, and starts with a colon, then:
 | 
					    // 3. If pseudoElt is provided, is not the empty string, and starts with a colon, then:
 | 
				
			||||||
    if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) {
 | 
					    if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue