1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibWeb: Move image viewport awareness from ImageBox to ImagePaintable

Images being aware of being visible inside the viewport is a painting
concern, not a layout concern.
This commit is contained in:
Andreas Kling 2023-05-09 07:02:28 +02:00
parent 8da9ff24e4
commit dbe961ca02
4 changed files with 26 additions and 26 deletions

View file

@ -21,6 +21,16 @@ JS::NonnullGCPtr<ImagePaintable> ImagePaintable::create(Layout::ImageBox const&
ImagePaintable::ImagePaintable(Layout::ImageBox const& layout_box)
: PaintableBox(layout_box)
{
browsing_context().register_viewport_client(*this);
}
void ImagePaintable::finalize()
{
Base::finalize();
// NOTE: We unregister from the browsing context in finalize() to avoid trouble
// in the scenario where our BrowsingContext has already been swept by GC.
browsing_context().unregister_viewport_client(*this);
}
Layout::ImageBox const& ImagePaintable::layout_box() const
@ -57,4 +67,9 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
}
}
void ImagePaintable::browsing_context_did_set_viewport_rect(CSSPixelRect const& viewport_rect)
{
layout_box().image_loader().set_visible_in_viewport(viewport_rect.intersects(absolute_rect()));
}
}