mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-21 18:42:53 +00:00
The CSS `fetch_foo()` functions resolve the URL relative to the CSSStyleSheet if one is provided. So, style values that do so need to know what CSSStyleSheet they are part of so that, for example, `url (foo.png)` is loaded relative to the style sheet's URL instead of the document's one. That all works without this change because we currently absolutize URLs during parsing, but we're in the process of stopping that. This commit adds the infrastructure for telling style values what their CSSStyleSheet is.
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2021, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <LibWeb/CSS/CSSGroupingRule.h>
|
|
#include <LibWeb/CSS/CSSStyleProperties.h>
|
|
#include <LibWeb/CSS/Selector.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class CSSStyleRule final : public CSSGroupingRule {
|
|
WEB_PLATFORM_OBJECT(CSSStyleRule, CSSGroupingRule);
|
|
GC_DECLARE_ALLOCATOR(CSSStyleRule);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<CSSStyleRule> create(JS::Realm&, SelectorList&&, CSSStyleProperties&, CSSRuleList&);
|
|
|
|
virtual ~CSSStyleRule() override = default;
|
|
|
|
SelectorList const& selectors() const { return m_selectors; }
|
|
SelectorList const& absolutized_selectors() const;
|
|
CSSStyleProperties const& declaration() const { return m_declaration; }
|
|
|
|
String selector_text() const;
|
|
void set_selector_text(StringView);
|
|
|
|
GC::Ref<CSSStyleProperties> style();
|
|
|
|
[[nodiscard]] FlyString const& qualified_layer_name() const { return parent_layer_internal_qualified_name(); }
|
|
|
|
private:
|
|
CSSStyleRule(JS::Realm&, SelectorList&&, CSSStyleProperties&, CSSRuleList&);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
virtual void clear_caches() override;
|
|
virtual String serialized() const override;
|
|
|
|
virtual void set_parent_style_sheet(CSSStyleSheet*) override;
|
|
|
|
CSSStyleRule const* parent_style_rule() const;
|
|
|
|
SelectorList m_selectors;
|
|
mutable Optional<SelectorList> m_cached_absolutized_selectors;
|
|
GC::Ref<CSSStyleProperties> m_declaration;
|
|
};
|
|
|
|
template<>
|
|
inline bool CSSRule::fast_is<CSSStyleRule>() const { return type() == CSSRule::Type::Style; }
|
|
|
|
}
|