mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibWeb: Fix position: fixed canvases/images disappearing when scrolling
This fixes the Serenity logo vanishing after scrolling on the 4th birthday post. The previous check did not account for any translation in the painter. This now uses the painter's clip rect and translation to work out if a rect is visible. It also makes use of `absolute_paint_rect()` rather than `absolute_rect()` which can account for things like box-shadows.
This commit is contained in:
parent
f5e68fcc20
commit
4507920187
4 changed files with 13 additions and 4 deletions
|
@ -34,8 +34,8 @@ void CanvasPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
auto canvas_rect = absolute_rect().to_rounded<int>();
|
auto canvas_rect = absolute_rect().to_rounded<int>();
|
||||||
ScopedCornerRadiusClip corner_clip { context.painter(), canvas_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
ScopedCornerRadiusClip corner_clip { context.painter(), canvas_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
||||||
|
|
||||||
// FIXME: This should be done at a different level. Also rect() does not include padding etc!
|
// FIXME: This should be done at a different level.
|
||||||
if (!context.viewport_rect().intersects(canvas_rect))
|
if (is_out_of_view(context))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (layout_box().dom_node().bitmap()) {
|
if (layout_box().dom_node().bitmap()) {
|
||||||
|
|
|
@ -33,8 +33,8 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
if (!is_visible())
|
if (!is_visible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// FIXME: This should be done at a different level. Also rect() does not include padding etc!
|
// FIXME: This should be done at a different level.
|
||||||
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
|
if (is_out_of_view(context))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PaintableBox::paint(context, phase);
|
PaintableBox::paint(context, phase);
|
||||||
|
|
|
@ -37,6 +37,13 @@ void PaintableBox::invalidate_stacking_context()
|
||||||
m_stacking_context = nullptr;
|
m_stacking_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PaintableBox::is_out_of_view(PaintContext& context) const
|
||||||
|
{
|
||||||
|
return !enclosing_int_rect(absolute_paint_rect())
|
||||||
|
.translated(context.painter().translation())
|
||||||
|
.intersects(context.painter().clip_rect());
|
||||||
|
}
|
||||||
|
|
||||||
PaintableWithLines::PaintableWithLines(Layout::BlockContainer const& layout_box)
|
PaintableWithLines::PaintableWithLines(Layout::BlockContainer const& layout_box)
|
||||||
: PaintableBox(layout_box)
|
: PaintableBox(layout_box)
|
||||||
{
|
{
|
||||||
|
|
|
@ -117,6 +117,8 @@ public:
|
||||||
|
|
||||||
void invalidate_stacking_context();
|
void invalidate_stacking_context();
|
||||||
|
|
||||||
|
bool is_out_of_view(PaintContext&) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PaintableBox(Layout::Box const&);
|
explicit PaintableBox(Layout::Box const&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue