mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-15 22:12:20 +00:00
LibWeb: Add stub implementation of FontFaceSet and Document.fonts
This is now enough for duolingo to load and use its fallback fonts.
This commit is contained in:
parent
2c31d7dddc
commit
e10721f1b5
Notes:
sideshowbarker
2024-07-17 05:03:11 +09:00
Author: https://github.com/ADKaster
Commit: e10721f1b5
Pull-request: https://github.com/SerenityOS/serenity/pull/24255
Issue: https://github.com/SerenityOS/serenity/issues/22014
13 changed files with 174 additions and 1 deletions
55
Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp
Normal file
55
Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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/FontFaceSetPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/FontFaceSet.h>
|
||||
#include <LibWeb/WebIDL/Promise.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(FontFaceSet);
|
||||
|
||||
JS::NonnullGCPtr<FontFaceSet> FontFaceSet::construct_impl(JS::Realm& realm, Vector<JS::Handle<FontFace>> initial_faces)
|
||||
{
|
||||
return realm.heap().allocate<FontFaceSet>(realm, realm, move(initial_faces));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<FontFaceSet> FontFaceSet::create(JS::Realm& realm)
|
||||
{
|
||||
return construct_impl(realm, {});
|
||||
}
|
||||
|
||||
FontFaceSet::FontFaceSet(JS::Realm& realm, Vector<JS::Handle<FontFace>>)
|
||||
: Bindings::PlatformObject(realm)
|
||||
{
|
||||
}
|
||||
|
||||
void FontFaceSet::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFaceSet);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-add
|
||||
JS::NonnullGCPtr<FontFaceSet> FontFaceSet::add(JS::Handle<FontFace>)
|
||||
{
|
||||
// FIXME: Do the steps
|
||||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-load
|
||||
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> FontFaceSet::load(String const&, String const&)
|
||||
{
|
||||
// FIXME: Do the steps
|
||||
auto promise = WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "FontFaceSet::load is not yet implemented"_fly_string));
|
||||
return verify_cast<JS::Promise>(*promise->promise());
|
||||
}
|
||||
|
||||
}
|
32
Userland/Libraries/LibWeb/CSS/FontFaceSet.h
Normal file
32
Userland/Libraries/LibWeb/CSS/FontFaceSet.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/CSS/FontFace.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class FontFaceSet final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(FontFace, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(FontFaceSet);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FontFaceSet> construct_impl(JS::Realm&, Vector<JS::Handle<FontFace>> initial_faces);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FontFaceSet> create(JS::Realm&);
|
||||
virtual ~FontFaceSet() override = default;
|
||||
|
||||
JS::NonnullGCPtr<FontFaceSet> add(JS::Handle<FontFace> face);
|
||||
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Promise>> load(String const& font, String const& text);
|
||||
|
||||
private:
|
||||
FontFaceSet(JS::Realm&, Vector<JS::Handle<FontFace>> initial_faces);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
49
Userland/Libraries/LibWeb/CSS/FontFaceSet.idl
Normal file
49
Userland/Libraries/LibWeb/CSS/FontFaceSet.idl
Normal file
|
@ -0,0 +1,49 @@
|
|||
#import <CSS/FontFace.idl>
|
||||
|
||||
dictionary FontFaceSetLoadEventInit : EventInit {
|
||||
sequence<FontFace> fontfaces = [];
|
||||
};
|
||||
|
||||
// FIXME
|
||||
// [Exposed=(Window,Worker)]
|
||||
//interface FontFaceSetLoadEvent : Event {
|
||||
// constructor(CSSOMString type, optional FontFaceSetLoadEventInit eventInitDict = {});
|
||||
// [SameObject] readonly attribute FrozenArray<FontFace> fontfaces;
|
||||
//};
|
||||
|
||||
enum FontFaceSetLoadStatus { "loading", "loaded" };
|
||||
|
||||
// https://drafts.csswg.org/css-font-loading/#fontfaceset
|
||||
[Exposed=(Window,Worker)]
|
||||
interface FontFaceSet : EventTarget {
|
||||
constructor(sequence<FontFace> initialFaces);
|
||||
|
||||
// FIXME: setlike<FontFace>;
|
||||
FontFaceSet add(FontFace font);
|
||||
// FIXME: boolean delete(FontFace font);
|
||||
// FIXME: clear();
|
||||
|
||||
// events for when loading state changes
|
||||
// FIXME: attribute EventHandler onloading;
|
||||
// FIXME: attribute EventHandler onloadingdone;
|
||||
// FIXME: attribute EventHandler onloadingerror;
|
||||
|
||||
// check and start loads if appropriate
|
||||
// and fulfill promise when all loads complete
|
||||
// FIXME: Promise<sequence<FontFace>> load(CSSOMString font, optional CSSOMString text = " ");
|
||||
Promise<sequence<FontFace>> load(CSSOMString font, optional CSSOMString text = "");
|
||||
|
||||
// return whether all fonts in the fontlist are loaded
|
||||
// (does not initiate load if not available)
|
||||
// FIXME: boolean check(CSSOMString font, optional CSSOMString text = " ");
|
||||
|
||||
// async notification that font loading and layout operations are done
|
||||
// FIXME: readonly attribute Promise<FontFaceSet> ready;
|
||||
|
||||
// loading state, "loading" while one or more fonts loading, "loaded" otherwise
|
||||
// FIXME: readonly attribute FontFaceSetLoadStatus status;
|
||||
};
|
||||
|
||||
interface mixin FontFaceSource {
|
||||
readonly attribute FontFaceSet fonts;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue