mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 02:10:26 +00:00
The spec states that updates to descriptors in a `@font-face` rule
should be reflected in the connected `FontFace`'s attributes.
Previously this was achieved by directly accessing those descriptors
when calling the attribute getters, but this has a couple of issues:
a) The changes are only reflected if we use the accessors (i.e.
`FontFace::family()` rather than `FontFace::m_family`) which isn't
the case everywhere
b) The changes aren't persisted after the `FontFace` is disconnected
from it's `CSSFontFaceRule`
To fix these issues we now reparse and store the `FontFace`'s attributes
whenever the `CSSFontFaceRule`'s descriptors change.
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org>
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/CSSFontFaceDescriptors.h>
|
|
#include <LibWeb/CSS/CSSRule.h>
|
|
#include <LibWeb/CSS/ParsedFontFace.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
class FontFace;
|
|
|
|
class CSSFontFaceRule final : public CSSRule {
|
|
WEB_PLATFORM_OBJECT(CSSFontFaceRule, CSSRule);
|
|
GC_DECLARE_ALLOCATOR(CSSFontFaceRule);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<CSSFontFaceRule> create(JS::Realm&, GC::Ref<CSSFontFaceDescriptors>);
|
|
|
|
virtual ~CSSFontFaceRule() override = default;
|
|
|
|
bool is_valid() const;
|
|
ParsedFontFace font_face() const;
|
|
GC::Ref<CSSStyleDeclaration> style() { return m_style; }
|
|
GC::Ref<CSSFontFaceDescriptors> descriptors() { return m_style; }
|
|
GC::Ref<CSSFontFaceDescriptors const> descriptors() const { return m_style; }
|
|
|
|
GC::Ptr<FontFace> css_connected_font_face() const { return m_css_connected_font_face; }
|
|
void set_css_connected_font_face(GC::Ptr<FontFace> font_face) { m_css_connected_font_face = font_face; }
|
|
void handle_descriptor_change(FlyString const& property);
|
|
void disconnect_font_face();
|
|
|
|
private:
|
|
CSSFontFaceRule(JS::Realm&, GC::Ref<CSSFontFaceDescriptors>);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual String serialized() const override;
|
|
virtual void visit_edges(Visitor&) override;
|
|
virtual void dump(StringBuilder&, int indent_levels) const override;
|
|
|
|
void handle_src_descriptor_change();
|
|
|
|
GC::Ref<CSSFontFaceDescriptors> m_style;
|
|
GC::Ptr<FontFace> m_css_connected_font_face;
|
|
};
|
|
|
|
template<>
|
|
inline bool CSSRule::fast_is<CSSFontFaceRule>() const { return type() == CSSRule::Type::FontFace; }
|
|
|
|
}
|