mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb: Move "visible in viewport" state tracking to ImageLoader
This should technically apply to any LayoutImage, so let's just move it to ImageLoader.
This commit is contained in:
parent
c45615128b
commit
73c9f7ebf4
Notes:
sideshowbarker
2024-07-19 05:38:48 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/73c9f7ebf4a
7 changed files with 12 additions and 13 deletions
|
@ -87,9 +87,4 @@ const Gfx::Bitmap* HTMLImageElement::bitmap() const
|
|||
return m_image_loader.bitmap();
|
||||
}
|
||||
|
||||
void HTMLImageElement::set_visible_in_viewport(Badge<LayoutDocument>, bool visible_in_viewport)
|
||||
{
|
||||
m_image_loader.set_visible_in_viewport(visible_in_viewport);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,8 +51,6 @@ public:
|
|||
const Gfx::Bitmap* bitmap() const;
|
||||
const Gfx::ImageDecoder* image_decoder() const;
|
||||
|
||||
void set_visible_in_viewport(Badge<LayoutDocument>, bool);
|
||||
|
||||
private:
|
||||
void animate();
|
||||
|
||||
|
|
|
@ -71,8 +71,7 @@ void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Gfx::IntRect& a_v
|
|||
{
|
||||
Gfx::FloatRect viewport_rect(a_viewport_rect.x(), a_viewport_rect.y(), a_viewport_rect.width(), a_viewport_rect.height());
|
||||
for_each_in_subtree_of_type<LayoutImage>([&](auto& layout_image) {
|
||||
if (is<HTMLImageElement>(layout_image.node()))
|
||||
const_cast<HTMLImageElement&>(to<HTMLImageElement>(layout_image.node())).set_visible_in_viewport({}, viewport_rect.intersects(layout_image.absolute_rect()));
|
||||
const_cast<LayoutImage&>(layout_image).set_visible_in_viewport({}, viewport_rect.intersects(layout_image.absolute_rect()));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -108,4 +108,9 @@ bool LayoutImage::renders_as_alt_text() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void LayoutImage::set_visible_in_viewport(Badge<LayoutDocument>, bool visible_in_viewport)
|
||||
{
|
||||
m_image_loader.set_visible_in_viewport(visible_in_viewport);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
|
||||
bool renders_as_alt_text() const;
|
||||
|
||||
void set_visible_in_viewport(Badge<LayoutDocument>, bool);
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "LayoutImage"; }
|
||||
virtual bool is_image() const override { return true; }
|
||||
|
|
|
@ -44,7 +44,7 @@ void ImageLoader::load(const URL& url)
|
|||
set_resource(ResourceLoader::the().load_resource(Resource::Type::Image, request));
|
||||
}
|
||||
|
||||
void ImageLoader::set_visible_in_viewport(bool visible_in_viewport)
|
||||
void ImageLoader::set_visible_in_viewport(bool visible_in_viewport) const
|
||||
{
|
||||
if (m_visible_in_viewport == visible_in_viewport)
|
||||
return;
|
||||
|
@ -54,7 +54,7 @@ void ImageLoader::set_visible_in_viewport(bool visible_in_viewport)
|
|||
// the whole document, updating "is visible in viewport" flags, and this could lead
|
||||
// to the same bitmap being marked volatile back and forth unnecessarily.
|
||||
if (resource())
|
||||
resource()->update_volatility();
|
||||
const_cast<ImageResource*>(resource())->update_volatility();
|
||||
}
|
||||
|
||||
void ImageLoader::resource_did_load()
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
const Gfx::Bitmap* bitmap() const;
|
||||
const Gfx::ImageDecoder* image_decoder() const;
|
||||
|
||||
void set_visible_in_viewport(bool);
|
||||
void set_visible_in_viewport(bool) const;
|
||||
|
||||
Function<void()> on_load;
|
||||
Function<void()> on_fail;
|
||||
|
@ -57,7 +57,7 @@ private:
|
|||
void animate();
|
||||
|
||||
RefPtr<Gfx::ImageDecoder> m_decoder;
|
||||
bool m_visible_in_viewport { false };
|
||||
mutable bool m_visible_in_viewport { false };
|
||||
|
||||
size_t m_current_frame_index { 0 };
|
||||
size_t m_loops_completed { 0 };
|
||||
|
|
Loading…
Add table
Reference in a new issue