diff --git a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp index bafaea3772..509b655eb7 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp @@ -6,10 +6,12 @@ #include #include +#include #include #include #include #include +#include #include namespace Web::Bindings { @@ -21,6 +23,8 @@ CSSRuleWrapper* wrap(JS::GlobalObject& global_object, CSS::CSSRule& rule) if (is(rule)) return static_cast(wrap_impl(global_object, verify_cast(rule))); + if (is(rule)) + return static_cast(wrap_impl(global_object, verify_cast(rule))); if (is(rule)) return static_cast(wrap_impl(global_object, verify_cast(rule))); return static_cast(wrap_impl(global_object, rule)); diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 9f16e6bb9d..e6cbeb6abd 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include #include @@ -363,6 +365,7 @@ ADD_WINDOW_OBJECT_INTERFACE(CSSConditionRule) \ ADD_WINDOW_OBJECT_INTERFACE(CSSFontFaceRule) \ ADD_WINDOW_OBJECT_INTERFACE(CSSGroupingRule) \ + ADD_WINDOW_OBJECT_INTERFACE(CSSImportRule) \ ADD_WINDOW_OBJECT_INTERFACE(CSSRule) \ ADD_WINDOW_OBJECT_INTERFACE(CSSRuleList) \ ADD_WINDOW_OBJECT_INTERFACE(CSSStyleDeclaration) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 91d7d3205a..9ccd60be65 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -454,6 +454,7 @@ libweb_js_wrapper(Crypto/SubtleCrypto) libweb_js_wrapper(CSS/CSSConditionRule) libweb_js_wrapper(CSS/CSSFontFaceRule) libweb_js_wrapper(CSS/CSSGroupingRule) +libweb_js_wrapper(CSS/CSSImportRule) libweb_js_wrapper(CSS/CSSRule) libweb_js_wrapper(CSS/CSSRuleList) libweb_js_wrapper(CSS/CSSStyleDeclaration) diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h index 667887d697..1bed34b17b 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSImportRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2021, the SerenityOS developers. - * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021-2022, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,25 +14,30 @@ namespace Web::CSS { -class CSSImportRule +class CSSImportRule final : public CSSRule , public ResourceClient { AK_MAKE_NONCOPYABLE(CSSImportRule); AK_MAKE_NONMOVABLE(CSSImportRule); public: + using WrapperType = Bindings::CSSImportRuleWrapper; + static NonnullRefPtr create(AK::URL url, DOM::Document& document) { return adopt_ref(*new CSSImportRule(move(url), document)); } - ~CSSImportRule() = default; + virtual ~CSSImportRule() = default; - const AK::URL& url() const { return m_url; } + 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(); } bool has_import_result() const { return !m_style_sheet.is_null(); } RefPtr loaded_style_sheet() { return m_style_sheet; } RefPtr const loaded_style_sheet() const { return m_style_sheet; } + NonnullRefPtr style_sheet_for_bindings() { return *m_style_sheet; } void set_style_sheet(RefPtr const& style_sheet) { m_style_sheet = style_sheet; } virtual StringView class_name() const override { return "CSSImportRule"; }; diff --git a/Userland/Libraries/LibWeb/CSS/CSSImportRule.idl b/Userland/Libraries/LibWeb/CSS/CSSImportRule.idl new file mode 100644 index 0000000000..838e64d77a --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSImportRule.idl @@ -0,0 +1,10 @@ +#import +#import +#import + +[Exposed=Window] +interface CSSImportRule : CSSRule { + readonly attribute USVString href; + // [SameObject, PutForwards=mediaText] readonly attribute MediaList media; + [SameObject, ImplementedAs=style_sheet_for_bindings] readonly attribute CSSStyleSheet styleSheet; +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6bbf21a341..c22f2aaedb 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -411,6 +411,7 @@ class CryptoWrapper; class CSSConditionRuleWrapper; class CSSFontFaceRuleWrapper; class CSSGroupingRuleWrapper; +class CSSImportRuleWrapper; class CSSRuleListWrapper; class CSSRuleWrapper; class CSSStyleDeclarationWrapper;