From e8739ddab76478b245b6c5c604988364a9191bd0 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 4 Apr 2021 00:12:37 +0200 Subject: [PATCH] LibWeb+WebContent: Keep track of screen rect It is now possible to get the up-to-date screen rect from a Web::Page. --- Userland/Libraries/LibWeb/InProcessWebView.h | 4 +++- Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 7 +++++++ Userland/Libraries/LibWeb/OutOfProcessWebView.h | 1 + Userland/Libraries/LibWeb/Page/Page.cpp | 5 +++++ Userland/Libraries/LibWeb/Page/Page.h | 2 ++ Userland/Services/WebContent/ClientConnection.cpp | 5 +++++ Userland/Services/WebContent/ClientConnection.h | 1 + Userland/Services/WebContent/PageHost.h | 4 ++++ Userland/Services/WebContent/WebContentServer.ipc | 1 + 9 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/InProcessWebView.h b/Userland/Libraries/LibWeb/InProcessWebView.h index 81538df551..7b20928bbf 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.h +++ b/Userland/Libraries/LibWeb/InProcessWebView.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include #include #include @@ -85,8 +86,9 @@ private: virtual void did_scroll() override; // ^Web::PageClient - virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); } virtual bool is_multi_process() const override { return false; } + virtual Gfx::Palette palette() const override { return GUI::ScrollableWidget::palette(); } + virtual Gfx::IntRect screen_rect() const override { return GUI::Desktop::the().rect(); } virtual void page_did_change_title(const String&) override; virtual void page_did_set_document_in_main_frame(DOM::Document*) override; virtual void page_did_start_loading(const URL&) override; diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 637dc76c38..c2c36024de 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,7 @@ void OutOfProcessWebView::create_client() }; client().post_message(Messages::WebContentServer::UpdateSystemTheme(Gfx::current_system_theme_buffer())); + client().post_message(Messages::WebContentServer::UpdateScreenRect(GUI::Desktop::the().rect())); } void OutOfProcessWebView::load(const URL& url) @@ -208,6 +210,11 @@ void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event) request_repaint(); } +void OutOfProcessWebView::screen_rect_change_event(GUI::ScreenRectChangeEvent& event) +{ + client().post_message(Messages::WebContentServer::UpdateScreenRect(event.rect())); +} + void OutOfProcessWebView::notify_server_did_paint(Badge, i32 bitmap_id) { if (m_client_state.back_bitmap_id == bitmap_id) { diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index e0fccc6ae7..b634bc1077 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -91,6 +91,7 @@ private: virtual void mousewheel_event(GUI::MouseEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override; virtual void theme_change_event(GUI::ThemeChangeEvent&) override; + virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override; // ^ScrollableWidget virtual void did_scroll() override; diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index 1ec5d15666..96b726189f 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -72,6 +72,11 @@ Gfx::Palette Page::palette() const return m_client.palette(); } +Gfx::IntRect Page::screen_rect() const +{ + return m_client.screen_rect(); +} + bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta) { return main_frame().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta); diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index a45072edab..6dfe853013 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -74,6 +74,7 @@ public: bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point); Gfx::Palette palette() const; + Gfx::IntRect screen_rect() const; private: PageClient& m_client; @@ -86,6 +87,7 @@ class PageClient { public: virtual bool is_multi_process() const = 0; virtual Gfx::Palette palette() const = 0; + virtual Gfx::IntRect screen_rect() const = 0; virtual void page_did_set_document_in_main_frame(DOM::Document*) { } virtual void page_did_change_title(const String&) { } virtual void page_did_start_loading(const URL&) { } diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp index 22e08f3e9b..142e62f690 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -89,6 +89,11 @@ void ClientConnection::handle(const Messages::WebContentServer::UpdateSystemThem m_page_host->set_palette_impl(*impl); } +void ClientConnection::handle(const Messages::WebContentServer::UpdateScreenRect& message) +{ + m_page_host->set_screen_rect(message.rect()); +} + void ClientConnection::handle(const Messages::WebContentServer::LoadURL& message) { dbgln_if(SPAM_DEBUG, "handle: WebContentServer::LoadURL: url={}", message.url()); diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h index c782b62dd2..3fd0a3c662 100644 --- a/Userland/Services/WebContent/ClientConnection.h +++ b/Userland/Services/WebContent/ClientConnection.h @@ -54,6 +54,7 @@ private: virtual OwnPtr handle(const Messages::WebContentServer::Greet&) override; virtual void handle(const Messages::WebContentServer::UpdateSystemTheme&) override; + virtual void handle(const Messages::WebContentServer::UpdateScreenRect&) override; virtual void handle(const Messages::WebContentServer::LoadURL&) override; virtual void handle(const Messages::WebContentServer::LoadHTML&) override; virtual void handle(const Messages::WebContentServer::Paint&) override; diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index 44aee5ffbd..315b3bc34c 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -26,6 +26,7 @@ #pragma once +#include #include namespace WebContent { @@ -47,6 +48,7 @@ public: void set_palette_impl(const Gfx::PaletteImpl&); void set_viewport_rect(const Gfx::IntRect&); + void set_screen_rect(const Gfx::IntRect& rect) { m_screen_rect = rect; }; void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; } @@ -54,6 +56,7 @@ private: // ^PageClient virtual bool is_multi_process() const override { return true; } virtual Gfx::Palette palette() const override; + virtual Gfx::IntRect screen_rect() const override { return m_screen_rect; } virtual void page_did_invalidate(const Gfx::IntRect&) override; virtual void page_did_change_selection() override; virtual void page_did_request_cursor_change(Gfx::StandardCursor) override; @@ -84,6 +87,7 @@ private: ClientConnection& m_client; NonnullOwnPtr m_page; RefPtr m_palette_impl; + Gfx::IntRect m_screen_rect; bool m_should_show_line_box_borders { false }; }; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index cf0dd86171..1b429c5579 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -3,6 +3,7 @@ endpoint WebContentServer = 89 Greet() => () UpdateSystemTheme(Core::AnonymousBuffer theme_buffer) =| + UpdateScreenRect(Gfx::IntRect rect) =| LoadURL(URL url) =| LoadHTML(String html, URL url) =|