summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-07 13:46:20 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-07 13:49:20 +0100
commit7f9f9164709870739540673f5bb21ac174ea0023 (patch)
tree0b3a1d822b4da8ab4befaab7654376a7eb764114 /Userland/Libraries
parent6c087480cf0b179918bd7b2b8c7d2017553043ad (diff)
downloadserenity-7f9f9164709870739540673f5bb21ac174ea0023.zip
LibWeb: Make tiled backgrounds scroll with content
Previously the page background was always draw relative to the viewport instead of following with the content. This should eventually become an opt-in mode (via CSS "background-attachment") but for now let's have the default behavior be that backgrounds scroll with content. Also take this opportunity to move the background painting code from the two web views to a shared location in InitialContainingBlockBox.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/InProcessWebView.cpp7
-rw-r--r--Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp19
-rw-r--r--Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.h2
3 files changed, 21 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp
index 7f664b3920..758f9a47a4 100644
--- a/Userland/Libraries/LibWeb/InProcessWebView.cpp
+++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp
@@ -262,14 +262,7 @@ void InProcessWebView::paint_event(GUI::PaintEvent& event)
return;
}
- painter.fill_rect(event.rect(), document()->background_color(palette()));
-
- if (auto background_bitmap = document()->background_image()) {
- painter.draw_tiled_bitmap(event.rect(), *background_bitmap);
- }
-
painter.translate(frame_thickness(), frame_thickness());
- painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
PaintContext context(painter, palette(), { horizontal_scrollbar().value(), vertical_scrollbar().value() });
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp
index fa74a76dda..b545670f97 100644
--- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <LibGfx/Painter.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Page/Frame.h>
@@ -61,8 +62,26 @@ void InitialContainingBlockBox::build_stacking_context_tree()
});
}
+void InitialContainingBlockBox::paint_document_background(PaintContext& context)
+{
+ context.painter().fill_rect(Gfx::IntRect { {}, context.viewport_rect().size() }, document().background_color(context.palette()));
+ context.painter().translate(-context.viewport_rect().location());
+
+ if (auto background_bitmap = document().background_image()) {
+ Gfx::IntRect background_rect {
+ 0,
+ 0,
+ context.viewport_rect().x() + context.viewport_rect().width(),
+ context.viewport_rect().y() + context.viewport_rect().height()
+ };
+ context.painter().blit_tiled(background_rect, *background_bitmap, background_bitmap->rect());
+ }
+}
+
void InitialContainingBlockBox::paint_all_phases(PaintContext& context)
{
+ paint_document_background(context);
+
paint(context, PaintPhase::Background);
paint(context, PaintPhase::Border);
paint(context, PaintPhase::Foreground);
diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.h b/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.h
index 92d2746ef4..edbf94b48b 100644
--- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.h
+++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlockBox.h
@@ -41,6 +41,8 @@ public:
void paint_all_phases(PaintContext&);
virtual void paint(PaintContext&, PaintPhase) override;
+ void paint_document_background(PaintContext&);
+
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
const LayoutRange& selection() const { return m_selection; }