浏览代码

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.
Andreas Kling 5 年之前
父节点
当前提交
e58e315e0f
共有 4 个文件被更改,包括 28 次插入3 次删除
  1. 14 0
      Libraries/LibWeb/Frame.cpp
  2. 2 0
      Libraries/LibWeb/Frame.h
  3. 11 3
      Libraries/LibWeb/Layout/LayoutWidget.cpp
  4. 1 0
      Libraries/LibWeb/PageView.cpp

+ 14 - 0
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<PageView>)
+{
+    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;
+    });
+}
+
 }

+ 2 - 0
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<PageView>);
+
 private:
     explicit Frame(PageView&);
 

+ 11 - 3
Libraries/LibWeb/Layout/LayoutWidget.cpp

@@ -24,11 +24,15 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <LibGfx/Font.h>
-#include <LibGfx/StylePainter.h>
 #include <LibGUI/Painter.h>
+#include <LibGUI/ScrollBar.h>
 #include <LibGUI/Widget.h>
+#include <LibGfx/Font.h>
+#include <LibGfx/StylePainter.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/Frame.h>
 #include <LibWeb/Layout/LayoutWidget.h>
+#include <LibWeb/PageView.h>
 
 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)

+ 1 - 0
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