LibWeb: Transform ScrollFrame from a struct to a class

This commit is contained in:
Aliaksandr Kalenik 2024-09-11 22:01:44 +02:00 committed by Andreas Kling
commit 112dd4af3b
Notes: github-actions[bot] 2024-09-12 05:38:16 +00:00
6 changed files with 37 additions and 23 deletions

View file

@ -5570,10 +5570,10 @@ RefPtr<Painting::DisplayList> Document::record_display_list(PaintConfig config)
Vector<RefPtr<Painting::ScrollFrame>> scroll_state; Vector<RefPtr<Painting::ScrollFrame>> scroll_state;
scroll_state.resize(viewport_paintable.scroll_state.size() + viewport_paintable.sticky_state.size()); scroll_state.resize(viewport_paintable.scroll_state.size() + viewport_paintable.sticky_state.size());
for (auto& [_, scrollable_frame] : viewport_paintable.scroll_state) { 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) { 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)); display_list->set_scroll_state(move(scroll_state));

View file

@ -12,14 +12,14 @@ namespace Web::Painting {
Optional<int> ClippableAndScrollable::own_scroll_frame_id() const Optional<int> ClippableAndScrollable::own_scroll_frame_id() const
{ {
if (m_own_scroll_frame) if (m_own_scroll_frame)
return m_own_scroll_frame->id; return m_own_scroll_frame->id();
return {}; return {};
} }
Optional<int> ClippableAndScrollable::scroll_frame_id() const Optional<int> ClippableAndScrollable::scroll_frame_id() const
{ {
if (m_enclosing_scroll_frame) if (m_enclosing_scroll_frame)
return m_enclosing_scroll_frame->id; return m_enclosing_scroll_frame->id();
return {}; return {};
} }
@ -51,7 +51,7 @@ void ClippableAndScrollable::apply_clip(PaintContext& context) const
for (auto const& clip_rect : clip_rects) { for (auto const& clip_rect : clip_rects) {
Optional<i32> clip_scroll_frame_id; Optional<i32> clip_scroll_frame_id;
if (clip_rect.enclosing_scroll_frame) 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); display_list_recorder.set_scroll_frame_id(clip_scroll_frame_id);
auto rect = context.rounded_device_rect(clip_rect.rect).to_type<int>(); auto rect = context.rounded_device_rect(clip_rect.rect).to_type<int>();
auto corner_radii = clip_rect.corner_radii.as_corners(context); auto corner_radii = clip_rect.corner_radii.as_corners(context);

View file

@ -28,7 +28,7 @@ public:
[[nodiscard]] CSSPixelPoint own_scroll_frame_offset() const [[nodiscard]] CSSPixelPoint own_scroll_frame_offset() const
{ {
if (m_own_scroll_frame) if (m_own_scroll_frame)
return m_own_scroll_frame->own_offset; return m_own_scroll_frame->own_offset();
return {}; return {};
} }
void set_own_scroll_frame(RefPtr<ScrollFrame> scroll_frame) { m_own_scroll_frame = scroll_frame; } void set_own_scroll_frame(RefPtr<ScrollFrame> scroll_frame) { m_own_scroll_frame = scroll_frame; }

View file

@ -37,7 +37,7 @@ void DisplayListPlayer::execute(DisplayList& display_list)
if (command.has<PaintScrollBar>()) { if (command.has<PaintScrollBar>()) {
auto& paint_scroll_bar = command.get<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) { if (paint_scroll_bar.vertical) {
auto offset = scroll_offset.y() * paint_scroll_bar.scroll_size; 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); paint_scroll_bar.rect.translate_by(0, -offset.to_int() * device_pixels_per_css_pixel);

View file

@ -10,17 +10,30 @@
namespace Web::Painting { namespace Web::Painting {
struct ScrollFrame : public RefCounted<ScrollFrame> { class ScrollFrame : public RefCounted<ScrollFrame> {
i32 id { -1 }; public:
CSSPixelPoint own_offset; ScrollFrame(i32 id, RefPtr<ScrollFrame const> parent)
RefPtr<ScrollFrame const> parent; : m_id(id)
, m_parent(move(parent))
{
}
i32 id() const { return m_id; }
CSSPixelPoint cumulative_offset() const CSSPixelPoint cumulative_offset() const
{ {
if (parent) if (m_parent)
return parent->cumulative_offset() + own_offset; return m_parent->cumulative_offset() + m_own_offset;
return 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;
}; };
} }

View file

@ -70,25 +70,26 @@ void ViewportPaintable::assign_scroll_frames()
for_each_in_inclusive_subtree_of_type<PaintableBox>([&](auto& paintable_box) { for_each_in_inclusive_subtree_of_type<PaintableBox>([&](auto& paintable_box) {
RefPtr<ScrollFrame> sticky_scroll_frame; RefPtr<ScrollFrame> sticky_scroll_frame;
if (paintable_box.is_sticky_position()) { 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(); auto const* nearest_scrollable_ancestor = paintable_box.nearest_scrollable_ancestor();
RefPtr<ScrollFrame const> parent_scroll_frame;
if (nearest_scrollable_ancestor) { 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_enclosing_scroll_frame(sticky_scroll_frame);
const_cast<PaintableBox&>(paintable_box).set_own_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); sticky_state.set(paintable_box, sticky_scroll_frame);
} }
if (paintable_box.has_scrollable_overflow() || is<ViewportPaintable>(paintable_box)) { if (paintable_box.has_scrollable_overflow() || is<ViewportPaintable>(paintable_box)) {
auto scroll_frame = adopt_ref(*new ScrollFrame()); RefPtr<ScrollFrame const> parent_scroll_frame;
scroll_frame->id = next_id++;
if (sticky_scroll_frame) { if (sticky_scroll_frame) {
scroll_frame->parent = sticky_scroll_frame; parent_scroll_frame = sticky_scroll_frame;
} else { } 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); paintable_box.set_own_scroll_frame(scroll_frame);
scroll_state.set(paintable_box, move(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) { for (auto& it : scroll_state) {
auto const& paintable_box = *it.key; auto const& paintable_box = *it.key;
auto& scroll_frame = *it.value; auto& scroll_frame = *it.value;
scroll_frame.own_offset = -paintable_box.scroll_offset(); scroll_frame.set_own_offset(-paintable_box.scroll_offset());
} }
} }