Browse Source

LibWeb: Allow calculated values for `background-size` dimensions

This fixes the sizing of the arrow icons displayed to the left of
parent sections on a table of contents on Wikipedia articles, which
are sized using the equation `calc(max(0.75em, 12px))`. Now, the icon
will not expand past the edges of the box they are within, avoiding
clipping the edges of the arrows.
Zaggy1024 1 năm trước cách đây
mục cha
commit
4cc3c41269

BIN
Tests/LibWeb/Ref/assets/2x2checkerboard.png


+ 15 - 0
Tests/LibWeb/Ref/background-size-calc.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <link rel="match" href="reference/background-size-calc-ref.html" />
+    <style>
+        span {
+            display: inline-block;
+            min-width: 12px;
+            min-height: 12px;
+            background-image: url("assets/2x2checkerboard.png");
+            background-size: calc(max(0.75em, 12px));
+        }
+    </style>
+</head>
+<body><span></span><img src="assets/2x2checkerboard.png">

+ 14 - 0
Tests/LibWeb/Ref/reference/background-size-calc-ref.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        span {
+            display: inline-block;
+            min-width: 12px;
+            min-height: 12px;
+            background-image: url("../assets/2x2checkerboard.png");
+            background-size: calc(max(0.75em, 12px));
+        }
+    </style>
+</head>
+<body><span></span><img src="../assets/2x2checkerboard.png">

+ 2 - 0
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -3169,6 +3169,8 @@ RefPtr<StyleValue> Parser::parse_single_background_size_value(TokenStream<Compon
             return LengthPercentage { style_value.as_percentage().percentage() };
         if (style_value.is_length())
             return LengthPercentage { style_value.as_length().length() };
+        if (style_value.is_calculated())
+            return LengthPercentage { style_value.as_calculated() };
         return {};
     };