1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:37:34 +00:00

LibWeb: Implement initial CSSFontFaceRule and FontFace classes

For now, this is the bare minimum that's needed: font-family and src.
This commit is contained in:
Sam Atkins 2022-03-28 20:30:26 +01:00 committed by Andreas Kling
parent 1dcde57922
commit 804b8c85e8
13 changed files with 173 additions and 6 deletions

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/CSSFontFaceRule.h>
namespace Web::CSS {
CSSFontFaceRule::CSSFontFaceRule(FontFace&& font_face)
: m_font_face(move(font_face))
{
}
CSSStyleDeclaration* CSSFontFaceRule::style()
{
// FIXME: Return a CSSStyleDeclaration subclass that directs changes to the FontFace.
return nullptr;
}
// https://www.w3.org/TR/cssom/#ref-for-cssfontfacerule
String CSSFontFaceRule::serialized() const
{
// FIXME: Implement this!
return "@font-face { /* FIXME: Implement CSSFontFaceRule::serialized()! */ }";
}
}

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/CSS/FontFace.h>
namespace Web::CSS {
class CSSFontFaceRule final : public CSSRule {
AK_MAKE_NONCOPYABLE(CSSFontFaceRule);
AK_MAKE_NONMOVABLE(CSSFontFaceRule);
public:
using WrapperType = Bindings::CSSFontFaceRuleWrapper;
static NonnullRefPtr<CSSFontFaceRule> create(FontFace&& font_face)
{
return adopt_ref(*new CSSFontFaceRule(move(font_face)));
}
virtual ~CSSFontFaceRule() override = default;
virtual StringView class_name() const override { return "CSSFontFaceRule"; }
virtual Type type() const override { return Type::FontFace; }
FontFace const& font_face() const { return m_font_face; }
CSSStyleDeclaration* style();
private:
explicit CSSFontFaceRule(FontFace&&);
virtual String serialized() const override;
FontFace m_font_face;
};
template<>
inline bool CSSRule::fast_is<CSSFontFaceRule>() const { return type() == CSSRule::Type::FontFace; }
}

View file

@ -0,0 +1,7 @@
#import <CSS/CSSRule.idl>
#import <CSS/CSSStyleDeclaration.idl>
[Exposed=Window]
interface CSSFontFaceRule : CSSRule {
readonly attribute CSSStyleDeclaration style;
};

View file

@ -29,6 +29,7 @@ public:
Import,
Media,
Supports,
FontFace,
__Count,
};

View file

@ -78,8 +78,7 @@ void CSSRuleList::for_each_effective_style_rule(Function<void(CSSStyleRule const
{
for (auto const& rule : m_rules) {
switch (rule.type()) {
case CSSRule::Type::Style:
callback(static_cast<CSSStyleRule const&>(rule));
case CSSRule::Type::FontFace:
break;
case CSSRule::Type::Import: {
auto const& import_rule = static_cast<CSSImportRule const&>(rule);
@ -90,6 +89,9 @@ void CSSRuleList::for_each_effective_style_rule(Function<void(CSSStyleRule const
case CSSRule::Type::Media:
static_cast<CSSMediaRule const&>(rule).for_each_effective_style_rule(callback);
break;
case CSSRule::Type::Style:
callback(static_cast<CSSStyleRule const&>(rule));
break;
case CSSRule::Type::Supports:
static_cast<CSSSupportsRule const&>(rule).for_each_effective_style_rule(callback);
break;
@ -105,7 +107,7 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
for (auto& rule : m_rules) {
switch (rule.type()) {
case CSSRule::Type::Style:
case CSSRule::Type::FontFace:
break;
case CSSRule::Type::Import: {
auto& import_rule = verify_cast<CSSImportRule>(rule);
@ -123,6 +125,8 @@ bool CSSRuleList::evaluate_media_queries(HTML::Window const& window)
any_media_queries_changed_match_state = true;
break;
}
case CSSRule::Type::Style:
break;
case CSSRule::Type::Supports: {
auto& supports_rule = verify_cast<CSSSupportsRule>(rule);
if (supports_rule.condition_matches() && supports_rule.css_rules().evaluate_media_queries(window))

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/FontFace.h>
namespace Web::CSS {
FontFace::FontFace(FlyString font_family, Vector<Source> sources)
: m_font_family(move(font_family))
, m_sources(move(sources))
{
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/URL.h>
namespace Web::CSS {
class FontFace {
public:
struct Source {
AK::URL url;
};
FontFace(FlyString font_family, Vector<Source> sources);
~FontFace() = default;
FlyString font_family() const { return m_font_family; }
Vector<Source> const& sources() const { return m_sources; }
// FIXME: font-style, font-weight, font-stretch, unicode-range, font-feature-settings
private:
FlyString m_font_family;
Vector<Source> m_sources;
};
}