LibWeb: Scroll elements into view when they become focused

This makes both user-interactive (tab keys) and programmatic focus
changes scroll the viewport if necessary to reveal the newly focused
element.
This commit is contained in:
Andreas Kling 2022-10-11 12:15:46 +02:00
parent 7dcbb403bb
commit 5ab501c92f
Notes: sideshowbarker 2024-07-17 06:02:42 +09:00
2 changed files with 5 additions and 1 deletions

View file

@ -1427,6 +1427,10 @@ void Document::set_focused_element(Element* element)
if (m_layout_root)
m_layout_root->set_needs_display();
// Scroll the viewport if necessary to make the newly focused element visible.
if (m_focused_element)
m_focused_element->scroll_into_view();
}
void Document::set_active_element(Element* element)

View file

@ -160,7 +160,7 @@ public:
WebIDL::ExceptionOr<void> insert_adjacent_text(String const& where, String const& data);
// https://w3c.github.io/csswg-drafts/cssom-view-1/#dom-element-scrollintoview
void scroll_into_view(Optional<Variant<bool, ScrollIntoViewOptions>>);
void scroll_into_view(Optional<Variant<bool, ScrollIntoViewOptions>> = {});
protected:
Element(Document&, DOM::QualifiedName);