summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-09-19 15:58:26 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-19 22:53:35 +0200
commitabc22b727c099ece8f13d9823b3e29de8769d61c (patch)
treea95ce56c025054b55fe166757a07454f8955dd98 /Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
parentb047c1bc97defe66ab5a0fcb72b47ce7035dd38d (diff)
downloadserenity-abc22b727c099ece8f13d9823b3e29de8769d61c.zip
LibWeb: Move background painting from Box to its own file
This makes the code accessible to things that aren't a Box, such as InlineNode.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp')
-rw-r--r--Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
new file mode 100644
index 0000000000..bcbbc98798
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGfx/Painter.h>
+#include <LibWeb/Painting/BackgroundPainting.h>
+#include <LibWeb/Painting/PaintContext.h>
+
+namespace Web::Painting {
+
+void paint_background(PaintContext& context, Gfx::IntRect const& background_rect, BackgroundData const& background_data, BorderRadiusData const& border_radius)
+{
+ // FIXME: Support elliptical corners
+ context.painter().fill_rect_with_rounded_corners(background_rect, background_data.color, border_radius.top_left, border_radius.top_right, border_radius.bottom_right, border_radius.bottom_left);
+
+ // FIXME: Support multiple background layers
+ if (background_data.image) {
+ auto image_rect = background_rect;
+ switch (background_data.repeat_x) {
+ case CSS::Repeat::Round:
+ case CSS::Repeat::Space:
+ // FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
+ case CSS::Repeat::Repeat:
+ // The background rect is already sized to align with 'repeat'.
+ break;
+ case CSS::Repeat::NoRepeat:
+ image_rect.set_width(background_data.image->width());
+ break;
+ }
+
+ switch (background_data.repeat_y) {
+ case CSS::Repeat::Round:
+ case CSS::Repeat::Space:
+ // FIXME: Support 'round' and 'space'. Fall through to 'repeat' since that most closely resembles these.
+ case CSS::Repeat::Repeat:
+ // The background rect is already sized to align with 'repeat'.
+ break;
+ case CSS::Repeat::NoRepeat:
+ image_rect.set_height(background_data.image->height());
+ break;
+ }
+
+ // FIXME: Handle rounded corners
+ context.painter().blit_tiled(image_rect, *background_data.image, background_data.image->rect());
+ }
+}
+
+}