Skip to content

Commit d9c6e9d

Browse files
zcorpansvgeesus
authored andcommitted
Parse as CSS 'transform' instead of SVG transform=""
Also refactor into a common algorithm for both DOMMatrix constructor and setMatrixValue, since they kept getting out of sync. Explicitly hook into the css-syntax "parse something according to a CSS grammar". Fixes #149. Fixes #144. Tests: web-platform-tests/wpt#5902
1 parent 765f86f commit d9c6e9d

File tree

1 file changed

+57
-60
lines changed

1 file changed

+57
-60
lines changed

geometry/Overview.bs

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,8 @@ caniuse=dommatrix>matrix</dfn> with the purpose of describing transformations in
601601
context. The following sections describe the details of the interface.
602602

603603
<div class="figure">
604-
<!--<img src="images/4x4matrix.png" alt="4x4 matrix with items m11 to m44">-->
605604
<math display=block><mrow><mfenced open=[ close=] separators=,><mrow><mtable><mtr><mtd><msub><mi>m</mi><mi>11</mi></msub></mtd><mtd><msub><mi>m</mi><mi>21</mi></msub></mtd><mtd><msub><mi>m</mi><mi>31</mi></msub></mtd><mtd><msub><mi>m</mi><mi>41</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>12</mi></msub></mtd><mtd><msub><mi>m</mi><mi>22</mi></msub></mtd><mtd><msub><mi>m</mi><mi>32</mi></msub></mtd><mtd><msub><mi>m</mi><mi>42</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>13</mi></msub></mtd><mtd><msub><mi>m</mi><mi>23</mi></msub></mtd><mtd><msub><mi>m</mi><mi>33</mi></msub></mtd><mtd><msub><mi>m</mi><mi>43</mi></msub></mtd></mtr><mtr><mtd><msub><mi>m</mi><mi>14</mi></msub></mtd><mtd><msub><mi>m</mi><mi>24</mi></msub></mtd><mtd><msub><mi>m</mi><mi>34</mi></msub></mtd><mtd><msub><mi>m</mi><mi>44</mi></msub></mtd></mtr></mtable></mrow></mfenced></mrow></math>
606-
<p class="capture">A 4x4 matrix representing a {{DOMMatrix}} with items m11 to m44.
605+
<p class="capture">A <dfn lt="abstract matrix">4x4 matrix</dfn> with items m11 to m44.
607606
</div>
608607

609608
<p>In the following sections, terms have the following meaning:
@@ -882,6 +881,51 @@ run the following steps:
882881
values, and also for ''0'' and ''-0''. [[!ECMA-262]]
883882

884883

884+
<h3 id=dommatrix-parse algorithm>Parsing a string into an abstract matrix</h3>
885+
886+
<p>To <dfn>parse a string into an abstract matrix</dfn>, given a string <var>transformList</var>,
887+
means to run the following steps. It will either return a <a lt="abstract matrix">4x4 matrix</a> and
888+
a boolean <var>2dTransform</var>, or failure.
889+
890+
<ol>
891+
<li><p>If <var>transformList</var> is the empty string, set it to the string "<code
892+
nohighlight>matrix(1, 0, 0, 1, 0, 0)</code>".
893+
894+
<li><p><a for=CSS>Parse</a> <var>transformList</var> into <var>parsedValue</var> given the grammar
895+
for the CSS 'transform' property. The result will be a <<transform-list>>, the keyword
896+
''transform/none'', or failure. If <var>parsedValue</var> is failure, or any <<transform-function>>
897+
has <<length>> values without <a spec=css-values>absolute length</a> units, or any keyword other
898+
than ''transform/none'' is used, then return failure. [[!CSS3-SYNTAX]] [[!CSS3-TRANSFORMS]]
899+
900+
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
901+
<<transform-list>> containing a single identity matrix.
902+
903+
<li>
904+
<p>Let <var>2dTransform</var> track the 2D/3D dimension status of <var>parsedValue</var>.
905+
906+
<dl class=switch>
907+
<dt>If <var>parsedValue</var> consists of any <a
908+
href="https://drafts.csswg.org/css-transforms-1/#transform-primitives">three-dimensional
909+
transform functions</a>
910+
<dd><p>Set <var>2dTransform</var> to <code>false</code>.
911+
912+
<dt>Otherwise
913+
<dd><p>Set <var>2dTransform</var> to <code>true</code>.
914+
</dl>
915+
916+
<li><p>Transform all <<transform-function>>s to <a lt="abstract matrix">4x4 matrices</a> by
917+
following the “<a
918+
href=https://drafts.csswg.org/css-transforms-1/#mathematical-description>Mathematical Description
919+
of Transform Functions</a>”. [[!CSS3-TRANSFORMS]]
920+
921+
<li><p>Let <var>matrix</var> be a <a lt="abstract matrix">4x4 matrix</a> as shown in the initial
922+
figure of this section. <a for=matrix>Post-multiply</a> all matrices from left to right and set
923+
<var>matrix</var> to this product.
924+
925+
<li><p>Return <var>matrix</var> and <var>2dTransform</var>.
926+
</ol>
927+
928+
885929
<h3 id=dommatrix-create>Creating DOMMatrixReadOnly and DOMMatrix objects</h3>
886930

887931
<p>To <dfn>create a 2d matrix</dfn> of type <var>type</var> being either {{DOMMatrixReadOnly}} or
@@ -935,48 +979,19 @@ must follow these steps:
935979
<li><p>If <a>current global object</a> is not a {{Window}} object, then throw a {{TypeError}}
936980
exception.
937981

938-
<li><p>If <var>init</var> is the empty string, set it to the string
939-
"<code nohighlight>matrix(1, 0, 0, 1, 0, 0)</code>".
940-
941-
<li><p>Parse <var>init</var> into <var>parsedValue</var> by following the syntax description in
942-
<a href=https://drafts.csswg.org/css-transforms-1/#svg-syntax>Syntax of the SVG ‘transform’
943-
attribute</a>” to a <<transform-list>> or the keyword ''transform/none''. If parsing is not
944-
successful, or any <<transform-function>> has <<length>> values without <a
945-
spec=css-values>absolute length</a> units<!--For WD: <a spec=css-values-3>absolute length
946-
units</a>-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}"
947-
{{DOMException}}. [[!CSS3-TRANSFORMS]]
948-
949-
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
950-
<<transform-list>> containing a single identity matrix
951-
952-
<li><p>Let <var>2dTransform</var> track the 2D/3D dimension status of <var>parsedValue</var>.
953-
<dl class=switch>
954-
<dt>If <var>parsedValue</var> consists of any <a
955-
href="https://drafts.csswg.org/css-transforms-1/#three-d-transform-functions">3D Transform
956-
functions</a>
957-
<dd>Set <var>2dTransform</var> to <code>false</code>.
958-
959-
<dt>Otherwise
960-
<dd>Set <var>2dTransform</var> to <code>true</code>.
961-
</dl>
962-
963-
<li><p>Transform all <<transform-function>>s to 4x4 matrices by following the “<a
964-
href=https://drafts.csswg.org/css-transforms-1/#mathematical-description>Mathematical
965-
Description of Transform Functions</a>”. [[!CSS3-TRANSFORMS]]
966-
967-
<li><p>Let <var>matrix</var> be a 4x4 matrix as shown in the initial figure of this section. <a
968-
for=matrix>Post-multiply</a> all matrices from left to right and set <var>matrix</var> to this
969-
product.
982+
<li><p><a lt="parse a string into an abstract matrix">Parse <var>init</var> into an abstract
983+
matrix</a>, and let <var>matrix</var> and <var>2dTransform</var> be the result. If the result is
984+
failure, then throw a "{{SyntaxError}}" {{DOMException}}.
970985

971986
<li>
972987
<dl class=switch>
973-
<dt>If <var>2dTransform</var> is set to <code>true</code>
988+
<dt>If <var>2dTransform</var> is <code>true</code>
974989
<dd>Return the result of invoking <a>create a 2d matrix</a> of type {{DOMMatrixReadOnly}} or
975990
{{DOMMatrix}} as appropriate, with a sequence of numbers, the values being the elements <var
976991
ignore>m11</var>, <var ignore>m12</var>, <var ignore>m21</var>, <var ignore>m22</var>, <var
977992
ignore>m41</var> and <var ignore>m42</var> of <var>matrix</var>.
978993

979-
<dt>If <var>2dTransform</var> is set to <code>false</code>
994+
<dt>Otherwise
980995
<dd>Return the result of invoking <a>create a 3d matrix</a> of type {{DOMMatrixReadOnly}} or
981996
{{DOMMatrix}} as appropriate, with a sequence of numbers, the values being the 16 elements of
982997
<var>matrix</var>.
@@ -1769,32 +1784,14 @@ user agents.
17691784
<dt><dfn>setMatrixValue(<var>transformList</var>)</dfn>
17701785
<dd>
17711786
<ol>
1772-
<li><p>If <var>transformList</var> is the empty string, set it to the string "<code nohighlight>matrix(1, 0,
1773-
0, 1, 0, 0)</code>".
1774-
1775-
<li><p>Parse <var>transformList</var> into <var>parsedValue</var> by following the syntax
1776-
description in “<a href=https://drafts.csswg.org/css-transforms-1/#svg-syntax>Syntax of the SVG
1777-
‘transform’ attribute</a>” to a <<transform-list>> or the keyword ''transform/none''. If parsing
1778-
is not successful, or any <<transform-function>> has <<length>> values without <a
1779-
spec=css-values>absolute length</a> units<!--For WD: <a spec=css-values-3>absolute length
1780-
units</a>-->, or any keyword other than ''transform/none'' is used, throw a "{{SyntaxError}}"
1781-
{{DOMException}}. [[!CSS3-TRANSFORMS]]
1782-
1783-
<li><p>If <var>parsedValue</var> is ''transform/none'', set <var>parsedValue</var> to a
1784-
<<transform-list>> containing a single identity matrix
1785-
1786-
<li><p>Set <a for=matrix>is 2D</a> to <code>false</code> if the <<transform-list>> consists of any
1787-
<a href="https://drafts.csswg.org/css-transforms-1/#three-d-transform-functions">3D Transform
1788-
functions</a>. Otherwise set <a for=matrix>is 2D</a> to <code>true</code>.
1789-
1790-
<li><p>Transform all <<transform-function>>s to 4x4 matrices by following the “<a
1791-
href="https://drafts.csswg.org/css-transforms-1/#mathematical-description">Mathematical
1792-
Description of Transform Functions</a>”. [[!CSS3-TRANSFORMS]]
1787+
<li><p><a lt="parse a string into an abstract matrix">Parse <var>transformList</var> into an
1788+
abstract matrix</a>, and let <var>matrix</var> and <var>2dTransform</var> be the result. If the
1789+
result is failure, then throw a "{{SyntaxError}}" {{DOMException}}.
17931790

1794-
<li><p><a>Post-multiply</a> all matrices from left to right to a combined 4x4 matrix.
1791+
<li><p>Set <a for=matrix>is 2D</a> to the value of <var>2dTransform</var>.
17951792

1796-
<li><p>Set the {{DOMMatrixReadOnly/m11}} to {{DOMMatrixReadOnly/m44}} attributes to the element
1797-
values of the 4x4 matrix in column-major order.
1793+
<li><p>Set <a for=matrix>m11 element</a> through <a for=matrix>m44 element</a> to the element
1794+
values of <var>matrix</var> in column-major order.
17981795

17991796
<li><p>Return the current matrix.
18001797
</ol>

0 commit comments

Comments
 (0)