diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 28ba89a630e..b8667ec3b4f 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -364,7 +364,7 @@ impl ApplicationHandler for App { }, ref event => { let response = - minibrowser.on_window_event(window.winit_window().unwrap(), event); + minibrowser.on_window_event(window.winit_window().unwrap(), state, event); // Update minibrowser if there's resize event to sync up with window. if let WindowEvent::Resized(_) = event { minibrowser.update( diff --git a/ports/servoshell/desktop/app_state.rs b/ports/servoshell/desktop/app_state.rs index b6fbb1f2cd9..313189bcc88 100644 --- a/ports/servoshell/desktop/app_state.rs +++ b/ports/servoshell/desktop/app_state.rs @@ -292,15 +292,22 @@ impl RunningAppState { inner_mut.need_update = true; } - fn has_active_dialog(&self) -> bool { - let Some(webview) = self.focused_webview() else { + pub(crate) fn has_active_dialog(&self) -> bool { + let last_created_webview_id = self.inner().creation_order.last().cloned(); + let Some(webview_id) = self + .focused_webview() + .as_ref() + .map(WebView::id) + .or(last_created_webview_id) + else { return false; }; + let inner = self.inner(); - let Some(dialogs) = inner.dialogs.get(&webview.id()) else { - return false; - }; - !dialogs.is_empty() + inner + .dialogs + .get(&webview_id) + .is_some_and(|dialogs| !dialogs.is_empty()) } pub(crate) fn get_focused_webview_index(&self) -> Option { diff --git a/ports/servoshell/desktop/minibrowser.rs b/ports/servoshell/desktop/minibrowser.rs index 3e420862118..4aa9c6578c8 100644 --- a/ports/servoshell/desktop/minibrowser.rs +++ b/ports/servoshell/desktop/minibrowser.rs @@ -117,8 +117,19 @@ impl Minibrowser { /// Preprocess the given [winit::event::WindowEvent], returning unconsumed for mouse events in /// the Servo browser rect. This is needed because the CentralPanel we create for our webview /// would otherwise make egui report events in that area as consumed. - pub fn on_window_event(&mut self, window: &Window, event: &WindowEvent) -> EventResponse { + pub fn on_window_event( + &mut self, + window: &Window, + app_state: &RunningAppState, + event: &WindowEvent, + ) -> EventResponse { let mut result = self.context.on_window_event(window, event); + + if app_state.has_active_dialog() { + result.consumed = true; + return result; + } + result.consumed &= match event { WindowEvent::CursorMoved { position, .. } => { let scale = Scale::<_, DeviceIndependentPixel, _>::new(