From 71ccaeda164dc493c1e7a201e0a5818f00f7bf67 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 12 Nov 2024 10:36:53 -0500 Subject: [PATCH] headless-browser: Store the viewport size as DevicePixelSize This will just avoid a bunch of needless conversion to/from IntSize in and upcoming commit. --- UI/Headless/Application.cpp | 2 +- UI/Headless/Application.h | 4 ++-- UI/Headless/HeadlessWebView.cpp | 4 ++-- UI/Headless/HeadlessWebView.h | 9 ++++----- UI/Headless/Test.cpp | 2 +- UI/Headless/Test.h | 4 ++-- UI/Headless/main.cpp | 2 +- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/UI/Headless/Application.cpp b/UI/Headless/Application.cpp index d13e20f6b74..eee2fad43bc 100644 --- a/UI/Headless/Application.cpp +++ b/UI/Headless/Application.cpp @@ -95,7 +95,7 @@ ErrorOr Application::launch_test_fixtures() return {}; } -HeadlessWebView& Application::create_web_view(Core::AnonymousBuffer theme, Gfx::IntSize window_size) +HeadlessWebView& Application::create_web_view(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size) { auto web_view = HeadlessWebView::create(move(theme), window_size); m_web_views.append(move(web_view)); diff --git a/UI/Headless/Application.h b/UI/Headless/Application.h index d956155a669..32b878174cd 100644 --- a/UI/Headless/Application.h +++ b/UI/Headless/Application.h @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include #include namespace Ladybird { @@ -40,7 +40,7 @@ public: static Requests::RequestClient& request_client() { return *the().m_request_client; } static ImageDecoderClient::Client& image_decoder_client() { return *the().m_image_decoder_client; } - HeadlessWebView& create_web_view(Core::AnonymousBuffer theme, Gfx::IntSize window_size); + HeadlessWebView& create_web_view(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size); HeadlessWebView& create_child_web_view(HeadlessWebView const&, u64 page_index); void destroy_web_views(); diff --git a/UI/Headless/HeadlessWebView.cpp b/UI/Headless/HeadlessWebView.cpp index aea811b8889..df761e4a588 100644 --- a/UI/Headless/HeadlessWebView.cpp +++ b/UI/Headless/HeadlessWebView.cpp @@ -16,7 +16,7 @@ namespace Ladybird { static Web::DevicePixelRect const screen_rect { 0, 0, 1920, 1080 }; -HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Gfx::IntSize viewport_size) +HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size) : m_theme(move(theme)) , m_viewport_size(viewport_size) , m_test_promise(TestPromise::construct()) @@ -121,7 +121,7 @@ HeadlessWebView::HeadlessWebView(Core::AnonymousBuffer theme, Gfx::IntSize viewp }; } -NonnullOwnPtr HeadlessWebView::create(Core::AnonymousBuffer theme, Gfx::IntSize window_size) +NonnullOwnPtr HeadlessWebView::create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size) { auto view = adopt_own(*new HeadlessWebView(move(theme), window_size)); view->initialize_client(CreateNewClient::Yes); diff --git a/UI/Headless/HeadlessWebView.h b/UI/Headless/HeadlessWebView.h index b8e043759ef..d0f627e7ef6 100644 --- a/UI/Headless/HeadlessWebView.h +++ b/UI/Headless/HeadlessWebView.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -22,7 +21,7 @@ namespace Ladybird { class HeadlessWebView final : public WebView::ViewImplementation { public: - static NonnullOwnPtr create(Core::AnonymousBuffer theme, Gfx::IntSize window_size); + static NonnullOwnPtr create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size); static NonnullOwnPtr create_child(HeadlessWebView const&, u64 page_index); void clear_content_filters(); @@ -35,19 +34,19 @@ public: Function on_web_content_crashed; private: - HeadlessWebView(Core::AnonymousBuffer theme, Gfx::IntSize viewport_size); + HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size); void update_zoom() override { } void initialize_client(CreateNewClient) override; - virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size.to_type(); } + virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size; } virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; } virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; } virtual void did_receive_screenshot(Badge, Gfx::ShareableBitmap const& screenshot) override; Core::AnonymousBuffer m_theme; - Gfx::IntSize m_viewport_size; + Web::DevicePixelSize m_viewport_size; RefPtr>> m_pending_screenshot; diff --git a/UI/Headless/Test.cpp b/UI/Headless/Test.cpp index 7a6d7762d74..67c46ce467b 100644 --- a/UI/Headless/Test.cpp +++ b/UI/Headless/Test.cpp @@ -384,7 +384,7 @@ static void run_test(HeadlessWebView& view, Test& test, Application& app) view.load("about:blank"sv); } -ErrorOr run_tests(Core::AnonymousBuffer const& theme, Gfx::IntSize window_size) +ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize window_size) { auto& app = Application::the(); TRY(load_test_config(app.test_root_path)); diff --git a/UI/Headless/Test.h b/UI/Headless/Test.h index 85995203c44..46b25dad707 100644 --- a/UI/Headless/Test.h +++ b/UI/Headless/Test.h @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include namespace Ladybird { @@ -78,7 +78,7 @@ struct TestCompletion { using TestPromise = Core::Promise; -ErrorOr run_tests(Core::AnonymousBuffer const& theme, Gfx::IntSize window_size); +ErrorOr run_tests(Core::AnonymousBuffer const& theme, Web::DevicePixelSize window_size); void run_dump_test(HeadlessWebView&, Test&, URL::URL const&, int timeout_in_milliseconds); } diff --git a/UI/Headless/main.cpp b/UI/Headless/main.cpp index 5ee648c2ab1..c9f832e1e1c 100644 --- a/UI/Headless/main.cpp +++ b/UI/Headless/main.cpp @@ -72,7 +72,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto theme = TRY(Gfx::load_system_theme(theme_path.string())); // FIXME: Allow passing the window size as an argument. - static constexpr Gfx::IntSize window_size { 800, 600 }; + static constexpr Web::DevicePixelSize window_size { 800, 600 }; if (!app->test_root_path.is_empty()) { app->test_root_path = LexicalPath::absolute_path(TRY(FileSystem::current_working_directory()), app->test_root_path);