From 1ae416fa947ecaaea5977cbac4a80a2d1c35173c Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 10 Feb 2024 20:34:03 +0100 Subject: [PATCH] LibWeb: Add `compute_combined_css_transform()` for PaintableBox This prepares for upcoming changes where the code that finds combined CSS transform will be reused in `clear_clip_overflow_rect()`. --- .../LibWeb/Painting/PaintableBox.cpp | 24 ++++++++++++------- .../Libraries/LibWeb/Painting/PaintableBox.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 9e0557a898..cfc279cc1e 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -142,6 +142,16 @@ CSSPixelRect PaintableBox::compute_absolute_padding_rect_with_css_transform_appl return padding_rect; } +Gfx::AffineTransform PaintableBox::compute_combined_css_transform() const +{ + Gfx::AffineTransform combined_transform; + for (auto const* ancestor = &this->layout_box(); ancestor; ancestor = ancestor->containing_block()) { + auto affine_transform = Gfx::extract_2d_affine_transform(ancestor->paintable_box()->transform()); + combined_transform = combined_transform.multiply(affine_transform); + } + return combined_transform; +} + CSSPixelRect PaintableBox::absolute_rect() const { if (!m_absolute_rect.has_value()) @@ -425,15 +435,11 @@ void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase ph if (clip_rect().has_value()) { auto overflow_clip_rect = clip_rect().value(); - for (auto const* ancestor = &this->layout_box(); ancestor; ancestor = ancestor->containing_block()) { - auto affine_transform = Gfx::extract_2d_affine_transform(ancestor->paintable_box()->transform()); - if (!affine_transform.is_identity()) { - // NOTE: Since the painting command executor applies a CSS transform and the clip rect is calculated - // with this transform in account, we need to remove the transform from the clip rect. - // Otherwise, the transform will be applied twice to the clip rect. - overflow_clip_rect.translate_by(-affine_transform.translation().to_type()); - } - } + // NOTE: Since the painting command executor applies a CSS transform and the clip rect is calculated + // with this transform in account, we need to remove the transform from the clip rect. + // Otherwise, the transform will be applied twice to the clip rect. + auto combined_transform = compute_combined_css_transform(); + overflow_clip_rect.translate_by(-combined_transform.translation().to_type()); m_clipping_overflow = true; context.recording_painter().save(); diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.h b/Userland/Libraries/LibWeb/Painting/PaintableBox.h index d38dba7a32..4ce58e87a2 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.h @@ -200,6 +200,7 @@ public: CSSPixelPoint const& transform_origin() const { return m_transform_origin; } CSSPixelRect compute_absolute_padding_rect_with_css_transform_applied() const; + Gfx::AffineTransform compute_combined_css_transform() const; Optional get_clip_rect() const;