From 91d8665ab4f082cd73b5ec54fa8cbced82dd7a05 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sun, 21 May 2023 22:03:53 +0100 Subject: [PATCH] LibWeb: Tidy up apply_clip_overflow_rect() a little Avoid possible null optional dereference when creating border radius clipper, and avoid creating clipper if the clip rect is empty (which prevents some debug spam). Also remove an unnecessary lambda. --- .../Libraries/LibWeb/Painting/PaintableBox.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 639b077bb3..52cfa907b3 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -349,19 +349,16 @@ void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase ph auto overflow_x = computed_values().overflow_x(); auto overflow_y = computed_values().overflow_y(); - auto clip_overflow = [&] { - if (!m_clipping_overflow) { - context.painter().save(); - context.painter().add_clip_rect(context.rounded_device_rect(*clip_rect).to_type()); - m_clipping_overflow = true; - } - }; + if (!clip_rect.has_value()) + return; - if (clip_rect.has_value()) { - clip_overflow(); + if (!m_clipping_overflow) { + context.painter().save(); + context.painter().add_clip_rect(context.rounded_device_rect(*clip_rect).to_type()); + m_clipping_overflow = true; } - if (overflow_y == CSS::Overflow::Hidden && overflow_x == CSS::Overflow::Hidden) { + if (!clip_rect->is_empty() && overflow_y == CSS::Overflow::Hidden && overflow_x == CSS::Overflow::Hidden) { auto border_radii_data = normalized_border_radii_data(ShrinkRadiiForBorders::Yes); if (border_radii_data.has_any_radius()) { auto corner_clipper = BorderRadiusCornerClipper::create(context, context.rounded_device_rect(*clip_rect), border_radii_data, CornerClip::Outside, BorderRadiusCornerClipper::UseCachedBitmap::No); @@ -369,7 +366,6 @@ void PaintableBox::apply_clip_overflow_rect(PaintContext& context, PaintPhase ph dbgln("Failed to create overflow border-radius corner clipper: {}", corner_clipper.error()); return; } - clip_overflow(); m_overflow_corner_radius_clipper = corner_clipper.release_value(); m_overflow_corner_radius_clipper->sample_under_corners(context.painter()); }