From 7ddb94c4d6ec3985e687f3c23f4bc257dfa86012 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 17 Aug 2024 18:11:07 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibWeb/HTML/Navigable.cpp | 2 +- Userland/Libraries/LibWeb/Painting/ClipFrame.cpp | 4 ++-- .../Libraries/LibWeb/Painting/ClippableAndScrollable.cpp | 4 ++-- Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.h | 2 +- Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp | 2 +- Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 4 ++-- Userland/Libraries/LibWeb/Painting/ScrollFrame.h | 2 +- Userland/Libraries/LibWeb/Painting/StackingContext.cpp | 4 ++-- Userland/Libraries/LibWeb/Painting/ViewportPaintable.cpp | 6 +++--- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index eaa1b2c75bf..1ffedb29990 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -2131,7 +2131,7 @@ RefPtr Navigable::record_display_list(PaintConfig config) Vector 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(); + auto scroll_offset = context.rounded_device_point(scrollable_frame->cumulative_offset).to_type(); scroll_offsets_by_frame_id[scrollable_frame->id] = scroll_offset; } display_list_recorder.display_list().apply_scroll_offsets(scroll_offsets_by_frame_id); diff --git a/Userland/Libraries/LibWeb/Painting/ClipFrame.cpp b/Userland/Libraries/LibWeb/Painting/ClipFrame.cpp index 76ced0b9a79..09df6d0e145 100644 --- a/Userland/Libraries/LibWeb/Painting/ClipFrame.cpp +++ b/Userland/Libraries/LibWeb/Painting/ClipFrame.cpp @@ -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); } diff --git a/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.cpp b/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.cpp index 9e90745e0ad..785f8514006 100644 --- a/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.cpp +++ b/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.cpp @@ -23,10 +23,10 @@ Optional 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 {}; } diff --git a/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.h b/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.h index d922a24dcf1..9cc5e982a6c 100644 --- a/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.h +++ b/Userland/Libraries/LibWeb/Painting/ClippableAndScrollable.h @@ -20,7 +20,7 @@ public: [[nodiscard]] RefPtr enclosing_scroll_frame() const { return m_enclosing_scroll_frame; } [[nodiscard]] Optional scroll_frame_id() const; - [[nodiscard]] CSSPixelPoint enclosing_scroll_frame_offset() const; + [[nodiscard]] CSSPixelPoint cumulative_offset_of_enclosing_scroll_frame() const; [[nodiscard]] Optional clip_rect_for_hit_testing() const; [[nodiscard]] Optional own_scroll_frame_id() const; diff --git a/Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp b/Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp index 823d6acc5ea..c6aaf6fce9b 100644 --- a/Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/InlinePaintable.cpp @@ -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()) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 2b674f2030d..65c39a8efa2 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -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); diff --git a/Userland/Libraries/LibWeb/Painting/ScrollFrame.h b/Userland/Libraries/LibWeb/Painting/ScrollFrame.h index 293a7570ac8..9a2cb25e045 100644 --- a/Userland/Libraries/LibWeb/Painting/ScrollFrame.h +++ b/Userland/Libraries/LibWeb/Painting/ScrollFrame.h @@ -12,7 +12,7 @@ namespace Web::Painting { struct ScrollFrame : public RefCounted { i32 id { -1 }; - CSSPixelPoint offset; + CSSPixelPoint cumulative_offset; }; } diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 22998250060..468dc55070f 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -412,10 +412,10 @@ TraversalDecision StackingContext::hit_test(CSSPixelPoint position, HitTestType CSSPixelPoint enclosing_scroll_offset; if (is(paintable())) { auto const& paintable_box = static_cast(paintable()); - enclosing_scroll_offset = paintable_box.enclosing_scroll_frame_offset(); + enclosing_scroll_offset = paintable_box.cumulative_offset_of_enclosing_scroll_frame(); } else if (is(paintable())) { auto const& inline_paintable = static_cast(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; diff --git a/Userland/Libraries/LibWeb/Painting/ViewportPaintable.cpp b/Userland/Libraries/LibWeb/Painting/ViewportPaintable.cpp index db14c8fe4fa..b4af10ff3be 100644 --- a/Userland/Libraries/LibWeb/Painting/ViewportPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/ViewportPaintable.cpp @@ -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; } }