mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibWeb: Account for scroll offset in hit-testing
The hit-testing position is now shifted by the scroll offsets before performing any checks for containment. This is implemented by assigning each PaintableBox/InlinePaintable an offset corresponding to the scroll frame in which it is contained. The non-scroll-adjusted position is still passed down when recursing to children because the assigned offset accumulated for nested scroll frames. With this change, hit testing works in the Inspector. Fixes https://github.com/SerenityOS/serenity/issues/22068
This commit is contained in:
parent
beb1c85b6b
commit
556679fedd
7 changed files with 81 additions and 10 deletions
|
@ -182,15 +182,19 @@ void InlinePaintable::for_each_fragment(Callback callback) const
|
|||
|
||||
Optional<HitTestResult> InlinePaintable::hit_test(CSSPixelPoint position, HitTestType type) const
|
||||
{
|
||||
auto position_adjusted_by_scroll_offset = position;
|
||||
if (m_enclosing_scroll_frame_offset.has_value())
|
||||
position_adjusted_by_scroll_offset.translate_by(-m_enclosing_scroll_frame_offset.value());
|
||||
|
||||
for (auto& fragment : m_fragments) {
|
||||
if (fragment.paintable().stacking_context())
|
||||
continue;
|
||||
auto fragment_absolute_rect = fragment.absolute_rect();
|
||||
if (fragment_absolute_rect.contains(position)) {
|
||||
if (fragment_absolute_rect.contains(position_adjusted_by_scroll_offset)) {
|
||||
if (auto result = fragment.paintable().hit_test(position, type); result.has_value())
|
||||
return result;
|
||||
return HitTestResult { const_cast<Paintable&>(fragment.paintable()),
|
||||
fragment.text_index_at(position.x()) };
|
||||
fragment.text_index_at(position_adjusted_by_scroll_offset.x()) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue