Просмотр исходного кода

LibWeb: Create EdgeStyleValue for BackgroundPositionXY with no offset

When specifying either `background-position-x: right` or
`background-position-y: bottom` without an offset value no
EdgeStyleValue was created.

However, the spec says the offset should be optional.

Now, if you do not provide an offset, it creates the EdgeStyleValue
with a default offset of 0 pixels.
Alan Kemp 2 лет назад
Родитель
Сommit
3fd870a429

+ 2 - 0
Base/res/html/misc/background-position-xy.html

@@ -15,6 +15,7 @@
 <div class="example" style="background-position-x: 25%"></div>
 <div class="example" style="background-position-x: 25%"></div>
 <div class="example" style="background-position-x: 2rem"></div>
 <div class="example" style="background-position-x: 2rem"></div>
 <div class="example" style="background-position-x: right 32px"></div>
 <div class="example" style="background-position-x: right 32px"></div>
+<div class="example" style="background-position-x: right"></div>
 <br>
 <br>
 <br>
 <br>
 <b>background-position-y</b><br>
 <b>background-position-y</b><br>
@@ -23,3 +24,4 @@
 <div class="example" style="background-position-y: 25%"></div>
 <div class="example" style="background-position-y: 25%"></div>
 <div class="example" style="background-position-y: 2rem"></div>
 <div class="example" style="background-position-y: 2rem"></div>
 <div class="example" style="background-position-y: bottom 32px"></div>
 <div class="example" style="background-position-y: bottom 32px"></div>
+<div class="example" style="background-position-y: bottom"></div>

+ 2 - 0
Tests/LibWeb/Text/expected/background-position-xy.txt

@@ -0,0 +1,2 @@
+ right 0px
+bottom 0px

+ 21 - 0
Tests/LibWeb/Text/input/background-position-xy.html

@@ -0,0 +1,21 @@
+<script src="include.js"></script>
+<script>
+    test(() => {
+        var pos_x = document.getElementById("position-x")
+        var pos_y = document.getElementById("position-y")
+        println(getComputedStyle(pos_x).backgroundPositionX)
+        println(getComputedStyle(pos_y).backgroundPositionY)
+    });
+</script>
+<style>
+.example {
+  display: inline-block;
+  width: 200px;
+  height: 200px;
+  border: 1px solid black;
+  background-repeat: no-repeat;
+  background-size: 30px 30px;
+  background-image: linear-gradient(red, red);
+}
+</style>
+<div id="position-x" class="example" style="background-position-x: right"></div><div id="position-y" class="example" style="background-position-y: bottom"></div>

+ 3 - 1
Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp

@@ -4783,7 +4783,9 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_single_background_position_x_or_y_valu
         return EdgeStyleValue::create(relative_edge, *offset);
         return EdgeStyleValue::create(relative_edge, *offset);
     }
     }
 
 
-    return nullptr;
+    // If no offset is provided create this element but with an offset of default value of zero
+    transaction.commit();
+    return EdgeStyleValue::create(relative_edge, Length::make_px(0));
 }
 }
 
 
 ErrorOr<RefPtr<StyleValue>> Parser::parse_single_background_repeat_value(TokenStream<ComponentValue>& tokens)
 ErrorOr<RefPtr<StyleValue>> Parser::parse_single_background_repeat_value(TokenStream<ComponentValue>& tokens)