diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-04 23:40:17 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-04 23:40:17 +0200 |
commit | c15f9e75932a3beb775b2083633879c04f2510a0 (patch) | |
tree | ef3e4ec0b413034361d4a602a7052d03bb687376 | |
parent | 7cb7bcb9244bccd1162f52f82d9ea36cbc0e9609 (diff) | |
download | serenity-c15f9e75932a3beb775b2083633879c04f2510a0.zip |
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. :^)
-rw-r--r-- | Demos/WebView/WebContentClient.cpp | 8 | ||||
-rw-r--r-- | Demos/WebView/WebContentClient.h | 1 | ||||
-rw-r--r-- | Demos/WebView/WebContentView.cpp | 6 | ||||
-rw-r--r-- | Demos/WebView/WebContentView.h | 3 | ||||
-rw-r--r-- | Demos/WebView/main.cpp | 6 | ||||
-rw-r--r-- | Services/WebContent/PageHost.cpp | 5 | ||||
-rw-r--r-- | Services/WebContent/PageHost.h | 1 | ||||
-rw-r--r-- | Services/WebContent/WebContentClient.ipc | 1 |
8 files changed, 30 insertions, 1 deletions
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<WebContentClient>, const Gfx set_content_size(content_size); } +void WebContentView::notify_server_did_change_title(Badge<WebContentClient>, 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<void(const String&)> on_title_change; + void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size); void notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id); void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&); void notify_server_did_change_selection(Badge<WebContentClient>); + void notify_server_did_change_title(Badge<WebContentClient>, 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<WebContentView>(); - 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) =| } |