2024-08-10 14:24:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-10-16 11:13:54 +02:00
|
|
|
#include <LibGC/Weak.h>
|
2024-10-11 19:32:32 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
2024-08-10 14:24:25 +02:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
2024-09-11 22:01:44 +02:00
|
|
|
class ScrollFrame : public RefCounted<ScrollFrame> {
|
|
|
|
public:
|
2024-10-11 20:31:19 +02:00
|
|
|
ScrollFrame(PaintableBox const& paintable_box, size_t id, bool sticky, RefPtr<ScrollFrame const> parent);
|
2024-10-11 19:32:32 +02:00
|
|
|
|
|
|
|
PaintableBox const& paintable_box() const { return *m_paintable_box; }
|
2024-09-11 22:01:44 +02:00
|
|
|
|
2024-10-11 19:32:32 +02:00
|
|
|
size_t id() const { return m_id; }
|
2024-08-24 19:11:01 +02:00
|
|
|
|
2024-10-11 20:31:19 +02:00
|
|
|
bool is_sticky() const { return m_sticky; }
|
|
|
|
|
2024-08-24 19:11:01 +02:00
|
|
|
CSSPixelPoint cumulative_offset() const
|
|
|
|
{
|
2025-09-17 15:48:22 +02:00
|
|
|
return m_cached_cumulative_offset.ensure([&] {
|
|
|
|
auto offset = m_own_offset;
|
|
|
|
if (m_parent)
|
|
|
|
offset += m_parent->cumulative_offset();
|
|
|
|
return offset;
|
|
|
|
});
|
2024-08-24 19:11:01 +02:00
|
|
|
}
|
2024-09-11 22:01:44 +02:00
|
|
|
|
|
|
|
CSSPixelPoint own_offset() const { return m_own_offset; }
|
2024-09-11 22:15:14 +02:00
|
|
|
void set_own_offset(CSSPixelPoint offset)
|
|
|
|
{
|
|
|
|
m_cached_cumulative_offset.clear();
|
|
|
|
m_own_offset = offset;
|
|
|
|
}
|
2024-09-11 22:01:44 +02:00
|
|
|
|
|
|
|
private:
|
2025-10-16 11:13:54 +02:00
|
|
|
GC::Weak<PaintableBox> m_paintable_box;
|
2024-10-11 19:32:32 +02:00
|
|
|
size_t m_id { 0 };
|
2024-10-11 20:31:19 +02:00
|
|
|
bool m_sticky { false };
|
2024-09-11 22:01:44 +02:00
|
|
|
RefPtr<ScrollFrame const> m_parent;
|
|
|
|
CSSPixelPoint m_own_offset;
|
2024-09-11 22:15:14 +02:00
|
|
|
|
|
|
|
// 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;
|
2024-08-10 14:24:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|