compositor: Request reflow when doing a page zooming (#38166)

Request a reflow when doing page zoom and only modify the scaling of the
WebView scene after the first root pipeline display list with the new
zoom is ready. In addition:

  - store zoom limits in `Scale` types
  - send `ViewportDetails` along with the display list so that we can
    detect when the root pipeline scale is ready.

Testing: This is quite hard to test as it requires verification that
contents are zoomed appropriately at the right time.
Fixes: #38091.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-07-29 12:04:37 +02:00 committed by GitHub
parent 3d2f0d1be5
commit 8d5faa9bf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 111 additions and 44 deletions

View file

@ -32,6 +32,7 @@ malloc_size_of_derive = { workspace = true }
profile_traits = { path = '../profile' }
raw-window-handle = { version = "0.6" }
serde = { workspace = true }
servo_geometry = { path = "../../geometry" }
smallvec = { workspace = true }
strum_macros = { workspace = true }
stylo = { workspace = true }

View file

@ -9,7 +9,7 @@ use std::collections::HashMap;
use base::id::ScrollTreeNodeId;
use base::print_tree::PrintTree;
use bitflags::bitflags;
use embedder_traits::Cursor;
use embedder_traits::{Cursor, ViewportDetails};
use euclid::SideOffsets2D;
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
@ -486,8 +486,9 @@ pub struct CompositorDisplayListInfo {
/// The WebRender [PipelineId] of this display list.
pub pipeline_id: PipelineId,
/// The size of the viewport that this display list renders into.
pub viewport_size: LayoutSize,
/// The [`ViewportDetails`] that describe the viewport in the script/layout thread at
/// the time this display list was created.
pub viewport_details: ViewportDetails,
/// The size of this display list's content.
pub content_size: LayoutSize,
@ -526,7 +527,7 @@ impl CompositorDisplayListInfo {
/// Create a new CompositorDisplayListInfo with the root reference frame
/// and scroll frame already added to the scroll tree.
pub fn new(
viewport_size: LayoutSize,
viewport_details: ViewportDetails,
content_size: LayoutSize,
pipeline_id: PipelineId,
epoch: Epoch,
@ -548,7 +549,10 @@ impl CompositorDisplayListInfo {
SpatialTreeNodeInfo::Scroll(ScrollableNodeInfo {
external_id: ExternalScrollId(0, pipeline_id),
content_rect: LayoutRect::from_origin_and_size(LayoutPoint::zero(), content_size),
clip_rect: LayoutRect::from_origin_and_size(LayoutPoint::zero(), viewport_size),
clip_rect: LayoutRect::from_origin_and_size(
LayoutPoint::zero(),
viewport_details.layout_size(),
),
scroll_sensitivity: viewport_scroll_sensitivity,
offset: LayoutVector2D::zero(),
}),
@ -556,7 +560,7 @@ impl CompositorDisplayListInfo {
CompositorDisplayListInfo {
pipeline_id,
viewport_size,
viewport_details,
content_size,
epoch,
hit_test_info: Default::default(),

View file

@ -7,17 +7,19 @@
use std::collections::HashMap;
use std::str::FromStr;
use euclid::default::Scale;
use euclid::Scale;
use serde::{Deserialize, Serialize};
use servo_geometry::DeviceIndependentPixel;
use style_traits::CSSPixel;
/// Default viewport constraints
///
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#initial-scale>
pub const MIN_ZOOM: f32 = 0.1;
pub const MIN_PAGE_ZOOM: Scale<f32, CSSPixel, DeviceIndependentPixel> = Scale::new(0.1);
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#initial-scale>
pub const MAX_ZOOM: f32 = 10.0;
pub const MAX_PAGE_ZOOM: Scale<f32, CSSPixel, DeviceIndependentPixel> = Scale::new(10.0);
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#initial-scale>
pub const DEFAULT_ZOOM: f32 = 1.0;
pub const DEFAULT_PAGE_ZOOM: Scale<f32, CSSPixel, DeviceIndependentPixel> = Scale::new(1.0);
/// <https://drafts.csswg.org/css-viewport/#parsing-algorithm>
const SEPARATORS: [char; 2] = [',', ';']; // Comma (0x2c) and Semicolon (0x3b)
@ -35,15 +37,15 @@ pub struct ViewportDescription {
// TODO: height Needs to be implemented
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#initial-scale>
/// the zoom level when the page is first loaded
pub initial_scale: Scale<f32>,
pub initial_scale: Scale<f32, CSSPixel, DeviceIndependentPixel>,
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#minimum_scale>
/// how much zoom out is allowed on the page.
pub minimum_scale: Scale<f32>,
pub minimum_scale: Scale<f32, CSSPixel, DeviceIndependentPixel>,
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#maximum_scale>
/// how much zoom in is allowed on the page
pub maximum_scale: Scale<f32>,
pub maximum_scale: Scale<f32, CSSPixel, DeviceIndependentPixel>,
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#user_scalable>
/// whether zoom in and zoom out actions are allowed on the page
@ -85,9 +87,9 @@ impl TryFrom<&str> for UserScalable {
impl Default for ViewportDescription {
fn default() -> Self {
ViewportDescription {
initial_scale: Scale::new(DEFAULT_ZOOM),
minimum_scale: Scale::new(MIN_ZOOM),
maximum_scale: Scale::new(MAX_ZOOM),
initial_scale: DEFAULT_PAGE_ZOOM,
minimum_scale: MIN_PAGE_ZOOM,
maximum_scale: MAX_PAGE_ZOOM,
user_scalable: UserScalable::Yes,
}
}
@ -126,7 +128,9 @@ impl ViewportDescription {
}
/// Parses a viewport zoom value.
fn parse_viewport_value_as_zoom(value: &str) -> Option<Scale<f32>> {
fn parse_viewport_value_as_zoom(
value: &str,
) -> Option<Scale<f32, CSSPixel, DeviceIndependentPixel>> {
value
.to_lowercase()
.as_str()

View file

@ -38,7 +38,7 @@ use style::queries::values::PrefersColorScheme;
use style_traits::CSSPixel;
use url::Url;
use uuid::Uuid;
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel, LayoutSize};
pub use crate::input_events::*;
pub use crate::webdriver::*;
@ -319,6 +319,14 @@ pub struct ViewportDetails {
pub hidpi_scale_factor: Scale<f32, CSSPixel, DevicePixel>,
}
impl ViewportDetails {
/// Convert this [`ViewportDetails`] size to a [`LayoutSize`]. This is the same numerical
/// value as [`Self::size`], because a `LayoutPixel` is the same as a `CSSPixel`.
pub fn layout_size(&self) -> LayoutSize {
Size2D::from_untyped(self.size.to_untyped())
}
}
/// Unlike [`ScreenGeometry`], the data is in device-independent pixels
/// to be used by DOM APIs
#[derive(Default, Deserialize, Serialize)]