diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h | 45 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.idl | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSRule.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/FontFace.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/FontFace.h | 32 |
7 files changed, 138 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp new file mode 100644 index 0000000000..f001068142 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp @@ -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()! */ }"; +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h new file mode 100644 index 0000000000..7eb1b487e8 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h @@ -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; } + +} diff --git a/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.idl b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.idl new file mode 100644 index 0000000000..cf5701a19b --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.idl @@ -0,0 +1,7 @@ +#import <CSS/CSSRule.idl> +#import <CSS/CSSStyleDeclaration.idl> + +[Exposed=Window] +interface CSSFontFaceRule : CSSRule { + readonly attribute CSSStyleDeclaration style; +}; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRule.h b/Userland/Libraries/LibWeb/CSS/CSSRule.h index 125f38d63d..ec7f9f29d9 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRule.h +++ b/Userland/Libraries/LibWeb/CSS/CSSRule.h @@ -29,6 +29,7 @@ public: Import, Media, Supports, + FontFace, __Count, }; diff --git a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp index 0ee0b1fd43..650dac3765 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -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)) diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp new file mode 100644 index 0000000000..b0401996cd --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp @@ -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)) +{ +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.h b/Userland/Libraries/LibWeb/CSS/FontFace.h new file mode 100644 index 0000000000..e90aa75b19 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/FontFace.h @@ -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; +}; + +} |