mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-14 13:01:55 +00: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:
parent
22532c769c
commit
c846616d51
Notes:
github-actions[bot]
2025-05-08 09:41:59 +00:00
Author: https://github.com/trflynn89
Commit: c846616d51
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4640
Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 12 additions and 2 deletions
|
@ -911,6 +911,8 @@ void PaintableWithLines::paint(PaintContext& context, PaintPhase phase) const
|
||||||
|
|
||||||
Paintable::DispatchEventOfSameName PaintableBox::handle_mousedown(Badge<EventHandler>, CSSPixelPoint position, unsigned, unsigned)
|
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 handle_scrollbar = [&](auto direction) {
|
||||||
auto scrollbar_data = compute_scrollbar_data(direction, AdjustThumbRectForScrollOffset::Yes);
|
auto scrollbar_data = compute_scrollbar_data(direction, AdjustThumbRectForScrollOffset::Yes);
|
||||||
if (!scrollbar_data.has_value())
|
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)
|
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()) {
|
if (m_last_mouse_tracking_position.has_value()) {
|
||||||
scroll_to_mouse_postion(position);
|
scroll_to_mouse_postion(position);
|
||||||
return Paintable::DispatchEventOfSameName::No;
|
return Paintable::DispatchEventOfSameName::No;
|
||||||
|
@ -1060,12 +1064,17 @@ TraversalDecision PaintableBox::hit_test_scrollbars(CSSPixelPoint position, Func
|
||||||
return TraversalDecision::Continue;
|
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
|
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))
|
if (clip_rect_for_hit_testing().has_value() && !clip_rect_for_hit_testing()->contains(position))
|
||||||
return TraversalDecision::Continue;
|
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)
|
if (computed_values().visibility() != CSS::Visibility::Visible)
|
||||||
return TraversalDecision::Continue;
|
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))
|
if (clip_rect_for_hit_testing().has_value() && !clip_rect_for_hit_testing()->contains(position))
|
||||||
return TraversalDecision::Continue;
|
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
|
// TextCursor hit testing mode should be able to place cursor in contenteditable elements even if they are empty
|
||||||
if (m_fragments.is_empty()
|
if (m_fragments.is_empty()
|
||||||
|
|
|
@ -274,6 +274,7 @@ protected:
|
||||||
[[nodiscard]] bool could_be_scrolled_by_wheel_event(ScrollDirection) const;
|
[[nodiscard]] bool could_be_scrolled_by_wheel_event(ScrollDirection) const;
|
||||||
|
|
||||||
TraversalDecision hit_test_scrollbars(CSSPixelPoint position, Function<TraversalDecision(HitTestResult)> const& callback) const;
|
TraversalDecision hit_test_scrollbars(CSSPixelPoint position, Function<TraversalDecision(HitTestResult)> const& callback) const;
|
||||||
|
CSSPixelPoint adjust_position_for_cumulative_scroll_offset(CSSPixelPoint) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] virtual bool is_paintable_box() const final { return true; }
|
[[nodiscard]] virtual bool is_paintable_box() const final { return true; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue