LibWeb: Add CSSImportRule wrapper

This commit is contained in:
Sam Atkins 2022-04-22 20:22:22 +01:00 committed by Andreas Kling
parent 1951873a5d
commit 0cf8986a1e
Notes: sideshowbarker 2024-07-17 11:05:47 +09:00
6 changed files with 28 additions and 4 deletions

View File

@ -6,10 +6,12 @@
#include <AK/TypeCasts.h>
#include <LibWeb/Bindings/CSSFontFaceRuleWrapper.h>
#include <LibWeb/Bindings/CSSImportRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleRuleWrapper.h>
#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/CSSStyleRule.h>
namespace Web::Bindings {
@ -21,6 +23,8 @@ CSSRuleWrapper* wrap(JS::GlobalObject& global_object, CSS::CSSRule& rule)
if (is<CSS::CSSStyleRule>(rule))
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSStyleRule>(rule)));
if (is<CSS::CSSImportRule>(rule))
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSImportRule>(rule)));
if (is<CSS::CSSFontFaceRule>(rule))
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSFontFaceRule>(rule)));
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, rule));

View File

@ -21,6 +21,8 @@
#include <LibWeb/Bindings/CSSFontFaceRulePrototype.h>
#include <LibWeb/Bindings/CSSGroupingRuleConstructor.h>
#include <LibWeb/Bindings/CSSGroupingRulePrototype.h>
#include <LibWeb/Bindings/CSSImportRuleConstructor.h>
#include <LibWeb/Bindings/CSSImportRulePrototype.h>
#include <LibWeb/Bindings/CSSRuleConstructor.h>
#include <LibWeb/Bindings/CSSRuleListConstructor.h>
#include <LibWeb/Bindings/CSSRuleListPrototype.h>
@ -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) \

View File

@ -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)

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* 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<CSSImportRule> 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<CSSStyleSheet> loaded_style_sheet() { return m_style_sheet; }
RefPtr<CSSStyleSheet> const loaded_style_sheet() const { return m_style_sheet; }
NonnullRefPtr<CSSStyleSheet> style_sheet_for_bindings() { return *m_style_sheet; }
void set_style_sheet(RefPtr<CSSStyleSheet> const& style_sheet) { m_style_sheet = style_sheet; }
virtual StringView class_name() const override { return "CSSImportRule"; };

View File

@ -0,0 +1,10 @@
#import <CSS/CSSRule.idl>
#import <CSS/CSSStyleSheet.idl>
#import <CSS/MediaList.idl>
[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;
};

View File

@ -411,6 +411,7 @@ class CryptoWrapper;
class CSSConditionRuleWrapper;
class CSSFontFaceRuleWrapper;
class CSSGroupingRuleWrapper;
class CSSImportRuleWrapper;
class CSSRuleListWrapper;
class CSSRuleWrapper;
class CSSStyleDeclarationWrapper;