forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.src.html
More file actions
1115 lines (1045 loc) · 45 KB
/
Overview.src.html
File metadata and controls
1115 lines (1045 loc) · 45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html lang="en">
<head>
<title>CSS 2D Transforms</title>
<link rel="stylesheet" type="text/css" href="default.css">
<style type="text/css">
.rhs { white-space: pre-wrap; }
code { font-size: inherit; }
#box-shadow-samples td { background: white; color: black; }
</style>
<link rel="stylesheet" type="text/css"
href="http://www.w3.org/StyleSheets/TR/W3C-WD.css">
</head>
<body>
<div class="head">
<!--logo-->
<h1>CSS 2D Transforms</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:
<dd>
<a href="[VERSION]">http://dev.w3.org/csswg/css3-2d-transforms/</a>
<!--http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]-->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-2d-transforms">[LATEST]</a>
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/">
http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/</a>
<dt id="editors-list">Editors:
<dd>Simon Fraser (<a href="http://www.apple.com/">Apple Inc</a>) <simon.fraser @apple.com>
<dd>Dean Jackson (<a href="http://www.apple.com/">Apple Inc</a>) <dino @apple.com>
<dd>David Hyatt (<a href="http://www.apple.com/">Apple Inc</a>) <hyatt @apple.com>
<dd>Chris Marrin (<a href="http://www.apple.com/">Apple Inc</a>) <cmarrin @apple.com>
<dd>Edward O'Connor (<a href="http://www.apple.com/">Apple Inc</a>) <eoconnor @apple.com>
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>CSS 2D Transforms allows elements rendered by CSS to be transformed
in two-dimensional space.
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<p>
The <a href="ChangeLog">list of changes made to this specification</a> is
available.
</p>
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<h2>Introduction</h2>
<p><em>This section is not normative.</em>
<p>
The CSS <a href="http://www.w3.org/TR/REC-CSS2/visuren.html">visual
formatting model</a> describes a coordinate system within which each
element is positioned. Positions and sizes in this coordinate space can
be thought of as being expressed in pixels, starting in the upper left
corner of the parent with positive values proceeding to the right and
down.
</p>
<p>
This coordinate space can be modified with the <span
class="prop-name">'transform'</span> property. Using transform, elements
can be translated, rotated and scaled in two dimensional space.
The coordinate space
behaves as described in the <a
href="http://www.w3.org/TR/SVG/coords.html#EstablishingANewUserSpace">coordinate
system transformations</a> section of the SVG 1.1 specification. This is
a coordinate system with two axes: the X axis increases horizontally to
the right; the Y axis increases vertically downwards.
</p>
<p>
Transforms apply to block-level and atomic inline-level
elements, but do not apply to elements which may be split into
multiple inline-level boxes.
</p>
<p>
Specifying a value other than 'none' for the <span class="prop-name">'transform'</span>
property establishes a new <em>local coordinate system</em> at the element that it is
applied to. Transformations are cumulative. That is, elements establish their local
coordinate system within the coordinate system of their parent. From the perspective of the
user, an element effectively accumulates all the <span class="prop-name">'transform'</span>
properties of its ancestors as well as any local transform applied to it. The accumulation
of these transforms defines a <em>current transformation matrix (CTM)</em> for the element.
</p>
<p>
The transform property does not affect the flow of the content
surrounding the transformed element. However, the value of the overflow
area takes into account transformed elements. This behavior is similar
to what happens when elements are translated via relative positioning.
Therefore, if the value of the <span class="prop-name">'overflow'</span>
property is <span class="prop-value">'scroll'</span> or <span
class="prop-value">'auto'</span>, scrollbars will appear as needed to
see content that is transformed outside the visible area.
</p>
<p>
Any value other than 'none' for the transform results in the creation of
both a stacking context and a containing block. The object acts as a
containing block for fixed positioned descendants.
</p>
<div class="todo">
Need to go into more detail here about why fixed positioned objects
should do this, i.e., that it's much harder to implement otherwise.
</div>
<div class="issue">
There are two roles for transformations in layout: (1) transformations
that adjust the position of the affected content without changing the
normal layout of that content (much like relative positioning) and (2)
transformation of the content prior to layout that affects the layout
of that content. See <a
href="http://lists.w3.org/Archives/Public/www-style/2007Oct/0209">http://lists.w3.org/Archives/Public/www-style/2007Oct/0209</a>
for examples of both cases. The "transform" property (as defined in
this document) is equally useful for both roles. This document is
focused on satisfying the first role. There is, however, an
architectural question that arises because there needs to be a way to
distinguish which role an author of a stylesheet wants. The key
question is which is the default behavior/role for the "transform"
property and how is the other behavior/role indicated by a stylesheet
author. If you have an opinion on this topic,
please send feedback.
</div>
<div class="issue">
What do fixed backgrounds do in transforms? They should probably ignore
the transform completely, since - even transformed - the object should
be acting as "porthole" through which the fixed background can be viewed
in its original form.
</div>
<div class="issue">
This property should also be applicable to SVG elements.
</div>
<div class="issue">
We also need to specify that SVG transforms *do* combine with this
transform, e.g., if a <foreignObject> is inside transformed SVG
and then defines a transform of its own. This means we may potentially
have to examine the current SVG transform and combine with it to set the
correct transform.
</div><!-- ======================================================================================================= -->
<h2 id="transform-property">
The <span class="prop-name">'transform'</span> Property
</h2>
<p>
A two-dimensional transformation is applied to the coordinate system an element
renders in through the <span
class="prop-name">'transform'</span> property. This property contains a
list of <a href="#transform-functions">transform functions</a>. The
final transformation value for a coordinate system is obtained by converting
each function in the list to its corresponding matrix (either defined in
this specification or by reference to the SVG specification), then multiplying
the matrices.
</p>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="effects">transform</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
none | <transform-function> [ <transform-function> ]*
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
none
</td>
</tr>
<tr>
<td>
<em>Applies to:</em>
</td>
<td>
block-level and atomic inline-level elements
</td>
</tr>
<tr>
<td>
<em>Inherited:</em>
</td>
<td>
no
</td>
</tr>
<tr>
<td>
<em>Percentages:</em>
</td>
<td>
refer to the size of the element's border box
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
Same as specified value.
</td>
</tr>
</tbody>
</table><!-- ======================================================================================================= -->
<h2 id="transform-origin-property">
The <span class="prop-name">'transform-origin'</span> Property
</h2>
<p>
The <span class="prop-name">'transform-origin'</span> property
establishes the origin of transformation for a coordinate system. This property
is applied by first translating the element's coordinate system by the negated value of the
property, then applying the local transform, then translating by the
property value. This effectively moves the desired transformation origin
of the element to (0,0) in the local coordinate system, then applies
the local transform, then moves the element back to its original
position.
</p>
<p>If only one value is specified, the second value is assumed to be
'center'. If two values are given and at least one value is not a keyword,
then the first value represents the horizontal position (or offset) and
the second represents the vertical position (or
offset). <var><percentage></var> and <var><length></var>
values here represent an offset of the transform origin from the top left corner
of the element's border box.
</p>
<p>If three or four values are given, then
each <var><percentage></var> or<var><length></var>
represents an offset and must be preceded by a keyword,
which specifies from which edge the offset is given. For example,
''transform-origin: bottom 10px right 20px'' represents a
''10px'' vertical offset up from the bottom edge and a
''20px'' horizontal offset leftward from the right edge. If
three values are given, the missing offset is assumed to be zero.
</p>
<p>Positive values represent an offset <em>inward</em> from the edge of
the border box. Negative values represent an offset
<em>outward</em> from the edge of the border box.
</p>
<table class="propdef">
<tbody>
<tr>
<td>
<em>Name:</em>
</td>
<td>
<dfn id="transform-origin">transform-origin</dfn>
</td>
</tr>
<tr>
<td>
<em>Value:</em>
</td>
<td>
[ top | bottom ] |<br>
[ <percentage> | <length> | left | center | right ] [ <percentage> | <length> | top | center | bottom ]? |<br>
[ center | [ left | right ] [ <percentage> | <length> ]? ] && [ center | [ top | bottom ] [ <percentage> | <length> ]? ]<br>
</td>
</tr>
<tr>
<td>
<em>Initial:</em>
</td>
<td>
50% 50%
</td>
</tr>
<tr>
<td>
<em>Applies to:</em>
</td>
<td>
block-level and atomic inline-level elements
</td>
</tr>
<tr>
<td>
<em>Inherited:</em>
</td>
<td>
no
</td>
</tr>
<tr>
<td>
<em>Percentages:</em>
</td>
<td>
refer to the size of the element's border box
</td>
</tr>
<tr>
<td>
<em>Media:</em>
</td>
<td>
visual
</td>
</tr>
<tr>
<td>
<em>Computed value:</em>
</td>
<td>
For <length> the absolute value, otherwise a percentage
</td>
</tr>
</tbody>
</table>
<!-- ======================================================================================================= -->
<h2 id="transform-functions">
The Transformation Functions
</h2>
<p>
The value of the <span class="prop-name">transform</span> property is a
list of <transform-functions> applied in the order provided. The
individual transform functions are separated by whitespace. The
set of allowed transform functions is given below. In this list the
type <translation-value> is defined as a <length> or
<percentage> value, and the <angle> type is defined by <a
href="http://www.w3.org/TR/css3-values/">CSS Values and Units.</a>
</p>
<dl>
<dt>
<span class="prop-value">matrix(<number>, <number>, <number>, <number>, <number>, <number>)</span>
</dt>
<dd>
specifies a 2D transformation in the form of a <a href="http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined">transformation matrix</a> of six values. <span class="prop-value">matrix(a,b,c,d,e,f)</span> is equivalent to applying the transformation matrix <strong>[a b c d e f]</strong>.
</dd>
<dt>
<span class="prop-value">translate(<translation-value>[, <translation-value>])</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">2D translation</a> by the vector [tx, ty], where tx is the first translation-value parameter and ty is the optional second translation-value parameter. If <em><ty></em> is not provided, ty has zero as a value.
</dd>
<dt>
<span class="prop-value">translateX(<translation-value>)</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">translation</a> by the given amount in the X direction.
</dd>
<dt>
<span class="prop-value">translateY(<translation-value>)</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">translation</a> by the given amount in the Y direction.
</dd>
<dt>
<span class="prop-value">scale(<number>[, <number>])</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#ScalingDefined">2D scale</a> operation by the [sx,sy] scaling vector described by the 2 parameters. If the second parameter is not provided, it is takes a value equal to the first. For example, scale(1, 1) would leave an element unchanged, while scale(2, 2) would cause it to appear twice as long in both the X
and Y axes, or four times its typical geometric size.
</dd>
<dt>
<span class="prop-value">scaleX(<number>)</span>
</dt>
<dd>
specifies a scale operation using the [sx,1] scaling vector, where sx is given as the parameter.
</dd>
<dt>
<span class="prop-value">scaleY(<number>)</span>
</dt>
<dd>
specifies a scale operation using the [1,sy] scaling vector, where sy is given as the parameter.
</dd>
<dt>
<span class="prop-value">rotate(<angle>)</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#RotationDefined">2D rotation</a> by the angle specified in the parameter about the origin of the element, as defined by the <em>transform-origin</em> property. For example, rotate(90deg) would cause elements to appear
rotated one-quarter of a turn in the clockwise direction.
</dd>
<dt>
<span class="prop-value">skewX(<angle>)</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#SkewXDefined">skew transformation along the X axis</a> by the given angle.
</dd>
<dt>
<span class="prop-value">skewY(<angle>)</span>
</dt>
<dd>
specifies a <a href="http://www.w3.org/TR/SVG/coords.html#SkewYDefined">skew transformation along the Y axis</a> by the given angle.
</dd>
</dl>
<h2 id="transform-values">
Transform Values and Lists
</h2>
<p>
The <translation-value> values are defined as [<percentage> | <length>]. All other value types are described <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#values">as CSS types</a>. If a list of transforms is provided, then the net effect is as if each transform had been specified separately in the order provided. For example,
</p>
<pre>
<div style="transform:translate(-10px,-20px) scale(2) rotate(45deg) translate(5px,10px)"/>
</pre>
<p>
is functionally equivalent to:
</p>
<pre>
<div style="transform:translate(-10px,-20px)">
<div style="transform:scale(2)">
<div style="transform:rotate(45deg)">
<div style="transform:translate(5px,10px)">
</div>
</div>
</div>
</div>
</pre>
<p>
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the outside in. The resulting transform is the matrix multiplication of the list of transforms.
</p>
<div class="example">
<pre>
div {
transform: translate(100px, 100px);
}
</pre>Move the element by 100 pixels in both the X and Y directions.
<div class="figure">
<img src="transform1.png" alt="The 100px translation in X and Y">
</div>
</div>
<div class="example">
<pre>
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
</pre>Move the element by 80 pixels in both the X and Y directions, then scale the element by 150%, then rotate it 45 degrees clockwise about the Z axis. Note that the scale and rotate operate about the center of the element, since the element has the default transform-origin of 50% 50%.
<div class="figure">
<img src="compound_transform.png" alt="The transform specified above">
</div>
</div>
<!-- ======================================================================================================= -->
<h2 id="animation">
Transitions and animations between transform values
</h2>
<p>
When animating or transitioning the value of a transform property
the rules described below are applied. The 'from' transform is
the transform at the start of the transition or current keyframe. The
'end' transform is the transform at the end of the transition or
current keyframe.
</p>
<ul>
<li>
If the 'from' and 'to' transforms are both single functions
of the same type:
<ul>
<li>
For translate, translateX, translateY, scale,
scaleX, scaleY, rotate, skew, skewX and skewY functions:
<ul>
<li>
the individual components of the function are
interpolated numerically.
</li>
</ul>
</li>
<li>
For matrix:
<ul>
<li>
the matrix is
decomposed using <a
href="http://tog.acm.org/GraphicsGems/gemsii/unmatrix.c">the
method described by unmatrix</a> into separate translation,
scale, rotation and skew matrices, then each
decomposed matrix is interpolated numerically, and finally
combined in order to produce a resulting 3x2 matrix.
</li>
</ul>
</li>
</ul>
</li>
<li>
If both the 'from' and 'to' transforms are "none":
<ul>
<li>
There is no interpolation necessary
</li>
</ul>
</li>
<li>
If one of the 'from' or 'to' transforms is "none":
<ul>
<li>
The 'none' is replaced by an equivalent identity function list for
the corresponding transform function list.
<p>
For example, if the 'from' transform is "scale(2)" and the 'to'
transform is "none" then the value "scale(1)" will be used as the
'to' value, and animation will proceed using the rule above.
Similarly, if the 'from' transform is "none" and the 'to' transform
is "scale(2) rotate(50deg)" then the animation will execute as
if the 'from' value is "scale(1) rotate(0)".
</p>
<p>
The identity functions are translate(0),
translateX(0), translateY(0), scale(1), scaleX(1), scaleY(1), rotate(0),
skewX(0), skewY(0) and matrix(1, 0, 0, 1, 0, 0).
</p>
</li>
</ul>
</li>
<li>
If both the 'from' and 'to' transforms have the same number of
transform functions and corresponding functions in each transform
list are of the same type:
<ul>
<li>
Each transform function is animated with its corresponding
destination function in isolation using the rules described above.
The individual values are then applied as a list to produce
resulting transform value.
</li>
</ul>
</li>
<li>
Otherwise:
<ul>
<li>
The transform function lists are each converted into the
equivalent matrix value and animation proceeds using the rule
for a single function above.
</li>
</ul>
</li>
</ul>
<p>
In some cases, an animation might cause a transformation matrix to
be singular or non-invertible. For example, an animation in which
scale moves from 1 to -1. At the time when the matrix is in such
a state, the transformed element is not rendered.
</p>
<h2 id="matrix-decomposition">
Matrix decomposition for animation
</h2>
<p>
When interpolating between 2 matrices, each is decomposed into the
corresponding translation, rotation, scale and skew
values. Not all matrices can be accurately described by these values.
Those that can't are decomposed into the most accurate representation
possible, using the technique below. This technique is taken from The
"unmatrix" method in "Graphics Gems II, edited by Jim Arvo", simplified
for the 2D case.
</p>
<h3 id="unmatrix">Unmatrix</h3>
<pre>
Input: a, b, c, d ; 2x2 matrix (rotate, scale, shear) components
tx, ty ; translation components
Output: translate ; a 2 component vector
rotate ; an angle
scale ; a 2 component vector
skew ; skew factor
Returns false if the matrix cannot be decomposed, true if it can
Supporting functions (point is a 2 component vector):
float length(point) returns the length of the passed vector
point normalize(point) normalizes the length of the passed point to 1
float dot(point, point) returns the dot product of the passed points
float atan2(float y, float x) returns the principal value of the arc tangent of
y/x, using the signs of both arguments to determine
the quadrant of the return value
Decomposition also makes use of the following function:
point combine(point a, point b, float ascl, float bscl)
result[0] = (ascl * a[0]) + (bscl * b[0])
result[1] = (ascl * a[1]) + (bscl * b[1])
return result
// Make sure the matrix is invertible
if ((a * d - b * c) == 0)
return false
// Take care of translation
translate[0] = tx
translate[1] = matrix[3][1]
// Put the components into a 2x2 matrix 'mat'
mat[0][0] = a
mat[0][1] = b
mat[1][0] = c
mat[1][1] = d
// Compute X scale factor and normalize first row.
scale[0] = length(row[0])
row[0] = normalize(row[0])
// Compute shear factor and make 2nd row orthogonal to 1st.
skew = dot(row[0], row[1])
row[1] = combine(row[1], row[0], 1.0, -skew)
// Now, compute Y scale and normalize 2nd row.
scale[1] = length(row[1])
row[1] = normalize(row[1])
skew /= scale[1];
// Now, get the rotation out
rotate = atan2(mat[0][1], mat[0][0])
return true;</pre>
<h3>Animating the components</h3>
<p>
Once decomposed, each component of each returned value of the source matrix is linearly interpolated
with the corresponding component of the destination matrix. For instance, the translate[0] and
translate[1] values are interpolated numerically, and the result is used to set the
translation of the animating element.
</p>
<h3>Recomposing the matrix</h3>
<p><em>This section is not normative.</em></p>
<p>
After interpolation the resulting values are used to position the element. One way to use these values
is to recompose them into a 3x2 matrix. This can be done using the Transformation Functions of the
<em>transform</em> property. The following JavaScript example produces a string for this purpose. The
values passed in are the output of the Unmatrix function above:
</p>
<pre>
function compose(translate, rotate, scale, skew, elementID)
{
var s = " translate(" + translate[0] + ", " + translate[1] + ")";
s += " rotate(" + rotate + ")";
s += " skewX(" + skew + ")";
s += " scale(" + scale[0] + ", " + scale[1] + ")";
document.getElementById(elementID).style.transform = s;
}</pre>
<h2 id="dom-interfaces">
DOM Interfaces
</h2>
<p>
This section describes the interfaces and functionality added to the DOM
to support runtime access to the functionality described above.
</p>
<h3 id="cssmatrix-interface">
CSSMatrix
</h3>
<dl>
<dt>
<b>Interface <i><a id="DOM-CSSMatrix" name='DOM-CSSMatrix'>CSSMatrix</a></i></b>
</dt>
<dd>
<p>
The <code>CSSMatrix</code> interface represents a 3x2 homogeneous matrix.
</p>
<div class="issue">
We actually describe a 3x2 matrix here, similar to <a href="http://www.w3.org/TR/SVG/coords.html#InterfaceSVGMatrix">SVGMatrix</a>.
</div>
<dl>
<dt>
<b>IDL Definition</b>
</dt>
<dd>
<div class='idl-code'>
<pre>
interface CSSMatrix {
attribute float a;
attribute float b;
attribute float c;
attribute float d;
attribute float e;
attribute float f;
void setMatrixValue(in DOMString string) raises(DOMException);
CSSMatrix multiply(in CSSMatrix secondMatrix);
CSSMatrix inverse() raises(DOMException);
CSSMatrix translate(in float x, in float y);
CSSMatrix scale(in float scaleX, in float scaleY);
CSSMatrix skewX(in float angle);
CSSMatrix skewY(in float angle);
CSSMatrix rotate(in float angle);
};</pre>
</div><br>
</dd> <!-- IDL -->
<dt>
<b>Attributes</b>
</dt>
<dd>
<dl>
<dt>
<code class='attribute-name'><a id="DOM-CSSMatrix-matrix" name='DOM-CSSMatrix-matrix'>a-f</a></code> of type <code>float</code>
</dt>
<dd>
Each of these attributes represents one of the values in the 3x2 matrix.<br>
</dd>
</dl>
</dd> <!-- Attributes -->
<dt>
<b>Methods</b>
</dt>
<dd>
<dl>
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-setMatrixValue" name='DOM-CSSMatrix-setMatrixValue'>setMatrixValue</a></code>
</dt>
<dd>
<div class='method'>
The <code>setMatrixValue</code> method replaces the existing matrix with one computed from parsing the passed string
as though it had been assigned to the transform property in a CSS style rule.
<div class='parameters'>
<b>Parameters</b>
<div class='paramtable'>
<dl>
<dt>
<code class='parameter-name'>string</code> of type <code>DOMString</code>
</dt>
<dd>
The string to parse.<br>
</dd>
</dl>
</div>
</div><!-- parameters -->
<div class='return-value'>
<b>No Return Value</b>
</div>
<div>
<b>Exceptions</b>
<div class='returnvalue'>
<dl>
<dt>
<code>DOMException SYNTAX_ERR</code>
</dt>
<dd>
Thrown when the provided string can not be
parsed into a CSSMatrix.
</dd>
</dl>
</div>
</div>
</div>
</dd> <!-- setMatrixValue -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-multiply" name='DOM-CSSMatrix-multiply'>multiply</a></code>
</dt>
<dd>
<div class='method'>
The <code>multiply</code> method returns a new CSSMatrix which is the result of this matrix multiplied by the passed matrix, with the passed matrix to the right. This matrix is not modified.
<div class='parameters'>
<b>Parameters</b>
<div class='paramtable'>
<dl>
<dt>
<code class='parameter-name'>secondMatrix</code> of type <code>CSSMatrix</code>
</dt>
<dd>
The matrix to multiply.<br>
</dd>
</dl>
</div>
</div><!-- parameters -->
<div class='return-value'>
<b>Return Value</b>
<div class='returnvalue'>
<dl>
<dt>
<code>CSSMatrix</code>
</dt>
<dd>
The result matrix.<br>
</dd>
</dl>
</div>
</div>
<div>
<b>No Exceptions</b>
</div>
</div>
</dd> <!-- multiply() -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-inverse" name='DOM-CSSMatrix-inverse'>inverse</a></code>
</dt>
<dd>
<div class='method'>
The <code>inverse</code> method returns a new matrix which is the inverse of this matrix. This matrix is not modified.
<div class='parameters'>
<b>No Parameters</b>
</div><!-- parameters -->
<div class='return-value'>
<b>Return Value</b>
<div class='returnvalue'>
<dl>
<dt>
<code>CSSMatrix</code>
</dt>
<dd>
The inverted matrix.<br>
</dd>
</dl>
</div>
</div>
<div>
<b>Exceptions</b>
<div class='returnvalue'>
<dl>
<dt>
<code>DOMException NOT_SUPPORTED_ERR</code>
</dt>
<dd>
Thrown when the CSSMatrix can not be
inverted.
</dd>
</dl>
</div>
</div>
</div><!-- ======================================================================================================= -->
</dd> <!-- inverse() -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-translate" name='DOM-CSSMatrix-translate'>translate</a></code>
</dt>
<dd>
<div class='method'>
The <code>translate</code> method returns a new matrix which is this matrix multiplied by a translation matrix containing the passed values. This matrix is not modified.
<div class='parameters'>
<b>Parameters</b>
<div class='paramtable'>
<dl>
<dt>
<code class='parameter-name'>x</code> of type <code>float</code>
</dt>
<dd>
The X component of the translation value.<br>
</dd>
<dt>
<code class='parameter-name'>y</code> of type <code>float</code>
</dt>
<dd>
The Y component of the translation value.<br>
</dd>
</dl>
</div>
</div><!-- parameters -->
<div class='return-value'>
<b>Return Value</b>
<div class='returnvalue'>
<dl>
<dt>
<code>CSSMatrix</code>
</dt>
<dd>
The result matrix.<br>
</dd>
</dl>
</div>
</div>
<div>
<b>No Exceptions</b>
</div>
</div><!-- ======================================================================================================= -->
</dd> <!-- translate() -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-scale" name='DOM-CSSMatrix-scale'>scale</a></code>
</dt>
<dd>
<div class='method'>
The <code>scale</code> method returns a new matrix which is this matrix multiplied by a scale matrix containing the passed values. If the y component is undefined, the x component value is used in its place. This matrix is not modified.
<div class='parameters'>
<b>Parameters</b>
<div class='paramtable'>
<dl>
<dt>
<code class='parameter-name'>scaleX</code> of type <code>float</code>
</dt>
<dd>
The X component of the scale value.<br>
</dd>
<dt>
<code class='parameter-name'>scaleY</code> of type <code>float</code>
</dt>
<dd>
The (optional) Y component of the scale value.<br>
</dd>
</dl>
</div>
</div><!-- parameters -->
<div class='return-value'>
<b>Return Value</b>
<div class='returnvalue'>
<dl>
<dt>
<code>CSSMatrix</code>
</dt>
<dd>
The result matrix.<br>
</dd>
</dl>
</div>
</div>
<div>
<b>No Exceptions</b>
</div>
</div><!-- ======================================================================================================= -->
</dd> <!-- scale() -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-rotate" name='DOM-CSSMatrix-rotate'>rotate</a></code>
</dt>
<dd>
<div class='method'>
The <code>rotate</code> method returns a new matrix which is this matrix multiplied by a <a href="http://www.w3.org/TR/SVG/coords.html#RotationDefined">rotation matrix</a>. The rotation value is in degrees. This matrix is not modified.
<div class='parameters'>
<b>Parameters</b>
<div class='paramtable'>
<dl>
<dt>
<code class='parameter-name'>angle</code> of type <code>float</code>
</dt>
<dd>
The angle of rotation.<br>
</dd>
</dl>
</div>
</div><!-- parameters -->
<div class='return-value'>
<b>Return Value</b>
<div class='returnvalue'>
<dl>
<dt>
<code>CSSMatrix</code>
</dt>
<dd>
The result matrix.<br>
</dd>
</dl>
</div>
</div>
<div>
<b>No Exceptions</b>
</div>
</div>
<!-- ======================================================================================================= -->
</dd> <!-- rotate() -->
<!-- ===================================================== -->
<dt>
<code class='method-name'><a id="DOM-CSSMatrix-skew-x" name='DOM-CSSMatrix-skew-x'>skewX</a></code>
</dt>
<dd>
<div class='method'>
The <code>skewX</code> method returns a new matrix which is this matrix multiplied by a matrix representing a <a href="http://www.w3.org/TR/SVG/coords.html#SkewXDefined">skew along the x-axis</a>. The rotation value is in degrees. This matrix is not modified.