summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/Layout/ImageBox.cpp15
-rw-r--r--Userland/Libraries/LibWeb/Layout/ImageBox.h11
-rw-r--r--Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp15
-rw-r--r--Userland/Libraries/LibWeb/Painting/ImagePaintable.h11
4 files changed, 26 insertions, 26 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
index 8750f760e3..76a111e3ba 100644
--- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
@@ -15,20 +15,10 @@ ImageBox::ImageBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr
: ReplacedBox(document, element, move(style))
, m_image_loader(image_loader)
{
- browsing_context().register_viewport_client(*this);
}
ImageBox::~ImageBox() = default;
-void ImageBox::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);
-}
-
int ImageBox::preferred_width() const
{
return dom_node().attribute(HTML::AttributeNames::width).to_int().value_or(m_image_loader.width());
@@ -90,11 +80,6 @@ bool ImageBox::renders_as_alt_text() const
return false;
}
-void ImageBox::browsing_context_did_set_viewport_rect(CSSPixelRect const& viewport_rect)
-{
- m_image_loader.set_visible_in_viewport(paintable_box() && viewport_rect.intersects(paintable_box()->absolute_rect()));
-}
-
JS::GCPtr<Painting::Paintable> ImageBox::create_paintable() const
{
return Painting::ImagePaintable::create(*this);
diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.h b/Userland/Libraries/LibWeb/Layout/ImageBox.h
index f37de8a4ab..f67cde4902 100644
--- a/Userland/Libraries/LibWeb/Layout/ImageBox.h
+++ b/Userland/Libraries/LibWeb/Layout/ImageBox.h
@@ -6,15 +6,12 @@
#pragma once
-#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/Layout/ReplacedBox.h>
namespace Web::Layout {
-class ImageBox final
- : public ReplacedBox
- , public HTML::BrowsingContext::ViewportClient {
+class ImageBox final : public ReplacedBox {
JS_CELL(ImageBox, ReplacedBox);
public:
@@ -34,12 +31,6 @@ public:
void dom_node_did_update_alt_text(Badge<HTML::HTMLImageElement>);
private:
- // ^BrowsingContext::ViewportClient
- virtual void browsing_context_did_set_viewport_rect(CSSPixelRect const&) final;
-
- // ^JS::Cell
- virtual void finalize() override;
-
int preferred_width() const;
int preferred_height() const;
diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
index f9e9841ad5..d74ab56e0f 100644
--- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
+++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp
@@ -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()));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.h b/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
index ac8db5ddff..480f71b8fe 100644
--- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
+++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.h
@@ -6,12 +6,15 @@
#pragma once
+#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/Layout/ImageBox.h>
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Painting {
-class ImagePaintable final : public PaintableBox {
+class ImagePaintable final
+ : public PaintableBox
+ , public HTML::BrowsingContext::ViewportClient {
JS_CELL(ImagePaintable, PaintableBox);
public:
@@ -22,6 +25,12 @@ public:
Layout::ImageBox const& layout_box() const;
private:
+ // ^JS::Cell
+ virtual void finalize() override;
+
+ // ^BrowsingContext::ViewportClient
+ virtual void browsing_context_did_set_viewport_rect(CSSPixelRect const&) final;
+
ImagePaintable(Layout::ImageBox const&);
};