mirror of
https://github.com/servo/servo.git
synced 2025-08-15 02:15:33 +01:00
libservo: Move size handling to RenderContext
from WindowMethods
(#35621)
This is the first step toward removing `WindowMethods`, which will gradually be integrated into the `WebView` and `WebViewDelegate`. Sizing of the `WebView` is now handled by the a size associated with a `RenderingContext`. `WebView`s will eventually just paint the entire size of their `RenderingContext`. Notes: - This is transitionary step so now there is a `WebView::resize` and a `WebView::move_resize`. The first is the future which will resize the `WebView` and its associated `RenderingContext`. The second is a function that the virtual `WebView`s that will soon be replaced by a the one-`WebView` per `WebView` model. - We do not need to call `WebView::move_resize` at as much any longer because the default size of the `WebView` is to take up the whole `RenderingContext`. - `SurfmanRenderingContext` is no longer exposed in the API, as a surfman context doesn't naturally have a size unless a surface is bound to it. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
ebb19bcd60
commit
23524a5413
19 changed files with 200 additions and 312 deletions
|
@ -16,7 +16,7 @@ use servo::compositing::windowing::{
|
|||
};
|
||||
use servo::euclid::{Box2D, Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel, DeviceRect};
|
||||
use servo::webrender_api::units::{DeviceIntRect, DeviceIntSize, DevicePixel};
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::{
|
||||
AllowOrDenyRequest, ContextMenuResult, EmbedderProxy, EventLoopWaker, ImeEvent, InputEvent,
|
||||
|
@ -34,30 +34,14 @@ use crate::prefs::ServoShellPreferences;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct Coordinates {
|
||||
pub viewport: Rect<i32, DevicePixel>,
|
||||
pub framebuffer: Size2D<i32, DevicePixel>,
|
||||
}
|
||||
|
||||
impl Coordinates {
|
||||
pub fn new(
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
fb_width: i32,
|
||||
fb_height: i32,
|
||||
) -> Coordinates {
|
||||
pub fn new(x: i32, y: i32, width: i32, height: i32) -> Coordinates {
|
||||
Coordinates {
|
||||
viewport: Rect::new(Point2D::new(x, y), Size2D::new(width, height)),
|
||||
framebuffer: Size2D::new(fb_width, fb_height),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn framebuffer_size(&self) -> PhysicalSize<u32> {
|
||||
PhysicalSize::new(
|
||||
self.framebuffer.width as u32,
|
||||
self.framebuffer.height as u32,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct ServoWindowCallbacks {
|
||||
|
@ -426,14 +410,12 @@ impl RunningAppState {
|
|||
|
||||
/// Let Servo know that the window has been resized.
|
||||
pub fn resize(&self, coordinates: Coordinates) {
|
||||
info!("resize to {:?}", coordinates);
|
||||
let size = coordinates.viewport.size;
|
||||
self.rendering_context
|
||||
.resize(Size2D::new(size.width, size.height));
|
||||
info!("resize to {:?}", coordinates,);
|
||||
self.active_webview().resize(PhysicalSize::new(
|
||||
coordinates.viewport.width() as u32,
|
||||
coordinates.viewport.height() as u32,
|
||||
));
|
||||
*self.callbacks.coordinates.borrow_mut() = coordinates;
|
||||
self.active_webview().notify_rendering_context_resized();
|
||||
self.active_webview()
|
||||
.move_resize(DeviceRect::from_size(size.to_f32()));
|
||||
self.perform_updates();
|
||||
}
|
||||
|
||||
|
@ -633,9 +615,10 @@ impl RunningAppState {
|
|||
|
||||
pub fn resume_compositor(&self, window_handle: RawWindowHandle, coords: Coordinates) {
|
||||
let window_handle = unsafe { WindowHandle::borrow_raw(window_handle) };
|
||||
let size = coords.viewport.size.to_u32();
|
||||
if let Err(e) = self
|
||||
.rendering_context
|
||||
.set_window(window_handle, &coords.framebuffer_size())
|
||||
.set_window(window_handle, PhysicalSize::new(size.width, size.height))
|
||||
{
|
||||
warn!("Binding native surface to context failed ({:?})", e);
|
||||
}
|
||||
|
@ -723,8 +706,6 @@ impl WindowMethods for ServoWindowCallbacks {
|
|||
let coords = self.coordinates.borrow();
|
||||
let screen_size = (coords.viewport.size.to_f32() / self.hidpi_factor).to_i32();
|
||||
EmbedderCoordinates {
|
||||
viewport: coords.viewport.to_box2d(),
|
||||
framebuffer: coords.framebuffer,
|
||||
window_rect: Box2D::from_origin_and_size(Point2D::zero(), screen_size),
|
||||
screen_size,
|
||||
available_screen_size: screen_size,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue