From a7b98a97617a11b0d948fbf449da453f7792ca96 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 6 Dec 2023 11:49:45 -0500 Subject: [PATCH] LibWeb+WebContent+WebWorker: Add an option to skip painting the overlay This will allow the Inspector to take a screenshot of a DOM node without the overlay which renders the inspected node outline / box data. --- Userland/Libraries/LibWeb/Page/Page.h | 11 ++++++++++- Userland/Libraries/LibWeb/Painting/PaintContext.h | 5 +++++ .../Libraries/LibWeb/Painting/StackingContext.cpp | 7 +++++-- Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp | 2 +- Userland/Services/WebContent/PageClient.cpp | 3 ++- Userland/Services/WebContent/PageClient.h | 2 +- Userland/Services/WebWorker/PageHost.cpp | 2 +- Userland/Services/WebWorker/PageHost.h | 2 +- 8 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index 45ca4932f5..b9845cdbfb 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -198,6 +198,15 @@ private: bool m_pdf_viewer_supported { false }; }; +struct PaintOptions { + enum class PaintOverlay { + No, + Yes, + }; + + PaintOverlay paint_overlay { PaintOverlay::Yes }; +}; + class PageClient : public JS::Cell { JS_CELL(PageClient, JS::Cell); @@ -209,7 +218,7 @@ public: virtual DevicePixelRect screen_rect() const = 0; virtual double device_pixels_per_css_pixel() const = 0; virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0; - virtual void paint(DevicePixelRect const&, Gfx::Bitmap&) = 0; + virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, PaintOptions = {}) = 0; virtual void page_did_change_title(DeprecatedString const&) { } virtual void page_did_request_navigate_back() { } virtual void page_did_request_navigate_forward() { } diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.h b/Userland/Libraries/LibWeb/Painting/PaintContext.h index 6303058c23..81cfeec9dc 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintContext.h +++ b/Userland/Libraries/LibWeb/Painting/PaintContext.h @@ -26,6 +26,9 @@ public: bool should_show_line_box_borders() const { return m_should_show_line_box_borders; } void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } + bool should_paint_overlay() const { return m_should_paint_overlay; } + void set_should_paint_overlay(bool should_paint_overlay) { m_should_paint_overlay = should_paint_overlay; } + DevicePixelRect device_viewport_rect() const { return m_device_viewport_rect; } void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; } CSSPixelRect css_viewport_rect() const; @@ -62,6 +65,7 @@ public: auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel); clone.m_device_viewport_rect = m_device_viewport_rect; clone.m_should_show_line_box_borders = m_should_show_line_box_borders; + clone.m_should_paint_overlay = m_should_paint_overlay; clone.m_focus = m_focus; return clone; } @@ -79,6 +83,7 @@ private: double m_device_pixels_per_css_pixel { 0 }; DevicePixelRect m_device_viewport_rect; bool m_should_show_line_box_borders { false }; + bool m_should_paint_overlay { true }; bool m_focus { false }; CSSPixelPoint m_scroll_offset; Gfx::AffineTransform m_svg_transform; diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index d4ef5a37f4..cb5b9d6ddd 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -264,8 +264,11 @@ void StackingContext::paint_internal(PaintContext& context) const } paint_node(paintable_box(), context, PaintPhase::Outline); - paint_node(paintable_box(), context, PaintPhase::Overlay); - paint_descendants(context, paintable_box(), StackingContextPaintPhase::FocusAndOverlay); + + if (context.should_paint_overlay()) { + paint_node(paintable_box(), context, PaintPhase::Overlay); + paint_descendants(context, paintable_box(), StackingContextPaintPhase::FocusAndOverlay); + } } Gfx::FloatMatrix4x4 StackingContext::combine_transformations(Vector const& transformations) const diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index d8c4d7d288..45b8d8b448 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -45,7 +45,7 @@ public: virtual double device_pixels_per_css_pixel() const override { return 1.0; } virtual CSS::PreferredColorScheme preferred_color_scheme() const override { return m_host_page.client().preferred_color_scheme(); } virtual void request_file(FileRequest) override { } - virtual void paint(DevicePixelRect const&, Gfx::Bitmap&) override { } + virtual void paint(DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override { } private: explicit SVGPageClient(Page& host_page) diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index 4c53f457fa..b97253943e 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -140,7 +140,7 @@ Gfx::Color PageClient::background_color() const return document->background_color(); } -void PageClient::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target) +void PageClient::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& target, Web::PaintOptions paint_options) { Gfx::IntRect bitmap_rect { {}, content_rect.size().to_type() }; @@ -162,6 +162,7 @@ void PageClient::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& ta return; context.set_should_show_line_box_borders(m_should_show_line_box_borders); + context.set_should_paint_overlay(paint_options.paint_overlay == Web::PaintOptions::PaintOverlay::Yes); context.set_device_viewport_rect(content_rect); context.set_has_focus(m_has_focus); document->paintable()->paint_all_phases(context); diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index 88c4489afd..576a9a5429 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -29,7 +29,7 @@ public: ErrorOr connect_to_webdriver(DeprecatedString const& webdriver_ipc_path); - virtual void paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap&) override; + virtual void paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap&, Web::PaintOptions = {}) override; void set_palette_impl(Gfx::PaletteImpl&); void set_viewport_rect(Web::DevicePixelRect const&); diff --git a/Userland/Services/WebWorker/PageHost.cpp b/Userland/Services/WebWorker/PageHost.cpp index 1de082b4c6..b5e6709938 100644 --- a/Userland/Services/WebWorker/PageHost.cpp +++ b/Userland/Services/WebWorker/PageHost.cpp @@ -65,7 +65,7 @@ Web::CSS::PreferredColorScheme PageHost::preferred_color_scheme() const return Web::CSS::PreferredColorScheme::Auto; } -void PageHost::paint(Web::DevicePixelRect const&, Gfx::Bitmap&) +void PageHost::paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions) { } diff --git a/Userland/Services/WebWorker/PageHost.h b/Userland/Services/WebWorker/PageHost.h index 44f26e5110..55e41a8e1d 100644 --- a/Userland/Services/WebWorker/PageHost.h +++ b/Userland/Services/WebWorker/PageHost.h @@ -28,7 +28,7 @@ public: virtual Web::DevicePixelRect screen_rect() const override; virtual double device_pixels_per_css_pixel() const override; virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override; - virtual void paint(Web::DevicePixelRect const&, Gfx::Bitmap&) override; + virtual void paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions = {}) override; virtual void request_file(Web::FileRequest) override; private: