1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibWeb/Painting/ScrollFrame.h
Aliaksandr Kalenik 6507d23e29 LibWeb: Save ScrollState snapshot in DisplayList to avoid race condition
With this change we save a copy of of scroll state at the time of
recording a display list, instead of actual ScrollState pointer that
could be modifed by the main thread while display list is beings
rasterized on the rendering thread, which leads to a frame painted with
inconsistent scroll state.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4288
2025-04-12 02:55:18 +02:00

55 lines
1.6 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/WeakPtr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/PixelUnits.h>
namespace Web::Painting {
class ScrollFrame : public RefCounted<ScrollFrame> {
public:
ScrollFrame(PaintableBox const& paintable_box, size_t id, bool sticky, RefPtr<ScrollFrame const> parent);
PaintableBox const& paintable_box() const { return *m_paintable_box; }
size_t id() const { return m_id; }
bool is_sticky() const { return m_sticky; }
CSSPixelPoint cumulative_offset() const
{
if (!m_cached_cumulative_offset.has_value()) {
m_cached_cumulative_offset = m_own_offset;
if (m_parent) {
m_cached_cumulative_offset.value() += m_parent->cumulative_offset();
}
}
return m_cached_cumulative_offset.value();
}
CSSPixelPoint own_offset() const { return m_own_offset; }
void set_own_offset(CSSPixelPoint offset)
{
m_cached_cumulative_offset.clear();
m_own_offset = offset;
}
private:
WeakPtr<PaintableBox> m_paintable_box;
size_t m_id { 0 };
bool m_sticky { false };
RefPtr<ScrollFrame const> m_parent;
CSSPixelPoint m_own_offset;
// Caching here relies on the fact that offsets of all scroll frames are invalidated when any of them changes,
// so we don't need to worry about invalidating the cache when the parent's offset changes.
mutable Optional<CSSPixelPoint> m_cached_cumulative_offset;
};
}