
This URL library ends up being a relatively fundamental base library of the system, as LibCore depends on LibURL. This change has two main benefits: * Moving AK back more towards being an agnostic library that can be used between the kernel and userspace. URL has never really fit that description - and is not used in the kernel. * URL _should_ depend on LibUnicode, as it needs punnycode support. However, it's not really possible to do this inside of AK as it can't depend on any external library. This change brings us a little closer to being able to do that, but unfortunately we aren't there quite yet, as the code generators depend on LibCore.
106 lines
4.1 KiB
C++
106 lines
4.1 KiB
C++
/*
|
|
* Copyright (c) 2019-2021, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2024, Tim Ledbetter <timledbetter@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Function.h>
|
|
#include <LibWeb/CSS/CSSNamespaceRule.h>
|
|
#include <LibWeb/CSS/CSSRule.h>
|
|
#include <LibWeb/CSS/CSSRuleList.h>
|
|
#include <LibWeb/CSS/CSSStyleRule.h>
|
|
#include <LibWeb/CSS/StyleSheet.h>
|
|
#include <LibWeb/WebIDL/Types.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class CSSImportRule;
|
|
|
|
struct CSSStyleSheetInit {
|
|
Optional<String> base_url {};
|
|
Variant<JS::Handle<MediaList>, String> media { String {} };
|
|
bool disabled { false };
|
|
};
|
|
|
|
class CSSStyleSheet final
|
|
: public StyleSheet
|
|
, public Weakable<CSSStyleSheet> {
|
|
WEB_PLATFORM_OBJECT(CSSStyleSheet, StyleSheet);
|
|
JS_DECLARE_ALLOCATOR(CSSStyleSheet);
|
|
|
|
public:
|
|
[[nodiscard]] static JS::NonnullGCPtr<CSSStyleSheet> create(JS::Realm&, CSSRuleList&, MediaList&, Optional<URL::URL> location);
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> construct_impl(JS::Realm&, Optional<CSSStyleSheetInit> const& options = {});
|
|
|
|
virtual ~CSSStyleSheet() override = default;
|
|
|
|
JS::GCPtr<CSSRule const> owner_rule() const { return m_owner_css_rule; }
|
|
JS::GCPtr<CSSRule> owner_rule() { return m_owner_css_rule; }
|
|
void set_owner_css_rule(CSSRule* rule) { m_owner_css_rule = rule; }
|
|
|
|
virtual String type() const override { return "text/css"_string; }
|
|
|
|
CSSRuleList const& rules() const { return *m_rules; }
|
|
CSSRuleList& rules() { return *m_rules; }
|
|
|
|
CSSRuleList* css_rules() { return m_rules; }
|
|
CSSRuleList const* css_rules() const { return m_rules; }
|
|
|
|
WebIDL::ExceptionOr<unsigned> insert_rule(StringView rule, unsigned index);
|
|
WebIDL::ExceptionOr<WebIDL::Long> add_rule(Optional<String> selector, Optional<String> style, Optional<WebIDL::UnsignedLong> index);
|
|
WebIDL::ExceptionOr<void> remove_rule(Optional<WebIDL::UnsignedLong> index);
|
|
WebIDL::ExceptionOr<void> delete_rule(unsigned index);
|
|
|
|
JS::NonnullGCPtr<JS::Promise> replace(String text);
|
|
WebIDL::ExceptionOr<void> replace_sync(StringView text);
|
|
|
|
void for_each_effective_style_rule(Function<void(CSSStyleRule const&)> const& callback) const;
|
|
// Returns whether the match state of any media queries changed after evaluation.
|
|
bool evaluate_media_queries(HTML::Window const&);
|
|
void for_each_effective_keyframes_at_rule(Function<void(CSSKeyframesRule const&)> const& callback) const;
|
|
|
|
void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
|
|
|
|
Optional<FlyString> default_namespace() const;
|
|
JS::GCPtr<CSSNamespaceRule> default_namespace_rule() const { return m_default_namespace_rule; }
|
|
|
|
Optional<FlyString> namespace_uri(StringView namespace_prefix) const;
|
|
|
|
Optional<URL::URL> base_url() const { return m_base_url; }
|
|
void set_base_url(Optional<URL::URL> base_url) { m_base_url = move(base_url); }
|
|
|
|
bool constructed() const { return m_constructed; }
|
|
|
|
JS::GCPtr<DOM::Document const> constructor_document() const { return m_constructor_document; }
|
|
void set_constructor_document(JS::GCPtr<DOM::Document const> constructor_document) { m_constructor_document = constructor_document; }
|
|
|
|
bool disallow_modification() const { return m_disallow_modification; }
|
|
|
|
private:
|
|
CSSStyleSheet(JS::Realm&, CSSRuleList&, MediaList&, Optional<URL::URL> location);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
void recalculate_namespaces();
|
|
|
|
void set_constructed(bool constructed) { m_constructed = constructed; }
|
|
void set_disallow_modification(bool disallow_modification) { m_disallow_modification = disallow_modification; }
|
|
|
|
JS::GCPtr<CSSRuleList> m_rules;
|
|
JS::GCPtr<CSSNamespaceRule> m_default_namespace_rule;
|
|
HashMap<FlyString, JS::GCPtr<CSSNamespaceRule>> m_namespace_rules;
|
|
|
|
JS::GCPtr<StyleSheetList> m_style_sheet_list;
|
|
JS::GCPtr<CSSRule> m_owner_css_rule;
|
|
|
|
Optional<URL::URL> m_base_url;
|
|
JS::GCPtr<DOM::Document const> m_constructor_document;
|
|
bool m_constructed { false };
|
|
bool m_disallow_modification { false };
|
|
};
|
|
|
|
}
|