mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
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:
Notes:
github-actions[bot]
2026-02-24 15:45:53 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/d9f12da712d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8110
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user