LibWeb: Add stub implementation of CSS FontFace Web API

This commit is contained in:
Andrew Kaster 2024-05-07 10:05:29 -06:00 committed by Andreas Kling
parent 3a5eabc43b
commit 2c31d7dddc
Notes: sideshowbarker 2024-07-17 03:35:16 +09:00
7 changed files with 130 additions and 0 deletions

View file

@ -48,6 +48,7 @@ static bool is_platform_object(Type const& type)
"DOMRectReadOnly"sv,
"EventTarget"sv,
"FileList"sv,
"FontFace"sv,
"FormData"sv,
"HTMLCollection"sv,
"ImageBitmap"sv,

View file

@ -54,6 +54,7 @@ set(SOURCES
CSS/CSSTransition.cpp
CSS/Display.cpp
CSS/EdgeRect.cpp
CSS/FontFace.cpp
CSS/Flex.cpp
CSS/Frequency.cpp
CSS/GridTrackPlacement.cpp

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/FontFacePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::CSS {
JS_DEFINE_ALLOCATOR(FontFace);
JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors)
{
return realm.heap().allocate<FontFace>(realm, realm, move(family), move(source), descriptors);
}
FontFace::FontFace(JS::Realm& realm, String, FontFaceSource, FontFaceDescriptors const&)
: Bindings::PlatformObject(realm)
{
}
void FontFace::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFace);
}
// https://drafts.csswg.org/css-font-loading/#dom-fontface-load
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> FontFace::load()
{
// FIXME: Do the steps
auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFace::load is not yet implemented"_fly_string));
return verify_cast<JS::Promise>(*promise->promise());
}
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::CSS {
struct FontFaceDescriptors {
String style = "normal"_string;
String weight = "normal"_string;
String stretch = "normal"_string;
String unicode_range = "U+0-10FFFF"_string;
String feature_settings = "normal"_string;
String variation_settings = "normal"_string;
String display = "auto"_string;
String ascent_override = "normal"_string;
String descent_override = "normal"_string;
String line_gap_override = "normal"_string;
};
class FontFace final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(FontFace, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(FontFace);
public:
using FontFaceSource = Variant<String, JS::Handle<JS::ArrayBuffer>, JS::Handle<WebIDL::ArrayBufferView>>;
[[nodiscard]] static JS::NonnullGCPtr<FontFace> construct_impl(JS::Realm&, String family, FontFaceSource source, FontFaceDescriptors const& descriptors);
virtual ~FontFace() override = default;
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> load();
private:
FontFace(JS::Realm&, String family, FontFaceSource source, FontFaceDescriptors const& descriptors);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,39 @@
typedef (ArrayBuffer or ArrayBufferView) BinaryData;
dictionary FontFaceDescriptors {
CSSOMString style = "normal";
CSSOMString weight = "normal";
CSSOMString stretch = "normal";
CSSOMString unicodeRange = "U+0-10FFFF";
CSSOMString featureSettings = "normal";
CSSOMString variationSettings = "normal";
CSSOMString display = "auto";
CSSOMString ascentOverride = "normal";
CSSOMString descentOverride = "normal";
CSSOMString lineGapOverride = "normal";
};
enum FontFaceLoadStatus { "unloaded", "loading", "loaded", "error" };
// https://drafts.csswg.org/css-font-loading/#fontface-interface
[Exposed=(Window,Worker)]
interface FontFace {
// FIXME: constructor(CSSOMString family, (CSSOMString or BinaryData) source, optional FontFaceDescriptors descriptors = {});
constructor(CSSOMString family, CSSOMString source, optional FontFaceDescriptors descriptors = {});
// FIXME: attribute CSSOMString family;
// FIXME: attribute CSSOMString style;
// FIXME: attribute CSSOMString weight;
// FIXME: attribute CSSOMString stretch;
// FIXME: attribute CSSOMString unicodeRange;
// FIXME: attribute CSSOMString featureSettings;
// FIXME: attribute CSSOMString variationSettings;
// FIXME: attribute CSSOMString display;
// FIXME: attribute CSSOMString ascentOverride;
// FIXME: attribute CSSOMString descentOverride;
// FIXME: attribute CSSOMString lineGapOverride;
// FIXME: readonly attribute FontFaceLoadStatus status;
Promise<FontFace> load();
// FIXME: readonly attribute Promise<FontFace> loaded;
};

View file

@ -124,6 +124,7 @@ class FilterValueListStyleValue;
class Flex;
class FlexOrCalculated;
class FlexStyleValue;
class FontFace;
class Frequency;
class FrequencyOrCalculated;
class FrequencyPercentage;

View file

@ -29,6 +29,7 @@ libweb_js_bindings(CSS/CSSStyleRule)
libweb_js_bindings(CSS/CSSStyleSheet)
libweb_js_bindings(CSS/CSSSupportsRule)
libweb_js_bindings(CSS/CSSTransition)
libweb_js_bindings(CSS/FontFace)
libweb_js_bindings(CSS/MediaList)
libweb_js_bindings(CSS/MediaQueryList)
libweb_js_bindings(CSS/MediaQueryListEvent)