Only handle most recent resize event in script thread (#33297)

This avoids having to do unnecessary layout work and
prevents resize events from accumulating, which looks
weird.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2024-09-04 13:30:39 +02:00 committed by GitHub
parent fc5f8e9237
commit 961fcfc46d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -13,7 +13,7 @@ use std::rc::Rc;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::{cmp, env, mem};
use std::{cmp, env};
use app_units::Au;
use backtrace::Backtrace;
@ -216,9 +216,9 @@ pub struct Window {
#[no_trace]
devtools_marker_sender: DomRefCell<Option<IpcSender<Option<TimelineMarker>>>>,
/// Pending resize events, if any.
/// Most recent unhandled resize event, if any.
#[no_trace]
resize_events: DomRefCell<Vec<(WindowSizeData, WindowSizeType)>>,
unhandled_resize_event: DomRefCell<Option<(WindowSizeData, WindowSizeType)>>,
/// Parent id associated with this page, if any.
#[no_trace]
@ -2339,11 +2339,13 @@ impl Window {
}
pub fn add_resize_event(&self, event: WindowSizeData, event_type: WindowSizeType) {
self.resize_events.borrow_mut().push((event, event_type));
// Whenever we receive a new resize event we forget about all the ones that came before
// it, to avoid unnecessary relayouts
*self.unhandled_resize_event.borrow_mut() = Some((event, event_type))
}
pub fn steal_resize_events(&self) -> Vec<(WindowSizeData, WindowSizeType)> {
mem::take(&mut self.resize_events.borrow_mut())
pub fn take_unhandled_resize_event(&self) -> Option<(WindowSizeData, WindowSizeType)> {
self.unhandled_resize_event.borrow_mut().take()
}
pub fn set_page_clip_rect_with_new_viewport(&self, viewport: UntypedRect<f32>) -> bool {
@ -2615,7 +2617,7 @@ impl Window {
bluetooth_thread,
bluetooth_extra_permission_data: BluetoothExtraPermissionData::new(),
page_clip_rect: Cell::new(MaxRect::max_rect()),
resize_events: Default::default(),
unhandled_resize_event: Default::default(),
window_size: Cell::new(window_size),
current_viewport: Cell::new(initial_viewport.to_untyped()),
suppress_reflow: Cell::new(true),