WebContent: Plumb hovered links from WebContent process over to widget
Also add a little GUI::StatusBar to the demo app so we can see the hovered link URL's live. :^)
This commit is contained in:
parent
aac362b883
commit
58b1ba2545
Notes:
sideshowbarker
2024-07-19 05:08:01 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/58b1ba2545a
8 changed files with 61 additions and 1 deletions
|
@ -98,3 +98,19 @@ void WebContentClient::handle(const Messages::WebContentClient::DidRequestScroll
|
|||
#endif
|
||||
m_view.notify_server_did_request_scroll_into_view({}, message.rect());
|
||||
}
|
||||
|
||||
void WebContentClient::handle(const Messages::WebContentClient::DidHoverLink& message)
|
||||
{
|
||||
#ifdef DEBUG_SPAM
|
||||
dbg() << "handle: WebContentClient::DidHoverLink! url=" << message.url();
|
||||
#endif
|
||||
m_view.notify_server_did_hover_link({}, message.url());
|
||||
}
|
||||
|
||||
void WebContentClient::handle(const Messages::WebContentClient::DidUnhoverLink&)
|
||||
{
|
||||
#ifdef DEBUG_SPAM
|
||||
dbg() << "handle: WebContentClient::DidUnhoverLink!";
|
||||
#endif
|
||||
m_view.notify_server_did_unhover_link({});
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ private:
|
|||
virtual void handle(const Messages::WebContentClient::DidLayout&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidChangeTitle&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidRequestScrollIntoView&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidHoverLink&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidUnhoverLink&) override;
|
||||
|
||||
WebContentView& m_view;
|
||||
};
|
||||
|
|
|
@ -125,6 +125,18 @@ void WebContentView::notify_server_did_request_scroll_into_view(Badge<WebContent
|
|||
scroll_into_view(rect, true, true);
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_hover_link(Badge<WebContentClient>, const URL& url)
|
||||
{
|
||||
if (on_link_hover)
|
||||
on_link_hover(url);
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_unhover_link(Badge<WebContentClient>)
|
||||
{
|
||||
if (on_link_hover)
|
||||
on_link_hover({});
|
||||
}
|
||||
|
||||
void WebContentView::did_scroll()
|
||||
{
|
||||
client().post_message(Messages::WebContentServer::SetViewportRect(visible_content_rect()));
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
void load(const URL&);
|
||||
|
||||
Function<void(const String&)> on_title_change;
|
||||
Function<void(const URL&)> on_link_hover;
|
||||
|
||||
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
|
||||
void notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id);
|
||||
|
@ -47,6 +48,8 @@ public:
|
|||
void notify_server_did_change_selection(Badge<WebContentClient>);
|
||||
void notify_server_did_change_title(Badge<WebContentClient>, const String&);
|
||||
void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, const Gfx::IntRect&);
|
||||
void notify_server_did_hover_link(Badge<WebContentClient>, const URL&);
|
||||
void notify_server_did_unhover_link(Badge<WebContentClient>);
|
||||
|
||||
private:
|
||||
WebContentView();
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "WebContentView.h"
|
||||
#include <AK/URL.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/StatusBar.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
#include <LibGUI/Window.h>
|
||||
|
||||
|
@ -34,7 +36,11 @@ int main(int argc, char** argv)
|
|||
{
|
||||
auto app = GUI::Application::construct(argc, argv);
|
||||
auto window = GUI::Window::construct();
|
||||
auto& view = window->set_main_widget<WebContentView>();
|
||||
auto& main_widget = window->set_main_widget<GUI::Widget>();
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.set_layout<GUI::VerticalBoxLayout>();
|
||||
auto& view = main_widget.add<WebContentView>();
|
||||
auto& statusbar = main_widget.add<GUI::StatusBar>();
|
||||
window->set_title("WebView");
|
||||
window->set_rect(100, 100, 640, 480);
|
||||
window->show();
|
||||
|
@ -43,6 +49,13 @@ int main(int argc, char** argv)
|
|||
window->set_title(String::format("%s - WebView", title.characters()));
|
||||
};
|
||||
|
||||
view.on_link_hover = [&](auto& url) {
|
||||
if (url.is_valid())
|
||||
statusbar.set_text(url.to_string());
|
||||
else
|
||||
statusbar.set_text("");
|
||||
};
|
||||
|
||||
view.load("file:///res/html/misc/welcome.html");
|
||||
|
||||
return app->exec();
|
||||
|
|
|
@ -134,4 +134,14 @@ void PageHost::page_did_request_scroll_into_view(const Gfx::IntRect& rect)
|
|||
m_client.post_message(Messages::WebContentClient::DidRequestScrollIntoView(rect));
|
||||
}
|
||||
|
||||
void PageHost::page_did_hover_link(const URL& url)
|
||||
{
|
||||
m_client.post_message(Messages::WebContentClient::DidHoverLink(url));
|
||||
}
|
||||
|
||||
void PageHost::page_did_unhover_link()
|
||||
{
|
||||
m_client.post_message(Messages::WebContentClient::DidUnhoverLink());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ private:
|
|||
virtual void page_did_layout() override;
|
||||
virtual void page_did_change_title(const String&) override;
|
||||
virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) override;
|
||||
virtual void page_did_hover_link(const URL&) override;
|
||||
virtual void page_did_unhover_link() override;
|
||||
|
||||
explicit PageHost(ClientConnection&);
|
||||
|
||||
|
|
|
@ -7,4 +7,6 @@ endpoint WebContentClient = 90
|
|||
DidLayout(Gfx::IntSize content_size) =|
|
||||
DidChangeTitle(String title) =|
|
||||
DidRequestScrollIntoView(Gfx::IntRect rect) =|
|
||||
DidHoverLink(URL url) =|
|
||||
DidUnhoverLink() =|
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue