1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 15:15:08 +00:00

WebContent: Basic scrolling support! :^)

The WebContentView widget now inherits from GUI::ScrollableWidget and
will pass its scroll offset over to the WebContent process as it's
changing. This is not super efficient and can get a bit laggy, but it
will do fine as an initial scrolling implementation.

Just like the single-process Web::PageView widget, WebContentView also
paints scrolled content by translating the Gfx::Painter.
This commit is contained in:
Andreas Kling 2020-07-04 23:19:32 +02:00
parent ada3c9ca46
commit e91871aed7
7 changed files with 58 additions and 13 deletions

View file

@ -28,6 +28,7 @@
#include "WebContentClient.h"
#include <AK/SharedBuffer.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h>
#include <LibGfx/SystemTheme.h>
WebContentView::WebContentView()
@ -59,8 +60,8 @@ void WebContentView::resize_event(GUI::ResizeEvent& event)
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, event.size());
m_bitmap = bitmap->to_bitmap_backed_by_shared_buffer();
m_bitmap->shared_buffer()->share_with(client().server_pid());
client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ 0, 0 }, event.size())));
client().post_message(Messages::WebContentServer::Paint(m_bitmap->rect(), m_bitmap->shbuf_id()));
client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, event.size())));
request_repaint();
}
void WebContentView::mousedown_event(GUI::MouseEvent& event)
@ -97,9 +98,20 @@ void WebContentView::notify_server_did_change_selection(Badge<WebContentClient>)
request_repaint();
}
void WebContentView::notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size)
{
set_content_size(content_size);
}
void WebContentView::did_scroll()
{
client().post_message(Messages::WebContentServer::SetViewportRect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, size())));
request_repaint();
}
void WebContentView::request_repaint()
{
client().post_message(Messages::WebContentServer::Paint(m_bitmap->rect(), m_bitmap->shbuf_id()));
client().post_message(Messages::WebContentServer::Paint(m_bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_bitmap->shbuf_id()));
}
WebContentClient& WebContentView::client()