Serenity Operating System
at master 61 lines 2.0 kB view raw
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 <AK/URL.h> 12#include <LibWeb/CSS/CSSRule.h> 13#include <LibWeb/CSS/CSSStyleSheet.h> 14#include <LibWeb/DOM/DocumentLoadEventDelayer.h> 15 16namespace Web::CSS { 17 18class CSSImportRule final 19 : public CSSRule 20 , public ResourceClient { 21 WEB_PLATFORM_OBJECT(CSSImportRule, CSSRule); 22 23public: 24 static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSImportRule>> create(AK::URL, DOM::Document&); 25 26 virtual ~CSSImportRule() = default; 27 28 AK::URL const& url() const { return m_url; } 29 // FIXME: This should return only the specified part of the url. eg, "stuff/foo.css", not "https://example.com/stuff/foo.css". 30 DeprecatedString href() const { return m_url.to_deprecated_string(); } 31 32 bool has_import_result() const { return !m_style_sheet; } 33 CSSStyleSheet* loaded_style_sheet() { return m_style_sheet; } 34 CSSStyleSheet const* loaded_style_sheet() const { return m_style_sheet; } 35 CSSStyleSheet* style_sheet_for_bindings() { return m_style_sheet; } 36 void set_style_sheet(CSSStyleSheet* style_sheet) { m_style_sheet = style_sheet; } 37 38 virtual Type type() const override { return Type::Import; }; 39 40private: 41 CSSImportRule(AK::URL, DOM::Document&); 42 43 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; 44 virtual void visit_edges(Cell::Visitor&) override; 45 46 virtual DeprecatedString serialized() const override; 47 48 // ^ResourceClient 49 virtual void resource_did_fail() override; 50 virtual void resource_did_load() override; 51 52 AK::URL m_url; 53 JS::GCPtr<DOM::Document> m_document; 54 JS::GCPtr<CSSStyleSheet> m_style_sheet; 55 Optional<DOM::DocumentLoadEventDelayer> m_document_load_event_delayer; 56}; 57 58template<> 59inline bool CSSRule::fast_is<CSSImportRule>() const { return type() == CSSRule::Type::Import; } 60 61}