summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--Services/WebContent/PageHost.cpp33
-rw-r--r--Services/WebContent/PageHost.h2
-rw-r--r--Services/WebContent/WebContentClient.ipc1
7 files changed, 58 insertions, 13 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();
diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp
index 35cb43b7fd..98d6d0d621 100644
--- a/Services/WebContent/PageHost.cpp
+++ b/Services/WebContent/PageHost.cpp
@@ -66,26 +66,33 @@ void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl)
m_palette_impl = impl;
}
-void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
+Web::LayoutDocument* PageHost::layout_root()
{
- Gfx::Painter painter(target);
-
auto* document = page().main_frame().document();
if (!document)
- return;
+ return nullptr;
+ return document->layout_node();
+}
- auto* layout_root = document->layout_node();
+void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
+{
+ Gfx::Painter painter(target);
+ Gfx::IntRect bitmap_rect { {}, content_rect.size() };
+
+ auto* layout_root = this->layout_root();
if (!layout_root) {
- painter.fill_rect(content_rect, Color::White);
+ painter.fill_rect(bitmap_rect, Color::White);
return;
}
- painter.fill_rect(content_rect, document->background_color(palette()));
+ painter.fill_rect(bitmap_rect, layout_root->document().background_color(palette()));
- if (auto background_bitmap = document->background_image()) {
- painter.draw_tiled_bitmap(content_rect, *background_bitmap);
+ if (auto background_bitmap = layout_root->document().background_image()) {
+ painter.draw_tiled_bitmap(bitmap_rect, *background_bitmap);
}
+ painter.translate(-content_rect.x(), -content_rect.y());
+
Web::PaintContext context(painter, palette(), Gfx::IntPoint());
context.set_viewport_rect(content_rect);
layout_root->paint_all_phases(context);
@@ -109,4 +116,12 @@ void PageHost::page_did_change_selection()
m_client.post_message(Messages::WebContentClient::DidChangeSelection());
}
+void PageHost::page_did_layout()
+{
+ auto* layout_root = this->layout_root();
+ ASSERT(layout_root);
+ auto content_size = enclosing_int_rect(layout_root->absolute_rect()).size();
+ m_client.post_message(Messages::WebContentClient::DidLayout(content_size));
+}
+
}
diff --git a/Services/WebContent/PageHost.h b/Services/WebContent/PageHost.h
index 396ef92ce5..8db4923926 100644
--- a/Services/WebContent/PageHost.h
+++ b/Services/WebContent/PageHost.h
@@ -53,9 +53,11 @@ private:
virtual Gfx::Palette palette() const override;
virtual void page_did_invalidate(const Gfx::IntRect&) override;
virtual void page_did_change_selection() override;
+ virtual void page_did_layout() override;
explicit PageHost(ClientConnection&);
+ Web::LayoutDocument* layout_root();
void setup_palette();
ClientConnection& m_client;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index a018a5f812..ea5f16f5e5 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -4,4 +4,5 @@ endpoint WebContentClient = 90
DidPaint(Gfx::IntRect content_rect, i32 shbuf_id) =|
DidInvalidateContentRect(Gfx::IntRect content_rect) =|
DidChangeSelection() =|
+ DidLayout(Gfx::IntSize content_size) =|
}