/src/serenity/Userland/Libraries/LibWeb/CSS/CSSImportRule.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, the SerenityOS developers. |
3 | | * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> |
4 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
5 | | * |
6 | | * SPDX-License-Identifier: BSD-2-Clause |
7 | | */ |
8 | | |
9 | | #pragma once |
10 | | |
11 | | #include <LibURL/URL.h> |
12 | | #include <LibWeb/CSS/CSSRule.h> |
13 | | #include <LibWeb/CSS/CSSStyleSheet.h> |
14 | | #include <LibWeb/DOM/DocumentLoadEventDelayer.h> |
15 | | #include <LibWeb/Loader/Resource.h> |
16 | | |
17 | | namespace Web::CSS { |
18 | | |
19 | | class CSSImportRule final |
20 | | : public CSSRule |
21 | | , public ResourceClient { |
22 | | WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule); |
23 | | JS_DECLARE_ALLOCATOR(CSSImportRule); |
24 | | |
25 | | public: |
26 | | [[nodiscard]] static JS::NonnullGCPtr<CSSImportRule> create(URL::URL, DOM::Document&); |
27 | | |
28 | 0 | virtual ~CSSImportRule() = default; |
29 | | |
30 | 0 | URL::URL const& url() const { return m_url; } |
31 | | // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css". |
32 | 0 | String href() const { return MUST(m_url.to_string()); } |
33 | | |
34 | 0 | CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; } |
35 | 0 | CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; } |
36 | 0 | CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; } |
37 | 0 | void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; } |
38 | | |
39 | 0 | virtual Type type() const override { return Type::Import; } |
40 | | |
41 | | private: |
42 | | CSSImportRule(URL::URL, DOM::Document&); |
43 | | |
44 | | virtual void initialize(JS::Realm&) override; |
45 | | virtual void visit_edges(Cell::Visitor&) override; |
46 | | |
47 | | virtual String serialized() const override; |
48 | | |
49 | | // ^ResourceClient |
50 | | virtual void resource_did_fail() override; |
51 | | virtual void resource_did_load() override; |
52 | | |
53 | | URL::URL m_url; |
54 | | JS::GCPtr<DOM::Document> m_document; |
55 | | JS::GCPtr<CSSStyleSheet> m_style_sheet; |
56 | | Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer; |
57 | | }; |
58 | | |
59 | | template<> |
60 | 0 | inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; } |
61 | | |
62 | | } |