From c15f9e75932a3beb775b2083633879c04f2510a0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 4 Jul 2020 23:40:17 +0200 Subject: WebContent: Plumb title changes over to the WebContentView WebContentView now fires its on_title_change hook, like Web::PageView. We use this in the WebView test app to update the window title. :^) --- Demos/WebView/WebContentClient.cpp | 8 ++++++++ Demos/WebView/WebContentClient.h | 1 + Demos/WebView/WebContentView.cpp | 6 ++++++ Demos/WebView/WebContentView.h | 3 +++ Demos/WebView/main.cpp | 6 +++++- Services/WebContent/PageHost.cpp | 5 +++++ Services/WebContent/PageHost.h | 1 + Services/WebContent/WebContentClient.ipc | 1 + 8 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Demos/WebView/WebContentClient.cpp b/Demos/WebView/WebContentClient.cpp index 2083fec29c..e39df2c24a 100644 --- a/Demos/WebView/WebContentClient.cpp +++ b/Demos/WebView/WebContentClient.cpp @@ -82,3 +82,11 @@ void WebContentClient::handle(const Messages::WebContentClient::DidLayout& messa #endif m_view.notify_server_did_layout({}, message.content_size()); } + +void WebContentClient::handle(const Messages::WebContentClient::DidChangeTitle& message) +{ +#ifdef DEBUG_SPAM + dbg() << "handle: WebContentClient::DidChangeTitle! title=" << message.title(); +#endif + m_view.notify_server_did_change_title({}, message.title()); +} diff --git a/Demos/WebView/WebContentClient.h b/Demos/WebView/WebContentClient.h index 1a8f4651e8..e0c6948a0b 100644 --- a/Demos/WebView/WebContentClient.h +++ b/Demos/WebView/WebContentClient.h @@ -49,6 +49,7 @@ private: virtual void handle(const Messages::WebContentClient::DidInvalidateContentRect&) override; virtual void handle(const Messages::WebContentClient::DidChangeSelection&) override; virtual void handle(const Messages::WebContentClient::DidLayout&) override; + virtual void handle(const Messages::WebContentClient::DidChangeTitle&) override; WebContentView& m_view; }; diff --git a/Demos/WebView/WebContentView.cpp b/Demos/WebView/WebContentView.cpp index 9e4c5ffe98..aa2b7eea34 100644 --- a/Demos/WebView/WebContentView.cpp +++ b/Demos/WebView/WebContentView.cpp @@ -108,6 +108,12 @@ void WebContentView::notify_server_did_layout(Badge, const Gfx set_content_size(content_size); } +void WebContentView::notify_server_did_change_title(Badge, const String& title) +{ + if (on_title_change) + on_title_change(title); +} + void WebContentView::did_scroll() { client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, size()))); diff --git a/Demos/WebView/WebContentView.h b/Demos/WebView/WebContentView.h index 02be9b4017..3fc7745984 100644 --- a/Demos/WebView/WebContentView.h +++ b/Demos/WebView/WebContentView.h @@ -39,10 +39,13 @@ public: void load(const URL&); + Function on_title_change; + void notify_server_did_layout(Badge, const Gfx::IntSize& content_size); void notify_server_did_paint(Badge, i32 shbuf_id); void notify_server_did_invalidate_content_rect(Badge, const Gfx::IntRect&); void notify_server_did_change_selection(Badge); + void notify_server_did_change_title(Badge, const String&); private: WebContentView(); diff --git a/Demos/WebView/main.cpp b/Demos/WebView/main.cpp index 6037a91260..3ea4563068 100644 --- a/Demos/WebView/main.cpp +++ b/Demos/WebView/main.cpp @@ -35,10 +35,14 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); auto window = GUI::Window::construct(); auto& view = window->set_main_widget(); - window->set_title("WebContentView"); + window->set_title("WebView"); window->set_rect(100, 100, 640, 480); window->show(); + view.on_title_change = [&](auto& title) { + window->set_title(String::format("%s - WebView", title.characters())); + }; + view.load("file:///res/html/misc/welcome.html"); return app->exec(); diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp index 98d6d0d621..0bd5702451 100644 --- a/Services/WebContent/PageHost.cpp +++ b/Services/WebContent/PageHost.cpp @@ -124,4 +124,9 @@ void PageHost::page_did_layout() m_client.post_message(Messages::WebContentClient::DidLayout(content_size)); } +void PageHost::page_did_change_title(const String& title) +{ + m_client.post_message(Messages::WebContentClient::DidChangeTitle(title)); +} + } diff --git a/Services/WebContent/PageHost.h b/Services/WebContent/PageHost.h index 8db4923926..8c9a611211 100644 --- a/Services/WebContent/PageHost.h +++ b/Services/WebContent/PageHost.h @@ -54,6 +54,7 @@ private: virtual void page_did_invalidate(const Gfx::IntRect&) override; virtual void page_did_change_selection() override; virtual void page_did_layout() override; + virtual void page_did_change_title(const String&) override; explicit PageHost(ClientConnection&); diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc index ea5f16f5e5..567298f3f3 100644 --- a/Services/WebContent/WebContentClient.ipc +++ b/Services/WebContent/WebContentClient.ipc @@ -5,4 +5,5 @@ endpoint WebContentClient = 90 DidInvalidateContentRect(Gfx::IntRect content_rect) =| DidChangeSelection() =| DidLayout(Gfx::IntSize content_size) =| + DidChangeTitle(String title) =| } -- cgit v1.2.3