script: Clean up Window::force_reflow a little (#37725)

- Move some of the image handling code to a separate function.
 - Move reflow event debugging into layout itself and use the `Debug`
   implementation to print the event.
 - A few other small cleanups

Testing: This should not change behavior and is thus 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 14:27:15 +02:00 committed by GitHub
parent a93d977020
commit 5e44582277
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 96 additions and 108 deletions

View file

@ -6,7 +6,7 @@ use std::cell::Cell;
use std::default::Default;
use base::id::BrowsingContextId;
use constellation_traits::{IFrameSizeMsg, WindowSizeType};
use constellation_traits::{IFrameSizeMsg, ScriptToConstellationMessage, WindowSizeType};
use embedder_traits::ViewportDetails;
use fnv::FnvHashMap;
use layout_api::IFrameSizes;
@ -15,7 +15,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::htmliframeelement::HTMLIFrameElement;
use crate::dom::node::{Node, ShadowIncluding};
use crate::dom::types::Document;
use crate::dom::types::{Document, Window};
use crate::script_thread::with_script_thread;
#[derive(JSTraceable, MallocSizeOf)]
@ -111,13 +111,14 @@ impl IFrameCollection {
/// message is only sent when the size actually changes.
pub(crate) fn handle_new_iframe_sizes_after_layout(
&mut self,
window: &Window,
new_iframe_sizes: IFrameSizes,
) -> Vec<IFrameSizeMsg> {
) {
if new_iframe_sizes.is_empty() {
return vec![];
return;
}
new_iframe_sizes
let size_messages: Vec<_> = new_iframe_sizes
.into_iter()
.filter_map(|(browsing_context_id, iframe_size)| {
// Batch resize message to any local `Pipeline`s now, rather than waiting for them
@ -151,7 +152,11 @@ impl IFrameCollection {
type_: size_type,
})
})
.collect()
.collect();
if !size_messages.is_empty() {
window.send_to_constellation(ScriptToConstellationMessage::IFrameSizes(size_messages));
}
}
pub(crate) fn iter(&self) -> impl Iterator<Item = DomRoot<HTMLIFrameElement>> + use<'_> {