Skip to content

Truly independent web browser

LibWeb: Handle scalar Typed OM border-image values

Andreas Kling5e9b5ca38a37
diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
index b430741ee84..960cb20cd51 100644
--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
@@ -68,6 +68,15 @@ static StyleValueVector subdivide_property_value(StyleValue const& value, Proper
return value.subdivide_into_iterations(property);
}
+static GC::Ref<CSSStyleValue> reify_property_value(StyleValue const& value, PropertyNameAndID const& property, bool is_computed)
+{
+ // INTEROP: Computed border-image values represent all four sides or both axes, even when their serialization
+ // collapses to a single numeric value or keyword.
+ if (is_computed && first_is_one_of(property.id(), PropertyID::BorderImageWidth, PropertyID::BorderImageOutset, PropertyID::BorderImageSlice, PropertyID::BorderImageRepeat))
+ return value.default_reify(property.name());
+ return value.reify(property.name());
+}
+
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapReadOnly::get(Utf16String property_name)
{
@@ -86,7 +95,7 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapRead
// 4. If props[property] exists, subdivide into iterations props[property], then reify the first item of the result and return it.
if (auto property_value = get_style_value(props, property.value())) {
auto iterations = subdivide_property_value(*property_value, property.value(), props.get_pointer<DOM::AbstractElement>());
- return iterations.first()->reify(property->name());
+ return reify_property_value(*iterations.first(), property.value(), props.has<DOM::AbstractElement>());
}
// 5. Otherwise, return undefined.
@@ -114,7 +123,7 @@ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> StylePropertyMapRead
if (auto property_value = get_style_value(props, property.value())) {
auto iterations = subdivide_property_value(*property_value, property.value(), props.get_pointer<DOM::AbstractElement>());
for (auto const& style_value : iterations)
- results.append(style_value->reify(property->name()));
+ results.append(reify_property_value(*style_value, property.value(), props.has<DOM::AbstractElement>()));
return results;
}
diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/border_image.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/border_image.rs
index 26cdf48a4b4..cd3efe27fdd 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/paint/border_image.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/border_image.rs
@@ -415,15 +415,22 @@ pub(crate) fn paint_border_image<O: Observer>(
let frame_id = recorder.register_image_frame(&frame);
let frame_size = (frame.width(), frame.height());
- let Some(StyleValueData::BorderImageSlice {
- top: slice_top,
- right: slice_right,
- bottom: slice_bottom,
- left: slice_left,
- fill,
- }) = style_queries::handle_value(&border.border_image_slice)
- else {
- unreachable!("computed border-image-slice holds a slice value");
+ let slice_value = style_queries::handle_value(&border.border_image_slice)
+ .expect("computed border-image-slice lost its style value");
+ let (slice_values, fill) = match slice_value {
+ StyleValueData::BorderImageSlice {
+ top,
+ right,
+ bottom,
+ left,
+ fill,
+ } => ([top.data(), right.data(), bottom.data(), left.data()], *fill),
+ // NB: Typed OM can supply a single numeric slice directly, without the parser's four-sided wrapper.
+ StyleValueData::Number { .. }
+ | StyleValueData::Integer { .. }
+ | StyleValueData::Percentage { .. }
+ | StyleValueData::Calculated { .. } => ([slice_value; 4], false),
+ _ => unreachable!("computed border-image-slice holds a slice or numeric value"),
};
let width_value = style_queries::handle_value(&border.border_image_width)
.expect("computed border-image-width lost its style value");
@@ -442,12 +449,7 @@ pub(crate) fn paint_border_image<O: Observer>(
let repeat_y = repeat_keyword(repeat_items[1 % repeat_items.len()]);
let geometry = resolve_border_image_geometry(
- [
- slice_top.data(),
- slice_right.data(),
- slice_bottom.data(),
- slice_left.data(),
- ],
+ slice_values,
component_items(width_value),
component_items(outset_value),
frame_size,
@@ -455,7 +457,6 @@ pub(crate) fn paint_border_image<O: Observer>(
css_border_widths,
present_edges,
);
- let fill = *fill;
let source_columns = geometry.source_columns;
let source_rows = geometry.source_rows;
let destination_columns = geometry.destination_columns;
diff --git a/Tests/LibWeb/Ref/expected/css/typed-om-border-image-slice-ref.html b/Tests/LibWeb/Ref/expected/css/typed-om-border-image-slice-ref.html
new file mode 100644
index 00000000000..bccd0028916
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/css/typed-om-border-image-slice-ref.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<style>
+ div {
+ width: 40px;
+ height: 40px;
+ margin: 10px;
+ border: 20px solid lime;
+ }
+</style>
+<div></div>
+<div></div>
+<div></div>
diff --git a/Tests/LibWeb/Ref/input/css/typed-om-border-image-slice.html b/Tests/LibWeb/Ref/input/css/typed-om-border-image-slice.html
new file mode 100644
index 00000000000..640e107866c
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/css/typed-om-border-image-slice.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<link rel="match" href="../../expected/css/typed-om-border-image-slice-ref.html">
+<style>
+ div {
+ width: 40px;
+ height: 40px;
+ margin: 10px;
+ border: 20px solid red;
+ border-image-source: url("../wpt-import/images/green.png");
+ }
+</style>
+<div id="number"></div>
+<div id="percentage"></div>
+<div id="calculation"></div>
+<script>
+ document.getElementById("number").attributeStyleMap.set("border-image-slice", CSS.number(20));
+ document.getElementById("percentage").attributeStyleMap.set("border-image-slice", CSS.percent(25));
+ document.getElementById("calculation").attributeStyleMap.set("border-image-slice", new CSSMathSum(CSS.number(10), CSS.number(10)));
+</script>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-outset.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-outset.txt
index 01df061a10e..e1c79385c13 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-outset.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-outset.txt
@@ -2,21 +2,20 @@ Harness status: OK
Found 34 tests
-26 Pass
-8 Fail
+34 Pass
Pass Can set 'border-image-outset' to CSS-wide keywords: initial
Pass Can set 'border-image-outset' to CSS-wide keywords: inherit
Pass Can set 'border-image-outset' to CSS-wide keywords: unset
Pass Can set 'border-image-outset' to CSS-wide keywords: revert
Pass Can set 'border-image-outset' to var() references: var(--A)
-Fail Can set 'border-image-outset' to a length: 0px
-Fail Can set 'border-image-outset' to a length: -3.14em
-Fail Can set 'border-image-outset' to a length: 3.14cm
-Fail Can set 'border-image-outset' to a length: calc(0px + 0em)
-Fail Can set 'border-image-outset' to a number: 0
-Fail Can set 'border-image-outset' to a number: -3.14
-Fail Can set 'border-image-outset' to a number: 3.14
-Fail Can set 'border-image-outset' to a number: calc(2 + 3)
+Pass Can set 'border-image-outset' to a length: 0px
+Pass Can set 'border-image-outset' to a length: -3.14em
+Pass Can set 'border-image-outset' to a length: 3.14cm
+Pass Can set 'border-image-outset' to a length: calc(0px + 0em)
+Pass Can set 'border-image-outset' to a number: 0
+Pass Can set 'border-image-outset' to a number: -3.14
+Pass Can set 'border-image-outset' to a number: 3.14
+Pass Can set 'border-image-outset' to a number: calc(2 + 3)
Pass Setting 'border-image-outset' to a percent: 0% throws TypeError
Pass Setting 'border-image-outset' to a percent: -3.14% throws TypeError
Pass Setting 'border-image-outset' to a percent: 3.14% throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-repeat.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-repeat.txt
index 587c3d0fa15..61432c118d1 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-repeat.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-repeat.txt
@@ -2,17 +2,16 @@ Harness status: OK
Found 37 tests
-33 Pass
-4 Fail
+37 Pass
Pass Can set 'border-image-repeat' to CSS-wide keywords: initial
Pass Can set 'border-image-repeat' to CSS-wide keywords: inherit
Pass Can set 'border-image-repeat' to CSS-wide keywords: unset
Pass Can set 'border-image-repeat' to CSS-wide keywords: revert
Pass Can set 'border-image-repeat' to var() references: var(--A)
-Fail Can set 'border-image-repeat' to the 'stretch' keyword: stretch
-Fail Can set 'border-image-repeat' to the 'repeat' keyword: repeat
-Fail Can set 'border-image-repeat' to the 'round' keyword: round
-Fail Can set 'border-image-repeat' to the 'space' keyword: space
+Pass Can set 'border-image-repeat' to the 'stretch' keyword: stretch
+Pass Can set 'border-image-repeat' to the 'repeat' keyword: repeat
+Pass Can set 'border-image-repeat' to the 'round' keyword: round
+Pass Can set 'border-image-repeat' to the 'space' keyword: space
Pass Setting 'border-image-repeat' to a length: 0px throws TypeError
Pass Setting 'border-image-repeat' to a length: -3.14em throws TypeError
Pass Setting 'border-image-repeat' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-slice.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-slice.txt
index ff646a417a0..2f5ba964376 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-slice.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-slice.txt
@@ -2,21 +2,20 @@ Harness status: OK
Found 34 tests
-26 Pass
-8 Fail
+34 Pass
Pass Can set 'border-image-slice' to CSS-wide keywords: initial
Pass Can set 'border-image-slice' to CSS-wide keywords: inherit
Pass Can set 'border-image-slice' to CSS-wide keywords: unset
Pass Can set 'border-image-slice' to CSS-wide keywords: revert
Pass Can set 'border-image-slice' to var() references: var(--A)
-Fail Can set 'border-image-slice' to a number: 0
-Fail Can set 'border-image-slice' to a number: -3.14
-Fail Can set 'border-image-slice' to a number: 3.14
-Fail Can set 'border-image-slice' to a number: calc(2 + 3)
-Fail Can set 'border-image-slice' to a percent: 0%
-Fail Can set 'border-image-slice' to a percent: -3.14%
-Fail Can set 'border-image-slice' to a percent: 3.14%
-Fail Can set 'border-image-slice' to a percent: calc(0% + 0%)
+Pass Can set 'border-image-slice' to a number: 0
+Pass Can set 'border-image-slice' to a number: -3.14
+Pass Can set 'border-image-slice' to a number: 3.14
+Pass Can set 'border-image-slice' to a number: calc(2 + 3)
+Pass Can set 'border-image-slice' to a percent: 0%
+Pass Can set 'border-image-slice' to a percent: -3.14%
+Pass Can set 'border-image-slice' to a percent: 3.14%
+Pass Can set 'border-image-slice' to a percent: calc(0% + 0%)
Pass Setting 'border-image-slice' to a length: 0px throws TypeError
Pass Setting 'border-image-slice' to a length: -3.14em throws TypeError
Pass Setting 'border-image-slice' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-width.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-width.txt
index 61cbcfd601a..81c42f8240f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-width.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/border-image-width.txt
@@ -2,26 +2,25 @@ Harness status: OK
Found 35 tests
-22 Pass
-13 Fail
+35 Pass
Pass Can set 'border-image-width' to CSS-wide keywords: initial
Pass Can set 'border-image-width' to CSS-wide keywords: inherit
Pass Can set 'border-image-width' to CSS-wide keywords: unset
Pass Can set 'border-image-width' to CSS-wide keywords: revert
Pass Can set 'border-image-width' to var() references: var(--A)
-Fail Can set 'border-image-width' to a length: 0px
-Fail Can set 'border-image-width' to a length: -3.14em
-Fail Can set 'border-image-width' to a length: 3.14cm
-Fail Can set 'border-image-width' to a length: calc(0px + 0em)
-Fail Can set 'border-image-width' to a percent: 0%
-Fail Can set 'border-image-width' to a percent: -3.14%
-Fail Can set 'border-image-width' to a percent: 3.14%
-Fail Can set 'border-image-width' to a percent: calc(0% + 0%)
-Fail Can set 'border-image-width' to a number: 0
-Fail Can set 'border-image-width' to a number: -3.14
-Fail Can set 'border-image-width' to a number: 3.14
-Fail Can set 'border-image-width' to a number: calc(2 + 3)
-Fail Can set 'border-image-width' to the 'auto' keyword: auto
+Pass Can set 'border-image-width' to a length: 0px
+Pass Can set 'border-image-width' to a length: -3.14em
+Pass Can set 'border-image-width' to a length: 3.14cm
+Pass Can set 'border-image-width' to a length: calc(0px + 0em)
+Pass Can set 'border-image-width' to a percent: 0%
+Pass Can set 'border-image-width' to a percent: -3.14%
+Pass Can set 'border-image-width' to a percent: 3.14%
+Pass Can set 'border-image-width' to a percent: calc(0% + 0%)
+Pass Can set 'border-image-width' to a number: 0
+Pass Can set 'border-image-width' to a number: -3.14
+Pass Can set 'border-image-width' to a number: 3.14
+Pass Can set 'border-image-width' to a number: calc(2 + 3)
+Pass Can set 'border-image-width' to the 'auto' keyword: auto
Pass Setting 'border-image-width' to a time: 0s throws TypeError
Pass Setting 'border-image-width' to a time: -3.14ms throws TypeError
Pass Setting 'border-image-width' to a time: 3.14s throws TypeError