servoshell: Add button to toggle experimental web platform features. (#39125)

This makes it easier to experiment with the impact of experimental
features when browsing around in servoshell. The toggle is global and
causes all webviews to reload with the new preference values.

Testing: Manually tested; no UI testing for servoshell.

Not enabled:
<img width="317" height="82" alt="Screenshot 2025-09-03 at 9 34 30 PM"
src="https://github.com/user-attachments/assets/ca521ad5-ce1b-434e-a0c3-ea1b75d76d53"
/>

Enabled:
<img width="320" height="82" alt="Screenshot 2025-09-03 at 9 34 36 PM"
src="https://github.com/user-attachments/assets/7b6529b5-1055-4ae0-924a-96d57e115714"
/>

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-09-03 22:53:12 -04:00 committed by GitHub
parent 912b83b58f
commit aac6aa6c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 2 deletions

View file

@ -119,6 +119,7 @@ impl App {
event_loop,
proxy,
self.initial_url.clone(),
&self.servoshell_preferences,
));
Rc::new(window)
},
@ -321,6 +322,12 @@ impl App {
focused_webview.reload();
}
},
MinibrowserEvent::ReloadAll => {
minibrowser.update_location_dirty(false);
for (_, webview) in state.webviews() {
webview.reload();
}
},
MinibrowserEvent::NewWebView => {
minibrowser.update_location_dirty(false);
state.create_and_focus_toplevel_webview(Url::parse("servo:newtab").unwrap());

View file

@ -22,7 +22,9 @@ use servo::base::id::WebViewId;
use servo::servo_geometry::DeviceIndependentPixel;
use servo::servo_url::ServoUrl;
use servo::webrender_api::units::DevicePixel;
use servo::{Image, LoadStatus, OffscreenRenderingContext, PixelFormat, RenderingContext, WebView};
use servo::{
Image, LoadStatus, OffscreenRenderingContext, PixelFormat, PrefValue, RenderingContext, WebView,
};
use winit::event::{ElementState, MouseButton, WindowEvent};
use winit::event_loop::ActiveEventLoop;
use winit::window::Window;
@ -33,6 +35,7 @@ use super::events_loop::EventLoopProxy;
use super::geometry::winit_position_to_euclid_point;
use super::headed_window::Window as ServoWindow;
use crate::desktop::window_trait::WindowPortsMethods;
use crate::prefs::{EXPERIMENTAL_PREFS, ServoShellPreferences};
pub struct Minibrowser {
rendering_context: Rc<OffscreenRenderingContext>,
@ -55,6 +58,9 @@ pub struct Minibrowser {
///
/// These need to be cached across egui draw calls.
favicon_textures: HashMap<WebViewId, (egui::TextureHandle, egui::load::SizedTexture)>,
/// Whether the user has enabled experimental preferences.
experimental_prefs_enabled: bool,
}
pub enum MinibrowserEvent {
@ -63,6 +69,7 @@ pub enum MinibrowserEvent {
Back,
Forward,
Reload,
ReloadAll,
NewWebView,
CloseWebView(WebViewId),
}
@ -88,6 +95,7 @@ impl Minibrowser {
event_loop: &ActiveEventLoop,
event_loop_proxy: EventLoopProxy,
initial_url: ServoUrl,
preferences: &ServoShellPreferences,
) -> Self {
let rendering_context = window.offscreen_rendering_context();
// Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs
@ -118,6 +126,7 @@ impl Minibrowser {
load_status: LoadStatus::Complete,
status_text: None,
favicon_textures: Default::default(),
experimental_prefs_enabled: preferences.experimental_prefs_enabled,
}
}
@ -336,6 +345,19 @@ impl Minibrowser {
ui.available_size(),
egui::Layout::right_to_left(egui::Align::Center),
|ui| {
let prefs_toggle = ui
.toggle_value(&mut self.experimental_prefs_enabled, "")
.on_hover_text("Enable experimental prefs");
if prefs_toggle.clicked() {
let enable = self.experimental_prefs_enabled;
for pref in EXPERIMENTAL_PREFS {
state
.servo()
.set_preference(pref, PrefValue::Bool(enable));
}
event_queue.borrow_mut().push(MinibrowserEvent::ReloadAll);
}
let location_id = egui::Id::new("location_input");
let location_field = ui.add_sized(
ui.available_size(),