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

servoshell: draft to show a status bar tooltip #31751

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 19 additions & 1 deletion ports/servoshell/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum PumpResult {
Continue {
history_changed: bool,
present: Present,
status: Option<String>,
},
}

Expand Down Expand Up @@ -124,7 +125,7 @@ impl App {

if let Some(mut minibrowser) = app.minibrowser() {
// Servo is not yet initialised, so there is no `servo_framebuffer_id`.
minibrowser.update(window.winit_window().unwrap(), None, "init");
minibrowser.update(window.winit_window().unwrap(), None, "init", None);
window.set_toolbar_height(minibrowser.toolbar_height);
}

Expand Down Expand Up @@ -221,6 +222,7 @@ impl App {
window.winit_window().unwrap(),
app.servo.as_ref().unwrap().offscreen_framebuffer_id(),
"RedrawRequested",
None,
);
minibrowser.paint(window.winit_window().unwrap());
}
Expand Down Expand Up @@ -301,6 +303,7 @@ impl App {
PumpResult::Continue {
history_changed,
present,
status,
} => {
if history_changed {
if let Some(mut minibrowser) = app.minibrowser() {
Expand All @@ -312,10 +315,21 @@ impl App {
window.winit_window().unwrap(),
app.servo.as_ref().unwrap().offscreen_framebuffer_id(),
"update_location_in_toolbar",
None,
);
}
}
}
if let Some(inner_status) = status {
if let Some(mut minibrowser) = app.minibrowser() {
minibrowser.update(
window.winit_window().unwrap(),
app.servo.as_ref().unwrap().offscreen_framebuffer_id(),
"update_status_message",
Some(inner_status),
);
}
}
match present {
Present::Immediate => {
// The window was resized.
Expand All @@ -330,6 +344,7 @@ impl App {
window.winit_window().unwrap(),
app.servo.as_ref().unwrap().offscreen_framebuffer_id(),
"PumpResult::Present::Immediate",
None,
);
minibrowser.paint(window.winit_window().unwrap());
}
Expand Down Expand Up @@ -433,11 +448,13 @@ impl App {
let mut need_resize = false;
let mut need_present = false;
let mut history_changed = false;
let mut status = None;
loop {
// Consume and handle those embedder messages.
let servo_event_response = webviews.handle_servo_events(embedder_messages);
need_present |= servo_event_response.need_present;
history_changed |= servo_event_response.history_changed;
status = status.or(servo_event_response.status);

// Route embedder events from the WebViewManager to the relevant Servo components,
// receives and collects embedder messages from various Servo components,
Expand Down Expand Up @@ -469,6 +486,7 @@ impl App {
PumpResult::Continue {
history_changed,
present,
status,
}
}

Expand Down
17 changes: 16 additions & 1 deletion ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::num::NonZeroU32;
use std::sync::Arc;
use std::time::Instant;

use egui::{CentralPanel, Frame, InnerResponse, Key, Modifiers, PaintCallback, TopBottomPanel};
use egui::{
CentralPanel, Frame, Id, InnerResponse, Key, Modifiers, PaintCallback, Pos2, TopBottomPanel,
};
use egui_glow::CallbackFn;
use egui_winit::EventResponse;
use euclid::{Length, Point2D, Scale};
Expand Down Expand Up @@ -123,6 +125,7 @@ impl Minibrowser {
window: &winit::window::Window,
servo_framebuffer_id: Option<gl::GLuint>,
reason: &'static str,
status: Option<String>,
) {
let now = Instant::now();
trace!(
Expand All @@ -144,6 +147,18 @@ impl Minibrowser {
let _duration = context.run(window, |ctx| {
let InnerResponse { inner: height, .. } =
TopBottomPanel::top("toolbar").show(ctx, |ui| {
if let Some(status_text) = &status {
let suggested_position = Some(Pos2::new(0.0, ui.cursor().max.y - 20.0));
let add_contents = |ui: &mut egui::Ui| {
ui.label(status_text);
};
egui::containers::popup::show_tooltip_at(
&ui.ctx(),
Id::new("status_tooltip"),
suggested_position,
add_contents,
);
}
ui.allocate_ui_with_layout(
ui.available_size(),
egui::Layout::left_to_right(egui::Align::Center),
Expand Down
5 changes: 4 additions & 1 deletion ports/servoshell/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct WebView {}
pub struct ServoEventResponse {
pub need_present: bool,
pub history_changed: bool,
pub status: Option<String>,
}

impl<Window> WebViewManager<Window>
Expand Down Expand Up @@ -411,6 +412,7 @@ where
) -> ServoEventResponse {
let mut need_present = false;
let mut history_changed = false;
let mut status = None;
for (webview_id, msg) in events {
if let Some(webview_id) = webview_id {
trace_embedder_msg!(msg, "{webview_id} {msg:?}");
Expand All @@ -419,7 +421,7 @@ where
}
match msg {
EmbedderMsg::Status(_status) => {
// FIXME: surface this status string in the UI somehow
status = _status;
},
EmbedderMsg::ChangePageTitle(title) => {
self.title = title;
Expand Down Expand Up @@ -681,6 +683,7 @@ where
ServoEventResponse {
need_present,
history_changed,
status,
}
}
}
Expand Down