2020-06-04 11:06:32 -03:00
|
|
|
/*
|
2024-08-20 09:55:28 -03:00
|
|
|
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
2023-02-27 21:05:39 -03:00
|
|
|
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
2025-04-14 09:53:11 -03:00
|
|
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
2020-06-04 11:06:32 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-04 11:06:32 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-01-09 20:05:03 -03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-03-08 07:22:18 -03:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2020-07-21 11:23:08 -03:00
|
|
|
namespace Web::CSS {
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API StyleSheetList final : public Bindings::PlatformObject {
|
2024-01-09 20:05:03 -03:00
|
|
|
WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::PlatformObject);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(StyleSheetList);
|
2021-03-08 07:22:18 -03:00
|
|
|
|
2022-08-07 08:29:49 -03:00
|
|
|
public:
|
2024-11-14 12:01:23 -03:00
|
|
|
[[nodiscard]] static GC::Ref<StyleSheetList> create(GC::Ref<DOM::Node> document_or_shadow_root);
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2025-04-14 09:53:11 -03: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 10:04:36 -03: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 18:46:16 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
Vector<GC::Ref<CSSStyleSheet>> const& sheets() const { return m_sheets; }
|
|
|
|
|
Vector<GC::Ref<CSSStyleSheet>>& sheets() { return m_sheets; }
|
2021-03-08 07:22:18 -03:00
|
|
|
|
2022-08-07 08:14:54 -03:00
|
|
|
CSSStyleSheet* item(size_t index) const
|
2021-03-08 07:22:18 -03:00
|
|
|
{
|
|
|
|
|
if (index >= m_sheets.size())
|
|
|
|
|
return {};
|
2022-09-09 06:08:56 -03:00
|
|
|
return const_cast<CSSStyleSheet*>(m_sheets[index].ptr());
|
2021-03-08 07:22:18 -03:00
|
|
|
}
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2021-03-08 07:22:18 -03:00
|
|
|
size_t length() const { return m_sheets.size(); }
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2024-07-25 03:15:51 -03:00
|
|
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
2021-09-29 09:03:09 -03:00
|
|
|
|
2024-08-20 09:55:28 -03: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 15:57:15 -03:00
|
|
|
|
2020-06-04 11:06:32 -03:00
|
|
|
private:
|
2024-11-14 12:01:23 -03:00
|
|
|
explicit StyleSheetList(GC::Ref<DOM::Node> document_or_shadow_root);
|
2022-08-28 08:42:07 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-07 08:29:49 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2020-06-04 11:06:32 -03:00
|
|
|
|
2024-04-15 17:42:46 -03:00
|
|
|
void add_sheet(CSSStyleSheet&);
|
|
|
|
|
void remove_sheet(CSSStyleSheet&);
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<DOM::Node> m_document_or_shadow_root;
|
|
|
|
|
Vector<GC::Ref<CSSStyleSheet>> m_sheets;
|
2024-04-16 18:59:40 -03: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 11:06:32 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|