mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 02:55:07 +00:00
Ladybird: Basic scrolling support
This commit is contained in:
parent
1eb653115b
commit
80526625e8
3 changed files with 27 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Dex♪ <dexes.ttp@gmail.com>
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -49,6 +50,7 @@
|
|||
#include <LibWebSocket/WebSocket.h>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
|
||||
class HeadlessBrowserPageClient final : public Web::PageClient {
|
||||
public:
|
||||
|
@ -198,6 +200,16 @@ public:
|
|||
|
||||
virtual void page_did_layout() override
|
||||
{
|
||||
auto* layout_root = this->layout_root();
|
||||
VERIFY(layout_root);
|
||||
Gfx::IntSize content_size;
|
||||
if (layout_root->paint_box()->has_overflow())
|
||||
content_size = enclosing_int_rect(layout_root->paint_box()->scrollable_overflow_rect().value()).size();
|
||||
else
|
||||
content_size = enclosing_int_rect(layout_root->paint_box()->absolute_rect()).size();
|
||||
|
||||
m_view.verticalScrollBar()->setMaximum(content_size.height() - m_viewport_rect.height());
|
||||
m_view.horizontalScrollBar()->setMaximum(content_size.width() - m_viewport_rect.width());
|
||||
}
|
||||
|
||||
virtual void page_did_request_scroll_into_view(Gfx::IntRect const&) override
|
||||
|
@ -273,10 +285,10 @@ void WebView::paintEvent(QPaintEvent* event)
|
|||
painter.setClipRect(event->rect());
|
||||
|
||||
auto output_rect = m_page_client->viewport_rect();
|
||||
output_rect.set_x(horizontalScrollBar()->value());
|
||||
output_rect.set_y(verticalScrollBar()->value());
|
||||
auto output_bitmap = MUST(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, output_rect.size()));
|
||||
|
||||
dbgln("paintEvent: {}", output_rect);
|
||||
|
||||
m_page_client->paint(output_rect, output_bitmap);
|
||||
|
||||
QImage q_image(output_bitmap->scanline_u8(0), output_bitmap->width(), output_bitmap->height(), QImage::Format_RGB32);
|
||||
|
@ -285,7 +297,7 @@ void WebView::paintEvent(QPaintEvent* event)
|
|||
|
||||
void WebView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
Gfx::IntRect rect(0, 0, event->size().width(), event->size().height());
|
||||
Gfx::IntRect rect(horizontalScrollBar()->value(), verticalScrollBar()->value(), event->size().width(), event->size().height());
|
||||
m_page_client->set_viewport_rect(rect);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue