diff --git a/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp index 2491ab25e65..35fbd076bcc 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp +++ b/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp @@ -17,7 +17,8 @@ JS_DEFINE_ALLOCATOR(FontFaceSet); JS::NonnullGCPtr FontFaceSet::construct_impl(JS::Realm& realm, Vector> initial_faces) { - return realm.heap().allocate(realm, realm, move(initial_faces)); + auto promise = WebIDL::create_promise(realm); + return realm.heap().allocate(realm, realm, promise, move(initial_faces)); } JS::NonnullGCPtr FontFaceSet::create(JS::Realm& realm) @@ -25,9 +26,14 @@ JS::NonnullGCPtr FontFaceSet::create(JS::Realm& realm) return construct_impl(realm, {}); } -FontFaceSet::FontFaceSet(JS::Realm& realm, Vector>) +FontFaceSet::FontFaceSet(JS::Realm& realm, JS::NonnullGCPtr ready_promise, Vector>) : Bindings::PlatformObject(realm) + , m_ready_promise(ready_promise) { + // FIXME: Only set this after all the initial faces have been loaded + m_status = Bindings::FontFaceSetLoadStatus::Loaded; + // FIXME: Only resolve the promise after all the initial faces have been loaded + WebIDL::resolve_promise(realm, *m_ready_promise); } void FontFaceSet::initialize(JS::Realm& realm) @@ -37,6 +43,12 @@ void FontFaceSet::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(FontFaceSet); } +void FontFaceSet::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_ready_promise); +} + // https://drafts.csswg.org/css-font-loading/#dom-fontfaceset-add JS::NonnullGCPtr FontFaceSet::add(JS::Handle) { @@ -52,4 +64,10 @@ JS::ThrowCompletionOr> FontFaceSet::load(String co return verify_cast(*promise->promise()); } +// https://drafts.csswg.org/css-font-loading/#font-face-set-ready +JS::NonnullGCPtr FontFaceSet::ready() const +{ + return verify_cast(*m_ready_promise->promise()); +} + } diff --git a/Userland/Libraries/LibWeb/CSS/FontFaceSet.h b/Userland/Libraries/LibWeb/CSS/FontFaceSet.h index fdeaaff7b38..a6bb5ec1e6e 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFaceSet.h +++ b/Userland/Libraries/LibWeb/CSS/FontFaceSet.h @@ -6,13 +6,14 @@ #pragma once +#include #include #include namespace Web::CSS { class FontFaceSet final : public Bindings::PlatformObject { - WEB_PLATFORM_OBJECT(FontFace, Bindings::PlatformObject); + WEB_PLATFORM_OBJECT(FontFaceSet, Bindings::PlatformObject); JS_DECLARE_ALLOCATOR(FontFaceSet); public: @@ -23,10 +24,17 @@ public: JS::NonnullGCPtr add(JS::Handle face); JS::ThrowCompletionOr> load(String const& font, String const& text); + JS::NonnullGCPtr ready() const; + Bindings::FontFaceSetLoadStatus status() const { return m_status; } + private: - FontFaceSet(JS::Realm&, Vector> initial_faces); + FontFaceSet(JS::Realm&, JS::NonnullGCPtr ready_promise, Vector> initial_faces); virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; + + JS::GCPtr m_ready_promise; // [[ReadyPromise]] + Bindings::FontFaceSetLoadStatus m_status { Bindings::FontFaceSetLoadStatus::Loading }; }; } diff --git a/Userland/Libraries/LibWeb/CSS/FontFaceSet.idl b/Userland/Libraries/LibWeb/CSS/FontFaceSet.idl index 51f131e4331..7668f349c7f 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFaceSet.idl +++ b/Userland/Libraries/LibWeb/CSS/FontFaceSet.idl @@ -38,10 +38,10 @@ interface FontFaceSet : EventTarget { // FIXME: boolean check(CSSOMString font, optional CSSOMString text = " "); // async notification that font loading and layout operations are done - // FIXME: readonly attribute Promise ready; + readonly attribute Promise ready; // loading state, "loading" while one or more fonts loading, "loaded" otherwise - // FIXME: readonly attribute FontFaceSetLoadStatus status; + readonly attribute FontFaceSetLoadStatus status; }; interface mixin FontFaceSource {