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

View file

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

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::browsingcontext::NewBrowsingContextInfo; use crate::browsingcontext::NewBrowsingContextInfo;
use euclid::Size2D;
use msg::constellation_msg::{ use msg::constellation_msg::{
BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId, BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId,
}; };
@ -10,6 +11,7 @@ use script_traits::LoadData;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::cmp::PartialEq; use std::cmp::PartialEq;
use std::{fmt, mem}; use std::{fmt, mem};
use style_traits::CSSPixel;
/// Represents the joint session history /// Represents the joint session history
/// https://html.spec.whatwg.org/multipage/#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 /// Holds data for not-yet constructed browsing contexts that are not
/// easily available when they need to be constructed. /// easily available when they need to be constructed.
pub new_browsing_context_info: Option<NewBrowsingContextInfo>, 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. /// 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::Painter;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg}; use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{DrawAPaintImageResult, IFrameSizeMsg, PaintWorkletError, WindowSizeType}; use script_traits::{DrawAPaintImageResult, IFrameSizeMsg, PaintWorkletError, WindowSizeType};
use script_traits::{ScrollState, UntrustedNodeAddress}; use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use selectors::Element; use selectors::Element;
use servo_arc::Arc as ServoArc; use servo_arc::Arc as ServoArc;
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_config::opts; use servo_config::opts;
use servo_config::pref; use servo_config::pref;
use servo_geometry::{DeviceIndependentPixel, MaxRect}; use servo_geometry::MaxRect;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -254,13 +254,6 @@ pub struct LayoutThread {
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows. /// Load web fonts synchronously to avoid non-deterministic network-driven reflows.
load_webfonts_synchronously: bool, 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. /// Dumps the display list form after a layout.
dump_display_list: bool, dump_display_list: bool,
@ -311,8 +304,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool, load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>, window_size: WindowSizeData,
device_pixels_per_px: Option<f32>,
dump_display_list: bool, dump_display_list: bool,
dump_display_list_json: bool, dump_display_list_json: bool,
dump_style_tree: bool, dump_style_tree: bool,
@ -360,8 +352,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics, paint_time_metrics,
busy, busy,
load_webfonts_synchronously, load_webfonts_synchronously,
initial_window_size, window_size,
device_pixels_per_px,
dump_display_list, dump_display_list,
dump_display_list_json, dump_display_list_json,
dump_style_tree, dump_style_tree,
@ -531,8 +522,7 @@ impl LayoutThread {
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool, load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>, window_size: WindowSizeData,
device_pixels_per_px: Option<f32>,
dump_display_list: bool, dump_display_list: bool,
dump_display_list_json: bool, dump_display_list_json: bool,
dump_style_tree: bool, dump_style_tree: bool,
@ -542,12 +532,10 @@ impl LayoutThread {
trace_layout: bool, trace_layout: bool,
dump_flow_tree: bool, dump_flow_tree: bool,
) -> LayoutThread { ) -> 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( let device = Device::new(
MediaType::screen(), MediaType::screen(),
initial_window_size.to_f32() * Scale::new(1.0), window_size.initial_viewport,
Scale::new(device_pixels_per_px.unwrap_or(1.0)), window_size.device_pixel_ratio,
); );
// Create the channel on which new animations can be sent. // Create the channel on which new animations can be sent.
@ -622,8 +610,6 @@ impl LayoutThread {
last_iframe_sizes: Default::default(), last_iframe_sizes: Default::default(),
busy, busy,
load_webfonts_synchronously, load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
dump_display_list, dump_display_list,
dump_display_list_json, dump_display_list_json,
dump_style_tree, dump_style_tree,
@ -954,8 +940,7 @@ impl LayoutThread {
info.paint_time_metrics, info.paint_time_metrics,
info.layout_is_busy, info.layout_is_busy,
self.load_webfonts_synchronously, self.load_webfonts_synchronously,
self.initial_window_size, info.window_size,
self.device_pixels_per_px,
self.dump_display_list, self.dump_display_list,
self.dump_display_list_json, self.dump_display_list_json,
self.dump_style_tree, 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::Painter;
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg}; use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
use script_traits::{DrawAPaintImageResult, PaintWorkletError}; use script_traits::{DrawAPaintImageResult, PaintWorkletError};
use script_traits::{ScrollState, UntrustedNodeAddress}; use script_traits::{ScrollState, UntrustedNodeAddress, WindowSizeData};
use selectors::Element; use selectors::Element;
use servo_arc::Arc as ServoArc; use servo_arc::Arc as ServoArc;
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_config::opts; use servo_config::opts;
use servo_config::pref; use servo_config::pref;
use servo_geometry::DeviceIndependentPixel;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap; use std::collections::HashMap;
@ -212,13 +211,6 @@ pub struct LayoutThread {
/// Load web fonts synchronously to avoid non-deterministic network-driven reflows. /// Load web fonts synchronously to avoid non-deterministic network-driven reflows.
load_webfonts_synchronously: bool, 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. /// Emits notifications when there is a relayout.
relayout_event: bool, relayout_event: bool,
} }
@ -246,8 +238,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool, load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>, window_size: WindowSizeData,
device_pixels_per_px: Option<f32>,
_dump_display_list: bool, _dump_display_list: bool,
_dump_display_list_json: bool, _dump_display_list_json: bool,
_dump_style_tree: bool, _dump_style_tree: bool,
@ -294,8 +285,7 @@ impl LayoutThreadFactory for LayoutThread {
paint_time_metrics, paint_time_metrics,
busy, busy,
load_webfonts_synchronously, load_webfonts_synchronously,
initial_window_size, window_size,
device_pixels_per_px,
relayout_event, relayout_event,
); );
@ -457,16 +447,15 @@ impl LayoutThread {
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
busy: Arc<AtomicBool>, busy: Arc<AtomicBool>,
load_webfonts_synchronously: bool, load_webfonts_synchronously: bool,
initial_window_size: Size2D<u32, DeviceIndependentPixel>, window_size: WindowSizeData,
device_pixels_per_px: Option<f32>,
relayout_event: bool, relayout_event: bool,
) -> LayoutThread { ) -> LayoutThread {
// The device pixel ratio is incorrect (it does not have the hidpi value), // 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. // but it will be set correctly when the initial reflow takes place.
let device = Device::new( let device = Device::new(
MediaType::screen(), MediaType::screen(),
initial_window_size.to_f32() * Scale::new(1.0), window_size.initial_viewport,
Scale::new(device_pixels_per_px.unwrap_or(1.0)), window_size.device_pixel_ratio,
); );
// Create the channel on which new animations can be sent. // Create the channel on which new animations can be sent.
@ -533,8 +522,6 @@ impl LayoutThread {
paint_time_metrics: paint_time_metrics, paint_time_metrics: paint_time_metrics,
busy, busy,
load_webfonts_synchronously, load_webfonts_synchronously,
initial_window_size,
device_pixels_per_px,
relayout_event, relayout_event,
} }
} }
@ -820,8 +807,7 @@ impl LayoutThread {
info.paint_time_metrics, info.paint_time_metrics,
info.layout_is_busy, info.layout_is_busy,
self.load_webfonts_synchronously, self.load_webfonts_synchronously,
self.initial_window_size, info.window_size,
self.device_pixels_per_px,
false, // dump_display_list false, // dump_display_list
false, // dump_display_list_json false, // dump_display_list_json
false, // dump_style_tree false, // dump_style_tree

View file

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

View file

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

View file

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

View file

@ -230,4 +230,5 @@ pub struct LayoutThreadInit {
pub image_cache: Arc<dyn ImageCache>, pub image_cache: Arc<dyn ImageCache>,
pub paint_time_metrics: PaintTimeMetrics, pub paint_time_metrics: PaintTimeMetrics,
pub layout_is_busy: Arc<AtomicBool>, 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>, pub old_pipeline_id: Option<PipelineId>,
/// Sandbox type of this iframe /// Sandbox type of this iframe
pub sandbox: IFrameSandboxState, 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. /// 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. /// Data about the window size.
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub struct WindowSizeData { pub struct WindowSizeData {
/// The size of the initial layout viewport, before parsing an /// The size of the initial layout viewport, before parsing an
/// <http://www.w3.org/TR/css-device-adapt/#initial-viewport> /// <http://www.w3.org/TR/css-device-adapt/#initial-viewport>