Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status tooltips #32011

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::sync::Arc;
use std::time::Instant;

use egui::{
CentralPanel, Color32, Frame, Key, Modifiers, PaintCallback, Pos2, Spinner, TopBottomPanel,
Vec2,
pos2, CentralPanel, Color32, Frame, Key, Modifiers, PaintCallback, Pos2, Spinner,
TopBottomPanel, Vec2,
};
use egui_glow::CallbackFn;
use egui_winit::EventResponse;
Expand Down Expand Up @@ -49,6 +49,8 @@ pub struct Minibrowser {
location_dirty: Cell<bool>,

load_status: LoadStatus,

status_text: Option<String>,
}

pub enum MinibrowserEvent {
Expand Down Expand Up @@ -86,6 +88,7 @@ impl Minibrowser {
location: RefCell::new(initial_url.to_string()),
location_dirty: false.into(),
load_status: LoadStatus::LoadComplete,
status_text: None,
}
}

Expand Down Expand Up @@ -235,6 +238,19 @@ impl Minibrowser {
return;
};
let mut embedder_events = vec![];

if let Some(status_text) = &self.status_text {
let position = Some(pos2(0.0, ctx.available_rect().max.y));
egui::containers::popup::show_tooltip_at(
ctx,
"tooltip_for_status_text".into(),
position,
|ui| {
ui.label(status_text.clone());
},
);
}

CentralPanel::default()
.frame(Frame::none())
.show(ctx, |ui| {
Expand Down Expand Up @@ -389,6 +405,15 @@ impl Minibrowser {
need_update
}

pub fn update_status_text(
&mut self,
browser: &mut WebViewManager<dyn WindowPortsMethods>,
) -> bool {
let need_update = browser.status_text() != self.status_text;
self.status_text = browser.status_text();
need_update
}

/// Updates all fields taken from the given [WebViewManager], such as the location field.
/// Returns true iff the egui needs an update.
pub fn update_webview_data(
Expand All @@ -399,6 +424,8 @@ impl Minibrowser {
// because logical OR would short-circuit if any of the functions return true.
// We want to ensure that all functions are called. The "bitwise OR" operator
// does not short-circuit.
self.update_location_in_toolbar(browser) | self.update_spinner_in_toolbar(browser)
self.update_location_in_toolbar(browser) |
self.update_spinner_in_toolbar(browser) |
self.update_status_text(browser)
}
}
11 changes: 9 additions & 2 deletions ports/servoshell/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
pub struct WebViewManager<Window: WindowPortsMethods + ?Sized> {
current_url: Option<ServoUrl>,
current_url_string: Option<String>,
status_text: Option<String>,

/// List of top-level browsing contexts.
/// Modified by EmbedderMsg::WebViewOpened and EmbedderMsg::WebViewClosed,
Expand Down Expand Up @@ -86,6 +87,7 @@ where
title: None,
current_url: None,
current_url_string: None,
status_text: None,
webviews: HashMap::default(),
creation_order: vec![],
focused_webview_id: None,
Expand Down Expand Up @@ -130,6 +132,10 @@ where
self.load_status
}

pub fn status_text(&self) -> Option<String> {
self.status_text.clone()
}

pub fn get_events(&mut self) -> Vec<EmbedderEvent> {
std::mem::take(&mut self.event_queue)
}
Expand Down Expand Up @@ -441,8 +447,9 @@ where
trace_embedder_msg!(msg, "{msg:?}");
}
match msg {
EmbedderMsg::Status(_status) => {
// FIXME: surface this status string in the UI somehow
EmbedderMsg::Status(status) => {
self.status_text = status;
need_update = true;
},
EmbedderMsg::ChangePageTitle(title) => {
self.title = title;
Expand Down