mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
script: Implement the FontFaceSet
DOM API (#32576)
Add a skeleton implementation of FontFaceSet interface with support for resolving the `document.fonts.ready` Promise when the loading of web fonts is completed. This change exposes new failures in the web platform tests. These were ERROR before the change because `document.fonts.ready` caused a `ReferenceError` causing the tests to be aborted and they now FAIL: - /css/CSS2/linebox/vertical-align-top-bottom-001.html - /css/css-flexbox/flex-one-sets-flex-basis-to-zero-px.html - /css/css-fonts/generic-family-keywords-001.html - /css/css-fonts/math-script-level-and-math-style/math-script-level-004.tentative.html - /css/css-fonts/math-script-level-and-math-style/math-script-level-002.tentative.html - /css/css-text/text-autospace/text-autospace-ligature-001.html - /css/css-values/calc-size/calc-size-width.tentative.html These were TIMEOUT before the change because `document.fonts.ready` was a ReferenceError and the tests were asynchronous (reftest-wait). These now FAIL because the assertions are now executed after fonts are loaded: - /css/css-fonts/matching/fixed-stretch-style-over-weight.html - /css/css-fonts/matching/range-descriptor-reversed.html - /css/css-fonts/matching/stretch-distance-over-weight-distance.html - /css/css-fonts/matching/style-ranges-over-weight-direction.html - /css/css-fonts/variations/variable-box-font.html - /css/css-fonts/variations/variable-gpos-m2b.html - /css/css-fonts/variations/variable-gsub.html - /css/css-fonts/variations/variable-opsz-size-adjust.html - /css/css-position/sticky/position-sticky-change-top.html - /css/css-position/sticky/position-sticky-fixed-ancestor.html - /css/css-position/sticky/position-sticky-flexbox.html - /css/css-position/sticky/position-sticky-grid.html - /css/css-position/sticky/position-sticky-inline.html - /css/css-position/sticky/position-sticky-rendering.html - /css/css-position/sticky/position-sticky-stacking-context.html - /css/css-position/sticky/position-sticky-table-td-left.html - /css/css-position/sticky/position-sticky-table-td-right.html - /css/css-position/sticky/position-sticky-table-tfoot-bottom.html - /css/css-position/sticky/position-sticky-table-th-right.html - /css/css-position/sticky/position-sticky-table-thead-top.html - /css/css-position/sticky/position-sticky-table-tr-bottom.html - /css/css-position/sticky/position-sticky-table-tr-top.html - /css/css-position/sticky/position-sticky-writing-modes.html - /css/css-pseudo/marker-intrinsic-contribution-001.html - /css/css-text/hyphens/hyphens-character.html These tests now PASS due to this patch: * FAIL -> PASS - /html/canvas/element/text/2d.text.draw.fill.maxWidth.fontface.html - /html/canvas/element/text/2d.text.measure.width.empty.html * TIMEOUT -> PASS - /css/css-fonts/variations/font-descriptor-range-reversed.html - /css/css-fonts/variations/variable-opsz.html - /css/css-position/sticky/position-sticky-table-th-left.html * ERROR -> PASS - /css/css-fonts/generic-family-keywords-002.html - /css/css-fonts/generic-family-keywords-003.html * These two tests only PASS in Layout 2020: - /css/CSS2/positioning/inline-static-position-001.html - /css/cssom-view/getBoundingClientRect-empty-inline.html These two tests have subtests that PASS intermittenttly: - /fetch/metadata/generated/css-font-face.sub.tentative.html - /css/css-fonts/generic-family-keywords-001.html These tests are new TIMEOUTS that used to FAIL because `documents.fonts.ready` was undefined: - /resource-timing/TAO-match.html - /resource-timing/content-type.html - /resource-timing/nextHopProtocol-is-tao-protected.https.html The failure in `/resize-observer/change-layout-in-error.html` could be due to an issue in the ResizeObserver implementation that is now exposed with this change, but this needs more investigation. Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
7ea894774f
commit
a730469b70
95 changed files with 642 additions and 212 deletions
|
@ -1952,6 +1952,10 @@ impl Window {
|
|||
/// may happen in the only case a query reflow may bail out, that is, if the
|
||||
/// viewport size is not present). See #11223 for an example of that.
|
||||
pub fn reflow(&self, reflow_goal: ReflowGoal, reason: ReflowReason) -> bool {
|
||||
// Fetch the pending web fonts before layout, in case a font loads during
|
||||
// the layout.
|
||||
let pending_web_fonts = self.layout.borrow().waiting_for_web_fonts_to_load();
|
||||
|
||||
self.Document().ensure_safe_to_run_script_or_layout();
|
||||
let for_display = reflow_goal == ReflowGoal::Full;
|
||||
|
||||
|
@ -1980,6 +1984,24 @@ impl Window {
|
|||
);
|
||||
}
|
||||
|
||||
let document = self.Document();
|
||||
let font_face_set = document.Fonts();
|
||||
let is_ready_state_complete = document.ReadyState() == DocumentReadyState::Complete;
|
||||
|
||||
// From https://drafts.csswg.org/css-font-loading/#font-face-set-ready:
|
||||
// > 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
|
||||
// > - the document has pending layout operations which might cause the user agent to request
|
||||
// > a font, or which depend on recently-loaded fonts
|
||||
//
|
||||
// Thus, we are queueing promise resolution here. This reflow should have been triggered by
|
||||
// a "rendering opportunity" in `ScriptThread::handle_web_font_loaded, which should also
|
||||
// make sure a microtask checkpoint happens, triggering the promise callback.
|
||||
if !pending_web_fonts && is_ready_state_complete {
|
||||
font_face_set.fulfill_ready_promise_if_needed();
|
||||
}
|
||||
|
||||
// If writing a screenshot, check if the script has reached a state
|
||||
// where it's safe to write the image. This means that:
|
||||
// 1) The reflow is for display (otherwise it could be a query)
|
||||
|
@ -1989,8 +2011,6 @@ impl Window {
|
|||
// that this pipeline is ready to write the image (from the script thread
|
||||
// perspective at least).
|
||||
if self.prepare_for_screenshot && for_display {
|
||||
let document = self.Document();
|
||||
|
||||
// Checks if the html element has reftest-wait attribute present.
|
||||
// See http://testthewebforward.org/docs/reftests.html
|
||||
let html_element = document.GetDocumentElement();
|
||||
|
@ -1998,9 +2018,7 @@ impl Window {
|
|||
elem.has_class(&atom!("reftest-wait"), CaseSensitivity::CaseSensitive)
|
||||
});
|
||||
|
||||
let pending_web_fonts = self.layout.borrow().waiting_for_web_fonts_to_load();
|
||||
let has_sent_idle_message = self.has_sent_idle_message.get();
|
||||
let is_ready_state_complete = document.ReadyState() == DocumentReadyState::Complete;
|
||||
let pending_images = !self.pending_layout_images.borrow().is_empty();
|
||||
|
||||
if !has_sent_idle_message &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue