Repository: LadybirdBrowser/ladybird
File: Libraries/LibWeb/Painting/Paintable.cpp (C++)

Code before:
        self_and_ancestors.append(paintable);
    }

    for (auto const* paintable : self_and_ancestors.in_reverse()) {
        if (auto const* box = as_if<PaintableBox>(paintable)) {
            box->apply_scroll_offset(context);
            if (box->stacking_context()) {
                auto to_device_pixels_scale = float(context.device_pixels_per_css_pixel());
                auto transform_matrix = box->transform();
                auto transform_origin = box->transform_origin().to_type<float>();
                // We only want the transform here, everything else undesirable for the inspector overlay
                DisplayListRecorder::PushStackingContextParams push_stacking_context_params {
                    .opacity = 1.0,
                    .compositing_and_blending_operator = Gfx::CompositingAndBlendingOperator::Normal,
                    .isolate = false,
                    .transform = StackingContextTransform(transform_origin, transform_matrix, to_device_pixels_scale),
                };
                context.display_list_recorder().push_stacking_context(push_stacking_context_params);
            }
        }
    }

    paint_inspector_overlay_internal(context);

    for (auto const* paintable : self_and_ancestors) {
        if (auto const* box = as_if<PaintableBox>(paintable); box && box->stacking_context()) {
            if (box->stacking_context()) {
                context.display_list_recorder().pop_stacking_context();
            }
            box->reset_scroll_offset(context);
        }
    }
}

void Paintable::set_needs_display(InvalidateDisplayList should_invalidate_display_list)
{
    auto& document = const_cast<DOM::Document&>(this->document());
    if (should_invalidate_display_list == InvalidateDisplayList::Yes)
        document.invalidate_display_list();

    auto* containing_block = this->containing_block();
    if (!containing_block)
        return;

    if (!is<Painting::PaintableWithLines>(*containing_block))
        return;
    static_cast<Painting::PaintableWithLines const&>(*containing_block).for_each_fragment([&](auto& fragment) {
        document.set_needs_display(fragment.absolute_rect(), InvalidateDisplayList::No);
        return IterationDecision::Continue;
    });
}

Review comment (suggestion):
You should remove `; box && box->stacking_context()` here since you check it again on the next line.

Code after:
        self_and_ancestors.append(paintable);
    }

    for (auto const* paintable : self_and_ancestors.in_reverse()) {
        if (auto const* box = as_if<PaintableBox>(paintable)) {
            box->apply_scroll_offset(context);
            if (box->stacking_context()) {
                auto to_device_pixels_scale = float(context.device_pixels_per_css_pixel());
                auto transform_matrix = box->transform();
                auto transform_origin = box->transform_origin().to_type<float>();
                // We only want the transform here, everything else undesirable for the inspector overlay
                DisplayListRecorder::PushStackingContextParams push_stacking_context_params {
                    .opacity = 1.0,
                    .compositing_and_blending_operator = Gfx::CompositingAndBlendingOperator::Normal,
                    .isolate = false,
                    .transform = StackingContextTransform(transform_origin, transform_matrix, to_device_pixels_scale),
                };
                context.display_list_recorder().push_stacking_context(push_stacking_context_params);
            }
        }
    }

    paint_inspector_overlay_internal(context);

    for (auto const* paintable : self_and_ancestors) {
        if (auto const* box = as_if<PaintableBox>(paintable)) {
            if (box->stacking_context()) {
                context.display_list_recorder().pop_stacking_context();
            }
            box->reset_scroll_offset(context);
        }
    }
}

void Paintable::set_needs_display(InvalidateDisplayList should_invalidate_display_list)
{
    auto& document = const_cast<DOM::Document&>(this->document());
    if (should_invalidate_display_list == InvalidateDisplayList::Yes)
        document.invalidate_display_list();

    auto* containing_block = this->containing_block();
    if (!containing_block)
        return;

    if (!is<Painting::PaintableWithLines>(*containing_block))
        return;
    static_cast<Painting::PaintableWithLines const&>(*containing_block).for_each_fragment([&](auto& fragment) {
        document.set_needs_display(fragment.absolute_rect(), InvalidateDisplayList::No);
        return IterationDecision::Continue;
    });
}