1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 06:04:57 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-12-06 11:49:45 -05:00 committed by Andreas Kling
parent bea11f6d99
commit a7b98a9761
8 changed files with 26 additions and 8 deletions

View file

@ -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() { }

View file

@ -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;

View file

@ -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<CSS::Transformation> const& transformations) const

View file

@ -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)

View file

@ -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<int>() };
@ -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);

View file

@ -29,7 +29,7 @@ public:
ErrorOr<void> 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&);

View file

@ -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)
{
}

View file

@ -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: