Skip to content
Permalink
Browse files
Computed value for stroke-dasharray should be in px
https://bugs.webkit.org/show_bug.cgi?id=249813

Reviewed by Simon Fraser.

Computed value for stroke-dasharray should be in px:
- https://svgwg.org/svg2-draft/painting.html#StrokeDashing

Previously, we would only convert other length units to px when applied to a
SVG element, not for other kinds of elements.

* LayoutTests/imported/w3c/web-platform-tests/css/css-typed-om/the-stylepropertymap/properties/stroke-dasharray-expected.txt:
* Source/WebCore/css/SVGCSSComputedStyleDeclaration.cpp:
(WebCore::strokeDashArrayToCSSValueList):

Canonical link: https://commits.webkit.org/258300@main
  • Loading branch information
cdumez committed Dec 23, 2022
1 parent c2f53e7 commit a618c9c0e8e382fd9557d620e9a378714d18f9e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
@@ -6,8 +6,8 @@ PASS Can set 'stroke-dasharray' to CSS-wide keywords: revert
PASS Can set 'stroke-dasharray' to var() references: var(--A)
PASS Can set 'stroke-dasharray' to the 'none' keyword: none
PASS Can set 'stroke-dasharray' to a length: 0px
FAIL Can set 'stroke-dasharray' to a length: -3.14em assert_equals: unit expected "px" but got "em"
FAIL Can set 'stroke-dasharray' to a length: 3.14cm assert_equals: unit expected "px" but got "cm"
PASS Can set 'stroke-dasharray' to a length: -3.14em
PASS Can set 'stroke-dasharray' to a length: 3.14cm
PASS Can set 'stroke-dasharray' to a length: calc(0px + 0em)
PASS Can set 'stroke-dasharray' to a percent: 0%
FAIL Can set 'stroke-dasharray' to a percent: -3.14% assert_approx_equals: expected -3.14 +/- 0.000001 but got 0
@@ -1,3 +1,3 @@

FAIL strokeDasharray responsive to style changes assert_not_equals: got disallowed value "10em, 10em"
FAIL strokeDasharray responsive to style changes assert_not_equals: got disallowed value "0px, 0px"

@@ -56,8 +56,14 @@ static Ref<CSSValue> strokeDashArrayToCSSValueList(const Vector<SVGLengthValue>&
return CSSPrimitiveValue::createIdentifier(CSSValueNone);

auto list = CSSValueList::createCommaSeparated();
for (auto& length : dashes)
list->append(length.toCSSPrimitiveValue());
for (auto& length : dashes) {
auto primitiveValue = length.toCSSPrimitiveValue();
// Computed lengths should always be in 'px' unit.
if (primitiveValue->isLength() && primitiveValue->primitiveType() != CSSUnitType::CSS_PX)
list->append(CSSPrimitiveValue::create(primitiveValue->doubleValue(CSSUnitType::CSS_PX), CSSUnitType::CSS_PX));
else
list->append(WTFMove(primitiveValue));
}

return list;
}

0 comments on commit a618c9c

Please sign in to comment.