diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-17 18:05:54 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | 6ee92a1fd05e6aa4b7745d307213f497a79e68de (patch) | |
tree | 594ca1ef0d7b44e2cc9531c4447d4902db276dfb | |
parent | 345faff5866343d9be59971cd6101fd8ecea2e67 (diff) | |
download | serenity-6ee92a1fd05e6aa4b7745d307213f497a79e68de.zip |
Ladybird/WebView: Implement page_did_request_scroll_into_view()
This makes #foo links actually scroll the #foo element into view.
-rw-r--r-- | Ladybird/WebView.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Ladybird/WebView.cpp b/Ladybird/WebView.cpp index ac4048fb2b..82f2e0e4aa 100644 --- a/Ladybird/WebView.cpp +++ b/Ladybird/WebView.cpp @@ -285,8 +285,16 @@ public: m_view.horizontalScrollBar()->setPageStep(m_viewport_rect.width()); } - virtual void page_did_request_scroll_into_view(Gfx::IntRect const&) override + virtual void page_did_request_scroll_into_view(Gfx::IntRect const& rect) override { + if (m_viewport_rect.contains(rect)) + return; + + if (rect.top() < m_viewport_rect.top()) { + m_view.verticalScrollBar()->setValue(rect.top()); + } else if (rect.top() > m_viewport_rect.top() && rect.bottom() > m_viewport_rect.bottom()) { + m_view.verticalScrollBar()->setValue(rect.bottom() - m_viewport_rect.height() + 1); + } } virtual void page_did_request_alert(String const& message) override |