mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
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. :^)
This commit is contained in:
parent
7cb7bcb924
commit
c15f9e7593
8 changed files with 30 additions and 1 deletions
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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())));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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&);
|
||||
|
||||
|
|
|
@ -5,4 +5,5 @@ endpoint WebContentClient = 90
|
|||
DidInvalidateContentRect(Gfx::IntRect content_rect) =|
|
||||
DidChangeSelection() =|
|
||||
DidLayout(Gfx::IntSize content_size) =|
|
||||
DidChangeTitle(String title) =|
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue