mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:37:46 +00:00
LibWeb: Move viewport subscriptions from BrowsingContext to Document
With this change, elements that want to receive viewport rect updates will need to register on document instead of the browsing context. This change solves the problem where a browsing context for a document is guaranteed to exist only while the document is active so browsing context might not exit by the time DOM node that want to register is constructed. This is a part of preparation work before switching to navigables where this issue becomes more visible.
This commit is contained in:
parent
48e9097aa4
commit
5ff7448fee
10 changed files with 66 additions and 61 deletions
|
@ -23,16 +23,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);
|
||||
const_cast<DOM::Document&>(layout_box.document()).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);
|
||||
// NOTE: We unregister from the document in finalize() to avoid trouble
|
||||
// in the scenario where our Document has already been swept by GC.
|
||||
document().unregister_viewport_client(*this);
|
||||
}
|
||||
|
||||
Layout::ImageBox const& ImagePaintable::layout_box() const
|
||||
|
@ -133,7 +133,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
}
|
||||
}
|
||||
|
||||
void ImagePaintable::browsing_context_did_set_viewport_rect(CSSPixelRect const& viewport_rect)
|
||||
void ImagePaintable::did_set_viewport_rect(CSSPixelRect const& viewport_rect)
|
||||
{
|
||||
const_cast<Layout::ImageProvider&>(layout_box().image_provider()).set_visible_in_viewport(viewport_rect.intersects(absolute_rect()));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
#include <LibWeb/Painting/PaintableBox.h>
|
||||
|
||||
|
@ -14,7 +13,7 @@ namespace Web::Painting {
|
|||
|
||||
class ImagePaintable final
|
||||
: public PaintableBox
|
||||
, public HTML::BrowsingContext::ViewportClient {
|
||||
, public DOM::Document::ViewportClient {
|
||||
JS_CELL(ImagePaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
|
@ -28,8 +27,8 @@ private:
|
|||
// ^JS::Cell
|
||||
virtual void finalize() override;
|
||||
|
||||
// ^BrowsingContext::ViewportClient
|
||||
virtual void browsing_context_did_set_viewport_rect(CSSPixelRect const&) final;
|
||||
// ^Document::ViewportClient
|
||||
virtual void did_set_viewport_rect(CSSPixelRect const&) final;
|
||||
|
||||
ImagePaintable(Layout::ImageBox const&);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue