Ensure layout/script always have a correct viewport size when a new pipeline is created.

This commit is contained in:
Josh Matthews 2019-11-06 16:13:43 -05:00
parent 2aa5ddf922
commit 91dfa354b1
10 changed files with 41 additions and 56 deletions

View file

@ -346,9 +346,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
// Set the size of the root layer.
compositor.update_zoom_transform();
// Tell the constellation about the initial window size.
compositor.send_window_size(WindowSizeType::Initial);
compositor
}
@ -638,8 +635,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
self.create_pipeline_details_for_frame_tree(&frame_tree);
self.send_window_size(WindowSizeType::Initial);
self.frame_tree_id.next();
}

View file

@ -2216,6 +2216,7 @@ where
new_pipeline_id: new_pipeline_id,
replace: None,
new_browsing_context_info: None,
window_size,
});
}
@ -2360,6 +2361,7 @@ where
is_private: is_private,
is_visible: is_visible,
}),
window_size,
});
}
@ -2531,6 +2533,10 @@ where
// https://github.com/rust-lang/rust/issues/59159
let browsing_context_size = browsing_context.size;
let browsing_context_is_visible = browsing_context.is_visible;
debug_assert_eq!(
browsing_context_size,
load_info.window_size.initial_viewport
);
// Create the new pipeline, attached to the parent and push to pending changes
self.new_pipeline(
@ -2552,6 +2558,7 @@ where
replace: replace,
// Browsing context for iframe already exists.
new_browsing_context_info: None,
window_size: load_info.window_size.initial_viewport,
});
}
@ -2610,6 +2617,7 @@ where
is_private: is_private,
is_visible: is_parent_visible,
}),
window_size: load_info.window_size.initial_viewport,
});
}
@ -2698,6 +2706,7 @@ where
is_private: is_opener_private,
is_visible: is_opener_visible,
}),
window_size: self.window_size.initial_viewport,
});
}
@ -2901,6 +2910,7 @@ where
replace,
// `load_url` is always invoked on an existing browsing context.
new_browsing_context_info: None,
window_size,
});
Some(new_pipeline_id)
},
@ -3220,6 +3230,7 @@ where
replace: Some(NeedsToReload::Yes(pipeline_id, load_data)),
// Browsing context must exist at this point.
new_browsing_context_info: None,
window_size,
});
return;
},
@ -3977,7 +3988,7 @@ where
change.top_level_browsing_context_id,
change.new_pipeline_id,
new_context_info.parent_pipeline_id,
self.window_size.initial_viewport, //XXXjdm is this valid?
change.window_size,
new_context_info.is_private,
new_context_info.is_visible,
);

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::browsingcontext::NewBrowsingContextInfo;
use euclid::Size2D;
use msg::constellation_msg::{
BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId,
};
@ -10,6 +11,7 @@ use script_traits::LoadData;
use servo_url::ServoUrl;
use std::cmp::PartialEq;
use std::{fmt, mem};
use style_traits::CSSPixel;
/// Represents the joint session history
/// https://html.spec.whatwg.org/multipage/#joint-session-history
@ -122,6 +124,9 @@ pub struct SessionHistoryChange {
/// Holds data for not-yet constructed browsing contexts that are not
/// easily available when they need to be constructed.
pub new_browsing_context_info: Option<NewBrowsingContextInfo>,
/// The size of the viewport for the browsing context.
pub window_size: Size2D<f32, CSSPixel>,
}
/// Represents a pipeline or discarded pipeline in a history entry.

View file

@ -86,13 +86,13 @@ use script_layout_interface::wrapper_traits::LayoutNode;
use script_traits::Painter;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{DrawAPaintImageResult, IFrameSizeMsg, PaintWorkletError, WindowSizeType};
use script_traits::{ScrollState, UntrustedNodeAddress};
use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use selectors::Element;
use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_config::opts;
use servo_config::pref;
use servo_geometry::{DeviceIndependentPixel, MaxRect};
use servo_geometry::MaxRect;
use servo_url::ServoUrl;
use std::borrow::ToOwned;
use std::cell::{Cell, RefCell};
@ -254,13 +254,6 @@ pub struct LayoutThread {
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows.
load_webfonts_synchronously: bool,
/// The initial request size of the window
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
/// The ratio of device pixels per px at the default scale.
/// If unspecified, will use the platform default setting.
device_pixels_per_px: Option<f32>,
/// Dumps the display list form after a layout.
dump_display_list: bool,
@ -311,8 +304,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
@ -360,8 +352,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics,
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
window_size,
dump_display_list,
dump_display_list_json,
dump_style_tree,
@ -531,8 +522,7 @@ impl LayoutThread {
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,
@ -542,12 +532,10 @@ impl LayoutThread {
trace_layout: bool,
dump_flow_tree: bool,
) -> LayoutThread {
// The device pixel ratio is incorrect (it does not have the hidpi value),
// but it will be set correctly when the initial reflow takes place.
let device = Device::new(
MediaType::screen(),
initial_window_size.to_f32() * Scale::new(1.0),
Scale::new(device_pixels_per_px.unwrap_or(1.0)),
window_size.initial_viewport,
window_size.device_pixel_ratio,
);
// Create the channel on which new animations can be sent.
@ -622,8 +610,6 @@ impl LayoutThread {
last_iframe_sizes: Default::default(),
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
dump_display_list,
dump_display_list_json,
dump_style_tree,
@ -954,8 +940,7 @@ impl LayoutThread {
info.paint_time_metrics,
info.layout_is_busy,
self.load_webfonts_synchronously,
self.initial_window_size,
self.device_pixels_per_px,
info.window_size,
self.dump_display_list,
self.dump_display_list_json,
self.dump_style_tree,

View file

@ -67,13 +67,12 @@ use script_layout_interface::rpc::{LayoutRPC, OffsetParentResponse, StyleRespons
use script_traits::Painter;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{DrawAPaintImageResult, PaintWorkletError};
use script_traits::{ScrollState, UntrustedNodeAddress};
use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use selectors::Element;
use servo_arc::Arc as ServoArc;
use servo_atoms::Atom;
use servo_config::opts;
use servo_config::pref;
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl;
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
@ -212,13 +211,6 @@ pub struct LayoutThread {
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows.
load_webfonts_synchronously: bool,
/// The initial request size of the window
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
/// The ratio of device pixels per px at the default scale.
/// If unspecified, will use the platform default setting.
device_pixels_per_px: Option<f32>,
/// Emits notifications when there is a relayout.
relayout_event: bool,
}
@ -246,8 +238,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
window_size: WindowSizeData,
_dump_display_list: bool,
_dump_display_list_json: bool,
_dump_style_tree: bool,
@ -294,8 +285,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics,
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
window_size,
relayout_event,
);
@ -457,16 +447,15 @@ impl LayoutThread {
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
window_size: WindowSizeData,
relayout_event: bool,
) -> LayoutThread {
// The device pixel ratio is incorrect (it does not have the hidpi value),
// but it will be set correctly when the initial reflow takes place.
let device = Device::new(
MediaType::screen(),
initial_window_size.to_f32() * Scale::new(1.0),
Scale::new(device_pixels_per_px.unwrap_or(1.0)),
window_size.initial_viewport,
window_size.device_pixel_ratio,
);
// Create the channel on which new animations can be sent.
@ -533,8 +522,6 @@ impl LayoutThread {
paint_time_metrics: paint_time_metrics,
busy,
load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
relayout_event,
}
}
@ -820,8 +807,7 @@ impl LayoutThread {
info.paint_time_metrics,
info.layout_is_busy,
self.load_webfonts_synchronously,
self.initial_window_size,
self.device_pixels_per_px,
info.window_size,
false, // dump_display_list
false, // dump_display_list_json
false, // dump_style_tree

View file

@ -10,7 +10,6 @@
// that these modules won't have to depend on layout.
use crossbeam_channel::{Receiver, Sender};
use euclid::Size2D;
use gfx::font_cache_thread::FontCacheThread;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use metrics::PaintTimeMetrics;
@ -19,8 +18,7 @@ use msg::constellation_msg::{BackgroundHangMonitorRegister, PipelineId};
use net_traits::image_cache::ImageCache;
use profile_traits::{mem, time};
use script_traits::LayoutMsg as ConstellationMsg;
use script_traits::{ConstellationControlMsg, LayoutControlMsg};
use servo_geometry::DeviceIndependentPixel;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, WindowSizeData};
use servo_url::ServoUrl;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
@ -48,8 +46,7 @@ pub trait LayoutThreadFactory {
paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>,
device_pixels_per_px: Option<f32>,
window_size: WindowSizeData,
dump_display_list: bool,
dump_display_list_json: bool,
dump_style_tree: bool,

View file

@ -190,6 +190,7 @@ impl HTMLIFrameElement {
load_data: load_data.clone(),
old_pipeline_id: old_pipeline_id,
sandbox: sandboxed,
window_size,
};
global_scope
.script_to_constellation_chan()
@ -216,6 +217,7 @@ impl HTMLIFrameElement {
load_data: load_data,
old_pipeline_id: old_pipeline_id,
sandbox: sandboxed,
window_size,
};
global_scope
.script_to_constellation_chan()

View file

@ -2392,6 +2392,7 @@ impl ScriptThread {
load_data.url.clone(),
),
layout_is_busy: layout_is_busy.clone(),
window_size,
});
// Pick a layout thread, any layout thread

View file

@ -230,4 +230,5 @@ pub struct LayoutThreadInit {
pub image_cache: Arc<dyn ImageCache>,
pub paint_time_metrics: PaintTimeMetrics,
pub layout_is_busy: Arc<AtomicBool>,
pub window_size: WindowSizeData,
}

View file

@ -739,6 +739,8 @@ pub struct IFrameLoadInfoWithData {
pub old_pipeline_id: Option<PipelineId>,
/// Sandbox type of this iframe
pub sandbox: IFrameSandboxState,
/// The initial viewport size for this iframe.
pub window_size: WindowSizeData,
}
/// Specifies whether the script or layout thread needs to be ticked for animation.
@ -760,7 +762,7 @@ pub struct ScrollState {
}
/// Data about the window size.
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub struct WindowSizeData {
/// The size of the initial layout viewport, before parsing an
/// <http://www.w3.org/TR/css-device-adapt/#initial-viewport>