servoshell: Display favicons in tab bar (#36680)

Before:

![image](https://github.com/user-attachments/assets/476ecc6b-8649-4f29-b138-aa94b938d846)

After:

![image](https://github.com/user-attachments/assets/33a37a64-2070-4c88-963d-719e32e7e8af)

This PR moves the favicon, title and close button into a single egui
Frame. Doing this allows us to get rid of some of the previous layout
magic (like setting a border radius on the left corners of the label and
the right corners of the button so they appear as one widget). It also
ensures that the tab is highlighted when the close button (not the
label) is hovered.

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-08-27 22:58:31 +02:00 committed by GitHub
parent 461ff26812
commit d65e16dd84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 154 additions and 66 deletions

View file

@ -5,6 +5,7 @@
use std::cell::{Ref, RefCell, RefMut};
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::mem;
use std::path::PathBuf;
use std::rc::Rc;
@ -84,6 +85,10 @@ pub struct RunningAppStateInner {
/// Whether or not Servo needs to repaint its display. Currently this is global
/// because every `WebView` shares a `RenderingContext`.
need_repaint: bool,
/// List of webviews that have favicon textures which are not yet uploaded
/// to the GPU by egui.
pending_favicon_loads: Vec<WebViewId>,
}
impl Drop for RunningAppState {
@ -114,6 +119,7 @@ impl RunningAppState {
gamepad_support: GamepadSupport::maybe_new(),
need_update: false,
need_repaint: false,
pending_favicon_loads: Default::default(),
}),
}
}
@ -513,6 +519,11 @@ impl RunningAppState {
.load_status_senders
.remove(&webview_id);
}
/// Return a list of all webviews that have favicons that have not yet been loaded by egui.
pub(crate) fn take_pending_favicon_loads(&self) -> Vec<WebViewId> {
mem::take(&mut self.inner_mut().pending_favicon_loads)
}
}
struct ServoShellServoDelegate;
@ -800,4 +811,10 @@ impl WebViewDelegate for RunningAppState {
},
}
}
fn notify_favicon_changed(&self, webview: WebView) {
let mut inner = self.inner_mut();
inner.pending_favicon_loads.push(webview.id());
inner.need_repaint = true;
}
}