Files
ladybird/Libraries/LibWeb/Painting/ImagePaintable.h
Andreas Kling ed26fdaa81 LibWeb: Remove ViewportClient from ImagePaintable and VideoBox
Neither of these classes did anything useful as ViewportClients:

- ImagePaintable called set_visible_in_viewport() which is a FIXME
  no-op in every ImageProvider implementation.
- VideoBox had an empty did_set_viewport_rect() with a FIXME comment.

More importantly, they caused a crash when a DOM node was adopted into
a different document: the old ImagePaintable/VideoBox would still be
registered with the old document, but their document() accessor (which
goes through the DOM node) would return the new document. During GC
finalization, unregister_viewport_client() would fail because it was
trying to unregister from the wrong document.

The only meaningful ViewportClient is HTMLImageElement (for responsive
image source selection), which already handles document adoption
correctly in adopted_from().

Fixes crash when loading https://msn.com/
2026-02-26 09:25:25 +01:00

41 lines
1.1 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Layout/ImageBox.h>
#include <LibWeb/Layout/SVGImageBox.h>
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Painting {
class ImagePaintable final : public PaintableBox {
GC_CELL(ImagePaintable, PaintableBox);
GC_DECLARE_ALLOCATOR(ImagePaintable);
public:
static GC::Ref<ImagePaintable> create(Layout::ImageBox const& layout_box);
static GC::Ref<ImagePaintable> create(Layout::SVGImageBox const& layout_box);
virtual void paint(DisplayListRecordingContext&, PaintPhase) const override;
virtual void reset_for_relayout() override;
private:
// ^JS::Cell
virtual void visit_edges(Visitor&) override;
ImagePaintable(Layout::Box const& layout_box, Layout::ImageProvider const& image_provider, bool renders_as_alt_text, String alt_text, bool is_svg_image);
bool m_renders_as_alt_text { false };
String m_alt_text;
Layout::ImageProvider const& m_image_provider;
bool m_is_svg_image { false };
};
}