Skip to content

Truly independent web browser

2.0 KB
Raw Blame
/*
 * Copyright (c) 2026, Callum Law <[email protected]>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibWeb/CSS/CustomPropertyData.h>
#include <LibWeb/CSS/CustomPropertyRegistration.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>

namespace Web::CSS {

struct HypotheticalElement;

class AbstractOrHypotheticalElement : public Variant<DOM::AbstractElement, HypotheticalElement*> {
public:
    AbstractOrHypotheticalElement(DOM::AbstractElement abstract_element)
        : Variant<DOM::AbstractElement, HypotheticalElement*>(abstract_element)
    {
    }

    explicit AbstractOrHypotheticalElement(HypotheticalElement& hypothetical_element)
        : Variant<DOM::AbstractElement, HypotheticalElement*>(&hypothetical_element)
    {
    }

    DOM::AbstractElement& abstract_element();
    DOM::AbstractElement const& abstract_element() const;

    DOM::Document const& document() const;

    Optional<AbstractOrHypotheticalElement> element_to_inherit_style_from() const;

    Optional<CustomPropertyRegistration const&> get_registered_custom_property(Utf16FlyString const& name) const;
    RefPtr<StyleValue const> get_custom_property(Utf16FlyString const& name) const;
    RefPtr<CustomPropertyData const> inheritable_custom_property_data(Layout::BegunRead const& read) const;
    RefPtr<CustomPropertyData const> custom_property_data() const;
    StyleScope const& style_scope() const;
};

// https://drafts.csswg.org/css-mixins/#using-custom-functions
struct HypotheticalElement {
    // NB: While this isn't technically part of the hypothetical element it shares the same scope and is needed to
    //     compute custom properties, so we store it here for convenience.
    HashMap<Utf16FlyString, CustomPropertyRegistration> custom_property_registry;
    StyleScope const& style_scope;

    GC::Ref<CSSFunctionRule const> custom_function;
    DOM::AbstractElement root_element;
    AbstractOrHypotheticalElement parent;
    NonnullRefPtr<CustomPropertyData> custom_property_data;
};

}