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
|
|
|
|
|
|
|
|
#include <AK/URL.h>
|
2022-08-07 13:14:54 +02:00
|
|
|
#include <LibJS/Heap/Handle.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>
|
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 {
|
2021-02-21 18:36:34 +02:00
|
|
|
AK_MAKE_NONCOPYABLE(CSSImportRule);
|
|
|
|
AK_MAKE_NONMOVABLE(CSSImportRule);
|
2022-08-07 15:46:44 +02:00
|
|
|
JS_OBJECT(CSSImportRule, CSSRule);
|
2021-02-21 18:36:34 +02:00
|
|
|
|
|
|
|
public:
|
2022-08-07 15:46:44 +02:00
|
|
|
static CSSImportRule* create(AK::URL, DOM::Document&);
|
|
|
|
CSSImportRule(AK::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
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSImportRule& impl() { return *this; }
|
|
|
|
|
2022-04-22 20:22:22 +01:00
|
|
|
AK::URL const& url() const { return m_url; }
|
|
|
|
// FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css".
|
|
|
|
String href() const { return m_url.to_string(); }
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2022-08-07 15:46:44 +02:00
|
|
|
bool has_import_result() const { return !m_style_sheet; }
|
|
|
|
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
|
|
|
|
2021-12-04 10:09:09 +01:00
|
|
|
virtual Type type() const override { return Type::Import; };
|
2021-02-21 18:36:34 +02:00
|
|
|
|
|
|
|
private:
|
2022-08-07 15:46:44 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-02-21 18:36:34 +02:00
|
|
|
|
2021-10-01 19:57:45 +02:00
|
|
|
virtual String serialized() const override;
|
|
|
|
|
2021-11-18 17:34:53 +00:00
|
|
|
// ^ResourceClient
|
|
|
|
virtual void resource_did_fail() override;
|
|
|
|
virtual void resource_did_load() override;
|
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
AK::URL m_url;
|
2021-12-05 15:28:38 +01:00
|
|
|
WeakPtr<DOM::Document> m_document;
|
2021-11-18 17:34:53 +00:00
|
|
|
Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer;
|
2022-08-07 15:46:44 +02:00
|
|
|
CSSStyleSheet* m_style_sheet { nullptr };
|
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
|
|
|
}
|
2022-08-07 15:46:44 +02:00
|
|
|
|
|
|
|
namespace Web::Bindings {
|
|
|
|
inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSImportRule& object) { return &object; }
|
|
|
|
using CSSImportRuleWrapper = Web::CSS::CSSImportRule;
|
|
|
|
}
|