script: Manage <iframe> sizes in Window (#34643)

Manage `<iframe>` size updates in `Window`. In addition to removing
duplicated code, this will allow setting `<iframe>` sizes synchronously
on child `Pipeline`s of the same origin in the script process in a
followup change. The goal is remove flakiness from `<iframe>` sizing.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-16 16:05:33 +01:00 committed by GitHub
parent eb82161a8a
commit 3e052676ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 165 additions and 200 deletions

View file

@ -46,8 +46,6 @@ pub struct IFrameSizeMsg {
/// Messages from the layout to the constellation.
#[derive(Deserialize, Serialize)]
pub enum LayoutMsg {
/// Inform the constellation of the size of the iframe's viewport.
IFrameSizes(Vec<IFrameSizeMsg>),
/// Requests that the constellation inform the compositor that it needs to record
/// the time when the frame with the given ID (epoch) is painted.
PendingPaintMetric(PipelineId, Epoch),
@ -57,7 +55,6 @@ impl fmt::Debug for LayoutMsg {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use self::LayoutMsg::*;
let variant = match *self {
IFrameSizes(..) => "IFrameSizes",
PendingPaintMetric(..) => "PendingPaintMetric",
};
write!(formatter, "LayoutMsg::{}", variant)
@ -260,6 +257,8 @@ pub enum ScriptMsg {
GetWebGPUChan(IpcSender<Option<WebGPU>>),
/// Notify the constellation of a pipeline's document's title.
TitleChanged(PipelineId, String),
/// Notify the constellation that the size of some `<iframe>`s has changed.
IFrameSizes(Vec<IFrameSizeMsg>),
}
impl fmt::Debug for ScriptMsg {
@ -320,6 +319,7 @@ impl fmt::Debug for ScriptMsg {
#[cfg(feature = "webgpu")]
GetWebGPUChan(..) => "GetWebGPUChan",
TitleChanged(..) => "TitleChanged",
IFrameSizes(..) => "IFramSizes",
};
write!(formatter, "ScriptMsg::{}", variant)
}

View file

@ -18,6 +18,7 @@ atomic_refcell = { workspace = true }
canvas_traits = { workspace = true }
crossbeam-channel = { workspace = true }
euclid = { workspace = true }
fnv = { workspace = true }
fonts = { path = "../../fonts" }
fonts_traits = { workspace = true }
html5ever = { workspace = true }

View file

@ -23,6 +23,7 @@ use base::Epoch;
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use euclid::default::{Point2D, Rect};
use euclid::Size2D;
use fnv::FnvHashMap;
use fonts::SystemFontServiceProxy;
use ipc_channel::ipc::IpcSender;
use libc::c_void;
@ -257,10 +258,6 @@ pub trait Layout {
fn query_content_boxes(&self, node: OpaqueNode) -> Vec<Rect<Au>>;
fn query_client_rect(&self, node: OpaqueNode) -> Rect<i32>;
fn query_element_inner_outer_text(&self, node: TrustedNodeAddress) -> String;
fn query_inner_window_dimension(
&self,
context: BrowsingContextId,
) -> Option<Size2D<f32, CSSPixel>>;
fn query_nodes_from_point(
&self,
point: Point2D<f32>,
@ -400,11 +397,24 @@ pub struct Reflow {
pub page_clip_rect: Rect<Au>,
}
#[derive(Clone, Debug, MallocSizeOf)]
pub struct IFrameSize {
pub browsing_context_id: BrowsingContextId,
pub pipeline_id: PipelineId,
pub size: Size2D<f32, CSSPixel>,
}
pub type IFrameSizes = FnvHashMap<BrowsingContextId, IFrameSize>;
/// Information derived from a layout pass that needs to be returned to the script thread.
#[derive(Debug, Default)]
pub struct ReflowResult {
/// The list of images that were encountered that are in progress.
pub pending_images: Vec<PendingImage>,
/// The list of iframes in this layout and their sizes, used in order
/// to communicate them with the Constellation and also the `Window`
/// element of their content pages.
pub iframe_sizes: IFrameSizes,
}
/// Information needed for a script-initiated reflow.