LibWeb: Implement background-attachment: local

This causes the background to scroll along with the element's contents.
This commit is contained in:
Sam Atkins 2023-08-08 20:45:38 +01:00 committed by Andreas Kling
parent ad859a8d0d
commit 8356ff283b
Notes: sideshowbarker 2024-07-17 00:37:23 +09:00

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, MacDue <macdue@dueutil.tech> * Copyright (c) 2022, MacDue <macdue@dueutil.tech>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -14,6 +14,7 @@
#include <LibWeb/Painting/BorderRadiusCornerClipper.h> #include <LibWeb/Painting/BorderRadiusCornerClipper.h>
#include <LibWeb/Painting/GradientPainting.h> #include <LibWeb/Painting/GradientPainting.h>
#include <LibWeb/Painting/PaintContext.h> #include <LibWeb/Painting/PaintContext.h>
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Painting { namespace Web::Painting {
@ -131,6 +132,15 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
background_positioning_area = layout_node.root().browsing_context().viewport_rect(); background_positioning_area = layout_node.root().browsing_context().viewport_rect();
break; break;
case CSS::BackgroundAttachment::Local: case CSS::BackgroundAttachment::Local:
background_positioning_area = get_box(layer.origin).rect;
if (is<Layout::Box>(layout_node)) {
auto* paintable_box = static_cast<Layout::Box const&>(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: case CSS::BackgroundAttachment::Scroll:
background_positioning_area = get_box(layer.origin).rect; background_positioning_area = get_box(layer.origin).rect;
break; break;