summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-28 20:30:26 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-28 22:25:25 +0200
commit804b8c85e8ff12ce8dd489b41d8626426c9f5488 (patch)
tree84cb0ae0781da17e7aa26e44deedc28b3f7bc13b /Userland/Libraries/LibWeb
parent1dcde5792265e6417bb2700a781dfc181bc7da0d (diff)
downloadserenity-804b8c85e8ff12ce8dd489b41d8626426c9f5488.zip
LibWeb: Implement initial CSSFontFaceRule and FontFace classes
For now, this is the bare minimum that's needed: font-family and src.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp4
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt3
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp29
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.h45
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSFontFaceRule.idl7
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSRule.h1
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSRuleList.cpp10
-rw-r--r--Userland/Libraries/LibWeb/CSS/FontFace.cpp17
-rw-r--r--Userland/Libraries/LibWeb/CSS/FontFace.h32
-rw-r--r--Userland/Libraries/LibWeb/Dump.cpp22
-rw-r--r--Userland/Libraries/LibWeb/Dump.h3
-rw-r--r--Userland/Libraries/LibWeb/Forward.h3
13 files changed, 173 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
index e20db17db7..bafaea3772 100644
--- a/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/CSSRuleWrapperFactory.cpp
@@ -5,9 +5,11 @@
*/
#include <AK/TypeCasts.h>
+#include <LibWeb/Bindings/CSSFontFaceRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapper.h>
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
#include <LibWeb/Bindings/CSSStyleRuleWrapper.h>
+#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSStyleRule.h>
namespace Web::Bindings {
@@ -19,6 +21,8 @@ CSSRuleWrapper* wrap(JS::GlobalObject& global_object, CSS::CSSRule& rule)
if (is<CSS::CSSStyleRule>(rule))
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSStyleRule>(rule)));
+ if (is<CSS::CSSFontFaceRule>(rule))
+ return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, verify_cast<CSS::CSSFontFaceRule>(rule)));
return static_cast<CSSRuleWrapper*>(wrap_impl(global_object, rule));
}
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index 805a6f6663..53dd04c7b8 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -15,6 +15,8 @@
#include <LibWeb/Bindings/AbstractRangeConstructor.h>
#include <LibWeb/Bindings/AbstractRangePrototype.h>
#include <LibWeb/Bindings/AudioConstructor.h>
+#include <LibWeb/Bindings/CSSFontFaceRuleConstructor.h>
+#include <LibWeb/Bindings/CSSFontFaceRulePrototype.h>
#include <LibWeb/Bindings/CSSRuleConstructor.h>
#include <LibWeb/Bindings/CSSRuleListConstructor.h>
#include <LibWeb/Bindings/CSSRuleListPrototype.h>
@@ -340,6 +342,7 @@
ADD_WINDOW_OBJECT_INTERFACE(AbortSignal) \
ADD_WINDOW_OBJECT_INTERFACE(AbstractRange) \
ADD_WINDOW_OBJECT_INTERFACE(Crypto) \
+ ADD_WINDOW_OBJECT_INTERFACE(CSSFontFaceRule) \
ADD_WINDOW_OBJECT_INTERFACE(CSSRule) \
ADD_WINDOW_OBJECT_INTERFACE(CSSRuleList) \
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleDeclaration) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index c036e24801..24486e80b1 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SOURCES
CSS/CSSConditionRule.cpp
CSS/CSSGroupingRule.cpp
CSS/CSSImportRule.cpp
+ CSS/CSSFontFaceRule.cpp
CSS/CSSMediaRule.cpp
CSS/CSSRule.cpp
CSS/CSSRuleList.cpp
@@ -31,6 +32,7 @@ set(SOURCES
CSS/CSSSupportsRule.cpp
CSS/DefaultStyleSheetSource.cpp
CSS/Display.cpp
+ CSS/FontFace.cpp
CSS/Frequency.cpp
CSS/Length.cpp
CSS/MediaFeatureID.cpp
@@ -433,6 +435,7 @@ endfunction()
libweb_js_wrapper(Crypto/Crypto)
libweb_js_wrapper(Crypto/SubtleCrypto)
+libweb_js_wrapper(CSS/CSSFontFaceRule)
libweb_js_wrapper(CSS/CSSRule)
libweb_js_wrapper(CSS/CSSRuleList)
libweb_js_wrapper(CSS/CSSStyleDeclaration)
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;
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp
index 7fda549794..850f3796c4 100644
--- a/Userland/Libraries/LibWeb/Dump.cpp
+++ b/Userland/Libraries/LibWeb/Dump.cpp
@@ -8,6 +8,7 @@
#include <AK/QuickSort.h>
#include <AK/StringBuilder.h>
#include <AK/Utf8View.h>
+#include <LibWeb/CSS/CSSFontFaceRule.h>
#include <LibWeb/CSS/CSSImportRule.h>
#include <LibWeb/CSS/CSSMediaRule.h>
#include <LibWeb/CSS/CSSRule.h>
@@ -547,8 +548,8 @@ void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_leve
builder.appendff("{}:\n", rule.class_name());
switch (rule.type()) {
- case CSS::CSSRule::Type::Style:
- dump_style_rule(builder, verify_cast<CSS::CSSStyleRule const>(rule), indent_levels);
+ case CSS::CSSRule::Type::FontFace:
+ dump_font_face_rule(builder, verify_cast<CSS::CSSFontFaceRule const>(rule), indent_levels);
break;
case CSS::CSSRule::Type::Import:
dump_import_rule(builder, verify_cast<CSS::CSSImportRule const>(rule), indent_levels);
@@ -556,6 +557,9 @@ void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_leve
case CSS::CSSRule::Type::Media:
dump_media_rule(builder, verify_cast<CSS::CSSMediaRule const>(rule), indent_levels);
break;
+ case CSS::CSSRule::Type::Style:
+ dump_style_rule(builder, verify_cast<CSS::CSSStyleRule const>(rule), indent_levels);
+ break;
case CSS::CSSRule::Type::Supports:
dump_supports_rule(builder, verify_cast<CSS::CSSSupportsRule const>(rule), indent_levels);
break;
@@ -564,6 +568,20 @@ void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_leve
}
}
+void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rule, int indent_levels)
+{
+ auto& font_face = rule.font_face();
+ indent(builder, indent_levels + 1);
+ builder.appendff("font-family: {}\n", font_face.font_family());
+
+ indent(builder, indent_levels + 1);
+ builder.append("sources:\n");
+ for (auto const& source : font_face.sources()) {
+ indent(builder, indent_levels + 2);
+ builder.appendff("{}\n", source.url);
+ }
+}
+
void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule, int indent_levels)
{
indent(builder, indent_levels);
diff --git a/Userland/Libraries/LibWeb/Dump.h b/Userland/Libraries/LibWeb/Dump.h
index aa12e4ba2f..a76b104a2a 100644
--- a/Userland/Libraries/LibWeb/Dump.h
+++ b/Userland/Libraries/LibWeb/Dump.h
@@ -20,9 +20,10 @@ void dump_sheet(StringBuilder&, CSS::StyleSheet const&);
void dump_sheet(CSS::StyleSheet const&);
void dump_rule(StringBuilder&, CSS::CSSRule const&, int indent_levels = 0);
void dump_rule(CSS::CSSRule const&);
-void dump_style_rule(StringBuilder&, CSS::CSSStyleRule const&, int indent_levels = 0);
+void dump_font_face_rule(StringBuilder&, CSS::CSSFontFaceRule const&, int indent_levels = 0);
void dump_import_rule(StringBuilder&, CSS::CSSImportRule const&, int indent_levels = 0);
void dump_media_rule(StringBuilder&, CSS::CSSMediaRule const&, int indent_levels = 0);
+void dump_style_rule(StringBuilder&, CSS::CSSStyleRule const&, int indent_levels = 0);
void dump_supports_rule(StringBuilder&, CSS::CSSSupportsRule const&, int indent_levels = 0);
void dump_selector(StringBuilder&, CSS::Selector const&);
void dump_selector(CSS::Selector const&);
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 215d28635a..cbba73e767 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -31,6 +31,7 @@ class CalculatedStyleValue;
class ColorStyleValue;
class ContentStyleValue;
class CSSImportRule;
+class CSSFontFaceRule;
class CSSMediaRule;
class CSSRule;
class CSSRuleList;
@@ -42,6 +43,7 @@ class Display;
class ElementInlineCSSStyleDeclaration;
class FlexFlowStyleValue;
class FlexStyleValue;
+class FontFace;
class FontStyleValue;
class Frequency;
class FrequencyPercentage;
@@ -381,6 +383,7 @@ class CharacterDataWrapper;
class CloseEventWrapper;
class CommentWrapper;
class CryptoWrapper;
+class CSSFontFaceRuleWrapper;
class CSSRuleListWrapper;
class CSSRuleWrapper;
class CSSStyleDeclarationWrapper;