2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2023-02-20 14:56:08 -03:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-20 18:25:25 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2020-02-14 17:41:10 -03:00
|
|
|
#include <AK/Vector.h>
|
2022-08-07 11:21:26 -03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/CSS/StyleValue.h>
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2020-07-26 15:01:35 -03:00
|
|
|
namespace Web::CSS {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2022-02-12 11:53:59 -03:00
|
|
|
enum class Important {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-30 15:06:17 -03:00
|
|
|
struct StyleProperty {
|
2022-02-12 11:53:59 -03:00
|
|
|
Important important { Important::No };
|
2019-10-08 10:34:19 -03:00
|
|
|
CSS::PropertyID property_id;
|
2023-02-20 14:56:08 -03:00
|
|
|
NonnullRefPtr<StyleValue const> value;
|
2022-12-04 15:02:33 -03:00
|
|
|
DeprecatedString custom_name {};
|
2019-09-30 15:06:17 -03:00
|
|
|
};
|
|
|
|
|
|
2022-08-07 11:21:26 -03:00
|
|
|
class CSSStyleDeclaration : public Bindings::PlatformObject {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject);
|
2021-03-13 18:39:55 -03:00
|
|
|
|
2022-08-07 11:21:26 -03:00
|
|
|
public:
|
2022-03-14 16:21:51 -03:00
|
|
|
virtual ~CSSStyleDeclaration() = default;
|
2021-09-12 14:24:01 -03:00
|
|
|
|
|
|
|
|
virtual size_t length() const = 0;
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual DeprecatedString item(size_t index) const = 0;
|
2021-09-12 14:24:01 -03:00
|
|
|
|
|
|
|
|
virtual Optional<StyleProperty> property(PropertyID) const = 0;
|
|
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority = ""sv) = 0;
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual WebIDL::ExceptionOr<DeprecatedString> remove_property(PropertyID) = 0;
|
2022-04-11 11:10:55 -03:00
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
WebIDL::ExceptionOr<void> set_property(StringView property_name, StringView css_text, StringView priority);
|
2022-12-04 15:02:33 -03:00
|
|
|
WebIDL::ExceptionOr<DeprecatedString> remove_property(StringView property_name);
|
2021-09-26 14:06:17 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
DeprecatedString get_property_value(StringView property) const;
|
|
|
|
|
DeprecatedString get_property_priority(StringView property) const;
|
2021-09-12 15:44:17 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
DeprecatedString css_text() const;
|
2022-11-05 01:51:05 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) = 0;
|
2021-10-01 14:57:45 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual DeprecatedString serialized() const = 0;
|
2021-10-01 14:57:45 -03:00
|
|
|
|
2022-08-07 11:21:26 -03:00
|
|
|
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override;
|
|
|
|
|
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver) const override;
|
|
|
|
|
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
|
|
|
|
|
|
2021-09-12 14:24:01 -03:00
|
|
|
protected:
|
2022-09-24 19:34:04 -03:00
|
|
|
explicit CSSStyleDeclaration(JS::Realm&);
|
2021-09-12 14:24:01 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration);
|
2021-09-12 14:24:01 -03:00
|
|
|
friend class ElementInlineCSSStyleDeclaration;
|
|
|
|
|
|
|
|
|
|
public:
|
2023-02-12 19:22:53 -03:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration>> create(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
2019-06-21 14:19:49 -03:00
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
virtual ~PropertyOwningCSSStyleDeclaration() override = default;
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2021-09-12 14:24:01 -03:00
|
|
|
virtual size_t length() const override;
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual DeprecatedString item(size_t index) const override;
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2021-09-12 14:24:01 -03:00
|
|
|
virtual Optional<StyleProperty> property(PropertyID) const override;
|
2022-04-11 11:10:55 -03:00
|
|
|
|
2022-09-25 13:03:42 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority) override;
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual WebIDL::ExceptionOr<DeprecatedString> remove_property(PropertyID) override;
|
2021-09-12 14:24:01 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
Vector<StyleProperty> const& properties() const { return m_properties; }
|
2022-12-04 15:02:33 -03:00
|
|
|
HashMap<DeprecatedString, StyleProperty> const& custom_properties() const { return m_custom_properties; }
|
|
|
|
|
Optional<StyleProperty> custom_property(DeprecatedString const& custom_property_name) const { return m_custom_properties.get(custom_property_name); }
|
2021-09-12 14:24:01 -03:00
|
|
|
size_t custom_property_count() const { return m_custom_properties.size(); }
|
2021-03-13 18:39:55 -03:00
|
|
|
|
2022-12-04 15:02:33 -03:00
|
|
|
virtual DeprecatedString serialized() const final override;
|
2022-11-05 01:51:05 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
2021-10-01 14:57:45 -03:00
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
protected:
|
2022-12-04 15:02:33 -03:00
|
|
|
PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty>);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2022-04-11 11:10:55 -03:00
|
|
|
virtual void update_style_attribute() { }
|
|
|
|
|
|
2022-11-05 01:51:05 -03:00
|
|
|
void empty_the_declarations();
|
2022-12-04 15:02:33 -03:00
|
|
|
void set_the_declarations(Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
2022-11-05 01:51:05 -03:00
|
|
|
|
2020-05-19 13:28:16 -03:00
|
|
|
private:
|
2023-02-20 14:56:08 -03:00
|
|
|
bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue const>, Important);
|
2022-04-11 11:10:55 -03:00
|
|
|
|
2019-09-30 15:06:17 -03:00
|
|
|
Vector<StyleProperty> m_properties;
|
2022-12-04 15:02:33 -03:00
|
|
|
HashMap<DeprecatedString, StyleProperty> m_custom_properties;
|
2019-06-20 18:25:25 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2021-09-12 14:24:01 -03:00
|
|
|
class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration);
|
2022-08-07 11:21:26 -03:00
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
public:
|
2023-02-12 19:22:53 -03:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration>> create(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
2022-08-07 11:21:26 -03:00
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
virtual ~ElementInlineCSSStyleDeclaration() override = default;
|
2021-03-16 14:55:53 -03:00
|
|
|
|
|
|
|
|
DOM::Element* element() { return m_element.ptr(); }
|
|
|
|
|
const DOM::Element* element() const { return m_element.ptr(); }
|
|
|
|
|
|
2022-04-11 11:56:52 -03:00
|
|
|
bool is_updating() const { return m_updating; }
|
|
|
|
|
|
2022-11-05 01:51:05 -03:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
|
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
private:
|
2022-12-04 15:02:33 -03:00
|
|
|
ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
2022-04-11 11:10:55 -03:00
|
|
|
virtual void update_style_attribute() override;
|
|
|
|
|
|
2022-08-28 08:42:07 -03:00
|
|
|
JS::GCPtr<DOM::Element> m_element;
|
2022-04-11 11:56:52 -03:00
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
|
|
|
|
|
bool m_updating { false };
|
2021-03-16 14:55:53 -03:00
|
|
|
};
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|