2020-06-04 16:06:32 +02:00
|
|
|
/*
|
2024-08-20 14:55:28 +02:00
|
|
|
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
2023-02-28 00:05:39 +00:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2025-04-14 13:53:11 +01:00
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
2020-06-04 16:06:32 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-04 16:06:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-01-09 16:05:03 -07:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-03-08 11:22:18 +01:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.h>
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2020-07-21 16:23:08 +02:00
|
|
|
namespace Web::CSS {
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
class WEB_API StyleSheetList final : public Bindings::PlatformObject {
|
2024-01-09 16:05:03 -07:00
|
|
|
WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(StyleSheetList);
|
2021-03-08 11:22:18 +01:00
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<StyleSheetList> create(GC::Ref<DOM::Node> document_or_shadow_root);
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2025-04-14 13:53:11 +01:00
|
|
|
void add_a_css_style_sheet(CSSStyleSheet&);
|
|
|
|
void remove_a_css_style_sheet(CSSStyleSheet&);
|
|
|
|
enum class Alternate : u8 {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
enum class OriginClean : u8 {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
2025-04-14 14:04:36 +01:00
|
|
|
GC::Ref<CSSStyleSheet> create_a_css_style_sheet(String const& css_text, String type, DOM::Element* owner_node, String media, String title, Alternate, OriginClean, Optional<::URL::URL> location, CSSStyleSheet* parent_style_sheet, CSSRule* owner_rule);
|
2021-09-29 23:46:16 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Ref<CSSStyleSheet>> const& sheets() const { return m_sheets; }
|
|
|
|
Vector<GC::Ref<CSSStyleSheet>>& sheets() { return m_sheets; }
|
2021-03-08 11:22:18 +01:00
|
|
|
|
2022-08-07 13:14:54 +02:00
|
|
|
CSSStyleSheet* item(size_t index) const
|
2021-03-08 11:22:18 +01:00
|
|
|
{
|
|
|
|
if (index >= m_sheets.size())
|
|
|
|
return {};
|
2022-09-09 11:08:56 +02:00
|
|
|
return const_cast<CSSStyleSheet*>(m_sheets[index].ptr());
|
2021-03-08 11:22:18 +01:00
|
|
|
}
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2021-03-08 11:22:18 +01:00
|
|
|
size_t length() const { return m_sheets.size(); }
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2024-07-25 18:15:51 +12:00
|
|
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
2021-09-29 13:03:09 +01:00
|
|
|
|
2024-08-20 14:55:28 +02:00
|
|
|
[[nodiscard]] DOM::Document& document();
|
|
|
|
[[nodiscard]] DOM::Document const& document() const;
|
|
|
|
|
|
|
|
[[nodiscard]] DOM::Node& document_or_shadow_root() { return m_document_or_shadow_root; }
|
|
|
|
[[nodiscard]] DOM::Node const& document_or_shadow_root() const { return m_document_or_shadow_root; }
|
2022-03-09 19:57:15 +01:00
|
|
|
|
2020-06-04 16:06:32 +02:00
|
|
|
private:
|
2024-11-15 04:01:23 +13:00
|
|
|
explicit StyleSheetList(GC::Ref<DOM::Node> document_or_shadow_root);
|
2022-08-28 13:42:07 +02:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-07 13:29:49 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2024-04-15 21:42:46 +01:00
|
|
|
void add_sheet(CSSStyleSheet&);
|
|
|
|
void remove_sheet(CSSStyleSheet&);
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<DOM::Node> m_document_or_shadow_root;
|
|
|
|
Vector<GC::Ref<CSSStyleSheet>> m_sheets;
|
2024-04-16 22:59:40 +01:00
|
|
|
|
|
|
|
// https://www.w3.org/TR/cssom/#preferred-css-style-sheet-set-name
|
|
|
|
String m_preferred_css_style_sheet_set_name;
|
|
|
|
// https://www.w3.org/TR/cssom/#last-css-style-sheet-set-name
|
|
|
|
Optional<String> m_last_css_style_sheet_set_name;
|
2020-06-04 16:06:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|