servoshell: Revert #38307 to fix resize bug (#38381)

Also added some comments to make things clear.
For details, see
https://github.com/servo/servo/issues/38369#issuecomment-3138378527

Testing: Tested on X11 Ubuntu, Wayland Ubuntu, macOS, Windows.
Fixes: #38369

Co-authored-by: minghuaw <michael.wu1107@gmail.com>

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
Co-authored-by: minghuaw <michael.wu1107@gmail.com>
This commit is contained in:
Euclid Ye 2025-07-31 16:55:00 +08:00 committed by GitHub
parent 36f1a373e3
commit d38781d71d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -62,6 +62,9 @@ pub struct Window {
monitor: winit::monitor::MonitorHandle, monitor: winit::monitor::MonitorHandle,
webview_relative_mouse_point: Cell<Point2D<f32, DevicePixel>>, webview_relative_mouse_point: Cell<Point2D<f32, DevicePixel>>,
last_pressed: Cell<Option<(KeyboardEvent, Option<LogicalKey>)>>, last_pressed: Cell<Option<(KeyboardEvent, Option<LogicalKey>)>>,
/// The inner size of the window in physical pixels which excludes OS decorations.
/// It equals viewport size + (0, toolbar height).
inner_size: Cell<PhysicalSize<u32>>,
/// A map of winit's key codes to key values that are interpreted from /// A map of winit's key codes to key values that are interpreted from
/// winit's ReceivedChar events. /// winit's ReceivedChar events.
keys_down: RefCell<HashMap<LogicalKey, Key>>, keys_down: RefCell<HashMap<LogicalKey, Key>>,
@ -73,7 +76,10 @@ pub struct Window {
/// The `RenderingContext` of Servo itself. This is used to render Servo results /// The `RenderingContext` of Servo itself. This is used to render Servo results
/// temporarily until they can be blitted into the egui scene. /// temporarily until they can be blitted into the egui scene.
rendering_context: Rc<OffscreenRenderingContext>, rendering_context: Rc<OffscreenRenderingContext>,
/// The RenderingContext that renders directly onto the Window. This is used as
/// the target of egui rendering and also where Servo rendering results are finally
/// blitted.
window_rendering_context: Rc<WindowRenderingContext>,
// Keep this as the last field of the struct to ensure that the rendering context is // Keep this as the last field of the struct to ensure that the rendering context is
// dropped first. // dropped first.
// (https://github.com/servo/servo/issues/36711) // (https://github.com/servo/servo/issues/36711)
@ -158,12 +164,14 @@ impl Window {
last_pressed: Cell::new(None), last_pressed: Cell::new(None),
keys_down: RefCell::new(HashMap::new()), keys_down: RefCell::new(HashMap::new()),
fullscreen: Cell::new(false), fullscreen: Cell::new(false),
inner_size: Cell::new(inner_size),
monitor, monitor,
screen_size, screen_size,
device_pixel_ratio_override: servoshell_preferences.device_pixel_ratio_override, device_pixel_ratio_override: servoshell_preferences.device_pixel_ratio_override,
xr_window_poses: RefCell::new(vec![]), xr_window_poses: RefCell::new(vec![]),
modifiers_state: Cell::new(ModifiersState::empty()), modifiers_state: Cell::new(ModifiersState::empty()),
toolbar_height: Cell::new(Default::default()), toolbar_height: Cell::new(Default::default()),
window_rendering_context,
rendering_context, rendering_context,
} }
} }
@ -677,6 +685,13 @@ impl WindowPortsMethods for Window {
winit::window::Theme::Dark => Theme::Dark, winit::window::Theme::Dark => Theme::Dark,
}); });
}, },
WindowEvent::Resized(new_inner_size) => {
if self.inner_size.get() != new_inner_size {
// This should always be set to inner size.
// See https://github.com/servo/servo/issues/38369#issuecomment-3138378527
self.window_rendering_context.resize(new_inner_size);
}
},
WindowEvent::Ime(ime) => match ime { WindowEvent::Ime(ime) => match ime {
Ime::Enabled => { Ime::Enabled => {
webview.notify_input_event(InputEvent::Ime(ImeEvent::Composition( webview.notify_input_event(InputEvent::Ime(ImeEvent::Composition(

View file

@ -409,6 +409,9 @@ impl Minibrowser {
let rect = Box2D::from_origin_and_size(Point2D::origin(), size); let rect = Box2D::from_origin_and_size(Point2D::origin(), size);
if rect != webview.rect() { if rect != webview.rect() {
webview.move_resize(rect); webview.move_resize(rect);
// `rect` is sized to just the WebView viewport, which is required by
// `OffscreenRenderingContext` See:
// <https://github.com/servo/servo/issues/38369#issuecomment-3138378527>
webview.resize(PhysicalSize::new(size.width as u32, size.height as u32)) webview.resize(PhysicalSize::new(size.width as u32, size.height as u32))
} }