diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-11-25 17:07:19 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-10 12:03:19 +0000 |
commit | 8dfeb67f8ceee2491615e11895f87e5172a7eae4 (patch) | |
tree | b67f35e2a1c5051701e363abc354fab61e20104c /Userland/Utilities | |
parent | 6361584d4a92c351f4f66ddf7b7924beb11e55ae (diff) | |
download | serenity-8dfeb67f8ceee2491615e11895f87e5172a7eae4.zip |
LibWeb+WebContent+headless-browser: Make Page aware of the display scale
For now, we just report it as "1" everywhere.
Replaced `screen_rect()` with `web_exposed_screen_area()` from the spec.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/headless-browser.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index bed46ac996..598af2bd89 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -73,23 +73,24 @@ public: page().load(url); } - virtual void paint(Gfx::IntRect const& content_rect, Gfx::Bitmap& target) override + virtual void paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target) override { Gfx::Painter painter(target); + Gfx::IntRect int_content_rect { content_rect.x().value(), content_rect.y().value(), content_rect.width().value(), content_rect.height().value() }; if (auto* document = page().top_level_browsing_context().active_document()) document->update_layout(); - painter.fill_rect({ {}, content_rect.size() }, palette().base()); + painter.fill_rect({ {}, int_content_rect.size() }, palette().base()); auto* layout_root = this->layout_root(); if (!layout_root) { return; } - Web::PaintContext context(painter, palette(), content_rect.top_left()); + Web::PaintContext context(painter, palette(), int_content_rect.top_left()); context.set_should_show_line_box_borders(false); - context.set_viewport_rect(content_rect); + context.set_viewport_rect(int_content_rect); context.set_has_focus(true); layout_root->paint_all_phases(context); } @@ -104,7 +105,7 @@ public: page().top_level_browsing_context().set_viewport_rect(viewport_rect); } - void set_screen_rect(Gfx::IntRect screen_rect) + void set_screen_rect(Web::DevicePixelRect screen_rect) { m_screen_rect = screen_rect; } @@ -141,11 +142,16 @@ public: return Gfx::Palette(*m_palette_impl); } - virtual Gfx::IntRect screen_rect() const override + virtual Web::DevicePixelRect screen_rect() const override { return m_screen_rect; } + virtual float device_pixels_per_css_pixel() const override + { + return 1.0f; + } + virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override { return m_preferred_color_scheme; @@ -259,7 +265,7 @@ private: NonnullOwnPtr<Web::Page> m_page; RefPtr<Gfx::PaletteImpl> m_palette_impl; - Gfx::IntRect m_screen_rect { 0, 0, 800, 600 }; + Web::DevicePixelRect m_screen_rect { 0, 0, 800, 600 }; Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto }; RefPtr<WebContent::WebDriverConnection> m_webdriver; @@ -699,7 +705,7 @@ static void load_page_for_screenshot_and_exit(HeadlessBrowserPageClient& page_cl auto output_file = MUST(Core::Stream::File::open(output_file_path, Core::Stream::OpenMode::Write)); auto output_rect = page_client.screen_rect(); - auto output_bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, output_rect.size())); + auto output_bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, output_rect.size().to_type<int>())); page_client.paint(output_rect, output_bitmap); |