layout: Do not require restyle information when not restyling (#37722)

This reduces the amount of work necessary when running layout, by making
restyle information optional in the `ReflowRequest`. When restyling
isn't
necessary, the option is `None`.

Testing: This shouldn't change any observable behavior and thus is
covered
by existing WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-06-27 10:08:29 +02:00 committed by GitHub
parent cbb0407ae6
commit 8e2ef5c248
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 67 additions and 47 deletions

View file

@ -395,17 +395,27 @@ pub struct ReflowResult {
pub iframe_sizes: IFrameSizes,
}
/// Information needed for a script-initiated reflow.
/// Information needed for a script-initiated reflow that requires a restyle
/// and reconstruction of box and fragment trees.
#[derive(Debug)]
pub struct ReflowRequest {
pub struct ReflowRequestRestyle {
/// Whether or not (and for what reasons) restyle needs to happen.
pub restyle_reason: RestyleReason,
/// The document node.
pub document: TrustedNodeAddress,
pub reason: RestyleReason,
/// The dirty root from which to restyle.
pub dirty_root: Option<TrustedNodeAddress>,
/// Whether the document's stylesheets have changed since the last script reflow.
pub stylesheets_changed: bool,
/// Restyle snapshot map.
pub pending_restyles: Vec<(TrustedNodeAddress, PendingRestyle)>,
}
/// Information needed for a script-initiated reflow.
#[derive(Debug)]
pub struct ReflowRequest {
/// The document node.
pub document: TrustedNodeAddress,
/// If a restyle is necessary, all of the informatio needed to do that restyle.
pub restyle: Option<ReflowRequestRestyle>,
/// The current [`ViewportDetails`] to use for this reflow.
pub viewport_details: ViewportDetails,
/// The goal of this reflow.
@ -414,8 +424,6 @@ pub struct ReflowRequest {
pub dom_count: u32,
/// The current window origin
pub origin: ImmutableOrigin,
/// Restyle snapshot map.
pub pending_restyles: Vec<(TrustedNodeAddress, PendingRestyle)>,
/// The current animation timeline value.
pub animation_timeline_value: f64,
/// The set of animations for this document.
@ -428,6 +436,14 @@ pub struct ReflowRequest {
pub highlighted_dom_node: Option<OpaqueNode>,
}
impl ReflowRequest {
pub fn stylesheets_changed(&self) -> bool {
self.restyle
.as_ref()
.is_some_and(|restyle| restyle.stylesheets_changed)
}
}
/// A pending restyle.
#[derive(Debug, Default, MallocSizeOf)]
pub struct PendingRestyle {