1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibWeb: Adjust positions by the scroll offset for scrollbar hit testing

This ensures we scroll to the correct position when dragging a scrollbar
or clicking its gutter.
This commit is contained in:
Timothy Flynn 2025-05-07 19:06:57 -04:00 committed by Sam Atkins
parent 22532c769c
commit c846616d51
Notes: github-actions[bot] 2025-05-08 09:41:59 +00:00
2 changed files with 12 additions and 2 deletions

View file

@ -911,6 +911,8 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
Paintable::DispatchEventOfSameName PaintableBox::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned, unsigned)
{
position = adjust_position_for_cumulative_scroll_offset(position);
auto handle_scrollbar = [&](auto direction) {
auto scrollbar_data = compute_scrollbar_data(direction, AdjustThumbRectForScrollOffset::Yes);
if (!scrollbar_data.has_value())
@ -956,6 +958,8 @@ Paintable::DispatchEventOfSameName PaintableBox::handle_mouseup(Badge<EventHandl
Paintable::DispatchEventOfSameName PaintableBox::handle_mousemove(Badge<EventHandler>, CSSPixelPoint position, unsigned, unsigned)
{
position = adjust_position_for_cumulative_scroll_offset(position);
if (m_last_mouse_tracking_position.has_value()) {
scroll_to_mouse_postion(position);
return Paintable::DispatchEventOfSameName::No;
@ -1060,12 +1064,17 @@ TraversalDecision PaintableBox::hit_test_scrollbars(CSSPixelPoint position, Func
return TraversalDecision::Continue;
}
CSSPixelPoint PaintableBox::adjust_position_for_cumulative_scroll_offset(CSSPixelPoint position) const
{
return position.translated(-cumulative_offset_of_enclosing_scroll_frame());
}
TraversalDecision PaintableBox::hit_test(CSSPixelPoint position, HitTestType type, Function<TraversalDecision(HitTestResult)> const& callback) const
{
if (clip_rect_for_hit_testing().has_value() && !clip_rect_for_hit_testing()->contains(position))
return TraversalDecision::Continue;
auto position_adjusted_by_scroll_offset = position.translated(-cumulative_offset_of_enclosing_scroll_frame());
auto position_adjusted_by_scroll_offset = adjust_position_for_cumulative_scroll_offset(position);
if (computed_values().visibility() != CSS::Visibility::Visible)
return TraversalDecision::Continue;
@ -1141,7 +1150,7 @@ TraversalDecision PaintableWithLines::hit_test(CSSPixelPoint position, HitTestTy
if (clip_rect_for_hit_testing().has_value() && !clip_rect_for_hit_testing()->contains(position))
return TraversalDecision::Continue;
auto position_adjusted_by_scroll_offset = position.translated(-cumulative_offset_of_enclosing_scroll_frame());
auto position_adjusted_by_scroll_offset = adjust_position_for_cumulative_scroll_offset(position);
// TextCursor hit testing mode should be able to place cursor in contenteditable elements even if they are empty
if (m_fragments.is_empty()

View file

@ -274,6 +274,7 @@ protected:
[[nodiscard]] bool could_be_scrolled_by_wheel_event(ScrollDirection) const;
TraversalDecision hit_test_scrollbars(CSSPixelPoint position, Function<TraversalDecision(HitTestResult)> const& callback) const;
CSSPixelPoint adjust_position_for_cumulative_scroll_offset(CSSPixelPoint) const;
private:
[[nodiscard]] virtual bool is_paintable_box() const final { return true; }