mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
layout: Load Web fonts asynchronously.
Improves page load times significantly. Closes #7343.
This commit is contained in:
parent
9523283c14
commit
9bb6acd690
8 changed files with 216 additions and 35 deletions
|
@ -100,6 +100,7 @@ pub enum ReflowReason {
|
|||
DocumentLoaded,
|
||||
ImageLoaded,
|
||||
RequestAnimationFrame,
|
||||
WebFontLoaded,
|
||||
}
|
||||
|
||||
pub type ScrollPoint = Point2D<Au>;
|
||||
|
@ -1378,6 +1379,7 @@ fn debug_reflow_events(goal: &ReflowGoal, query_type: &ReflowQueryType, reason:
|
|||
ReflowReason::DocumentLoaded => "\tDocumentLoaded",
|
||||
ReflowReason::ImageLoaded => "\tImageLoaded",
|
||||
ReflowReason::RequestAnimationFrame => "\tRequestAnimationFrame",
|
||||
ReflowReason::WebFontLoaded => "\tWebFontLoaded",
|
||||
});
|
||||
|
||||
println!("{}", debug_msg);
|
||||
|
|
|
@ -51,6 +51,9 @@ pub enum Msg {
|
|||
/// Requests that the layout task render the next frame of all animations.
|
||||
TickAnimations,
|
||||
|
||||
/// Requests that the layout task reflow with a newly-loaded Web font.
|
||||
ReflowWithNewlyLoadedWebFont,
|
||||
|
||||
/// Updates the layout visible rects, affecting the area that display lists will be constructed
|
||||
/// for.
|
||||
SetVisibleRects(Vec<(LayerId, Rect<Au>)>),
|
||||
|
@ -76,6 +79,10 @@ pub enum Msg {
|
|||
/// Get the last epoch counter for this layout task.
|
||||
GetCurrentEpoch(IpcSender<Epoch>),
|
||||
|
||||
/// Asks the layout task whether any Web fonts have yet to load (if true, loads are pending;
|
||||
/// false otherwise).
|
||||
GetWebFontLoadState(IpcSender<bool>),
|
||||
|
||||
/// Creates a new layout task.
|
||||
///
|
||||
/// This basically exists to keep the script-layout dependency one-way.
|
||||
|
|
|
@ -942,6 +942,8 @@ impl ScriptTask {
|
|||
self.handle_webdriver_msg(pipeline_id, msg),
|
||||
ConstellationControlMsg::TickAllAnimations(pipeline_id) =>
|
||||
self.handle_tick_all_animations(pipeline_id),
|
||||
ConstellationControlMsg::WebFontLoaded(pipeline_id) =>
|
||||
self.handle_web_font_loaded(pipeline_id),
|
||||
ConstellationControlMsg::StylesheetLoadComplete(id, url, responder) => {
|
||||
responder.respond();
|
||||
self.handle_resource_loaded(id, LoadType::Stylesheet(url));
|
||||
|
@ -1478,6 +1480,15 @@ impl ScriptTask {
|
|||
document.r().run_the_animation_frame_callbacks();
|
||||
}
|
||||
|
||||
/// Handles a Web font being loaded. Does nothing if the page no longer exists.
|
||||
fn handle_web_font_loaded(&self, pipeline_id: PipelineId) {
|
||||
if let Some(page) = self.page.borrow().as_ref() {
|
||||
if let Some(page) = page.find(pipeline_id) {
|
||||
self.rebuild_and_force_reflow(&*page, ReflowReason::WebFontLoaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The entry point to document loading. Defines bindings, sets up the window and document
|
||||
/// objects, parses HTML and CSS, and kicks off initial layout.
|
||||
fn load(&self, metadata: Metadata, incomplete: InProgressLoad) -> Root<ServoHTMLParser> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue