summaryrefslogtreecommitdiff
path: root/Demos
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-04 23:19:32 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-04 23:19:32 +0200
commite91871aed7f6a1e76961ff616b70582c38088df3 (patch)
tree3bdbede22127a92d8e5b92f8365145cac9dc95fb /Demos
parentada3c9ca466b95d81d4f5c8fe7e26466aca99828 (diff)
downloadserenity-e91871aed7f6a1e76961ff616b70582c38088df3.zip
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.
Diffstat (limited to 'Demos')
-rw-r--r--Demos/WebView/WebContentClient.cpp8
-rw-r--r--Demos/WebView/WebContentClient.h1
-rw-r--r--Demos/WebView/WebContentView.cpp18
-rw-r--r--Demos/WebView/WebContentView.h8
4 files changed, 31 insertions, 4 deletions
diff --git a/Demos/WebView/WebContentClient.cpp b/Demos/WebView/WebContentClient.cpp
index 03a6d3497f..2083fec29c 100644
--- a/Demos/WebView/WebContentClient.cpp
+++ b/Demos/WebView/WebContentClient.cpp
@@ -74,3 +74,11 @@ void WebContentClient::handle(const Messages::WebContentClient::DidChangeSelecti
#endif
m_view.notify_server_did_change_selection({});
}
+
+void WebContentClient::handle(const Messages::WebContentClient::DidLayout& message)
+{
+#ifdef DEBUG_SPAM
+ dbg() << "handle: WebContentClient::DidLayout! content_size=" << message.content_size();
+#endif
+ m_view.notify_server_did_layout({}, message.content_size());
+}
diff --git a/Demos/WebView/WebContentClient.h b/Demos/WebView/WebContentClient.h
index 2e0e6f5358..1a8f4651e8 100644
--- a/Demos/WebView/WebContentClient.h
+++ b/Demos/WebView/WebContentClient.h
@@ -48,6 +48,7 @@ private:
virtual void handle(const Messages::WebContentClient::DidFinishLoad&) override;
virtual void handle(const Messages::WebContentClient::DidInvalidateContentRect&) override;
virtual void handle(const Messages::WebContentClient::DidChangeSelection&) override;
+ virtual void handle(const Messages::WebContentClient::DidLayout&) override;
WebContentView& m_view;
};
diff --git a/Demos/WebView/WebContentView.cpp b/Demos/WebView/WebContentView.cpp
index 46a5b18e16..e48bd64bc2 100644
--- a/Demos/WebView/WebContentView.cpp
+++ b/Demos/WebView/WebContentView.cpp
@@ -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()
diff --git a/Demos/WebView/WebContentView.h b/Demos/WebView/WebContentView.h
index 64734e1c4f..02be9b4017 100644
--- a/Demos/WebView/WebContentView.h
+++ b/Demos/WebView/WebContentView.h
@@ -26,11 +26,12 @@
#pragma once
+#include <LibGUI/ScrollableWidget.h>
#include <LibGUI/Widget.h>
class WebContentClient;
-class WebContentView final : public GUI::Widget {
+class WebContentView final : public GUI::ScrollableWidget {
C_OBJECT(WebContentView);
public:
@@ -38,6 +39,7 @@ public:
void load(const URL&);
+ void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
void notify_server_did_paint(Badge<WebContentClient>, i32 shbuf_id);
void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);
void notify_server_did_change_selection(Badge<WebContentClient>);
@@ -45,12 +47,16 @@ public:
private:
WebContentView();
+ // ^Widget
virtual void paint_event(GUI::PaintEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
+ // ^ScrollableWidget
+ virtual void did_scroll() override;
+
void request_repaint();
WebContentClient& client();