LibWeb: Rename offset to cumulative_offset in ScrollFrame

New name reflects that offset is not just a frame's own offset but a sum
of offsets from containing block chain.
This commit is contained in:
Aliaksandr Kalenik 2024-08-17 18:11:07 +02:00 committed by Andreas Kling
parent a59a839df8
commit 7ddb94c4d6
Notes: github-actions[bot] 2024-08-19 16:58:27 +00:00
9 changed files with 15 additions and 15 deletions

View file

@ -2131,7 +2131,7 @@ RefPtr<Painting::DisplayList> Navigable::record_display_list(PaintConfig config)
Vector<Gfx::IntPoint> scroll_offsets_by_frame_id;
scroll_offsets_by_frame_id.resize(viewport_paintable.scroll_state.size());
for (auto [_, scrollable_frame] : viewport_paintable.scroll_state) {
auto scroll_offset = context.rounded_device_point(scrollable_frame->offset).to_type<int>();
auto scroll_offset = context.rounded_device_point(scrollable_frame->cumulative_offset).to_type<int>();
scroll_offsets_by_frame_id[scrollable_frame->id] = scroll_offset;
}
display_list_recorder.display_list().apply_scroll_offsets(scroll_offsets_by_frame_id);

View file

@ -24,12 +24,12 @@ CSSPixelRect ClipFrame::clip_rect_for_hit_testing() const
VERIFY(!m_clip_rects.is_empty());
auto rect = m_clip_rects[0].rect;
if (m_clip_rects[0].enclosing_scroll_frame) {
rect.translate_by(m_clip_rects[0].enclosing_scroll_frame->offset);
rect.translate_by(m_clip_rects[0].enclosing_scroll_frame->cumulative_offset);
}
for (size_t i = 1; i < m_clip_rects.size(); ++i) {
auto clip_rect = m_clip_rects[i].rect;
if (m_clip_rects[i].enclosing_scroll_frame) {
clip_rect.translate_by(m_clip_rects[i].enclosing_scroll_frame->offset);
clip_rect.translate_by(m_clip_rects[i].enclosing_scroll_frame->cumulative_offset);
}
rect.intersect(clip_rect);
}

View file

@ -23,10 +23,10 @@ Optional<int> ClippableAndScrollable::scroll_frame_id() const
return {};
}
CSSPixelPoint ClippableAndScrollable::enclosing_scroll_frame_offset() const
CSSPixelPoint ClippableAndScrollable::cumulative_offset_of_enclosing_scroll_frame() const
{
if (m_enclosing_scroll_frame)
return m_enclosing_scroll_frame->offset;
return m_enclosing_scroll_frame->cumulative_offset;
return {};
}

View file

@ -20,7 +20,7 @@ public:
[[nodiscard]] RefPtr<ScrollFrame const> enclosing_scroll_frame() const { return m_enclosing_scroll_frame; }
[[nodiscard]] Optional<int> scroll_frame_id() const;
[[nodiscard]] CSSPixelPoint enclosing_scroll_frame_offset() const;
[[nodiscard]] CSSPixelPoint cumulative_offset_of_enclosing_scroll_frame() const;
[[nodiscard]] Optional<CSSPixelRect> clip_rect_for_hit_testing() const;
[[nodiscard]] Optional<int> own_scroll_frame_id() const;

View file

@ -191,7 +191,7 @@ TraversalDecision InlinePaintable::hit_test(CSSPixelPoint position, HitTestType
return TraversalDecision::Continue;
auto position_adjusted_by_scroll_offset = position;
position_adjusted_by_scroll_offset.translate_by(-enclosing_scroll_frame_offset());
position_adjusted_by_scroll_offset.translate_by(-cumulative_offset_of_enclosing_scroll_frame());
for (auto const& fragment : m_fragments) {
if (fragment.paintable().stacking_context())

View file

@ -806,7 +806,7 @@ TraversalDecision PaintableBox::hit_test(CSSPixelPoint position, HitTestType typ
return TraversalDecision::Continue;
auto position_adjusted_by_scroll_offset = position;
position_adjusted_by_scroll_offset.translate_by(-enclosing_scroll_frame_offset());
position_adjusted_by_scroll_offset.translate_by(-cumulative_offset_of_enclosing_scroll_frame());
if (!is_visible())
return TraversalDecision::Continue;
@ -858,7 +858,7 @@ TraversalDecision PaintableWithLines::hit_test(CSSPixelPoint position, HitTestTy
return TraversalDecision::Continue;
auto position_adjusted_by_scroll_offset = position;
position_adjusted_by_scroll_offset.translate_by(-enclosing_scroll_frame_offset());
position_adjusted_by_scroll_offset.translate_by(-cumulative_offset_of_enclosing_scroll_frame());
if (!layout_box().children_are_inline() || m_fragments.is_empty()) {
return PaintableBox::hit_test(position, type, callback);

View file

@ -12,7 +12,7 @@ namespace Web::Painting {
struct ScrollFrame : public RefCounted<ScrollFrame> {
i32 id { -1 };
CSSPixelPoint offset;
CSSPixelPoint cumulative_offset;
};
}

View file

@ -412,10 +412,10 @@ TraversalDecision StackingContext::hit_test(CSSPixelPoint position, HitTestType
CSSPixelPoint enclosing_scroll_offset;
if (is<PaintableBox>(paintable())) {
auto const& paintable_box = static_cast<PaintableBox const&>(paintable());
enclosing_scroll_offset = paintable_box.enclosing_scroll_frame_offset();
enclosing_scroll_offset = paintable_box.cumulative_offset_of_enclosing_scroll_frame();
} else if (is<InlinePaintable>(paintable())) {
auto const& inline_paintable = static_cast<InlinePaintable const&>(paintable());
enclosing_scroll_offset = inline_paintable.enclosing_scroll_frame_offset();
enclosing_scroll_offset = inline_paintable.cumulative_offset_of_enclosing_scroll_frame();
}
auto position_adjusted_by_scroll_offset = transformed_position;

View file

@ -162,14 +162,14 @@ void ViewportPaintable::refresh_scroll_state()
for (auto& it : scroll_state) {
auto const& paintable_box = *it.key;
auto& scroll_frame = *it.value;
CSSPixelPoint offset;
CSSPixelPoint cumulative_offset;
for (auto const* block = &paintable_box.layout_box(); block; block = block->containing_block()) {
auto const& block_paintable_box = *block->paintable_box();
offset.translate_by(block_paintable_box.scroll_offset());
cumulative_offset.translate_by(block_paintable_box.scroll_offset());
if (block->is_fixed_position())
break;
}
scroll_frame.offset = -offset;
scroll_frame.cumulative_offset = -cumulative_offset;
}
}