mirror of
https://github.com/servo/servo.git
synced 2025-08-18 11:55:39 +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
|
@ -7,14 +7,14 @@ use std::collections::HashMap;
|
|||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
use euclid::Vector2D;
|
||||
use euclid::{Point2D, Vector2D};
|
||||
use image::{DynamicImage, ImageFormat};
|
||||
use keyboard_types::{Key, KeyboardEvent, Modifiers, ShortcutMatcher};
|
||||
use log::{error, info};
|
||||
use servo::base::id::WebViewId;
|
||||
use servo::config::pref;
|
||||
use servo::ipc_channel::ipc::IpcSender;
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::{
|
||||
AllowOrDenyRequest, AuthenticationRequest, FilterPattern, GamepadHapticEffectType, LoadStatus,
|
||||
|
@ -130,13 +130,8 @@ impl RunningAppState {
|
|||
};
|
||||
|
||||
let inner = self.inner();
|
||||
let viewport_rect = inner
|
||||
.window
|
||||
.get_coordinates()
|
||||
.viewport
|
||||
.to_rect()
|
||||
.to_untyped()
|
||||
.to_u32();
|
||||
let size = inner.window.rendering_context().size2d().to_i32();
|
||||
let viewport_rect = DeviceIntRect::from_origin_and_size(Point2D::origin(), size);
|
||||
let Some(image) = inner
|
||||
.window
|
||||
.rendering_context()
|
||||
|
@ -467,17 +462,8 @@ impl WebViewDelegate for RunningAppState {
|
|||
}
|
||||
|
||||
fn notify_ready_to_show(&self, webview: servo::WebView) {
|
||||
let rect = self
|
||||
.inner()
|
||||
.window
|
||||
.get_coordinates()
|
||||
.get_viewport()
|
||||
.to_f32();
|
||||
|
||||
webview.focus();
|
||||
webview.move_resize(rect);
|
||||
webview.raise_to_top(true);
|
||||
webview.notify_rendering_context_resized();
|
||||
}
|
||||
|
||||
fn notify_closed(&self, webview: servo::WebView) {
|
||||
|
|
|
@ -121,7 +121,7 @@ impl Window {
|
|||
.window_handle()
|
||||
.expect("could not get window handle from window");
|
||||
let window_rendering_context = Rc::new(
|
||||
WindowRenderingContext::new(display_handle, window_handle, &inner_size)
|
||||
WindowRenderingContext::new(display_handle, window_handle, inner_size)
|
||||
.expect("Could not create RenderingContext for Window"),
|
||||
);
|
||||
|
||||
|
@ -135,9 +135,7 @@ impl Window {
|
|||
// Make sure the gl context is made current.
|
||||
window_rendering_context.make_current().unwrap();
|
||||
|
||||
let rendering_context_size = Size2D::new(inner_size.width, inner_size.height);
|
||||
let rendering_context =
|
||||
Rc::new(window_rendering_context.offscreen_context(rendering_context_size));
|
||||
let rendering_context = Rc::new(window_rendering_context.offscreen_context(inner_size));
|
||||
|
||||
debug!("Created window {:?}", winit_window.id());
|
||||
Window {
|
||||
|
@ -614,11 +612,8 @@ impl WindowPortsMethods for Window {
|
|||
},
|
||||
WindowEvent::Resized(new_size) => {
|
||||
if self.inner_size.get() != new_size {
|
||||
let rendering_context_size = Size2D::new(new_size.width, new_size.height);
|
||||
self.window_rendering_context
|
||||
.resize(rendering_context_size.to_i32());
|
||||
self.window_rendering_context.resize(new_size);
|
||||
self.inner_size.set(new_size);
|
||||
webview.notify_rendering_context_resized();
|
||||
}
|
||||
},
|
||||
WindowEvent::ThemeChanged(theme) => {
|
||||
|
@ -736,17 +731,9 @@ impl WindowMethods for Window {
|
|||
let window_scale: Scale<f64, DeviceIndependentPixel, DevicePixel> =
|
||||
Scale::new(self.winit_window.scale_factor());
|
||||
let window_rect = (window_rect.to_f64() / window_scale).to_i32();
|
||||
|
||||
let viewport_origin = DeviceIntPoint::zero(); // bottom left
|
||||
let mut viewport_size = winit_size_to_euclid_size(self.winit_window.inner_size()).to_f32();
|
||||
viewport_size.height -= (self.toolbar_height() * self.hidpi_factor()).0;
|
||||
|
||||
let viewport = DeviceIntRect::from_origin_and_size(viewport_origin, viewport_size.to_i32());
|
||||
let screen_size = self.screen_size.to_i32();
|
||||
|
||||
EmbedderCoordinates {
|
||||
viewport,
|
||||
framebuffer: viewport.size(),
|
||||
window_rect,
|
||||
screen_size,
|
||||
// FIXME: Winit doesn't have API for available size. Fallback to screen size
|
||||
|
|
|
@ -86,7 +86,7 @@ impl WindowPortsMethods for Window {
|
|||
// Because we are managing the rendering surface ourselves, there will be no other
|
||||
// notification (such as from the display manager) that it has changed size, so we
|
||||
// must notify the compositor here.
|
||||
webview.notify_rendering_context_resized();
|
||||
webview.resize(PhysicalSize::new(size.width as u32, size.height as u32));
|
||||
|
||||
Some(new_size)
|
||||
}
|
||||
|
@ -149,10 +149,7 @@ impl WindowPortsMethods for Window {
|
|||
|
||||
impl WindowMethods for Window {
|
||||
fn get_coordinates(&self) -> EmbedderCoordinates {
|
||||
let inner_size = self.inner_size.get();
|
||||
EmbedderCoordinates {
|
||||
viewport: Box2D::from_origin_and_size(Point2D::zero(), inner_size),
|
||||
framebuffer: inner_size,
|
||||
window_rect: self.window_rect,
|
||||
screen_size: self.screen_size,
|
||||
available_screen_size: self.screen_size,
|
||||
|
|
|
@ -7,6 +7,7 @@ use std::rc::Rc;
|
|||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use dpi::PhysicalSize;
|
||||
use egui::text::{CCursor, CCursorRange};
|
||||
use egui::text_edit::TextEditState;
|
||||
use egui::{
|
||||
|
@ -379,13 +380,11 @@ impl Minibrowser {
|
|||
// If the top parts of the GUI changed size, then update the size of the WebView and also
|
||||
// the size of its RenderingContext.
|
||||
let available_size = ui.available_size();
|
||||
let rect = Box2D::from_origin_and_size(
|
||||
Point2D::origin(),
|
||||
Size2D::new(available_size.x, available_size.y),
|
||||
) * scale;
|
||||
let size = Size2D::new(available_size.x, available_size.y) * scale;
|
||||
let rect = Box2D::from_origin_and_size(Point2D::origin(), size);
|
||||
if rect != webview.rect() {
|
||||
webview.move_resize(rect);
|
||||
rendering_context.resize(rect.size().to_i32().to_untyped());
|
||||
webview.resize(PhysicalSize::new(size.width as u32, size.height as u32))
|
||||
}
|
||||
|
||||
let min = ui.cursor().min;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue