From 8356ff283beb86c0d02d0ab260aac06a46be69d5 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 8 Aug 2023 20:45:38 +0100 Subject: [PATCH] LibWeb: Implement `background-attachment: local` This causes the background to scroll along with the element's contents. --- .../Libraries/LibWeb/Painting/BackgroundPainting.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 7475c4bcda..764d72765e 100644 --- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling - * Copyright (c) 2021-2022, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * Copyright (c) 2022, MacDue * * SPDX-License-Identifier: BSD-2-Clause @@ -14,6 +14,7 @@ #include #include #include +#include namespace Web::Painting { @@ -131,6 +132,15 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet background_positioning_area = layout_node.root().browsing_context().viewport_rect(); break; case CSS::BackgroundAttachment::Local: + background_positioning_area = get_box(layer.origin).rect; + if (is(layout_node)) { + auto* paintable_box = static_cast(layout_node).paintable_box(); + if (paintable_box) { + auto scroll_offset = paintable_box->scroll_offset(); + background_positioning_area.translate_by(-scroll_offset.x(), -scroll_offset.y()); + } + } + break; case CSS::BackgroundAttachment::Scroll: background_positioning_area = get_box(layer.origin).rect; break;