constellation: Stop assuming that the viewport is shared by all WebViews (#36312)

The `Constellation` previously held a `window_size` member, but this
assumes that all `WebView`s have the same size. This change removes that
assumption as well as making sure that all `WebView`s pass their size
and HiDIP scaling to the `Constellation` when they are created.

In addition

- `WindowSizeData` is renamed to `ViewportDetails`, as it was
holding more than just the size and it didn't necessarily correspond to
  a "window." It's used for tracking viewport data, whether for an
  `<iframe>` or the main `WebView` viewport.
- `ViewportDetails` is stored more consistently so that conceptually an
  `<iframe>` can also have its own HiDPI scaling. This isn't something
  we necessarily want, but it makes everything conceptually simpler.

The goal with this change is to work toward allowing per-`WebView` HiDPI
scaling and sizing. There are still some corresponding changes in the
compositor to make that happen, but they will in a subsequent change.

Testing: This is covered by existing tests. There should be no behavior
changes.
Fixes: This is part of #36232.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-04 19:06:34 +02:00 committed by GitHub
parent 7c89e24f34
commit fb344ba4e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 272 additions and 256 deletions

View file

@ -36,7 +36,7 @@ use base::cross_process_instant::CrossProcessInstant;
use base::id::{BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, WebViewId};
use canvas_traits::webgl::WebGLPipeline;
use chrono::{DateTime, Local};
use constellation_traits::{CompositorHitTestResult, ScrollState, WindowSizeData, WindowSizeType};
use constellation_traits::{CompositorHitTestResult, ScrollState, WindowSizeType};
use crossbeam_channel::unbounded;
use devtools_traits::{
CSSError, DevtoolScriptControlMsg, DevtoolsPageInfo, NavigationState,
@ -44,7 +44,7 @@ use devtools_traits::{
};
use embedder_traits::user_content_manager::UserContentManager;
use embedder_traits::{
EmbedderMsg, InputEvent, MediaSessionActionType, Theme, WebDriverScriptCommand,
EmbedderMsg, InputEvent, MediaSessionActionType, Theme, ViewportDetails, WebDriverScriptCommand,
};
use euclid::default::Rect;
use fonts::{FontContext, SystemFontServiceProxy};
@ -401,7 +401,7 @@ impl ScriptThreadFactory for ScriptThread {
let parent_info = state.parent_info;
let opener = state.opener;
let memory_profiler_sender = state.memory_profiler_sender.clone();
let window_size = state.window_size;
let viewport_details = state.viewport_details;
let script_thread = ScriptThread::new(state, layout_factory, system_font_service);
@ -418,7 +418,7 @@ impl ScriptThreadFactory for ScriptThread {
webview_id,
parent_info,
opener,
window_size,
viewport_details,
origin,
load_data,
));
@ -2337,18 +2337,18 @@ impl ScriptThread {
pub(crate) fn handle_resize_message(
&self,
id: PipelineId,
size: WindowSizeData,
viewport_details: ViewportDetails,
size_type: WindowSizeType,
) {
self.profile_event(ScriptThreadEventCategory::Resize, Some(id), || {
let window = self.documents.borrow().find_window(id);
if let Some(ref window) = window {
window.add_resize_event(size, size_type);
window.add_resize_event(viewport_details, size_type);
return;
}
let mut loads = self.incomplete_loads.borrow_mut();
if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
load.window_size = size;
load.viewport_details = viewport_details;
}
})
}
@ -2390,7 +2390,7 @@ impl ScriptThread {
webview_id,
opener,
load_data,
window_size,
viewport_details,
} = new_layout_info;
// Kick off the fetch for the new resource.
@ -2401,7 +2401,7 @@ impl ScriptThread {
webview_id,
parent_info,
opener,
window_size,
viewport_details,
origin,
load_data,
);
@ -2647,10 +2647,10 @@ impl ScriptThread {
}
/// Window was resized, but this script was not active, so don't reflow yet
fn handle_resize_inactive_msg(&self, id: PipelineId, new_size: WindowSizeData) {
fn handle_resize_inactive_msg(&self, id: PipelineId, new_viewport_details: ViewportDetails) {
let window = self.documents.borrow().find_window(id)
.expect("ScriptThread: received a resize msg for a pipeline not in this script thread. This is a bug.");
window.set_window_size(new_size);
window.set_viewport_details(new_viewport_details);
}
/// We have received notification that the response associated with a load has completed.
@ -3066,7 +3066,7 @@ impl ScriptThread {
font_context: font_context.clone(),
time_profiler_chan: self.senders.time_profiler_sender.clone(),
compositor_api: self.compositor_api.clone(),
window_size: incomplete.window_size,
viewport_details: incomplete.viewport_details,
};
// Create the window and document objects.
@ -3088,7 +3088,7 @@ impl ScriptThread {
self.senders.constellation_sender.clone(),
incomplete.pipeline_id,
incomplete.parent_info,
incomplete.window_size,
incomplete.viewport_details,
origin.clone(),
final_url.clone(),
incomplete.navigation_start,