mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibWeb: Transform ScrollFrame from a struct to a class
This commit is contained in:
parent
863416e3ac
commit
112dd4af3b
Notes:
github-actions[bot]
2024-09-12 05:38:16 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/112dd4af3b6 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1375
|
@ -5570,10 +5570,10 @@ RefPtr<Painting::DisplayList> Document::record_display_list(PaintConfig config)
|
|||
Vector<RefPtr<Painting::ScrollFrame>> scroll_state;
|
||||
scroll_state.resize(viewport_paintable.scroll_state.size() + viewport_paintable.sticky_state.size());
|
||||
for (auto& [_, scrollable_frame] : viewport_paintable.scroll_state) {
|
||||
scroll_state[scrollable_frame->id] = scrollable_frame;
|
||||
scroll_state[scrollable_frame->id()] = scrollable_frame;
|
||||
}
|
||||
for (auto& [_, scrollable_frame] : viewport_paintable.sticky_state) {
|
||||
scroll_state[scrollable_frame->id] = scrollable_frame;
|
||||
scroll_state[scrollable_frame->id()] = scrollable_frame;
|
||||
}
|
||||
|
||||
display_list->set_scroll_state(move(scroll_state));
|
||||
|
|
|
@ -12,14 +12,14 @@ namespace Web::Painting {
|
|||
Optional<int> ClippableAndScrollable::own_scroll_frame_id() const
|
||||
{
|
||||
if (m_own_scroll_frame)
|
||||
return m_own_scroll_frame->id;
|
||||
return m_own_scroll_frame->id();
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<int> ClippableAndScrollable::scroll_frame_id() const
|
||||
{
|
||||
if (m_enclosing_scroll_frame)
|
||||
return m_enclosing_scroll_frame->id;
|
||||
return m_enclosing_scroll_frame->id();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ void ClippableAndScrollable::apply_clip(PaintContext& context) const
|
|||
for (auto const& clip_rect : clip_rects) {
|
||||
Optional<i32> clip_scroll_frame_id;
|
||||
if (clip_rect.enclosing_scroll_frame)
|
||||
clip_scroll_frame_id = clip_rect.enclosing_scroll_frame->id;
|
||||
clip_scroll_frame_id = clip_rect.enclosing_scroll_frame->id();
|
||||
display_list_recorder.set_scroll_frame_id(clip_scroll_frame_id);
|
||||
auto rect = context.rounded_device_rect(clip_rect.rect).to_type<int>();
|
||||
auto corner_radii = clip_rect.corner_radii.as_corners(context);
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
[[nodiscard]] CSSPixelPoint own_scroll_frame_offset() const
|
||||
{
|
||||
if (m_own_scroll_frame)
|
||||
return m_own_scroll_frame->own_offset;
|
||||
return m_own_scroll_frame->own_offset();
|
||||
return {};
|
||||
}
|
||||
void set_own_scroll_frame(RefPtr<ScrollFrame> scroll_frame) { m_own_scroll_frame = scroll_frame; }
|
||||
|
|
|
@ -37,7 +37,7 @@ void DisplayListPlayer::execute(DisplayList& display_list)
|
|||
|
||||
if (command.has<PaintScrollBar>()) {
|
||||
auto& paint_scroll_bar = command.get<PaintScrollBar>();
|
||||
auto const& scroll_offset = scroll_state[paint_scroll_bar.scroll_frame_id]->own_offset;
|
||||
auto const& scroll_offset = scroll_state[paint_scroll_bar.scroll_frame_id]->own_offset();
|
||||
if (paint_scroll_bar.vertical) {
|
||||
auto offset = scroll_offset.y() * paint_scroll_bar.scroll_size;
|
||||
paint_scroll_bar.rect.translate_by(0, -offset.to_int() * device_pixels_per_css_pixel);
|
||||
|
|
|
@ -10,17 +10,30 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
struct ScrollFrame : public RefCounted<ScrollFrame> {
|
||||
i32 id { -1 };
|
||||
CSSPixelPoint own_offset;
|
||||
RefPtr<ScrollFrame const> parent;
|
||||
class ScrollFrame : public RefCounted<ScrollFrame> {
|
||||
public:
|
||||
ScrollFrame(i32 id, RefPtr<ScrollFrame const> parent)
|
||||
: m_id(id)
|
||||
, m_parent(move(parent))
|
||||
{
|
||||
}
|
||||
|
||||
i32 id() const { return m_id; }
|
||||
|
||||
CSSPixelPoint cumulative_offset() const
|
||||
{
|
||||
if (parent)
|
||||
return parent->cumulative_offset() + own_offset;
|
||||
return own_offset;
|
||||
if (m_parent)
|
||||
return m_parent->cumulative_offset() + m_own_offset;
|
||||
return m_own_offset;
|
||||
}
|
||||
|
||||
CSSPixelPoint own_offset() const { return m_own_offset; }
|
||||
void set_own_offset(CSSPixelPoint offset) { m_own_offset = offset; }
|
||||
|
||||
private:
|
||||
i32 m_id { -1 };
|
||||
RefPtr<ScrollFrame const> m_parent;
|
||||
CSSPixelPoint m_own_offset;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -70,25 +70,26 @@ void ViewportPaintable::assign_scroll_frames()
|
|||
for_each_in_inclusive_subtree_of_type<PaintableBox>([&](auto& paintable_box) {
|
||||
RefPtr<ScrollFrame> sticky_scroll_frame;
|
||||
if (paintable_box.is_sticky_position()) {
|
||||
sticky_scroll_frame = adopt_ref(*new ScrollFrame());
|
||||
sticky_scroll_frame->id = next_id++;
|
||||
auto const* nearest_scrollable_ancestor = paintable_box.nearest_scrollable_ancestor();
|
||||
RefPtr<ScrollFrame const> parent_scroll_frame;
|
||||
if (nearest_scrollable_ancestor) {
|
||||
sticky_scroll_frame->parent = nearest_scrollable_ancestor->nearest_scroll_frame();
|
||||
parent_scroll_frame = nearest_scrollable_ancestor->nearest_scroll_frame();
|
||||
}
|
||||
sticky_scroll_frame = adopt_ref(*new ScrollFrame(next_id++, parent_scroll_frame));
|
||||
|
||||
const_cast<PaintableBox&>(paintable_box).set_enclosing_scroll_frame(sticky_scroll_frame);
|
||||
const_cast<PaintableBox&>(paintable_box).set_own_scroll_frame(sticky_scroll_frame);
|
||||
sticky_state.set(paintable_box, sticky_scroll_frame);
|
||||
}
|
||||
|
||||
if (paintable_box.has_scrollable_overflow() || is<ViewportPaintable>(paintable_box)) {
|
||||
auto scroll_frame = adopt_ref(*new ScrollFrame());
|
||||
scroll_frame->id = next_id++;
|
||||
RefPtr<ScrollFrame const> parent_scroll_frame;
|
||||
if (sticky_scroll_frame) {
|
||||
scroll_frame->parent = sticky_scroll_frame;
|
||||
parent_scroll_frame = sticky_scroll_frame;
|
||||
} else {
|
||||
scroll_frame->parent = paintable_box.nearest_scroll_frame();
|
||||
parent_scroll_frame = paintable_box.nearest_scroll_frame();
|
||||
}
|
||||
auto scroll_frame = adopt_ref(*new ScrollFrame(next_id++, parent_scroll_frame));
|
||||
paintable_box.set_own_scroll_frame(scroll_frame);
|
||||
scroll_state.set(paintable_box, move(scroll_frame));
|
||||
}
|
||||
|
@ -252,13 +253,13 @@ void ViewportPaintable::refresh_scroll_state()
|
|||
}
|
||||
}
|
||||
|
||||
scroll_frame.own_offset = sticky_offset;
|
||||
scroll_frame.set_own_offset(sticky_offset);
|
||||
}
|
||||
|
||||
for (auto& it : scroll_state) {
|
||||
auto const& paintable_box = *it.key;
|
||||
auto& scroll_frame = *it.value;
|
||||
scroll_frame.own_offset = -paintable_box.scroll_offset();
|
||||
scroll_frame.set_own_offset(-paintable_box.scroll_offset());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue