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

@ -21,13 +21,13 @@ use compositing_traits::{
};
use constellation_traits::{
AnimationTickType, CompositorHitTestResult, ConstellationMsg, PaintMetricEvent,
UntrustedNodeAddress, WindowSizeData, WindowSizeType,
UntrustedNodeAddress, WindowSizeType,
};
use crossbeam_channel::Sender;
use dpi::PhysicalSize;
use embedder_traits::{
Cursor, InputEvent, MouseButtonEvent, MouseMoveEvent, ScreenGeometry, ShutdownState,
TouchEventType,
TouchEventType, ViewportDetails,
};
use euclid::{Box2D, Point2D, Rect, Scale, Size2D, Transform3D};
use fnv::FnvHashMap;
@ -479,6 +479,17 @@ impl IOCompositor {
}
}
pub fn default_webview_viewport_details(&self) -> ViewportDetails {
// The division by 1 represents the page's default zoom of 100%,
// and gives us the appropriate CSSPixel type for the viewport.
let hidpi_scale_factor = self.window.hidpi_factor();
let scaled_viewport_size = self.rendering_context.size2d().to_f32() / hidpi_scale_factor;
ViewportDetails {
size: scaled_viewport_size / Scale::new(1.0),
hidpi_scale_factor: Scale::new(hidpi_scale_factor.0),
}
}
fn set_needs_repaint(&self, reason: RepaintReason) {
let mut needs_repaint = self.needs_repaint.get();
needs_repaint.insert(reason);
@ -1248,13 +1259,13 @@ impl IOCompositor {
) {
// The device pixel ratio used by the style system should include the scale from page pixels
// to device pixels, but not including any pinch zoom.
let device_pixel_ratio = self.device_pixels_per_page_pixel_not_including_page_zoom();
let initial_viewport = rect.size().to_f32() / device_pixel_ratio;
let msg = ConstellationMsg::WindowSize(
let hidpi_scale_factor = self.device_pixels_per_page_pixel_not_including_page_zoom();
let size = rect.size().to_f32() / hidpi_scale_factor;
let msg = ConstellationMsg::ChangeViewportDetails(
webview_id,
WindowSizeData {
device_pixel_ratio,
initial_viewport,
ViewportDetails {
size,
hidpi_scale_factor,
},
WindowSizeType::Resize,
);