mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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:
parent
7c89e24f34
commit
fb344ba4e9
26 changed files with 272 additions and 256 deletions
|
@ -6,13 +6,11 @@ use std::cell::Cell;
|
|||
use std::default::Default;
|
||||
|
||||
use base::id::BrowsingContextId;
|
||||
use constellation_traits::{WindowSizeData, WindowSizeType};
|
||||
use euclid::{Scale, Size2D};
|
||||
use constellation_traits::WindowSizeType;
|
||||
use embedder_traits::ViewportDetails;
|
||||
use fnv::FnvHashMap;
|
||||
use script_layout_interface::IFrameSizes;
|
||||
use script_traits::IFrameSizeMsg;
|
||||
use style_traits::CSSPixel;
|
||||
use webrender_api::units::DevicePixel;
|
||||
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
|
@ -26,7 +24,7 @@ use crate::script_thread::with_script_thread;
|
|||
pub(crate) struct IFrame {
|
||||
pub(crate) element: Dom<HTMLIFrameElement>,
|
||||
#[no_trace]
|
||||
pub(crate) size: Option<Size2D<f32, CSSPixel>>,
|
||||
pub(crate) size: Option<ViewportDetails>,
|
||||
}
|
||||
|
||||
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||
|
@ -98,11 +96,11 @@ impl IFrameCollection {
|
|||
|
||||
/// Set the size of an `<iframe>` in the collection given its `BrowsingContextId` and
|
||||
/// the new size. Returns the old size.
|
||||
pub(crate) fn set_size(
|
||||
pub(crate) fn set_viewport_details(
|
||||
&mut self,
|
||||
browsing_context_id: BrowsingContextId,
|
||||
new_size: Size2D<f32, CSSPixel>,
|
||||
) -> Option<Size2D<f32, CSSPixel>> {
|
||||
new_size: ViewportDetails,
|
||||
) -> Option<ViewportDetails> {
|
||||
self.get_mut(browsing_context_id)
|
||||
.expect("Tried to set a size for an unknown <iframe>")
|
||||
.size
|
||||
|
@ -115,7 +113,6 @@ impl IFrameCollection {
|
|||
pub(crate) fn handle_new_iframe_sizes_after_layout(
|
||||
&mut self,
|
||||
new_iframe_sizes: IFrameSizes,
|
||||
device_pixel_ratio: Scale<f32, CSSPixel, DevicePixel>,
|
||||
) -> Vec<IFrameSizeMsg> {
|
||||
if new_iframe_sizes.is_empty() {
|
||||
return vec![];
|
||||
|
@ -123,37 +120,35 @@ impl IFrameCollection {
|
|||
|
||||
new_iframe_sizes
|
||||
.into_iter()
|
||||
.filter_map(|(browsing_context_id, size)| {
|
||||
.filter_map(|(browsing_context_id, iframe_size)| {
|
||||
// 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 new_size = size.size;
|
||||
let viewport_details = iframe_size.viewport_details;
|
||||
with_script_thread(|script_thread| {
|
||||
script_thread.handle_resize_message(
|
||||
size.pipeline_id,
|
||||
WindowSizeData {
|
||||
initial_viewport: new_size,
|
||||
device_pixel_ratio,
|
||||
},
|
||||
iframe_size.pipeline_id,
|
||||
viewport_details,
|
||||
WindowSizeType::Resize,
|
||||
);
|
||||
});
|
||||
|
||||
let old_size = self.set_size(browsing_context_id, new_size);
|
||||
let old_viewport_details =
|
||||
self.set_viewport_details(browsing_context_id, viewport_details);
|
||||
// The `Constellation` should be up-to-date even when the in-ScriptThread pipelines
|
||||
// might not be.
|
||||
if old_size == Some(size.size) {
|
||||
if old_viewport_details == Some(viewport_details) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let size_type = match old_size {
|
||||
let size_type = match old_viewport_details {
|
||||
Some(_) => WindowSizeType::Resize,
|
||||
None => WindowSizeType::Initial,
|
||||
};
|
||||
|
||||
Some(IFrameSizeMsg {
|
||||
browsing_context_id,
|
||||
size: new_size,
|
||||
size: viewport_details,
|
||||
type_: size_type,
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue