script: Get the screen metrics from the WebViewDelegate instead of via the compositor (#38020)

Similar to #37960, previously, `AvailHeight`, `AvailWidth`, `Height`,
`Width` ask compositor for screen metrics. This PR moves the request to
embedder.

This simplifies code, and reduces workload of compositor, which is
busier most of time.

Testing: No behaviour change. Updated some tests. `Width/Height` matches
other browsers.

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-07-13 00:07:39 +08:00 committed by GitHub
parent d0a93a8b02
commit d38ffb82b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 79 additions and 102 deletions

View file

@ -6,9 +6,12 @@ use std::f32;
use app_units::{Au, MAX_AU, MIN_AU};
use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect, Size2D as UntypedSize2D};
use euclid::{Box2D, Length, Point2D, SideOffsets2D, Size2D, Vector2D};
use euclid::{Box2D, Length, Point2D, Scale, SideOffsets2D, Size2D, Vector2D};
use malloc_size_of_derive::MallocSizeOf;
use webrender_api::units::{FramebufferPixel, LayoutPoint, LayoutRect, LayoutSize};
use webrender_api::units::{
DeviceIntRect, DeviceIntSize, DevicePixel, FramebufferPixel, LayoutPoint, LayoutRect,
LayoutSize,
};
// Units for use with euclid::length and euclid::scale_factor.
@ -51,6 +54,22 @@ pub trait MaxRect {
fn max_rect() -> Self;
}
/// A helper function to convert a Device rect to CSS pixels.
pub fn convert_rect_to_css_pixel(
rect: DeviceIntRect,
scale: Scale<f32, DeviceIndependentPixel, DevicePixel>,
) -> DeviceIndependentIntRect {
(rect.to_f32() / scale).round().to_i32()
}
/// A helper function to convert a Device size to CSS pixels.
pub fn convert_size_to_css_pixel(
size: DeviceIntSize,
scale: Scale<f32, DeviceIndependentPixel, DevicePixel>,
) -> DeviceIndependentIntSize {
(size.to_f32() / scale).round().to_i32()
}
impl MaxRect for UntypedRect<Au> {
#[inline]
fn max_rect() -> Self {