layout: Allow same ScriptThread <iframe>s to be resized synchronously (#34656)

Post layout, when a `Window` has all of the new `<iframe>` sizes, size
any `Window`s for `Pipeline`s in the same `ScriptThread` synchronously.
This ensures that when laying out from the outermost frame to the
innermost frames, the frames sizes are set properly.

There is still an issue where a non-same-`ScriptThread` `<iframe>` sits
in between two `<iframe>`s of the same origin. According to the
specification these frames should all be synchrnously laid out --
something quite difficult in Servo. This is issue #34655.

This is the first change in a series of changes to improve the
consistency of `<iframe>` loading and sizing.

Fixes #14719.
Fixes #24569.
Fixes #24571.
Fixes #25269.
Fixes #25275.
Fixes #25285.
Fixes #30571.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-12-17 10:37:52 +01:00 committed by GitHub
parent 1e17dfdf31
commit 0a01d06968
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 56 additions and 80 deletions

View file

@ -151,7 +151,7 @@ use crate::script_runtime::{
CanGc, CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptPort, ScriptThreadEventCategory,
};
use crate::script_thread::{
ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg, ScriptThread,
with_script_thread, ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg, ScriptThread,
SendableMainThreadScriptChan,
};
use crate::task_manager::TaskManager;
@ -380,6 +380,8 @@ pub struct Window {
/// Sizes of the various `<iframes>` that we might have on this [`Window`].
/// This is used to:
/// - Let same-`ScriptThread` `<iframe>`s know synchronously when their
/// size has changed, ensuring that the next layout has the right size.
/// - Send the proper size for the `<iframe>` during new-Pipeline creation
/// when the `src` attribute changes.
/// - Let the `Constellation` know about `BrowsingContext` (one per `<iframe>`)
@ -1982,6 +1984,24 @@ impl Window {
return;
}
// Batch resize message to any local `Pipeline`s now, rather than waiting for them
// to filter asynchronously through the `Constellation`. This allows the new value
// to be reflected immediately in layout.
let device_pixel_ratio = self.device_pixel_ratio();
with_script_thread(|script_thread| {
for iframe_size in new_iframe_sizes.values() {
script_thread.handle_resize_message(
iframe_size.pipeline_id,
WindowSizeData {
initial_viewport: iframe_size.size,
device_pixel_ratio,
},
// TODO: This might send an extra resize event. This can fixed by explicitly
// supporting `<iframe>` creation when the size isn't known yet.
WindowSizeType::Resize,
);
}
});
// Send asynchronous updates to `Constellation.`
let size_messages: Vec<_> = new_iframe_sizes
.iter()