/* * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::CSS { struct StyleProperty { CSS::PropertyID property_id; NonnullRefPtr value; String custom_name {}; bool important { false }; }; class CSSStyleDeclaration : public RefCounted , public Bindings::Wrappable { public: using WrapperType = Bindings::CSSStyleDeclarationWrapper; static NonnullRefPtr create(Vector&& properties, HashMap&& custom_properties) { return adopt_ref(*new CSSStyleDeclaration(move(properties), move(custom_properties))); } virtual ~CSSStyleDeclaration(); const Vector& properties() const { return m_properties; } const Optional custom_property(const String& custom_property_name) const { return m_custom_properties.get(custom_property_name); } size_t custom_property_count() const { return m_custom_properties.size(); }; size_t length() const { return m_properties.size(); } String item(size_t index) const; protected: explicit CSSStyleDeclaration(Vector&&, HashMap&&); private: friend class Bindings::CSSStyleDeclarationWrapper; Vector m_properties; HashMap m_custom_properties; }; class ElementInlineCSSStyleDeclaration final : public CSSStyleDeclaration { public: static NonnullRefPtr create(DOM::Element& element) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element)); } virtual ~ElementInlineCSSStyleDeclaration() override; DOM::Element* element() { return m_element.ptr(); } const DOM::Element* element() const { return m_element.ptr(); } private: explicit ElementInlineCSSStyleDeclaration(DOM::Element&); WeakPtr m_element; }; } namespace Web::Bindings { CSSStyleDeclarationWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleDeclaration&); }