mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 05:35:52 +03:00
LibWeb: Save image provider in ImagePaintable
Refactoring towards making paintable be independant from layout nodes. No behaviour change intended.
This commit is contained in:
parent
ef01c735cd
commit
6f5a0bd5de
Notes:
sideshowbarker
2024-07-17 03:10:07 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/6f5a0bd5de Pull-request: https://github.com/SerenityOS/serenity/pull/23349 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/trflynn89
@ -28,10 +28,17 @@ ImagePaintable::ImagePaintable(Layout::ImageBox const& layout_box, String alt_te
|
||||
: PaintableBox(layout_box)
|
||||
, m_renders_as_alt_text(layout_box.renders_as_alt_text())
|
||||
, m_alt_text(move(alt_text))
|
||||
, m_image_provider(layout_box.image_provider())
|
||||
{
|
||||
const_cast<DOM::Document&>(layout_box.document()).register_viewport_client(*this);
|
||||
}
|
||||
|
||||
void ImagePaintable::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_image_provider.to_html_element());
|
||||
}
|
||||
|
||||
void ImagePaintable::finalize()
|
||||
{
|
||||
Base::finalize();
|
||||
@ -59,7 +66,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
auto enclosing_rect = context.enclosing_device_rect(absolute_rect()).to_type<int>();
|
||||
context.recording_painter().paint_frame(enclosing_rect, context.palette(), Gfx::FrameStyle::SunkenContainer);
|
||||
context.recording_painter().draw_text(enclosing_rect, m_alt_text, Platform::FontPlugin::the().default_font(), Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right);
|
||||
} else if (auto bitmap = layout_box().image_provider().current_image_bitmap(image_rect.size().to_type<int>())) {
|
||||
} else if (auto bitmap = m_image_provider.current_image_bitmap(image_rect.size().to_type<int>())) {
|
||||
ScopedCornerRadiusClip corner_clip { context, image_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
||||
auto image_int_rect = image_rect.to_type<int>();
|
||||
auto bitmap_rect = bitmap->rect();
|
||||
@ -180,7 +187,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
|
||||
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()));
|
||||
const_cast<Layout::ImageProvider&>(m_image_provider).set_visible_in_viewport(viewport_rect.intersects(absolute_rect()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
|
||||
private:
|
||||
// ^JS::Cell
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
virtual void finalize() override;
|
||||
|
||||
// ^Document::ViewportClient
|
||||
@ -34,6 +35,8 @@ private:
|
||||
|
||||
bool m_renders_as_alt_text { false };
|
||||
String m_alt_text;
|
||||
|
||||
Layout::ImageProvider const& m_image_provider;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user