LibWeb: Implement missing code for FontFace/FontFaceSet loading

As FontFaces are added or removed from a FontFaceSet, and as they load
or fail, the FontFaceSet moves them between a few different lists, and
updates its loading/loaded status. In the spec, this is how the
FontFaceSet.[[ReadyPromise]] gets fulfilled: When the document has
finished loading and FontFaceSet.[[LoadingFonts]] is empty, it resolves
the promise.

To support this, FontFace now keeps a set of FontFaceSets that it is
contained in.

This lets us remove the non-spec resolve_ready_promise() call in
EventLoop which was sometimes triggering before any fonts had attempted
to load.

As noted, there's a spec issue with the ready promise: If nothing
modifies the document's fonts, then it would never resolve. My ad-hoc
fix is to also switch the FontFaceSet to the loaded state if it is
empty, which appears to solve the issues but is not ideal.
This commit is contained in:
Sam Atkins
2026-02-20 12:20:20 +00:00
parent bca6f3e4b5
commit d9f12da712
Notes: github-actions[bot] 2026-02-24 15:45:53 +00:00
5 changed files with 194 additions and 29 deletions

View File

@@ -532,10 +532,13 @@ void EventLoop::update_the_rendering()
}
for (auto& document : docs) {
if (document->readiness() == HTML::DocumentReadyState::Complete && document->font_computer().number_of_css_font_faces_with_loading_in_progress() == 0) {
HTML::TemporaryExecutionContext context(document->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
document->fonts()->resolve_ready_promise();
}
// https://drafts.csswg.org/css-font-loading/#fontfaceset-pending-on-the-environment
// A FontFaceSet is pending on the environment if any of the following are true:
// - the document is still loading
// - the document has pending stylesheet requests
// FIXME: - the document has pending layout operations which might cause the user agent to request a font, or which depend on recently-loaded fonts
TemporaryExecutionContext context(document->realm(), TemporaryExecutionContext::CallbacksEnabled::Yes);
document->fonts()->set_is_pending_on_the_environment(document->readiness() == DocumentReadyState::Loading);
}
}