From a1d053296d84c556dfdf57503ed38651342a362c Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Wed, 9 Jun 2021 21:17:21 +0000 Subject: [PATCH] Bug 1340422 - Part 2: Map SVG d attribute to CSS. r=emilio We parse the attribute and store it into CSS. We have tests already in wpt, svg/path/property/*, but we cannot pass them for now because we don't convert the relative commands into absolute commands. Those will be fixed in Bug 1489392 once the spec issue is resolved. Differential Revision: https://phabricator.services.mozilla.com/D81238 --- dom/svg/SVGElement.cpp | 15 ++++++++ dom/svg/SVGPathElement.cpp | 2 ++ .../path/property/getComputedStyle.svg.ini | 6 +++- .../svg/path/property/serialization.svg.ini | 14 +++++++- .../svg/path/property/getComputedStyle.svg | 32 ++++++++--------- .../tests/svg/path/property/serialization.svg | 36 +++++++++---------- 6 files changed, 66 insertions(+), 39 deletions(-) diff --git a/dom/svg/SVGElement.cpp b/dom/svg/SVGElement.cpp index 21dd07e2e0fe..cacaea1d0a5a 100644 --- a/dom/svg/SVGElement.cpp +++ b/dom/svg/SVGElement.cpp @@ -1278,6 +1278,21 @@ void SVGElement::UpdateContentDeclarationBlock() { nsAutoString value; mAttrs.AttrAt(i)->ToString(value); + + // FIXME: Now we still have to parse twice for d property because we are + // using the different data structure in SVG and CSS. This will be fixed in + // the patch series. + if (attrName->Equals(nsGkAtoms::d, kNameSpaceID_None)) { + // The value of d attribute is a raw svg path string. We convert it as a + // path() to align the syntax in CSS parser. We will drop this in the + // later patch. + nsAutoString path; + path.AppendLiteral("path(\""); + path.Append(value); + path.AppendLiteral("\")"); + value = path; + } + mappedAttrParser.ParseMappedAttrValue(attrName->Atom(), value); } mContentDeclarationBlock = mappedAttrParser.GetDeclarationBlock(); diff --git a/dom/svg/SVGPathElement.cpp b/dom/svg/SVGPathElement.cpp index ec90ffcf4961..a98efacc8f17 100644 --- a/dom/svg/SVGPathElement.cpp +++ b/dom/svg/SVGPathElement.cpp @@ -230,6 +230,8 @@ SVGPathElement::IsAttributeMapped(const nsAtom* name) const { static const MappedAttributeEntry* const map[] = {sMarkersMap}; return FindAttributeDependence(name, map) || + (StaticPrefs::layout_css_d_property_enabled() && + name == nsGkAtoms::d) || SVGPathElementBase::IsAttributeMapped(name); } diff --git a/testing/web-platform/meta/svg/path/property/getComputedStyle.svg.ini b/testing/web-platform/meta/svg/path/property/getComputedStyle.svg.ini index 4fb758a23501..a42d8a379193 100644 --- a/testing/web-platform/meta/svg/path/property/getComputedStyle.svg.ini +++ b/testing/web-platform/meta/svg/path/property/getComputedStyle.svg.ini @@ -1,4 +1,8 @@ [getComputedStyle.svg] - [getComputedStyle] + [d property of g5 should be path("M 10 5 H 50").] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 + [d property of p6 should be path("M 10 5 H 50").] + expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 diff --git a/testing/web-platform/meta/svg/path/property/serialization.svg.ini b/testing/web-platform/meta/svg/path/property/serialization.svg.ini index 6bfdeeb9885f..138d748a137b 100644 --- a/testing/web-platform/meta/svg/path/property/serialization.svg.ini +++ b/testing/web-platform/meta/svg/path/property/serialization.svg.ini @@ -1,4 +1,16 @@ [serialization.svg] - [serialization] + [Property d value 'path("m 10 20 q 30 60 40 50 q 100 70 90 80")'] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 + [Property d value 'path("m 10 20 l 20 30 Z l 50 60 Z m 70 80 l 90 60 Z t 70 120")'] + expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 + + [Property d value 'path("m 10.0 170.0 h 90.00 v 30.00 m 0 0 s 1 2 3 4 z c 9 8 7 6 5 4")'] + expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 + + [Property d value ' path( "m 10 20 a 10 20 30 1 0 40 50 a 110 120 30 1 1 140 50" )'] + expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1489392 diff --git a/testing/web-platform/tests/svg/path/property/getComputedStyle.svg b/testing/web-platform/tests/svg/path/property/getComputedStyle.svg index 392c570e3525..400f92ec8417 100644 --- a/testing/web-platform/tests/svg/path/property/getComputedStyle.svg +++ b/testing/web-platform/tests/svg/path/property/getComputedStyle.svg @@ -29,24 +29,20 @@ diff --git a/testing/web-platform/tests/svg/path/property/serialization.svg b/testing/web-platform/tests/svg/path/property/serialization.svg index 297f8ede687a..3199beb92b2e 100644 --- a/testing/web-platform/tests/svg/path/property/serialization.svg +++ b/testing/web-platform/tests/svg/path/property/serialization.svg @@ -8,29 +8,27 @@ + +