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.
This commit is contained in:
Andreas Kling 2020-06-01 19:50:47 +02:00
parent 889a8e7d0f
commit e58e315e0f
Notes: sideshowbarker 2024-07-19 05:54:33 +09:00
4 changed files with 28 additions and 3 deletions

View file

@ -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;
});
}
}

View file

@ -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&);

View file

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

View file

@ -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