mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Add stub implementation of CSS FontFace Web API
This commit is contained in:
parent
3a5eabc43b
commit
2c31d7dddc
Notes:
sideshowbarker
2024-07-17 03:35:16 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/2c31d7dddc Pull-request: https://github.com/SerenityOS/serenity/pull/24255 Issue: https://github.com/SerenityOS/serenity/issues/22014
7 changed files with 130 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
43
Userland/Libraries/LibWeb/CSS/FontFace.cpp
Normal file
43
Userland/Libraries/LibWeb/CSS/FontFace.cpp
Normal 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());
|
||||
}
|
||||
|
||||
}
|
44
Userland/Libraries/LibWeb/CSS/FontFace.h
Normal file
44
Userland/Libraries/LibWeb/CSS/FontFace.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
39
Userland/Libraries/LibWeb/CSS/FontFace.idl
Normal file
39
Userland/Libraries/LibWeb/CSS/FontFace.idl
Normal 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;
|
||||
};
|
|
@ -124,6 +124,7 @@ class FilterValueListStyleValue;
|
|||
class Flex;
|
||||
class FlexOrCalculated;
|
||||
class FlexStyleValue;
|
||||
class FontFace;
|
||||
class Frequency;
|
||||
class FrequencyOrCalculated;
|
||||
class FrequencyPercentage;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue