2021-02-21 18:36:34 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
2022-04-22 20:22:22 +01:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2022-08-07 15:46:44 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
2021-02-21 18:36:34 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-21 18:36:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2021-02-21 18:36:34 +02:00
|
|
|
#include <LibWeb/CSS/CSSRule.h>
|
2021-09-30 22:57:35 +02:00
|
|
|
#include <LibWeb/CSS/CSSStyleSheet.h>
|
2021-11-18 17:34:53 +00:00
|
|
|
#include <LibWeb/DOM/DocumentLoadEventDelayer.h>
|
2023-07-09 11:40:17 +03:30
|
|
|
#include <LibWeb/Loader/Resource.h>
|
2021-02-21 18:36:34 +02:00
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2022-04-22 20:22:22 +01:00
|
|
|
class CSSImportRule final
|
2021-11-18 17:34:53 +00:00
|
|
|
: public CSSRule
|
|
|
|
, public ResourceClient {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule);
|
2023-11-19 19:47:52 +01:00
|
|
|
JS_DECLARE_ALLOCATOR(CSSImportRule);
|
2021-02-21 18:36:34 +02:00
|
|
|
|
|
|
|
public:
|
2024-03-18 16:22:27 +13:00
|
|
|
[[nodiscard]] static JS::NonnullGCPtr<CSSImportRule> create(URL::URL, DOM::Document&);
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2022-04-22 20:22:22 +01:00
|
|
|
virtual ~CSSImportRule() = default;
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL const& url() const { return m_url; }
|
2022-04-22 20:22:22 +01:00
|
|
|
// FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
|
2023-12-01 16:55:34 +00:00
|
|
|
String href() const { return MUST(m_url.to_string()); }
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; }
|
|
|
|
CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; }
|
|
|
|
CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; }
|
|
|
|
void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; }
|
2021-02-21 18:44:17 +02:00
|
|
|
|
2023-07-07 22:48:11 -04:00
|
|
|
virtual Type type() const override { return Type::Import; }
|
2021-02-21 18:36:34 +02:00
|
|
|
|
|
|
|
private:
|
2024-03-18 16:22:27 +13:00
|
|
|
CSSImportRule(URL::URL, DOM::Document&);
|
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 15:46:44 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2023-11-20 23:16:39 +13:00
|
|
|
virtual String serialized() const override;
|
2021-10-01 19:57:45 +02:00
|
|
|
|
2021-11-18 17:34:53 +00:00
|
|
|
// ^ResourceClient
|
|
|
|
virtual void resource_did_fail() override;
|
|
|
|
virtual void resource_did_load() override;
|
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL m_url;
|
2022-09-03 15:44:06 +02:00
|
|
|
JS::GCPtr<DOM::Document> m_document;
|
|
|
|
JS::GCPtr<CSSStyleSheet> m_style_sheet;
|
2021-11-18 17:34:53 +00:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
|
2021-02-21 18:36:34 +02:00
|
|
|
};
|
|
|
|
|
2021-03-18 21:50:52 +01:00
|
|
|
template<>
|
|
|
|
inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; }
|
|
|
|
|
2021-02-21 18:36:34 +02:00
|
|
|
}
|