Serenity Operating System
1/*
2 * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <LibWeb/Bindings/LegacyPlatformObject.h>
11#include <LibWeb/CSS/CSSStyleSheet.h>
12
13namespace Web::CSS {
14
15class StyleSheetList : public Bindings::LegacyPlatformObject {
16 WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::LegacyPlatformObject);
17
18public:
19 static WebIDL::ExceptionOr<JS::NonnullGCPtr<StyleSheetList>> create(DOM::Document& document);
20
21 void add_sheet(CSSStyleSheet&);
22 void remove_sheet(CSSStyleSheet&);
23
24 Vector<JS::NonnullGCPtr<CSSStyleSheet>> const& sheets() const { return m_sheets; }
25 Vector<JS::NonnullGCPtr<CSSStyleSheet>>& sheets() { return m_sheets; }
26
27 CSSStyleSheet* item(size_t index) const
28 {
29 if (index >= m_sheets.size())
30 return {};
31 return const_cast<CSSStyleSheet*>(m_sheets[index].ptr());
32 }
33
34 size_t length() const { return m_sheets.size(); }
35
36 virtual bool is_supported_property_index(u32 index) const override;
37 virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
38
39 DOM::Document& document() { return m_document; }
40 DOM::Document const& document() const { return m_document; }
41
42private:
43 explicit StyleSheetList(DOM::Document&);
44
45 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
46 virtual void visit_edges(Cell::Visitor&) override;
47
48 // ^Bindings::LegacyPlatformObject
49 virtual bool supports_indexed_properties() const override { return true; }
50 virtual bool supports_named_properties() const override { return false; }
51 virtual bool has_indexed_property_setter() const override { return false; }
52 virtual bool has_named_property_setter() const override { return false; }
53 virtual bool has_named_property_deleter() const override { return false; }
54 virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
55 virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
56 virtual bool has_global_interface_extended_attribute() const override { return false; }
57 virtual bool indexed_property_setter_has_identifier() const override { return false; }
58 virtual bool named_property_setter_has_identifier() const override { return false; }
59 virtual bool named_property_deleter_has_identifier() const override { return false; }
60
61 void sort_sheets();
62
63 DOM::Document& m_document;
64 Vector<JS::NonnullGCPtr<CSSStyleSheet>> m_sheets;
65};
66
67}