mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
WebContent: Plumb link clicks to the WebContentView :^)
You can now react to links being clicked via the on_link_click hook.
This commit is contained in:
parent
fd65a24834
commit
32243e1df2
Notes:
sideshowbarker
2024-07-19 05:06:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/32243e1df24
8 changed files with 48 additions and 1 deletions
|
@ -114,3 +114,13 @@ void WebContentClient::handle(const Messages::WebContentClient::DidUnhoverLink&)
|
|||
#endif
|
||||
m_view.notify_server_did_unhover_link({});
|
||||
}
|
||||
|
||||
void WebContentClient::handle(const Messages::WebContentClient::DidClickLink& message)
|
||||
{
|
||||
m_view.notify_server_did_click_link({}, message.url(), message.target(), message.modifiers());
|
||||
}
|
||||
|
||||
void WebContentClient::handle(const Messages::WebContentClient::DidMiddleClickLink& message)
|
||||
{
|
||||
m_view.notify_server_did_middle_click_link({}, message.url(), message.target(), message.modifiers());
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ private:
|
|||
virtual void handle(const Messages::WebContentClient::DidRequestScrollIntoView&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidHoverLink&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidUnhoverLink&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidClickLink&) override;
|
||||
virtual void handle(const Messages::WebContentClient::DidMiddleClickLink&) override;
|
||||
|
||||
WebContentView& m_view;
|
||||
};
|
||||
|
|
|
@ -137,6 +137,18 @@ void WebContentView::notify_server_did_unhover_link(Badge<WebContentClient>)
|
|||
on_link_hover({});
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_click_link(Badge<WebContentClient>, const URL& url, const String& target, unsigned int modifiers)
|
||||
{
|
||||
if (on_link_click)
|
||||
on_link_click(url, target, modifiers);
|
||||
}
|
||||
|
||||
void WebContentView::notify_server_did_middle_click_link(Badge<WebContentClient>, const URL& url, const String& target, unsigned int modifiers)
|
||||
{
|
||||
if (on_link_middle_click)
|
||||
on_link_middle_click(url, target, modifiers);
|
||||
}
|
||||
|
||||
void WebContentView::did_scroll()
|
||||
{
|
||||
client().post_message(Messages::WebContentServer::SetViewportRect(visible_content_rect()));
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
|
||||
Function<void(const String&)> on_title_change;
|
||||
Function<void(const URL&)> on_link_hover;
|
||||
Function<void(const URL&, const String& target, unsigned modifiers)> on_link_click;
|
||||
Function<void(const URL&, const String& target, unsigned modifiers)> on_link_middle_click;
|
||||
|
||||
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
|
||||
void notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id);
|
||||
|
@ -50,6 +52,8 @@ public:
|
|||
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>);
|
||||
void notify_server_did_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
|
||||
void notify_server_did_middle_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
|
||||
|
||||
private:
|
||||
WebContentView();
|
||||
|
|
|
@ -56,6 +56,11 @@ int main(int argc, char** argv)
|
|||
statusbar.set_text("");
|
||||
};
|
||||
|
||||
view.on_link_click = [&](auto& url, auto&, auto) {
|
||||
if (url.is_valid())
|
||||
view.load(url);
|
||||
};
|
||||
|
||||
view.load("file:///res/html/misc/welcome.html");
|
||||
|
||||
return app->exec();
|
||||
|
|
|
@ -144,4 +144,14 @@ void PageHost::page_did_unhover_link()
|
|||
m_client.post_message(Messages::WebContentClient::DidUnhoverLink());
|
||||
}
|
||||
|
||||
void PageHost::page_did_click_link(const URL& url, const String& target, unsigned modifiers)
|
||||
{
|
||||
m_client.post_message(Messages::WebContentClient::DidClickLink(url, target, modifiers));
|
||||
}
|
||||
|
||||
void PageHost::page_did_middle_click_link(const URL& url, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers)
|
||||
{
|
||||
m_client.post_message(Messages::WebContentClient::DidMiddleClickLink(url, target, modifiers));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
void set_viewport_rect(const Gfx::IntRect&);
|
||||
|
||||
private:
|
||||
// ^PageHost
|
||||
// ^PageClient
|
||||
virtual Gfx::Palette palette() const override;
|
||||
virtual void page_did_invalidate(const Gfx::IntRect&) override;
|
||||
virtual void page_did_change_selection() override;
|
||||
|
@ -58,6 +58,8 @@ private:
|
|||
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;
|
||||
virtual void page_did_click_link(const URL&, const String& target, unsigned modifiers) override;
|
||||
virtual void page_did_middle_click_link(const URL&, const String& target, unsigned modifiers) override;
|
||||
|
||||
explicit PageHost(ClientConnection&);
|
||||
|
||||
|
|
|
@ -9,4 +9,6 @@ endpoint WebContentClient = 90
|
|||
DidRequestScrollIntoView(Gfx::IntRect rect) =|
|
||||
DidHoverLink(URL url) =|
|
||||
DidUnhoverLink() =|
|
||||
DidClickLink(URL url, String target, unsigned modifiers) =|
|
||||
DidMiddleClickLink(URL url, String target, unsigned modifiers) =|
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue