mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-23 08:30:50 +00:00
This allows the calculation of the cumulative scroll offset for a scroll frame by adding its scroll offset to the parent’s scroll offset, rather than traversing the containing block chain. While it doesn't greatly simplify calculations for typical scroll frames, it serves as a preparation for supporting "position: sticky".
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/Painting/ClipFrame.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
void ClipFrame::add_clip_rect(CSSPixelRect rect, BorderRadiiData radii, RefPtr<ScrollFrame const> enclosing_scroll_frame)
|
|
{
|
|
for (auto& existing_clip : m_clip_rects) {
|
|
if (rect == existing_clip.rect && enclosing_scroll_frame == existing_clip.enclosing_scroll_frame) {
|
|
existing_clip.corner_radii.union_max_radii(radii);
|
|
return;
|
|
}
|
|
}
|
|
m_clip_rects.append({ rect, radii, move(enclosing_scroll_frame) });
|
|
}
|
|
|
|
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->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->cumulative_offset());
|
|
}
|
|
rect.intersect(clip_rect);
|
|
}
|
|
return rect;
|
|
}
|
|
|
|
}
|