2020-06-04 16:06:32 +02:00
|
|
|
/*
|
2022-08-07 13:29:49 +02:00
|
|
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.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
|
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
#include <LibWeb/Bindings/LegacyPlatformObject.h>
|
2021-03-08 11:22:18 +01:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.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
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
class StyleSheetList : public Bindings::LegacyPlatformObject {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(StyleSheetList, Bindings::LegacyPlatformObject);
|
2021-03-08 11:22:18 +01:00
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
public:
|
|
|
|
static StyleSheetList* create(DOM::Document& document);
|
2020-06-04 16:06:32 +02:00
|
|
|
|
2022-08-07 13:14:54 +02:00
|
|
|
void add_sheet(CSSStyleSheet&);
|
2021-09-29 23:46:16 +02:00
|
|
|
void remove_sheet(CSSStyleSheet&);
|
|
|
|
|
2022-09-09 11:08:56 +02:00
|
|
|
Vector<JS::NonnullGCPtr<CSSStyleSheet>> const& sheets() const { return m_sheets; }
|
|
|
|
Vector<JS::NonnullGCPtr<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
|
|
|
|
2022-08-07 13:29:49 +02:00
|
|
|
virtual bool is_supported_property_index(u32 index) const override;
|
|
|
|
virtual JS::Value item_value(size_t index) const override;
|
2021-09-29 13:03:09 +01:00
|
|
|
|
2022-03-09 19:57:15 +01:00
|
|
|
DOM::Document& document() { return m_document; }
|
|
|
|
DOM::Document const& document() const { return m_document; }
|
|
|
|
|
2020-06-04 16:06:32 +02:00
|
|
|
private:
|
2022-08-28 13:42:07 +02:00
|
|
|
explicit StyleSheetList(DOM::Document&);
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
virtual JS::ThrowCompletionOr<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
|
|
|
|
2022-09-09 11:08:56 +02:00
|
|
|
void sort_sheets();
|
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
DOM::Document& m_document;
|
2022-09-09 11:08:56 +02:00
|
|
|
Vector<JS::NonnullGCPtr<CSSStyleSheet>> m_sheets;
|
2020-06-04 16:06:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|