Truly independent web browser
LibWeb+UI/Qt: Leave the menu bar and dock out of screen.availHeight
sideshowbarker92149d5a4f1c
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cppindex fdb18ca9d23..73464a1957e 100644--- a/Libraries/LibWeb/Page/Page.cpp+++ b/Libraries/LibWeb/Page/Page.cpp@@ -279,9 +279,8 @@ Gfx::Palette Page::palette() constreturn m_client->palette();}-static CSSPixelRect screen_rect_in_css_pixels_ignoring_zoom(PageClient const& client)+static CSSPixelRect device_pixel_rect_in_css_pixels_ignoring_zoom(PageClient const& client, DevicePixelRect device_pixel_rect){- auto device_pixel_rect = client.screen_rect();auto scale = client.device_pixel_ratio();return {device_pixel_rect.x().value() / scale,@@ -304,7 +303,7 @@ CSSPixelRect Page::web_exposed_screen_area() const// NB: This is the area of the output device in CSS pixels at a zoom level of 1. Like Chrome and Safari, we leave the// page zoom out of it, so zooming in doesn't make sites switch to their tablet or phone layouts.// See: https://github.com/LadybirdBrowser/ladybird/pull/4084- return screen_rect_in_css_pixels_ignoring_zoom(*m_client);+ return device_pixel_rect_in_css_pixels_ignoring_zoom(*m_client, m_client->screen_rect());}// https://drafts.csswg.org/cssom-view-1/#web-exposed-available-screen-area@@ -318,8 +317,8 @@ CSSPixelRect Page::web_exposed_available_screen_area() const// - The available area of the rendering surface of the output device, in CSS pixels.// - The area of the output device, in CSS pixels.// - The area of the viewport, in CSS pixels.- // NB: This is the area of the output device. See note in web_exposed_screen_area().- return screen_rect_in_css_pixels_ignoring_zoom(*m_client);+ // NB: This is the available area of the output device, at a zoom level of 1 like web_exposed_screen_area().+ return device_pixel_rect_in_css_pixels_ignoring_zoom(*m_client, m_client->available_screen_rect());}CSS::PreferredColorScheme Page::preferred_color_scheme() constdiff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex 8568e275be6..f44f9db86c2 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -675,6 +675,9 @@ public:virtual void send_bad_ipc_message_for_testing([[maybe_unused]] StringView kind, [[maybe_unused]] URL::URL const& active_document_url) { }virtual Gfx::Palette palette() const = 0;virtual DevicePixelRect screen_rect() const = 0;+ // The part of the screen that windows may occupy: the screen less the areas the system keeps for itself, such as+ // a menu bar or a dock. A client that doesn't know it reports the whole screen.+ virtual DevicePixelRect available_screen_rect() const { return screen_rect(); }virtual double zoom_level() const = 0;virtual double device_pixel_ratio() const = 0;virtual double device_pixels_per_css_pixel() const = 0;diff --git a/Libraries/LibWebView/HeadlessWebView.cpp b/Libraries/LibWebView/HeadlessWebView.cppindex 41829087da4..dfe74fc12b6 100644--- a/Libraries/LibWebView/HeadlessWebView.cpp+++ b/Libraries/LibWebView/HeadlessWebView.cpp@@ -272,7 +272,7 @@ void HeadlessWebView::prepare_page_for_tab(WebContentPage& page){ViewImplementation::prepare_page_for_tab(page);- page.async_update_screen_rects({ { screen_rect } }, 0);+ page.async_update_screen_rects({ { screen_rect } }, { { screen_rect } }, 0);}void HeadlessWebView::reset_viewport_size(Web::DevicePixelSize size)diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex 429a72e64d0..ca9b3227c9a 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -508,10 +508,10 @@ void ConnectionFromClient::set_site_compatibility_data(JsonValue data)Web::ResourceLoader::the().set_site_compatibility_data(parsed_data.release_value());}-void ConnectionFromClient::update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect> rects, u32 main_screen)+void ConnectionFromClient::update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect> rects, Vector<Web::DevicePixelRect> available_rects, u32 main_screen){if (auto page = this->page(page_id); page.has_value())- page->set_screen_rects(rects, main_screen);+ page->set_screen_rects(rects, available_rects, main_screen);}void ConnectionFromClient::populate_navigation(Web::PageId page_id, Web::HTML::NavigationPopulationRequest request, Web::HTML::NavigationPopulationResult result)diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.hindex c727faa1044..4c58f3b175d 100644--- a/Services/WebContent/ConnectionFromClient.h+++ b/Services/WebContent/ConnectionFromClient.h@@ -120,7 +120,7 @@ private:virtual void set_site_compatibility_data(JsonValue data) override;virtual void compositor_process_reconnected() override;virtual void update_system_theme(Web::PageId page_id, Core::AnonymousBuffer) override;- virtual void update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect>, u32) override;+ virtual void update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect>, Vector<Web::DevicePixelRect>, u32) override;virtual void populate_navigation(Web::PageId page_id, Web::HTML::NavigationPopulationRequest, Web::HTML::NavigationPopulationResult) override;virtual void stop_loading(Web::PageId page_id) override;virtual void cancel_download(Web::PageId page_id, u64 download_id) override;diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.hindex 177a0715170..b664cc1779a 100644--- a/Services/WebContent/PageClient.h+++ b/Services/WebContent/PageClient.h@@ -76,9 +76,10 @@ public:void set_palette_impl(Gfx::PaletteImpl&);void set_viewport(Web::DevicePixelSize const&, double device_pixel_ratio);void set_hosted_root_viewport(Web::HTML::CrossProcessId, Web::DevicePixelSize const&, Web::DevicePixelRect const& viewport_intersection, double device_pixel_ratio);- void set_screen_rects(Vector<Web::DevicePixelRect> const& rects, size_t main_screen_index)+ void set_screen_rects(Vector<Web::DevicePixelRect> const& rects, Vector<Web::DevicePixelRect> const& available_rects, size_t main_screen_index){m_all_screen_rects = rects;+ m_all_available_screen_rects = available_rects;m_main_screen_index = main_screen_index;}void set_zoom_level(double zoom_level);@@ -214,6 +215,12 @@ private:virtual void send_bad_ipc_message_for_testing(StringView kind, URL::URL const& active_document_url) override;virtual Gfx::Palette palette() const override;virtual Web::DevicePixelRect screen_rect() const override { return m_all_screen_rects[m_main_screen_index]; }+ virtual Web::DevicePixelRect available_screen_rect() const override+ {+ if (m_main_screen_index < m_all_available_screen_rects.size())+ return m_all_available_screen_rects[m_main_screen_index];+ return screen_rect();+ }virtual size_t screen_count() const override { return m_all_screen_rects.size(); }virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override { return m_preferred_color_scheme; }virtual Web::CSS::PreferredContrast preferred_contrast() const override { return m_preferred_contrast; }@@ -389,6 +396,7 @@ private:GC::Ref<Web::Page> m_page;RefPtr<Gfx::PaletteImpl> m_palette_impl;Vector<Web::DevicePixelRect> m_all_screen_rects { Web::DevicePixelRect {} };+ Vector<Web::DevicePixelRect> m_all_available_screen_rects { Web::DevicePixelRect {} };size_t m_main_screen_index { 0 };Web::DevicePixelSize m_viewport_size;double m_device_pixel_ratio { 1.0 };diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipcindex 8cd4775333f..2d4c7f08dcb 100644--- a/Services/WebContent/WebContentServer.ipc+++ b/Services/WebContent/WebContentServer.ipc@@ -93,7 +93,7 @@ endpoint WebContentServer routed by Web::PageId page_idset_site_compatibility_data(JsonValue data) =|update_system_theme(Web::PageId page_id, Core::AnonymousBuffer theme_buffer) =|- update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect> rects, u32 main_screen_index) =|+ update_screen_rects(Web::PageId page_id, Vector<Web::DevicePixelRect> rects, Vector<Web::DevicePixelRect> available_rects, u32 main_screen_index) =|populate_navigation(Web::PageId page_id, Web::HTML::NavigationPopulationRequest request, Web::HTML::NavigationPopulationResult result) =|stop_loading(Web::PageId page_id) =|diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex 2f9e9660d4e..8a41092b93e 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -143,10 +143,14 @@ WebContentView::WebContentView(QWidget* window, Optional<WebView::CanonicalTraveupdate_screen_rects();});- QObject::connect(qGuiApp, &QGuiApplication::screenAdded, this, [this](QScreen*) {+ QObject::connect(qGuiApp, &QGuiApplication::screenAdded, this, [this](QScreen* screen) {+ watch_screen_geometry(*screen);update_screen_rects();});+ for (auto* screen : QGuiApplication::screens())+ watch_screen_geometry(*screen);+QObject::connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, [this] {QTimer::singleShot(0, this, [this] {update_palette();@@ -1696,9 +1700,23 @@ void WebContentView::accessibilityActiveChanged(bool active)}#endif+// A screen's geometry changes when its resolution or scale does, and its available geometry when the dock or a+// taskbar changes size, so each is reported as it happens.+void WebContentView::watch_screen_geometry(QScreen& screen)+{+ QObject::connect(&screen, &QScreen::geometryChanged, this, [this](QRect const&) {+ update_screen_rects();+ });+ QObject::connect(&screen, &QScreen::availableGeometryChanged, this, [this](QRect const&) {+ update_screen_rects();+ });+}+void WebContentView::update_screen_rects(){- update_screen_rects(page());+ traversable().for_each_hosting_page([&](WebView::WebContentPage& page) {+ update_screen_rects(page);+ });}void WebContentView::update_screen_rects(WebView::WebContentPage& page)@@ -1707,18 +1725,23 @@ void WebContentView::update_screen_rects(WebView::WebContentPage& page)if (!screens.empty()) {Vector<Web::DevicePixelRect> screen_rects;+ Vector<Web::DevicePixelRect> available_screen_rects;for (auto const& screen : screens) {// NOTE: QScreen::geometry() returns the 'device-independent pixels', we multiply// by the device pixel ratio to get the 'physical pixels' of the display.- auto geometry = screen->geometry();auto device_pixel_ratio = screen->devicePixelRatio();- screen_rects.append(Web::DevicePixelRect(geometry.x() * device_pixel_ratio, geometry.y() * device_pixel_ratio, geometry.width() * device_pixel_ratio, geometry.height() * device_pixel_ratio));+ auto to_device_pixels = [&](QRect const& geometry) {+ return Web::DevicePixelRect(geometry.x() * device_pixel_ratio, geometry.y() * device_pixel_ratio, geometry.width() * device_pixel_ratio, geometry.height() * device_pixel_ratio);+ };+ screen_rects.append(to_device_pixels(screen->geometry()));+ // The available geometry leaves out what the system keeps for itself, such as a menu bar or a dock.+ available_screen_rects.append(to_device_pixels(screen->availableGeometry()));}// NOTE: The first item in QGuiApplication::screens is always the primary screen.// This is not specified in the documentation but QGuiApplication::primaryScreen// always returns the first item in the list if it isn't empty.- page.async_update_screen_rects(screen_rects, 0);+ page.async_update_screen_rects(screen_rects, available_screen_rects, 0);}}diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex ef3d9d048af..ee10e1c4e48 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -57,6 +57,7 @@class QKeyEvent;class QLabel;class QPushButton;+class QScreen;class QShortcut;class QSinglePointEvent;class QCursor;@@ -210,6 +211,7 @@ private:void enqueue_native_event(Web::KeyEvent::Type, QKeyEvent const& event);void finish_handling_key_event(Web::KeyEvent const&);+ void watch_screen_geometry(QScreen&);void update_screen_rects();void update_screen_rects(WebView::WebContentPage&);