Truly independent web browser
LibWeb: Implement SVGGraphicsElement.getCTM()
Jelle Raaijmakers6a6644bd4603
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex e5c54d69ccb..a861dfcb0eb 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -189,6 +189,7 @@ enum class InvalidateLayoutTreeReason {X(ScrollCursorIntoView, false) \X(ProcessScreenshot, false) \X(SVGGraphicsElementGetBBox, true) \+ X(SVGGraphicsElementGetCTM, false) \X(SVGGraphicsElementGetScreenCTM, false) \X(SVGLengthValue, false) \X(SVGPathLength, false) \diff --git a/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Libraries/LibWeb/SVG/SVGGraphicsElement.cppindex cabaf772153..3f89c67e4d4 100644--- a/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp+++ b/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp@@ -234,10 +234,69 @@ GC::Ptr<Geometry::DOMMatrix> SVGGraphicsElement::get_screen_ctm()return Geometry::DOMMatrix::create(ctm);}+// https://svgwg.org/svg2-draft/types.html#__svg__SVGGraphicsElement__getCTMGC::Ptr<Geometry::DOMMatrix> SVGGraphicsElement::get_ctm(){- dbgln("(STUBBED) SVGGraphicsElement::get_ctm(). Called on: {}", debug_description());- return Geometry::DOMMatrix::create();+ // 1. If the current element is not in the document, then return null.+ if (!is_connected())+ return {};++ Layout::ForcedReadScope read { document() };+ document().update_layout_if_needed_for_node(*this, DOM::UpdateLayoutReason::SVGGraphicsElementGetCTM);++ // 2. If the current element is a non-rendered element, and the UA is not able to resolve the style of the element,+ // then return null.+ // NB: We require committed box data for the current element and each of its ancestors up to the element ctm+ // transforms to, which also excludes geometry in resource-only subtrees such as masks, clip paths, and patterns.+ auto const* layout_node = this->layout_node(read);+ if (!layout_node || !Painting::has_committed_box(*layout_node))+ return {};++ // 3. Let ctm be a matrix determined based on what the current element is:+ // -> the current element is the outermost svg element+ // ctm is a matrix that transforms the coordinate space of the ‘svg’ (including its transform property) to the+ // coordinate space of the document's viewport. The matrix includes the transforms produced by the ‘viewBox’ and+ // ‘preserveAspectRatio’ attributes, the transform property, and any transform due to currentScale and+ // currentTranslate properties on the SVGSVGElement.+ // AD-HOC: Like Blink and WebKit, transform to the coordinate space of the svg element's SVG viewport instead, which+ // leaves only the transform produced by the viewBox and preserveAspectRatio attributes. Gecko returns null.+ // -> any other element+ // ctm is a matrix that transforms the coordinate space of the current element (including its transform property)+ // to the coordinate space of its closest ancestor viewport-establishing element (also including its transform+ // property).+ // NB: Like Blink and WebKit, the coordinate space of an svg element includes the transforms produced by its position+ // and its viewBox attribute.+ auto outermost_svg_element = this->outermost_svg_element();+ GC::Ptr<DOM::Node const> target = this;+ if (outermost_svg_element.ptr() != this)+ target = viewport_element();+ if (!target)+ return {};++ Gfx::AffineTransform ctm;+ for (auto const* node = layout_node;; node = node->parent()) {+ if (!node || !Painting::has_committed_box(*node))+ return {};++ Gfx::AffineTransform local_transform;+ auto viewport_transform = Painting::svg_viewport_transform(*node);+ if (node->dom_node() == outermost_svg_element.ptr()) {+ local_transform = viewport_transform.value_or({});+ } else {+ local_transform = Painting::svg_element_transform(*node);+ if (viewport_transform.has_value()) {+ local_transform.translate(Painting::absolute_rect(*node).location().to_type<float>());+ local_transform.multiply(*viewport_transform);+ }+ }+ ctm = local_transform.multiply(ctm);++ if (node->dom_node() == target.ptr())+ break;+ }++ // 4. Return a newly created, detached DOMMatrix object that represents the same matrix as ctm.+ return Geometry::DOMMatrix::create(ctm.to_matrix());}}diff --git a/Tests/LibWeb/Text/expected/SVG/get-ctm.txt b/Tests/LibWeb/Text/expected/SVG/get-ctm.txtnew file mode 100644index 00000000000..cc8d6664ed6--- /dev/null+++ b/Tests/LibWeb/Text/expected/SVG/get-ctm.txt@@ -0,0 +1,14 @@+outer: 2 0 0 2 0 0+translated: 2 0 0 2 20 40+scaled-rect: 4 0 0 4 20 40+inner: 4 0 0 4 34 58+inner-rect: 2 0 0 2 13 17+inner-group: 2 0 0 2 7 9+inner-group-rect: 2 0 0 2 7 9+display-none: null+mask-rect: 2 0 0 2 0 0+zero-height: 1 0 0 1 0 0+in-zero-height: 1 0 0 1 1 2+zero-view-box: 1 0 0 1 0 0+in-zero-view-box: null+detached: nulldiff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-mpath.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-mpath.txtnew file mode 100644index 00000000000..67079a6bb9b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-mpath.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass animateMotion with mpath\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-moveto-only.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-moveto-only.txtnew file mode 100644index 00000000000..176e086933b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-moveto-only.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++3 Pass+1 Fail+Pass path="M 100 100" translates to the initial point of the path+Pass <mpath> referencing d="M 100 100" translates to the initial point of the path+Fail accumulate="sum" on a single-moveto path adds the end of the path per repeat+Pass path="M 200 100" with rotate="auto" uses a 0 degree angle, not the position vector\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.txtnew file mode 100644index 00000000000..9e500dd4f28--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 3 tests++2 Pass+1 Fail+Pass path="M 100 100 L 100 100" stays at the initial point, with a 0 degree angle+Pass path="M 100 100 Z" stays at the initial point, with a 0 degree angle+Fail accumulate="sum" on a zero-length path adds the end of the path per repeat\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rotate-angle.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rotate-angle.txtnew file mode 100644index 00000000000..7f334f81554--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/animations/animateMotion-rotate-angle.txt@@ -0,0 +1,13 @@+Harness status: OK++Found 7 tests++3 Pass+4 Fail+Fail rotate="45" applies a constant 45 degree rotation+Fail rotate="-90" applies a constant -90 degree rotation+Fail rotate="30" applies a constant 30 degree rotation to a path animation+Pass rotate="0" applies no rotation+Pass an absent rotate attribute applies no rotation+Pass an unparseable rotate value applies no rotation+Fail rotate="auto" follows the direction of motion\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.txt b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.txtnew file mode 100644index 00000000000..ac06c98b2f9--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Pass+Pass getCTM+Pass getScreenCTM\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/SVG/get-ctm.html b/Tests/LibWeb/Text/input/SVG/get-ctm.htmlnew file mode 100644index 00000000000..14cb77eb2ca--- /dev/null+++ b/Tests/LibWeb/Text/input/SVG/get-ctm.html@@ -0,0 +1,33 @@+<!doctype html>+<script src="../include.js"></script>+<svg id="outer" width="200" height="200" viewBox="0 0 100 100" style="padding: 5px; border: 3px solid; transform: rotate(10deg)">+ <g id="translated" transform="translate(10 20)">+ <rect id="scaled-rect" transform="scale(2)" width="10" height="10" />+ <svg id="inner" x="7" y="9" width="50" height="50" viewBox="0 0 25 25">+ <rect id="inner-rect" x="1" width="5" height="5" transform="translate(3 4)" />+ <g id="inner-group"><rect id="inner-group-rect" width="1" height="1" /></g>+ </svg>+ </g>+ <rect id="display-none" style="display: none" width="10" height="10" />+ <defs>+ <mask id="mask"><rect id="mask-rect" width="50" height="20" /></mask>+ </defs>+ <rect width="50" height="20" mask="url(#mask)" />+</svg>+<div style="height: 0">+ <svg id="zero-height" width="100%" height="100%">+ <g id="in-zero-height" transform="translate(1 2)"></g>+ </svg>+</div>+<svg id="zero-view-box" width="200" height="100" viewBox="0 0 0 100">+ <rect id="in-zero-view-box" width="10" height="10" />+</svg>+<script>+ test(() => {+ for (const element of [...document.querySelectorAll("svg [id], svg[id]")].filter(element => element.getCTM)) {+ const matrix = element.getCTM();+ println(`${element.id}: ${matrix ? [matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f].join(" ") : null}`);+ }+ println(`detached: ${document.createElementNS("http://www.w3.org/2000/svg", "rect").getCTM()}`);+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-mpath.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-mpath.htmlnew file mode 100644index 00000000000..508090d25ec--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-mpath.html@@ -0,0 +1,51 @@+<!doctype html>+<title>animateMotion with mpath</title>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../../resources/SVGAnimationTestCase-testharness.js"></script>+<svg>+<path id="route" fill="none" stroke="#666" d="M0,300 q100,-100 200,0 t200,0 t200,0 t200,0 t200,-50"/>+<g id="car">+ <path id="body" d="M0,20 v-7 h7 l7,-7 h14 l7,7 h7 v7z" />+ <circle class="tire" cx="10" cy="20" r="5" />+ <circle class="tire" cx="32" cy="20" r="5" />+ <animateMotion dur="4s" repeatCount="indefinite" fill="remove">+ <mpath href="#route"/>+ </animateMotion>+</g>+</svg>+<script>+const rootSVGElement = document.querySelector('svg');+const car = document.getElementById('car');++function assert_ctm_position(element, x, y) {+ const ctm = element.getCTM();+ const epsilon = 2;+ assert_approx_equals(ctm.e, x, epsilon, 'ctm e');+ assert_approx_equals(ctm.f, y, epsilon, 'ctm f');+}++function sample1() {+ assert_ctm_position(car, 0, 0);+}++function sample2() {+ assert_ctm_position(car, 496, 250);+}++function sample3() {+ assert_ctm_position(car, 0, 300);+}++smil_async_test(t => {+ const expectedValues = [+ // [animationId, time, sampleCallback]+ ['anim', 0.0, sample1],+ ['anim', 2.0, sample2],+ ['anim', 4.0, sample3],+ ];+ runAnimationTest(t, expectedValues);+});++window.animationStartsImmediately = true;+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-moveto-only.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-moveto-only.htmlnew file mode 100644index 00000000000..85bda7acfe9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-moveto-only.html@@ -0,0 +1,107 @@+<!doctype html>+<meta charset="utf-8">+<title><animateMotion> with a motion path that is a single moveto</title>+<link rel="help" href="https://svgwg.org/specs/animations/#AnimateMotionElement">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>++<!-- "M 100 100" is a legal path: a path data segment must begin with a moveto,+ and nothing requires a second command. Because it is legal, the SMIL rule+ that an illegal value makes the animation have no effect does not apply.+ Its total length is 0, so t/dur distance along it is 0 at every t and the+ computed coordinate is its initial point, (100, 100) -- exactly as for the+ other zero-length spellings in animateMotion-path-zero-length-subpaths.html. -->++<svg id="svg-path" width="300" height="300">+ <rect id="rect-path" width="10" height="10" fill="green">+ <animateMotion path="M 100 100" rotate="auto" dur="2s" fill="freeze"/>+ </rect>+</svg>++<svg id="svg-mpath" width="300" height="300">+ <defs><path id="motion-path" d="M 100 100"/></defs>+ <rect id="rect-mpath" width="10" height="10" fill="green">+ <animateMotion rotate="auto" dur="2s" fill="freeze">+ <mpath href="#motion-path"/>+ </animateMotion>+ </rect>+</svg>++<svg id="svg-accumulate" width="300" height="300">+ <rect id="rect-accumulate" width="10" height="10" fill="green">+ <animateMotion path="M 100 100" dur="2s"+ repeatCount="2" accumulate="sum" fill="freeze"/>+ </rect>+</svg>++<!-- (200,100) is not on the x==y diagonal, so an angle taken from the position+ vector (26.57 degrees here) is distinguishable from one taken from the+ undefined tangent (0 degrees). -->+<svg id="svg-off-diagonal" width="400" height="300">+ <rect id="rect-off-diagonal" width="10" height="10" fill="green">+ <animateMotion path="M 200 100" rotate="auto" dur="2s" fill="freeze"/>+ </rect>+</svg>++<script>+for (const svg of document.querySelectorAll('svg'))+ svg.pauseAnimations();++function sampleAt(svg, t) {+ svg.setCurrentTime(t);+ return new Promise(resolve => requestAnimationFrame(resolve));+}++function assertTransform(rect, x, y, angle, description) {+ const m = rect.getCTM();+ assert_not_equals(m, null, `${description}: getCTM()`);+ const epsilon = 0.01;+ assert_approx_equals(m.e, x, epsilon, `${description}: translate x`);+ assert_approx_equals(m.f, y, epsilon, `${description}: translate y`);+ const degrees = Math.atan2(m.b, m.a) * 180 / Math.PI;+ assert_approx_equals(degrees, angle, epsilon, `${description}: rotation angle`);+}++promise_setup(() => new Promise(+ resolve => window.addEventListener('load', resolve, {once: true})));++promise_test(async t => {+ const svg = document.getElementById('svg-path');+ const rect = document.getElementById('rect-path');+ for (const time of [0, 1, 2, 4]) {+ await sampleAt(svg, time);+ assertTransform(rect, 100, 100, 0, `t=${time}`);+ }+}, 'path="M 100 100" translates to the initial point of the path');++promise_test(async t => {+ const svg = document.getElementById('svg-mpath');+ const rect = document.getElementById('rect-mpath');+ for (const time of [0, 1, 2, 4]) {+ await sampleAt(svg, time);+ assertTransform(rect, 100, 100, 0, `t=${time}`);+ }+}, '<mpath> referencing d="M 100 100" translates to the initial point of the path');++promise_test(async t => {+ const svg = document.getElementById('svg-accumulate');+ const rect = document.getElementById('rect-accumulate');+ await sampleAt(svg, 1);+ assertTransform(rect, 100, 100, 0, 't=1, first iteration');+ await sampleAt(svg, 2);+ assertTransform(rect, 200, 200, 0, 't=2, second iteration accumulates');+ await sampleAt(svg, 4);+ assertTransform(rect, 200, 200, 0, 't=4, frozen');+}, 'accumulate="sum" on a single-moveto path adds the end of the path per repeat');++promise_test(async t => {+ // The tangent of a zero-length path is undefined, so rotate="auto" must not+ // fall back to the angle of the position vector, which would be 26.57 degrees.+ const svg = document.getElementById('svg-off-diagonal');+ const rect = document.getElementById('rect-off-diagonal');+ for (const time of [0, 1, 2, 4]) {+ await sampleAt(svg, time);+ assertTransform(rect, 200, 100, 0, `t=${time}`);+ }+}, 'path="M 200 100" with rotate="auto" uses a 0 degree angle, not the position vector');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.htmlnew file mode 100644index 00000000000..98cbc81d9f1--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-path-zero-length-subpaths.html@@ -0,0 +1,92 @@+<!doctype html>+<meta charset="utf-8">+<title><animateMotion> with a zero-length motion path made of several path elements</title>+<link rel="help" href="https://svgwg.org/specs/animations/#AnimateMotionElement">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>++<!-- Every path below has a total length of 0, so t/dur distance along the path is+ 0 at every t, and the computed coordinate is the path's initial point. -->++<svg id="svg-line" width="300" height="300">+ <rect id="rect-line" width="10" height="10" fill="green">+ <animateMotion path="M 100 100 L 100 100" rotate="auto" dur="2s" fill="freeze"/>+ </rect>+</svg>++<svg id="svg-close" width="300" height="300">+ <rect id="rect-close" width="10" height="10" fill="green">+ <animateMotion path="M 100 100 Z" rotate="auto" dur="2s" fill="freeze"/>+ </rect>+</svg>++<!-- Deliberately not tested here: path="M 100 100 M 200 200". Which of the two+ zero-length subpaths a distance of 0 lands on is not resolved -- SVG 2 says+ "the point which is t/dur distance along the motion path", while SMIL says a+ moveto happens instantaneously, which argues for the second one. WebKit uses+ the first moveto; Chrome and Firefox use the last. Needs a spec answer before+ it is worth asserting either way. -->++<svg id="svg-accumulate" width="300" height="300">+ <rect id="rect-accumulate" width="10" height="10" fill="green">+ <animateMotion path="M 100 100 L 100 100" dur="2s"+ repeatCount="2" accumulate="sum" fill="freeze"/>+ </rect>+</svg>++<script>+// Drive the timelines by hand rather than waiting on wall-clock time.+for (const svg of document.querySelectorAll('svg'))+ svg.pauseAnimations();++function sampleAt(svg, t) {+ svg.setCurrentTime(t);+ return new Promise(resolve => requestAnimationFrame(resolve));+}++// The supplemental transform is translate(x, y) * rotate(angle), so the CTM of a+// rect in an untransformed viewport is [cos, sin, -sin, cos, x, y].+function assertTransform(rect, x, y, angle, description) {+ const m = rect.getCTM();+ assert_not_equals(m, null, `${description}: getCTM()`);+ const epsilon = 0.01;+ assert_approx_equals(m.e, x, epsilon, `${description}: translate x`);+ assert_approx_equals(m.f, y, epsilon, `${description}: translate y`);+ // An undefined tangent must not leak a NaN angle into the matrix; the+ // approx_equals below would fail on NaN, which is the point.+ const degrees = Math.atan2(m.b, m.a) * 180 / Math.PI;+ assert_approx_equals(degrees, angle, epsilon, `${description}: rotation angle`);+}++promise_setup(() => new Promise(+ resolve => window.addEventListener('load', resolve, {once: true})));++promise_test(async t => {+ const svg = document.getElementById('svg-line');+ const rect = document.getElementById('rect-line');+ for (const time of [0, 1, 2, 4]) {+ await sampleAt(svg, time);+ assertTransform(rect, 100, 100, 0, `t=${time}`);+ }+}, 'path="M 100 100 L 100 100" stays at the initial point, with a 0 degree angle');++promise_test(async t => {+ const svg = document.getElementById('svg-close');+ const rect = document.getElementById('rect-close');+ for (const time of [0, 1, 2, 4]) {+ await sampleAt(svg, time);+ assertTransform(rect, 100, 100, 0, `t=${time}`);+ }+}, 'path="M 100 100 Z" stays at the initial point, with a 0 degree angle');++promise_test(async t => {+ const svg = document.getElementById('svg-accumulate');+ const rect = document.getElementById('rect-accumulate');+ await sampleAt(svg, 1);+ assertTransform(rect, 100, 100, 0, 't=1, first iteration');+ await sampleAt(svg, 2);+ assertTransform(rect, 200, 200, 0, 't=2, second iteration accumulates');+ await sampleAt(svg, 4);+ assertTransform(rect, 200, 200, 0, 't=4, frozen');+}, 'accumulate="sum" on a zero-length path adds the end of the path per repeat');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rotate-angle.html b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rotate-angle.htmlnew file mode 100644index 00000000000..98d4e896c85--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/animations/animateMotion-rotate-angle.html@@ -0,0 +1,104 @@+<!doctype html>+<title><animateMotion> with a numeric 'rotate' value</title>+<link rel="help" href="https://w3c.github.io/svgwg/specs/animations/#RotateAttribute">+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<svg id="svg" width="400" height="400">+ <!-- rotate="<number>" applies a constant rotation of that many degrees. -->+ <rect id="angle" width="10" height="10">+ <animateMotion from="0,0" to="200,0" rotate="45" fill="freeze" dur="4s"/>+ </rect>+ <rect id="angle-negative" width="10" height="10">+ <animateMotion from="0,0" to="200,0" rotate="-90" fill="freeze" dur="4s"/>+ </rect>+ <!-- The same holds for path animations; 'path' is not special w.r.t. 'rotate'. -->+ <rect id="angle-path" width="10" height="10">+ <animateMotion path="M0,0 L200,0" rotate="30" fill="freeze" dur="4s"/>+ </rect>+ <!-- Explicit zero, absent, and unparseable values all mean no rotation:+ the initial value of 'rotate' is 0. -->+ <rect id="angle-zero" width="10" height="10">+ <animateMotion from="0,0" to="200,0" rotate="0" fill="freeze" dur="4s"/>+ </rect>+ <rect id="no-rotate" width="10" height="10">+ <animateMotion from="0,0" to="200,0" fill="freeze" dur="4s"/>+ </rect>+ <rect id="bogus-rotate" width="10" height="10">+ <animateMotion from="0,0" to="200,0" rotate="bogus" fill="freeze" dur="4s"/>+ </rect>+ <!-- Control: rotate="auto" follows the direction of motion. -->+ <rect id="auto" width="10" height="10">+ <animateMotion from="0,0" to="0,200" rotate="auto" fill="freeze" dur="4s"/>+ </rect>+</svg>+<script>+const rootSVGElement = document.getElementById('svg');++// The rotation is post-multiplied onto the translation computed for the motion,+// so the resulting matrix is [cos, sin, -sin, cos, tx, ty].+function assert_animation_transform(id, angleInDegrees, tx, ty) {+ const ctm = document.getElementById(id).getCTM();+ const radians = angleInDegrees * Math.PI / 180;+ const epsilon = 1e-4;+ assert_approx_equals(ctm.a, Math.cos(radians), epsilon, `${id}: matrix a`);+ assert_approx_equals(ctm.b, Math.sin(radians), epsilon, `${id}: matrix b`);+ assert_approx_equals(ctm.c, -Math.sin(radians), epsilon, `${id}: matrix c`);+ assert_approx_equals(ctm.d, Math.cos(radians), epsilon, `${id}: matrix d`);+ assert_approx_equals(ctm.e, tx, epsilon, `${id}: translation x`);+ assert_approx_equals(ctm.f, ty, epsilon, `${id}: translation y`);+}++// Document begin is the moment the load event is triggered, so the timeline+// cannot be sampled until after that event has been dispatched. Yield once+// before pausing and driving it manually.+const ready = new Promise(resolve => {+ window.addEventListener('load', () => requestAnimationFrame(() => {+ rootSVGElement.pauseAnimations();+ resolve();+ }));+});++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('angle', 45, 100, 0);+ rootSVGElement.setCurrentTime(4);+ assert_animation_transform('angle', 45, 200, 0);+}, 'rotate="45" applies a constant 45 degree rotation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('angle-negative', -90, 100, 0);+}, 'rotate="-90" applies a constant -90 degree rotation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('angle-path', 30, 100, 0);+}, 'rotate="30" applies a constant 30 degree rotation to a path animation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('angle-zero', 0, 100, 0);+}, 'rotate="0" applies no rotation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('no-rotate', 0, 100, 0);+}, 'an absent rotate attribute applies no rotation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('bogus-rotate', 0, 100, 0);+}, 'an unparseable rotate value applies no rotation');++promise_test(async () => {+ await ready;+ rootSVGElement.setCurrentTime(2);+ assert_animation_transform('auto', 90, 0, 100);+}, 'rotate="auto" follows the direction of motion');+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.htmlnew file mode 100644index 00000000000..26bd6b343fa--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGraphicsElement.getCTM-empty-viewBox.html@@ -0,0 +1,40 @@+<!doctype html>+<title>SVGGraphicsElement.getCTM and co with empty viewbox</title>+<link rel="author" href="mailto:[email protected]" title="Emilio Cobos Álvarez">+<link rel="author" href="https://mozilla.com" title="Mozilla">+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1997351">+<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#InterfaceSVGGraphicsElement" />+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ svg { vertical-align: top } /* To avoid baseline alignment */+</style>+<div id="container" style="width: 500px; height: 0px;">+ <svg width="100%" height="100%" xmlns:xlink="http://www.w3.org/1999/xlink">+ <defs></defs>+ <g class="viewport">+ </g>+ </svg>+</div>+<script>+ function assert_identity(m) {+ assert_equals(m.a, 1, "a");+ assert_equals(m.d, 1, "d");+ for (let member of ["b", "c", "e", "f"]) {+ assert_equals(m[member], 0, member);+ }+ }+ test(function () {+ assert_identity(document.querySelector(".viewport").getCTM());+ }, "getCTM");+ test(function() {+ let m = document.querySelector(".viewport").getScreenCTM();+ assert_equals(m.a, 1, "a");+ assert_equals(m.d, 1, "d");+ assert_equals(m.b, 0, "b");+ assert_equals(m.c, 0, "c");+ // For the <body> margin.+ assert_equals(m.e, 8, "e");+ assert_equals(m.f, 8, "f");+ }, "getScreenCTM");+</script>