/* * Copyright (c) 2018-2023, Andreas Kling * Copyright (c) 2024-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::CSS { // https://drafts.csswg.org/cssom/#cssstyleproperties class CSSStyleProperties : public CSSStyleDeclaration , public Bindings::GeneratedCSSStyleProperties { WEB_PLATFORM_OBJECT(CSSStyleProperties, CSSStyleDeclaration); GC_DECLARE_ALLOCATOR(CSSStyleProperties); public: [[nodiscard]] static GC::Ref create(JS::Realm&, Vector, HashMap custom_properties); [[nodiscard]] static GC::Ref create_resolved_style(DOM::ElementReference); [[nodiscard]] static GC::Ref create_element_inline_style(DOM::ElementReference, Vector, HashMap custom_properties); virtual ~CSSStyleProperties() override = default; virtual void initialize(JS::Realm&) override; virtual size_t length() const override; virtual String item(size_t index) const override; Optional property(PropertyID) const; Optional custom_property(FlyString const& custom_property_name) const; WebIDL::ExceptionOr set_property(PropertyID, StringView css_text, StringView priority = ""sv); WebIDL::ExceptionOr remove_property(PropertyID); virtual WebIDL::ExceptionOr set_property(StringView property_name, StringView css_text, StringView priority) override; virtual WebIDL::ExceptionOr remove_property(StringView property_name) override; virtual String get_property_value(StringView property_name) const override; virtual StringView get_property_priority(StringView property_name) const override; Vector const& properties() const { return m_properties; } HashMap const& custom_properties() const { return m_custom_properties; } size_t custom_property_count() const { return m_custom_properties.size(); } String css_float() const; WebIDL::ExceptionOr set_css_float(StringView); virtual String serialized() const final override; virtual WebIDL::ExceptionOr set_css_text(StringView) override; void set_declarations_from_text(StringView); // ^Bindings::GeneratedCSSStyleProperties virtual CSSStyleProperties& generated_style_properties_to_css_style_properties() override { return *this; } private: CSSStyleProperties(JS::Realm&, Computed, Readonly, Vector properties, HashMap custom_properties, Optional); virtual void visit_edges(Cell::Visitor&) override; RefPtr style_value_for_computed_property(Layout::NodeWithStyle const&, PropertyID) const; Optional get_property_internal(PropertyID) const; bool set_a_css_declaration(PropertyID, NonnullRefPtr, Important); void empty_the_declarations(); void set_the_declarations(Vector properties, HashMap custom_properties); Vector m_properties; HashMap m_custom_properties; }; }