summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-06 20:01:46 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-06 20:02:30 +0200
commit32243e1df24820b8da8bcf5bc491cd812d261483 (patch)
treee4e496d26f2c7544b343065448347ec933521264
parentfd65a2483492dfd50cae61b613d9bd8ed95306b3 (diff)
downloadserenity-32243e1df24820b8da8bcf5bc491cd812d261483.zip
WebContent: Plumb link clicks to the WebContentView :^)
You can now react to links being clicked via the on_link_click hook.
-rw-r--r--Demos/WebView/WebContentClient.cpp10
-rw-r--r--Demos/WebView/WebContentClient.h2
-rw-r--r--Demos/WebView/WebContentView.cpp12
-rw-r--r--Demos/WebView/WebContentView.h4
-rw-r--r--Demos/WebView/main.cpp5
-rw-r--r--Services/WebContent/PageHost.cpp10
-rw-r--r--Services/WebContent/PageHost.h4
-rw-r--r--Services/WebContent/WebContentClient.ipc2
8 files changed, 48 insertions, 1 deletions
diff --git a/Demos/WebView/WebContentClient.cpp b/Demos/WebView/WebContentClient.cpp
index 3835c3ebbb..0042cc14db 100644
--- a/Demos/WebView/WebContentClient.cpp
+++ b/Demos/WebView/WebContentClient.cpp
@@ -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());
+}
diff --git a/Demos/WebView/WebContentClient.h b/Demos/WebView/WebContentClient.h
index 7f51a53861..638cf22b40 100644
--- a/Demos/WebView/WebContentClient.h
+++ b/Demos/WebView/WebContentClient.h
@@ -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;
};
diff --git a/Demos/WebView/WebContentView.cpp b/Demos/WebView/WebContentView.cpp
index 90630c6c5d..67ceffecd8 100644
--- a/Demos/WebView/WebContentView.cpp
+++ b/Demos/WebView/WebContentView.cpp
@@ -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()));
diff --git a/Demos/WebView/WebContentView.h b/Demos/WebView/WebContentView.h
index 87a7d2fab1..6af604a31c 100644
--- a/Demos/WebView/WebContentView.h
+++ b/Demos/WebView/WebContentView.h
@@ -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();
diff --git a/Demos/WebView/main.cpp b/Demos/WebView/main.cpp
index 3d6446bb98..4fe29c725f 100644
--- a/Demos/WebView/main.cpp
+++ b/Demos/WebView/main.cpp
@@ -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();
diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp
index 7f35aea60d..29cc5cc2c1 100644
--- a/Services/WebContent/PageHost.cpp
+++ b/Services/WebContent/PageHost.cpp
@@ -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));
+}
+
}
diff --git a/Services/WebContent/PageHost.h b/Services/WebContent/PageHost.h
index eef6d5918e..22be237acf 100644
--- a/Services/WebContent/PageHost.h
+++ b/Services/WebContent/PageHost.h
@@ -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&);
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index 906978a6f4..70c6158827 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -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) =|
}