Files
ladybird/Userland/Libraries/LibWeb/Painting/ScrollState.h
Aliaksandr Kalenik d07643b122 LibWeb: Introduce a new class responsible for scroll state
It's good to have a wrapper for scroll and sticky state instead of
directly mutating vectors with frames.

No behavior change.
2024-10-12 13:13:14 +02:00

44 lines
1.2 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Painting/ScrollFrame.h>
namespace Web::Painting {
class ScrollState {
public:
NonnullRefPtr<ScrollFrame> create_scroll_frame_for(PaintableBox const& paintable, RefPtr<ScrollFrame const> parent)
{
auto scroll_frame = adopt_ref(*new ScrollFrame(paintable, m_next_id++, parent));
m_scroll_frames.append(scroll_frame);
return scroll_frame;
}
NonnullRefPtr<ScrollFrame> create_sticky_frame_for(PaintableBox const& paintable, RefPtr<ScrollFrame const> parent)
{
auto scroll_frame = adopt_ref(*new ScrollFrame(paintable, m_next_id++, parent));
m_sticky_frames.append(scroll_frame);
return scroll_frame;
}
void clear()
{
m_scroll_frames.clear();
}
Vector<NonnullRefPtr<ScrollFrame>> const& scroll_frames() const { return m_scroll_frames; }
Vector<NonnullRefPtr<ScrollFrame>> const& sticky_frames() const { return m_sticky_frames; }
private:
size_t m_next_id { 0 };
Vector<NonnullRefPtr<ScrollFrame>> m_scroll_frames;
Vector<NonnullRefPtr<ScrollFrame>> m_sticky_frames;
};
}