From 78d8989ea4739f9b39ca98f875eb250c19e26a50 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 17 Oct 2024 22:04:12 +0200 Subject: [PATCH] LibWeb: Accept paintable instead of layout node in paint_background() After InlinePaintable is gone it's possible to make this function accept a PaintableBox instead of more broad Layout::NodeWithStyleAndBoxModelMetrics type. --- .../LibWeb/Painting/BackgroundPainting.cpp | 33 +++++++++---------- .../LibWeb/Painting/BackgroundPainting.h | 2 +- .../LibWeb/Painting/PaintableBox.cpp | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index b1b1ebd52b8..b35550ce993 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -48,17 +48,17 @@ static RefPtr compute_text_clip_paths(PaintContext& context, Painta return text_clip_paths; } -static BackgroundBox get_box(CSS::BackgroundBox box_clip, BackgroundBox border_box, auto const& layout_node) +static BackgroundBox get_box(CSS::BackgroundBox box_clip, BackgroundBox border_box, auto const& paintable_box) { auto box = border_box; switch (box_clip) { case CSS::BackgroundBox::ContentBox: { - auto& padding = layout_node.box_model().padding; + auto& padding = paintable_box.box_model().padding; box.shrink(padding.top, padding.right, padding.bottom, padding.left); [[fallthrough]]; } case CSS::BackgroundBox::PaddingBox: { - auto& border = layout_node.box_model().border; + auto& border = paintable_box.box_model().border; box.shrink(border.top, border.right, border.bottom, border.left); [[fallthrough]]; } @@ -69,13 +69,13 @@ static BackgroundBox get_box(CSS::BackgroundBox box_clip, BackgroundBox border_b } // https://www.w3.org/TR/css-backgrounds-3/#backgrounds -void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMetrics const& layout_node, CSS::ImageRendering image_rendering, ResolvedBackground resolved_background, BorderRadiiData const& border_radii) +void paint_background(PaintContext& context, PaintableBox const& paintable_box, CSS::ImageRendering image_rendering, ResolvedBackground resolved_background, BorderRadiiData const& border_radii) { auto& display_list_recorder = context.display_list_recorder(); DisplayListRecorderStateSaver state { display_list_recorder }; if (resolved_background.needs_text_clip) { - auto display_list = compute_text_clip_paths(context, *layout_node.first_paintable(), resolved_background.background_rect.location()); + auto display_list = compute_text_clip_paths(context, paintable_box, resolved_background.background_rect.location()); auto rect = context.rounded_device_rect(resolved_background.background_rect); display_list_recorder.add_mask(move(display_list), rect.to_type()); } @@ -102,10 +102,10 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet DevicePixels right { 0 }; } clip_shrink; - auto border_top = layout_node.computed_values().border_top(); - auto border_bottom = layout_node.computed_values().border_bottom(); - auto border_left = layout_node.computed_values().border_left(); - auto border_right = layout_node.computed_values().border_right(); + auto border_top = paintable_box.computed_values().border_top(); + auto border_bottom = paintable_box.computed_values().border_bottom(); + auto border_left = paintable_box.computed_values().border_left(); + auto border_right = paintable_box.computed_values().border_right(); if (border_top.color.alpha() == 255 && border_bottom.color.alpha() == 255 && border_left.color.alpha() == 255 && border_right.color.alpha() == 255) { @@ -120,7 +120,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet DisplayListRecorderStateSaver state { display_list_recorder }; // Clip - auto clip_box = get_box(layer.clip, border_box, layout_node); + auto clip_box = get_box(layer.clip, border_box, paintable_box); CSSPixelRect const& css_clip_rect = clip_box.rect; auto clip_rect = context.rounded_device_rect(css_clip_rect); @@ -139,15 +139,12 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet switch (layer.attachment) { case CSS::BackgroundAttachment::Fixed: - background_positioning_area.set_location(layout_node.root().navigable()->viewport_scroll_offset()); + background_positioning_area.set_location(paintable_box.layout_node().root().navigable()->viewport_scroll_offset()); break; case CSS::BackgroundAttachment::Local: - if (is(layout_node)) { - auto const* paintable_box = static_cast(layout_node).paintable_box(); - if (paintable_box && !paintable_box->is_viewport()) { - auto scroll_offset = paintable_box->scroll_offset(); - background_positioning_area.translate_by(-scroll_offset.x(), -scroll_offset.y()); - } + if (!paintable_box.is_viewport()) { + auto scroll_offset = paintable_box.scroll_offset(); + background_positioning_area.translate_by(-scroll_offset.x(), -scroll_offset.y()); } break; case CSS::BackgroundAttachment::Scroll: @@ -244,7 +241,7 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet CSSPixels initial_image_x = image_rect.x(); CSSPixels image_y = image_rect.y(); - image.resolve_for_size(layout_node, image_rect.size()); + image.resolve_for_size(paintable_box.layout_node_with_style_and_box_metrics(), image_rect.size()); auto for_each_image_device_rect = [&](auto callback) { while (image_y < css_clip_rect.bottom()) { diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.h b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.h index 349ae414a58..91e1cd9625c 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.h +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.h @@ -47,6 +47,6 @@ struct ResolvedBackground { ResolvedBackground resolve_background_layers(Vector const& layers, Layout::NodeWithStyleAndBoxModelMetrics const& layout_node, Color background_color, CSSPixelRect const& border_rect, BorderRadiiData const& border_radii); -void paint_background(PaintContext&, Layout::NodeWithStyleAndBoxModelMetrics const&, CSS::ImageRendering, ResolvedBackground resolved_background, BorderRadiiData const&); +void paint_background(PaintContext&, PaintableBox const&, CSS::ImageRendering, ResolvedBackground resolved_background, BorderRadiiData const&); } diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 05ca0e48f9a..1895ed84404 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -476,7 +476,7 @@ void PaintableBox::paint_background(PaintContext& context) const if (layout_node_with_style_and_box_metrics().is_body() && document().html_element()->should_use_body_background_properties()) return; - Painting::paint_background(context, layout_node_with_style_and_box_metrics(), computed_values().image_rendering(), m_resolved_background, normalized_border_radii_data()); + Painting::paint_background(context, *this, computed_values().image_rendering(), m_resolved_background, normalized_border_radii_data()); } void PaintableBox::paint_box_shadow(PaintContext& context) const