From e58e315e0f2a4c69ee637cd4b88d76f89e8c2c14 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 1 Jun 2020 19:50:47 +0200 Subject: [PATCH] LibWeb: Make input widget (buttons, text boxes, etc) scroll with page We now relayout all LayoutWidgets when the view is scrolled. This will cause them to follow along with the rest of the page content. --- Libraries/LibWeb/Frame.cpp | 14 ++++++++++++++ Libraries/LibWeb/Frame.h | 2 ++ Libraries/LibWeb/Layout/LayoutWidget.cpp | 14 +++++++++++--- Libraries/LibWeb/PageView.cpp | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/Frame.cpp b/Libraries/LibWeb/Frame.cpp index 94feac2e79..0a9182ebf2 100644 --- a/Libraries/LibWeb/Frame.cpp +++ b/Libraries/LibWeb/Frame.cpp @@ -81,4 +81,18 @@ void Frame::set_needs_display(const Gfx::Rect& rect) on_set_needs_display(rect); } +void Frame::did_scroll(Badge) +{ + if (!m_document) + return; + if (!m_document->layout_node()) + return; + m_document->layout_node()->for_each_in_subtree([&](LayoutNode& layout_node) { + if (layout_node.is_widget()) { + layout_node.layout(LayoutNode::LayoutMode::Default); + } + return IterationDecision::Continue; + }); +} + } diff --git a/Libraries/LibWeb/Frame.h b/Libraries/LibWeb/Frame.h index 97e2e3854a..9d30cdf8a1 100644 --- a/Libraries/LibWeb/Frame.h +++ b/Libraries/LibWeb/Frame.h @@ -61,6 +61,8 @@ public: void set_viewport_rect(const Gfx::Rect&); Gfx::Rect viewport_rect() const { return m_viewport_rect; } + void did_scroll(Badge); + private: explicit Frame(PageView&); diff --git a/Libraries/LibWeb/Layout/LayoutWidget.cpp b/Libraries/LibWeb/Layout/LayoutWidget.cpp index 72ef5a0c07..2d612d7843 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.cpp +++ b/Libraries/LibWeb/Layout/LayoutWidget.cpp @@ -24,11 +24,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include #include #include -#include -#include +#include +#include #include +#include namespace Web { @@ -47,7 +51,11 @@ void LayoutWidget::layout(LayoutMode layout_mode) { rect().set_size(widget().width(), widget().height()); LayoutReplaced::layout(layout_mode); - widget().move_to(rect().x(), rect().y()); + + auto adjusted_widget_position = rect().location().to_int_point(); + if (auto* page_view = document().frame()->page_view()) + adjusted_widget_position.move_by(-page_view->horizontal_scrollbar().value(), -page_view->vertical_scrollbar().value()); + widget().move_to(adjusted_widget_position); } void LayoutWidget::render(RenderingContext& context) diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp index 02af758924..354a6e3f61 100644 --- a/Libraries/LibWeb/PageView.cpp +++ b/Libraries/LibWeb/PageView.cpp @@ -624,6 +624,7 @@ void PageView::dump_selection(const char* event_name) void PageView::did_scroll() { main_frame().set_viewport_rect(viewport_rect_in_content_coordinates()); + main_frame().did_scroll({}); } Gfx::Point PageView::compute_mouse_event_offset(const Gfx::Point& event_position, const LayoutNode& layout_node) const