2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
2025-03-18 15:05:42 +00:00
|
|
|
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-20 23:25:25 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-11-21 10:39:54 +13:00
|
|
|
#include <AK/String.h>
|
2022-08-07 16:21:26 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2023-05-08 06:57:55 +02:00
|
|
|
#include <LibWeb/CSS/StyleProperty.h>
|
2025-08-08 10:11:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2025-06-18 10:19:56 +01:00
|
|
|
#include <LibWeb/DOM/AbstractElement.h>
|
2025-10-02 13:42:02 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2019-06-20 23:25:25 +02:00
|
|
|
|
2020-07-26 20:01:35 +02:00
|
|
|
namespace Web::CSS {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2025-03-18 15:05:42 +00:00
|
|
|
// https://drafts.csswg.org/cssom/#css-declaration-blocks
|
2024-11-14 16:57:14 +00:00
|
|
|
class CSSStyleDeclaration
|
2025-03-18 14:07:08 +00:00
|
|
|
: public Bindings::PlatformObject {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(CSSStyleDeclaration);
|
2021-03-13 22:39:55 +01:00
|
|
|
|
2022-08-07 16:21:26 +02:00
|
|
|
public:
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~CSSStyleDeclaration() = default;
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2021-09-12 19:24:01 +02:00
|
|
|
|
|
|
|
virtual size_t length() const = 0;
|
2023-09-06 19:07:24 +12:00
|
|
|
virtual String item(size_t index) const = 0;
|
2021-09-12 19:24:01 +02:00
|
|
|
|
2025-09-25 12:43:52 +01:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_property(FlyString const& property_name, StringView css_text, StringView priority) = 0;
|
|
|
|
virtual WebIDL::ExceptionOr<String> remove_property(FlyString const& property_name) = 0;
|
2021-09-26 19:06:17 +02:00
|
|
|
|
2025-09-25 12:43:52 +01:00
|
|
|
virtual String get_property_value(FlyString const& property_name) const = 0;
|
|
|
|
virtual StringView get_property_priority(FlyString const& property_name) const = 0;
|
2021-09-12 20:44:17 +02:00
|
|
|
|
2023-11-21 10:39:54 +13:00
|
|
|
String css_text() const;
|
2022-11-05 04:51:05 +00:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) = 0;
|
2021-10-01 19:57:45 +02:00
|
|
|
|
2024-11-14 16:57:14 +00:00
|
|
|
virtual String serialized() const = 0;
|
2022-08-07 16:21:26 +02:00
|
|
|
|
2024-12-07 01:10:11 +01:00
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag
|
2025-03-18 15:05:42 +00:00
|
|
|
[[nodiscard]] bool is_computed() const { return m_computed; }
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-readonly-flag
|
|
|
|
[[nodiscard]] bool is_readonly() const { return m_readonly; }
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-parent-css-rule
|
|
|
|
GC::Ptr<CSSRule> parent_rule() const { return m_parent_rule; }
|
|
|
|
void set_parent_rule(GC::Ptr<CSSRule> parent) { m_parent_rule = parent; }
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
|
2025-06-18 10:19:56 +01:00
|
|
|
Optional<DOM::AbstractElement> owner_node() const { return m_owner_node; }
|
|
|
|
void set_owner_node(Optional<DOM::AbstractElement> owner_node) { m_owner_node = move(owner_node); }
|
2025-03-18 15:05:42 +00:00
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
|
|
|
|
[[nodiscard]] bool is_updating() const { return m_updating; }
|
|
|
|
void set_is_updating(bool value) { m_updating = value; }
|
2024-12-07 01:10:11 +01:00
|
|
|
|
2025-09-26 12:08:54 +01:00
|
|
|
virtual bool has_property(PropertyNameAndID const&) const { VERIFY_NOT_REACHED(); }
|
|
|
|
virtual RefPtr<StyleValue const> get_property_style_value(PropertyNameAndID const&) const { VERIFY_NOT_REACHED(); }
|
2025-10-02 13:42:02 +01:00
|
|
|
virtual WebIDL::ExceptionOr<void> set_property_style_value(PropertyNameAndID const&, NonnullRefPtr<StyleValue const>) { VERIFY_NOT_REACHED(); }
|
2025-08-13 13:07:28 +01:00
|
|
|
|
2021-09-12 19:24:01 +02:00
|
|
|
protected:
|
2025-03-18 15:05:42 +00:00
|
|
|
enum class Computed : u8 {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
enum class Readonly : u8 {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
explicit CSSStyleDeclaration(JS::Realm&, Computed, Readonly);
|
|
|
|
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
2024-11-14 16:57:14 +00:00
|
|
|
|
2025-03-17 13:04:41 +00:00
|
|
|
void update_style_attribute();
|
|
|
|
|
2024-11-14 16:57:14 +00:00
|
|
|
private:
|
|
|
|
// ^PlatformObject
|
|
|
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
2025-03-18 15:05:42 +00:00
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-parent-css-rule
|
|
|
|
GC::Ptr<CSSRule> m_parent_rule { nullptr };
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-owner-node
|
2025-06-18 10:19:56 +01:00
|
|
|
Optional<DOM::AbstractElement> m_owner_node {};
|
2025-03-18 15:05:42 +00:00
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag
|
|
|
|
bool m_computed { false };
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-readonly-flag
|
|
|
|
bool m_readonly { false };
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyledeclaration-updating-flag
|
|
|
|
bool m_updating { false };
|
2021-09-12 19:24:01 +02:00
|
|
|
};
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|