summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-11-16 17:01:09 +0000
committerAndreas Kling <kling@serenityos.org>2021-11-17 22:20:01 +0100
commit493435c655dcd54f77a40a4f5c7bd48d9be0510d (patch)
treeedd0041e68eb29d99851275227479b5a0077a664 /Userland/Libraries/LibWeb
parent3d1ee5b2de81bf3aa3c3fb21b8673a06b97902be (diff)
downloadserenity-493435c655dcd54f77a40a4f5c7bd48d9be0510d.zip
LibWeb: Implement `background-repeat: space`
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
index b16f4114bf..107e580374 100644
--- a/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/BackgroundPainting.cpp
@@ -127,8 +127,19 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
switch (layer.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.
+ break;
+ case CSS::Repeat::Space: {
+ int whole_images = background_positioning_area.width() / image_rect.width();
+ if (whole_images <= 1) {
+ x_step = image_rect.width();
+ repeat_x = false;
+ } else {
+ int space = background_positioning_area.width() % image_rect.width();
+ x_step = image_rect.width() + ((float)space / (float)(whole_images - 1));
+ repeat_x = true;
+ }
+ break;
+ }
case CSS::Repeat::Repeat:
x_step = image_rect.width();
repeat_x = true;
@@ -145,8 +156,19 @@ void paint_background(PaintContext& context, Layout::NodeWithStyleAndBoxModelMet
switch (layer.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.
+ break;
+ case CSS::Repeat::Space: {
+ int whole_images = background_positioning_area.height() / image_rect.height();
+ if (whole_images <= 1) {
+ y_step = image_rect.height();
+ repeat_y = false;
+ } else {
+ int space = background_positioning_area.height() % image_rect.height();
+ y_step = image_rect.height() + ((float)space / (float)(whole_images - 1));
+ repeat_y = true;
+ }
+ break;
+ }
case CSS::Repeat::Repeat:
y_step = image_rect.height();
repeat_y = true;