Skip to content

Truly independent web browser

LibWebView: Show tooltips for the paused debugger overlay's buttons

Luke Wildea953096f3942
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 2bab09c3495..c6f019ee617 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -1740,6 +1740,18 @@ void ViewImplementation::did_request_cursor_change(Badge<WebContentPage>, Gfx::C
apply_cursor();
}
+void ViewImplementation::did_enter_tooltip_area(Badge<WebContentPage>, ByteString title)
+{
+ m_page_tooltip = move(title);
+ apply_tooltip();
+}
+
+void ViewImplementation::did_leave_tooltip_area(Badge<WebContentPage>)
+{
+ m_page_tooltip.clear();
+ apply_tooltip();
+}
+
// Returns the action of the button that the event activated.
template<typename Action, typename ButtonsForViewport>
Optional<Action> ViewImplementation::handle_ui_overlay_mouse_event(Compositing::OverlayPointerState<Action>& pointer_state, Web::MouseEvent const& event, ButtonsForViewport const& buttons_for_viewport)
@@ -1749,6 +1761,7 @@ Optional<Action> ViewImplementation::handle_ui_overlay_mouse_event(Compositing::
if (outcome.hover_changed) {
update_ui_overlays();
apply_cursor();
+ apply_tooltip();
}
return outcome.activated_action;
}
@@ -1759,6 +1772,31 @@ void ViewImplementation::apply_cursor()
on_cursor_change(is_ui_overlay_hovered() ? Gfx::Cursor { Gfx::StandardCursor::Hand } : m_page_cursor);
}
+static StringView paused_debugger_overlay_action_tooltip(Compositing::PausedDebuggerOverlayAction action)
+{
+ switch (action) {
+ case Compositing::PausedDebuggerOverlayAction::StepOver:
+ return "Step over"sv;
+ case Compositing::PausedDebuggerOverlayAction::Continue:
+ return "Resume"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+void ViewImplementation::apply_tooltip()
+{
+ auto tooltip = m_page_tooltip;
+ if (auto action = m_debugger_overlay_pointer_state.hovered_action(); action.has_value())
+ tooltip = paused_debugger_overlay_action_tooltip(*action);
+
+ if (tooltip.has_value()) {
+ if (on_enter_tooltip_area)
+ on_enter_tooltip_area(*tooltip);
+ } else if (on_leave_tooltip_area) {
+ on_leave_tooltip_area();
+ }
+}
+
void ViewImplementation::set_debugger_paused(bool paused)
{
if (m_debugger_paused == paused)
@@ -1768,6 +1806,7 @@ void ViewImplementation::set_debugger_paused(bool paused)
if (!paused) {
m_debugger_overlay_pointer_state.reset();
apply_cursor();
+ apply_tooltip();
}
update_ui_overlays();
}
@@ -2400,6 +2439,7 @@ void ViewImplementation::handle_resize()
m_debugger_overlay_pointer_state.reset();
update_ui_overlays();
apply_cursor();
+ apply_tooltip();
}
}
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 698eb229b5c..8cd5f938749 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -216,6 +216,8 @@ public:
size_t pending_input_event_count_for_testing() const { return m_pending_input_events.size(); }
void handle_external_url(Badge<WebContentPage>, URL::URL, URL::Origin, bool has_transient_activation);
void did_request_cursor_change(Badge<WebContentPage>, Gfx::Cursor);
+ void did_enter_tooltip_area(Badge<WebContentPage>, ByteString title);
+ void did_leave_tooltip_area(Badge<WebContentPage>);
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
void set_preferred_contrast(Web::CSS::PreferredContrast);
@@ -636,6 +638,7 @@ protected:
Optional<Action> handle_ui_overlay_mouse_event(Compositing::OverlayPointerState<Action>&, Web::MouseEvent const&, ButtonsForViewport const&);
bool is_ui_overlay_hovered() const { return m_debugger_overlay_pointer_state.hovered_action().has_value(); }
void apply_cursor();
+ void apply_tooltip();
void update_ui_overlays();
void set_page_background_color_to_system_canvas(bool dark);
void set_page_background_color(Gfx::Color);
@@ -827,6 +830,7 @@ protected:
bool m_debugger_paused { false };
Compositing::OverlayPointerState<Compositing::PausedDebuggerOverlayAction> m_debugger_overlay_pointer_state;
Gfx::Cursor m_page_cursor { Gfx::StandardCursor::Arrow };
+ Optional<ByteString> m_page_tooltip;
struct PendingExternalURLRequest {
URL::URL url;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 06061b70409..243a10e76ff 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -879,14 +879,12 @@ void WebContentPage::did_stop_tooltip_override()
void WebContentPage::did_enter_tooltip_area(ByteString title)
{
- if (view().on_enter_tooltip_area)
- view().on_enter_tooltip_area(title);
+ view().did_enter_tooltip_area({}, move(title));
}
void WebContentPage::did_leave_tooltip_area()
{
- if (view().on_leave_tooltip_area)
- view().on_leave_tooltip_area();
+ view().did_leave_tooltip_area({});
}
void WebContentPage::did_hover_link(URL::URL url)