Geometry Interfaces Module Level 1

Editor’s Draft,

This version:
http://dev.w3.org/fxtf/geometry/
Latest version:
http://www.w3.org/TR/geometry-1/
Previous Versions:
http://www.w3.org/TR/2014/WD-geometry-1-20140522/
http://www.w3.org/TR/2013/WD-matrix-20130919/
Feedback:
public-fx@w3.org with subject line “[geometry] … message topic …” (archives)
Test Suite:
http://test.csswg.org/suites/geometry-1_dev/nightly-unstable/
Issue Tracking:
Inline In Spec
Editors:
(Opera Software ASA)
(Adobe Systems Inc.)
(Adobe Systems Inc.)
Issues list:
Bugzilla (file a bug)

Abstract

This specification provides basic geometric interfaces to represent points, rectangles, quadrilaterals and transformation matrices that can be used by other modules or specifications.

Status of this document

This is a public copy of the editors' draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

The (archived) public mailing list public-fx@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “geometry” in the subject, preferably like this: “[geometry] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity) and the SVG Working Group (part of the Graphics Activity).

This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (CSS) and a public list of any patent disclosures (SVG) made in connection with the deliverables of each group; these pages also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

The following features are at-risk, and may be dropped during the CR period:

Table of Contents

1. Introduction

This specification describes several geometry interfaces [WEBIDL] for the representation of points, rectangles, quadrilaterals and transformation matrices with the dimension of 3x2 and 4x4.

The SVG interfaces SVGPoint, SVGRect and SVGMatrix [SVG11] are aliasing the here defined interfaces in favor for common interfaces used by SVG, Canvas 2D Context [2DCONTEXT] and CSS Transforms [CSS3-TRANSFORMS].

The IDL in this specification is currently in an experimental state. An approach of avoiding overloading in constructors and instead using factory static methods, and supporting dictionary types everywhere, is explored. Readers interested in a specification that more closely matches implementations as of April 2015 are referred to an earlier revision of this specification.

2. The DOMPoint interfaces

A 2D or a 3D point can be represented by the following WebIDL interfaces:

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double z = 0, optional unrestricted double w = 1),
 Exposed=(Window,Worker)]
interface DOMPointReadOnly {
    [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit point);

    readonly attribute unrestricted double x;
    readonly attribute unrestricted double y;
    readonly attribute unrestricted double z;
    readonly attribute unrestricted double w;

    DOMPoint matrixTransform(optional DOMMatrixInit matrix);
};

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double z = 0, optional unrestricted double w = 1),
 Exposed=(Window,Worker)]
interface DOMPoint : DOMPointReadOnly {
    [NewObject] static DOMPoint fromPoint(optional DOMPointInit other);

    inherit attribute unrestricted double x;
    inherit attribute unrestricted double y;
    inherit attribute unrestricted double z;
    inherit attribute unrestricted double w;
};

dictionary DOMPointInit {
    unrestricted double x = 0;
    unrestricted double y = 0;
    unrestricted double z = 0;
    unrestricted double w = 1;
};

The following algorithms assume that DOMPointReadOnly objects have the internal member variables x coordinate, y coordinate, z coordinate and w perspective. DOMPointReadOnly as well as the inheriting interface DOMPoint must be able to access and set the value of these variables.

An interface returning an DOMPointReadOnly object by an attribute or function may be able to modify internal member variable values. Such an interface must specify this ability explicitly in prose.

Internal member variables must not be exposed in any way.

The DOMPointReadOnly(x, y, z, w) and DOMPoint(x, y, z, w) constructors, when invoked, must run the following steps:

  1. Let point be a new DOMPointReadOnly or DOMPoint object as appropriate.
  2. Set point’s variables x coordinate to x, y coordinate to y, z coordinate to z and w perspective to w.
  3. Return point.

The fromPoint(other) static method on DOMPointReadOnly and the fromPoint(other) static method on DOMPoint must run the following steps:

  1. Let point be a new DOMPointReadOnly or DOMPoint as appropriate.
  2. Set point’s variables x coordinate to other’s x dictionary member, y coordinate to other’s y dictionary member, z coordinate to other’s z dictionary member and w perspective to other’s w dictionary member.
  3. Return point.
The x attribute, on getting, must return the x coordinate value of the object it was invoked on. For the DOMPoint interface, setting the x attribute must set the x coordinate value of the object it was invoked on to the new value.

The y attribute, on getting, must return the y coordinate value of the object it was invoked on. For the DOMPoint interface, setting the y attribute must set the y coordinate value of the object it was invoked on to the new value.

The z attribute, on getting, must return the z coordinate value of the object it was invoked on. For the DOMPoint interface, setting the z attribute must set the z coordinate value of the object it was invoked on to the new value.

The w attribute, on getting, must return the w perspective value of the object it was invoked on. For the DOMPoint interface, setting the w attribute must set the w perspective value of the object it was invoked on to the new value.

matrixTransform(matrix), when invoked, must run the following steps

  1. Create a new DOMPoint point initialized to x, y, z and w of the current point.
  2. Let matrix object be the result of calling fromMatrix() with matrix as the argument.
  3. Post-multiply point with matrix object.
  4. Return point.

matrixTransform() does not modify the current DOMPointReadOnly object and returns a new DOMPoint object.

In this example the method matrixTransform() on point is called with a DOMMatrix argument matrix.

var point = new DOMPoint(5, 4);var matrix = new DOMMatrix([2, 0, 0, 2, 10, 10]);
var transformedPoint = point.matrixTransform(matrix);

point creates a new DOMPoint object initialized to the same attribute values as point. This new DOMPoint is now scaled and the translated by matrix. This resulting transformPoint has the attribute values x: 20 and y: 18.

For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGPoint whose value is the DOMPoint interface object.

3. The DOMRect interfaces

Objects implementing the DOMRectReadOnly interface represent a rectangle. The type of box is specified by the method or attribute that returns a DOMRect or DOMRectReadOnly object.

Rectangles have the following properties:

origin
When the rectangle has a non-negative width dimension, the rectangle’s horizontal origin is the left edge; otherwise, it is the right edge. Similarly, when the rectangle has a non-negative height dimension, the rectangle’s vertical origin is the top edge; otherwise, it is the bottom edge.
x coordinate
The horizontal distance between the viewport’s left edge and the rectangle’s origin.
y coordinate
The vertical distance between the viewport’s top edge and the rectangle’s origin.
width dimension
The width of the rectangle. Can be negative.
height dimension
The height of the rectangle. Can be negative.
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double width = 0, optional unrestricted double height = 0),
 Exposed=(Window,Worker)]
interface DOMRectReadOnly {
    [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);

    readonly attribute unrestricted double x;
    readonly attribute unrestricted double y;
    readonly attribute unrestricted double width;
    readonly attribute unrestricted double height;
    readonly attribute unrestricted double top;
    readonly attribute unrestricted double right;
    readonly attribute unrestricted double bottom;
    readonly attribute unrestricted double left;
};

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double width = 0, optional unrestricted double height = 0),
 Exposed=(Window,Worker)]
interface DOMRect : DOMRectReadOnly {
    [NewObject] static DOMRect fromRect(optional DOMRectInit other);

    inherit attribute unrestricted double x;
    inherit attribute unrestricted double y;
    inherit attribute unrestricted double width;
    inherit attribute unrestricted double height;
};

dictionary DOMRectInit {
    unrestricted double x = 0;
    unrestricted double y = 0;
    unrestricted double width = 0;
    unrestricted double height = 0;
};

The following algorithms assume that DOMRectReadOnly objects have the internal member variables x coordinate, y coordinate, width dimension and height dimension. DOMRectReadOnly as well as the inheriting interface DOMRect must be able to access and set the value of these variables.

An interface returning an DOMRectReadOnly object by an attribute or function may be able to modify internal member variable values. Such an interface must specify this ability explicitly in prose.

Internal member variables must not be exposed in any way.

The DOMRectReadOnly(x, y, width, height) and DOMRect(x, y, width, height) constructors, when invoked, must run the following steps:

  1. Let rect be a new DOMRectReadOnly or DOMRect object as appropriate.
  2. Set rect’s variables x coordinate to x, y coordinate to y, width dimension to width and height dimension to height.
  3. Return rect.

The fromRect(other) static method on DOMRectReadOnly and the fromRect(other) static method on DOMRect must run the following steps:

  1. Let rect be a new DOMRectReadOnly or DOMRect as appropriate.
  2. Set rect’s variables x coordinate to other’s x dictionary member, y coordinate to other’s y dictionary member, width dimension to other’s width dictionary member and height dimension to other’s height dictionary member.
  3. Return rect.
The x attribute, on getting, must return the x coordinate value of the object it was invoked on. For the DOMRect interface, setting the x attribute must set the x coordinate value of the object it was invoked on to the new value.

The y attribute, on getting, it must return the y coordinate value of the object it was invoked on. For the DOMRect interface, setting the y attribute must set the y coordinate value of the object it was invoked on to the new value.

The width attribute, on getting, must return the width dimension value of the object it was invoked on. For the DOMRect interface, setting the width attribute must set the width dimension value of the object it was invoked on to the new value.

The height attribute, on getting, must return the height dimension value. For the DOMRect interface, setting the height attribute must set the height dimension value to the new value.

The top attribute, on getting, must return min(y coordinate, y coordinate + height dimension) of the object it was invoked on.

The right attribute, on getting, must return max(x coordinate, x coordinate + width dimension) of the object it was invoked on.

The bottom attribute, on getting, must return max(y coordinate, y coordinate + height dimension) of the object it was invoked on.

The left attribute, on getting, must return min(x coordinate, x coordinate + width dimension) of the object it was invoked on.

For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGRect whose value is the DOMRect interface object.

4. The DOMRectList Interface

[NoInterfaceObject,
 ArrayClass]
interface DOMRectList {
    readonly attribute unsigned long length;
    getter DOMRect? item(unsigned long index);
};

The length attribute must return the total number of DOMRect objects associated with the object.

The item(index) method, when invoked, must return a null value when index is greater than or equal to the number of DOMRect objects associated with the DOMRectList. Otherwise, the DOMRect object at index must be returned. Indices are zero-based.

DOMRectList must be supported for legacy reasons. New interfaces must not use DOMRectList and may use Sequences [WEBIDL] instead.

5. The DOMQuad interface

Objects implementing the DOMQuad interface represents a quadrilateral.

[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
             optional DOMPointInit p3, optional DOMPointInit p4),
 Exposed=(Window,Worker)]
interface DOMQuad {
    [NewObject] static DOMQuad fromRect(optional DOMRectInit other);
    [NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);

    [SameObject] readonly attribute DOMPoint p1;
    [SameObject] readonly attribute DOMPoint p2;
    [SameObject] readonly attribute DOMPoint p3;
    [SameObject] readonly attribute DOMPoint p4;
    [SameObject] readonly attribute DOMRectReadOnly bounds;
};

dictionary DOMQuadInit {
  DOMPointInit p1;
  DOMPointInit p2;
  DOMPointInit p3;
  DOMPointInit p4;
};

The DOMQuad(p1, p2, p3, p4) constructor, when invoked, must run the following steps:

  1. Let point 1 be a new DOMPoint object with its attributes set to the values of the namesake dictionary members in p1.
  2. Let point 2 be a new DOMPoint object with its attributes set to the values of the namesake dictionary members in p2.
  3. Let point 3 be a new DOMPoint object with its attributes set to the values of the namesake dictionary members in p3.
  4. Let point 4 be a new DOMPoint object with its attributes set to the values of the namesake dictionary members in p4.
  5. Return a new DOMQuad with p1 set to point 1, p2 set to point 2, p3 set to point 3 and p4 set to point 4, and let the associated bounding rectangle be bounds.

Note: It is possible to pass DOMPoint/DOMPointReadOnly arguments as well. The passed arguments will be transformed to the correct object type internally following the WebIDL rules [WEBIDL].

The fromRect(other) static method on DOMQuad must run the following steps:

  1. Let x, y, width and height be the value of other’s x, y, width and height attributes, respectively.
  2. Let point 1 be a new DOMPoint object with x set to x, y set to y, z set to zero and w set to one.
  3. Let point 2 be a new DOMPoint object with x set to x + width, y set to y, z set to zero and w set to one.
  4. Let point 3 be a new DOMPoint object with x set to x + width, y set to y + height, z set to zero and w set to one.
  5. Let point 4 be a new DOMPoint object with x set to x, y set to y + height, z set to zero and w set to one.
  6. Return a new DOMQuad with p1 set to point 1, p2 set to point 2, p3 set to point 3 and p4 set to point 4, and let the associated bounding rectangle be bounds.

The fromQuad(other)> static method on DOMQuad must run the following steps:

  1. Let point 1 be the result of invoking fromPoint() static method on DOMPoint with the p1 dictionary member of other as argument, if it exists.

  2. Let point 2 be the result of invoking fromPoint() static method on DOMPoint with the p2 dictionary member of other as argument, if it exists.

  3. Let point 3 be the result of invoking fromPoint() static method on DOMPoint with the p3 dictionary member of other as argument, if it exists.

  4. Let point 4 be the result of invoking fromPoint() static method on DOMPoint with the p4 dictionary member of other as argument, if it exists.

  5. Return a new DOMQuad with p1 set to point 1, p2 set to point 2, p3 set to point 3 and p4 set to point 4.

The p1 attribute must return a DOMPoint that represents p1 of the quadrilateral it was invoked on. The author can modify the returned DOMPoint object, which directly affects the quadrilateral.

The p2 attribute must return a DOMPoint that represents p2 of the quadrilateral it was invoked on. The author can modify the returned DOMPoint object, which directly affects the quadrilateral.

The p3 attribute must return a DOMPoint that represents p3 of the quadrilateral it was invoked on. The author can modify the returned DOMPoint object, which directly affects the quadrilateral.

The p4 attribute must return a DOMPoint that represents p4 of the quadrilateral it was invoked on. The author can modify the returned DOMPoint object, which directly affects the quadrilateral.

The bounds attribute must return the associated bounding rectangle of the quadrilateral it was invoked on.

DOMQuad objects have an associated bounding rectangle set to a DOMRectReadOnly object when created. DOMQuad objects must have read and write access to the internal member variables of the associated bounding rectangle. The associated bounding rectangle is live; whenever the objects for p1, p2, p3 or p4 change, the associated bounding rectangle must update its internal member variable values as appropriate to describe the new smallest bounding box of the four points.

The associated bounding rectangle is computed as follows:

  1. Let bounds be a DOMRectReadOnly object.
  2. Let left be the minimum of p1.x, p2.x, p3.x and p4.x.
  3. Let top be the minimum of p1.y, p2.y, p3.y and p4.y.
  4. Let right be the maximum of p1.x, p2.x, p3.x and p4.x.
  5. Let bottom be the maximum of p1.y, p2.y, p3.y and p4.y.
  6. Let x coordinate of bounds be left, y coordinate of bounds be top, width dimension of bounds be right - left and height dimension of bounds be bottom - top.

In this example the DOMQuad constructor is called with arguments of type DOMPoint and DOMPointInit. Both arguments are accepted and can be used.

var point = new DOMPoint(2, 0);var quad1 = new DOMQuad(point, {x: 12, y: 0}, {x: 2, y: 10}, {x: 12, y: 10});

The attribute values of the resulting DOMQuad quad1 above are also equal to the attribute values of the following DOMQuad quad2:

var rect = new DOMRect(2, 0, 10, 10);var quad2 = DOMQuad.fromRect(rect);

This is an example of an irregular quadrilateral:

new DOMQuad({x: 40, y: 25}, {x: 180, y: 8}, {x: 210, y: 150}, {x: 10, y: 180});
An irregular quadrilateral with none of the sides being vertical or horizontal. Its four corners are marked with red circles. Around this quadrilateral is a dashed rectangle. All sides of this rectangle are vertical or horizontal and tangent the quadrilateral.

An irregular quadrilateral represented by a DOMQuad. The four red colored circles represent the DOMPoint attributes p1 to p4. The dashed rectangle represents the associated bounding rectangle bounds of the DOMQuad.

6. The DOMMatrix interfaces

The DOMMatrix and DOMMatrixReadOnly interfaces each represent a mathematical matrix with the purpose of describing transformations in a graphical context. The following sections describe the details of the interface.

m 11 m 21 m 31 m 41 m 12 m 22 m 32 m 42 m 13 m 23 m 33 m 43 m 14 m 24 m 34 m 44

A 4x4 matrix representing a DOMMatrix with items m11 to m44.

In the following sections, terms have the following meaning:

post-multiply
Term A post-multiplied by term B is equal to A · B.
pre-multiply
Term A pre-multiplied by term B is equal to B · A.
multiply
Multiply term A by term B is equal to A · B.
[Constructor(sequence<unrestricted double> numberSequence),
 Exposed=(Window,Worker)]
interface DOMMatrixReadOnly {
    [NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
    [NewObject] static DOMMatrixReadOnly fromString(DOMString transformList);
    [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
    [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);

    // These attributes are simple aliases for certain elements of the 4x4 matrix
    readonly attribute unrestricted double a;
    readonly attribute unrestricted double b;
    readonly attribute unrestricted double c;
    readonly attribute unrestricted double d;
    readonly attribute unrestricted double e;
    readonly attribute unrestricted double f;

    readonly attribute unrestricted double m11;
    readonly attribute unrestricted double m12;
    readonly attribute unrestricted double m13;
    readonly attribute unrestricted double m14;
    readonly attribute unrestricted double m21;
    readonly attribute unrestricted double m22;
    readonly attribute unrestricted double m23;
    readonly attribute unrestricted double m24;
    readonly attribute unrestricted double m31;
    readonly attribute unrestricted double m32;
    readonly attribute unrestricted double m33;
    readonly attribute unrestricted double m34;
    readonly attribute unrestricted double m41;
    readonly attribute unrestricted double m42;
    readonly attribute unrestricted double m43;
    readonly attribute unrestricted double m44;

    readonly attribute boolean is2D;
    readonly attribute boolean isIdentity;

    // Immutable transform methods
    DOMMatrix translate(unrestricted double tx,
                        unrestricted double ty,
                        optional unrestricted double tz = 0);
    DOMMatrix scale(unrestricted double scale,
                    optional unrestricted double originX = 0,
                    optional unrestricted double originY = 0);
    DOMMatrix scale3d(unrestricted double scale,
                      optional unrestricted double originX = 0,
                      optional unrestricted double originY = 0,
                      optional unrestricted double originZ = 0);
    DOMMatrix scaleNonUniform(unrestricted double scaleX,
                              optional unrestricted double scaleY = 1,
                              optional unrestricted double scaleZ = 1,
                              optional unrestricted double originX = 0,
                              optional unrestricted double originY = 0,
                              optional unrestricted double originZ = 0);
    DOMMatrix rotate(unrestricted double angle,
                     optional unrestricted double originX = 0,
                     optional unrestricted double originY = 0);
    DOMMatrix rotateFromVector(unrestricted double x,
                               unrestricted double y);
    DOMMatrix rotateAxisAngle(unrestricted double x,
                              unrestricted double y,
                              unrestricted double z,
                              unrestricted double angle);
    DOMMatrix skewX(unrestricted double sx);
    DOMMatrix skewY(unrestricted double sy);
    DOMMatrix multiply(optional DOMMatrixInit other);
    DOMMatrix flipX();
    DOMMatrix flipY();
    DOMMatrix inverse();

    DOMPoint            transformPoint(optional DOMPointInit point);
    Float32Array        toFloat32Array();
    Float64Array        toFloat64Array();
                        stringifier;
};

[Constructor(sequence<unrestricted double> numberSequence),
 Exposed=(Window,Worker)]
interface DOMMatrix : DOMMatrixReadOnly {
    [NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
    [NewObject] static DOMMatrix fromString(DOMString transformList);
    [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
    [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);

    // These attributes are simple aliases for certain elements of the 4x4 matrix
    inherit attribute unrestricted double a;
    inherit attribute unrestricted double b;
    inherit attribute unrestricted double c;
    inherit attribute unrestricted double d;
    inherit attribute unrestricted double e;
    inherit attribute unrestricted double f;

    inherit attribute unrestricted double m11;
    inherit attribute unrestricted double m12;
    inherit attribute unrestricted double m13;
    inherit attribute unrestricted double m14;
    inherit attribute unrestricted double m21;
    inherit attribute unrestricted double m22;
    inherit attribute unrestricted double m23;
    inherit attribute unrestricted double m24;
    inherit attribute unrestricted double m31;
    inherit attribute unrestricted double m32;
    inherit attribute unrestricted double m33;
    inherit attribute unrestricted double m34;
    inherit attribute unrestricted double m41;
    inherit attribute unrestricted double m42;
    inherit attribute unrestricted double m43;
    inherit attribute unrestricted double m44;

    // Mutable transform methods
    DOMMatrix multiplySelf(optional DOMMatrixInit other);
    DOMMatrix preMultiplySelf(optional DOMMatrixInit other);
    DOMMatrix translateSelf(unrestricted double tx,
                     unrestricted double ty,
                     optional unrestricted double tz = 0);
    DOMMatrix scaleSelf(unrestricted double scale,
                 optional unrestricted double originX = 0,
                 optional unrestricted double originY = 0);
    DOMMatrix scale3dSelf(unrestricted double scale,
                   optional unrestricted double originX = 0,
                   optional unrestricted double originY = 0,
                   optional unrestricted double originZ = 0);
    DOMMatrix scaleNonUniformSelf(unrestricted double scaleX,
                           optional unrestricted double scaleY = 1,
                           optional unrestricted double scaleZ = 1,
                           optional unrestricted double originX = 0,
                           optional unrestricted double originY = 0,
                           optional unrestricted double originZ = 0);
    DOMMatrix rotateSelf(unrestricted double angle,
                  optional unrestricted double originX = 0,
                  optional unrestricted double originY = 0);
    DOMMatrix rotateFromVectorSelf(unrestricted double x,
                            unrestricted double y);
    DOMMatrix rotateAxisAngleSelf(unrestricted double x,
                           unrestricted double y,
                           unrestricted double z,
                           unrestricted double angle);
    DOMMatrix skewXSelf(unrestricted double sx);
    DOMMatrix skewYSelf(unrestricted double sy);
    DOMMatrix invertSelf();

    DOMMatrix setMatrixValue(DOMString transformList);
};

dictionary DOMMatrixInit {
    unrestricted double a;
    unrestricted double b;
    unrestricted double c;
    unrestricted double d;
    unrestricted double e;
    unrestricted double f;
    unrestricted double m11;
    unrestricted double m12;
    unrestricted double m13 = 0;
    unrestricted double m14 = 0;
    unrestricted double m21;
    unrestricted double m22;
    unrestricted double m23 = 0;
    unrestricted double m24 = 0;
    unrestricted double m31 = 0;
    unrestricted double m32 = 0;
    unrestricted double m33 = 1;
    unrestricted double m34 = 0;
    unrestricted double m41;
    unrestricted double m42;
    unrestricted double m43 = 0;
    unrestricted double m44 = 1;
    boolean is2D;
};

The following algorithms assume that DOMMatrixReadOnly objects have the internal member variables m11 element, m12 element, m13 element, m14 element, m21 element, m22 element, m23 element, m24 element, m31 element, m32 element, m33 element, m34 element, m41 element, m42 element, m43 element, m44 element and is2D. DOMMatrixReadOnly as well as the inheriting interface DOMMatrix must be able to access and set the value of these variables.

An interface returning an DOMMatrixReadOnly object by an attribute or function may be able to modify internal member variable values. Such an interface must specify this ability explicitly in prose.

Internal member variables must not be exposed in any way.

The DOMMatrix and DOMMatrixReadOnly interfaces replace the SVGMatrix interface from SVG [SVG11].

For historical reasons, Window objects must also have a writable, configurable, non-enumerable property named SVGMatrix whose value is the DOMMatrix interface object.

6.1. DOMMatrixInit dictionary

To validate and fixup a DOMMatrixInit dictionary dict, run the following steps:

  1. If if at least one of the following conditions are true for dict, throw a TypeError exception and abort these steps.
    • a and m11 are both present and their values are not the same.
    • b and m12 are both present and their values are not the same.
    • c and m21 are both present and their values are not the same.
    • d and m22 are both present and their values are not the same.
    • e and m41 are both present and their values are not the same.
    • f and m42 are both present and their values are not the same.
    • is2D is true and at least one of m31, m32, m13, m23, m43, m14, m24, m34 are present with a value other than 0, or at least one of m33, m44 are present with a value other than 1.
  2. Set the dictionary members a and m11 with fallback value 1.
  3. Set the dictionary members b and m12 with fallback value 0.
  4. Set the dictionary members c and m21 with fallback value 0.
  5. Set the dictionary members d and m22 with fallback value 1.
  6. Set the dictionary members e and m41 with fallback value 0.
  7. Set the dictionary members f and m42 with fallback value 0.
  8. If is2D is not present and at least one of m31, m32, m13, m23, m43, m14, m24, m34 are present with a value other than 0, or at least one of m33, m44 are present with a value other than 1, set is2D to false.
  9. If is2D is still not present, set it to true.

For the purpose of the algorithm above, two WebIDL unrestricted double values are the same if they have identical IEEE 754 double-precision bit patterns.

Note: This means that two NaN values are the same.

To set the dictionary members a and b of a DOMMatrixInit dictionary, with a fallback value fallback, run the following steps:

  1. If a is present and b is not present, set the b dictionary member to the value of a.
  2. Otherwise, if b is present and a is not present, set the a dictionary member to the value of b.
  3. Otherwise, set a and b dictionary members to fallback.

6.2. Creating DOMMatrixReadOnly and DOMMatrix objects

To create a 2d matrix of type type being either DOMMatrixReadOnly or DOMMatrix, with a sequence numberSequence of 6 elements, follow these steps:

  1. Let matrix be a new instance of type.

  2. Set m11 element, m12 element, m21 element, m22 element, m41 element and m42 element to the values of numberSequence in order starting with the first value.

  3. Set m31 element, m32 element, m13 element, m23 element, m43 element, m14 element, m24 element and m34 element to 0.

  4. Set m33 element and m44 element to 1.

  5. Set is2D to true.

  6. Return matrix

To create a 3d matrix with type being either DOMMatrixReadOnly or DOMMatrix, with a sequence numberSequence of 16 elements, follow these steps:

  1. Let matrix be a new instance of type.

  2. Set m11 element to m44 element to the values of numberSequence in column-major order.

  3. Set is2D to false.

  4. Return matrix

The DOMMatrixReadOnly(numberSequence) and the DOMMatrix(numberSequence) constructors, when invoked, must run the following steps:

If numberSequence has 6 elements
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with the sequence numberSequence.
If numberSequence has 16 elements
Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with the sequence numberSequence.
Otherwise
Throw a TypeError exception.

The fromMatrix(other) static method on DOMMatrixReadOnly and the fromMatrix(other) static method on DOMMatrix must follow these steps:

  1. Validate and fixup other.
  2. If the is2D dictionary member of other is true
    Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers, the values being the 6 elements m11, m12, m21, m22, m41 and m42 of other in the given order.
    Otherwise
    Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers, the values being the 16 elements m11, m12, m13, ..., m44 of other in the given order.

The fromString(transformList) static method on DOMMatrixReadOnly and the fromString(transformList) static method on DOMMatrix must follow these steps:

  1. Parse transformList by following the syntax description in “Syntax of the SVG ‘transform’ attribute[CSS3-TRANSFORMS] to a <transform-list>. If parsing is not successful or any <transform-function> has <length> values without absolute length units, throw a SyntaxError exception.
  2. Let 2dTransform track the 2D/3D dimension status of the <transform-list>.
    If the <transform-list> consists of any 3D Transform functions
    Set 2dTransform to false.
    Otherwise
    Set 2dTransform to true.
  3. Transform all <transform-function>s to 4x4 matrices by following the “Mathematical Description of Transform Functions[CSS3-TRANSFORMS].
  4. Let matrix be a 4x4 matrix as shown in the initial figure of this section. Post-multiply all matrices from left to right and set matrix to this product.
  5. If 2dTransform is set to true
    Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers, the values being the elements m11, m12, 21, m22, m41 and m42 of matrix of matrix.
    If 2dTransform is set to false
    Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers, the values being the 16 elements of matrix.

The fromFloat32Array(array32) static method on DOMMatrixReadOnly and the fromFloat32Array(array32) static method on DOMMatrix must follow these steps:

If array32 has 6 elements
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array32 in the provided order.
If array32 has 16 elements
Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array32 in the provided order.
Otherwise
Throw a TypeError exception.

The fromFloat64Array(array64) static method on DOMMatrixReadOnly and the fromFloat64Array(array64) static method on DOMMatrix must follow these steps:

If array64 has 6 elements
Return the result of invoking create a 2d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array64 in the provided order.
If array32 has 16 elements
Return the result of invoking create a 3d matrix of type DOMMatrixReadOnly or DOMMatrix as appropriate, with a sequence of numbers taking the values from array64 in the provided order.
Otherwise
Throw a TypeError exception.

6.3. DOMMatrix attributes

The following attributes m11 to m44 correspond to the 16 items of the matrix interfaces. For the DOMMatrix interface, if the attributes m31, m32, m13, m23, m43, m14, m24, m34 are set to something else than 0 or m33, m44 are set to something else than 1 set is2D to false.

The m11 attribute, on getting, must return the m11 element value of the object it was invoked on. For the DOMMatrix interface, setting the m11 attribute must set the m11 element value of the object it was invoked on to the new value.

The m12 attribute, on getting, must return the m12 element value of the object it was invoked on. For the DOMMatrix interface, setting the m12 attribute must set the m12 element value of the object it was invoked on to the new value.

The m13 attribute, on getting, must return the m13 element value of the object it was invoked on. For the DOMMatrix interface, setting the m13 attribute must set the m13 element value of the object it was invoked on to the new value.

The m14 attribute, on getting, must return the m14 element value of the object it was invoked on. For the DOMMatrix interface, setting the m14 attribute must set the m14 element value of the object it was invoked on to the new value.

The m21 attribute, on getting, must return the m21 element value of the object it was invoked on. For the DOMMatrix interface, setting the m21 attribute must set the m21 element value of the object it was invoked on to the new value.

The m22 attribute, on getting, must return the m22 element value of the object it was invoked on. For the DOMMatrix interface, setting the m22 attribute must set the m22 element value of the object it was invoked on to the new value.

The m23 attribute, on getting, must return the m23 element value of the object it was invoked on. For the DOMMatrix interface, setting the m23 attribute must set the m23 element value of the object it was invoked on to the new value.

The m24 attribute, on getting, must return the m24 element value of the object it was invoked on. For the DOMMatrix interface, setting the m24 attribute must set the m24 element value of the object it was invoked on to the new value.

The m31 attribute, on getting, must return the m31 element value of the object it was invoked on. For the DOMMatrix interface, setting the m31 attribute must set the m31 element value of the object it was invoked on to the new value.

The m32 attribute, on getting, must return the m32 element value of the object it was invoked on. For the DOMMatrix interface, setting the m32 attribute must set the m32 element value of the object it was invoked on to the new value.

The m33 attribute, on getting, must return the m33 element value of the object it was invoked on. For the DOMMatrix interface, setting the m33 attribute must set the m33 element value of the object it was invoked on to the new value.

The m34 attribute, on getting, must return the m34 element value of the object it was invoked on. For the DOMMatrix interface, setting the m34 attribute must set the m34 element value of the object it was invoked on to the new value.

The m41 attribute, on getting, must return the m41 element value of the object it was invoked on. For the DOMMatrix interface, setting the m41 attribute must set the m41 element value of the object it was invoked on to the new value.

The m42 attribute, on getting, must return the m42 element value of the object it was invoked on. For the DOMMatrix interface, setting the m42 attribute must set the m42 element value of the object it was invoked on to the new value.

The m43 attribute, on getting, must return the m43 element value of the object it was invoked on. For the DOMMatrix interface, setting the m43 attribute must set the m43 element value of the object it was invoked on to the new value.

The m44 attribute, on getting, must return the m44 element value of the object it was invoked on. For the DOMMatrix interface, setting the m44 attribute must set the m44 element value of the object it was invoked on to the new value.

The following attributes a to f correspond to the 2D components of the matrix interfaces.

The a attribute is an alias to the m11 attribute.

The b attribute is an alias to the m12 attribute.

The c attribute is an alias to the m21 attribute.

The d attribute is an alias to the m22 attribute.

The e attribute is an alias to the m41 attribute.

The f attribute is an alias to the m42 attribute.

The following attributes provide status information about DOMMatrixReadOnly.

is2D, of type boolean, readonly

Every DOMMatrixReadOnly object must be flagged with a boolean is2D. This flag indicates that

  1. The current matrix was initialized as a 2D matrix. See individual creators for more details.
  2. Only 2D transformation operations were applied. Each mutable or immutable transformation method defines if is2D must be set to false.

is2D can never be set to true when it was set to false before on a DOMMatrix object with the exception of calling the setMatrixValue() method.

Returns the value of is2D.

isIdentity, of type boolean, readonly
Returns true if m12, m13, m14, m21, m23, m24, m31, m32, m34, m41, m42, m43 are 0 and m11, m22, m33, m44 are 1. Otherwise returns false.

6.4. Immutable transformation methods

The following methods do not modify the current matrix and return a new DOMMatrix object.

translate(tx, ty, tz)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a translateSelf() transformation on result with the arguments tx, ty, tz.
  3. Return result.

The current matrix is not modified.

scale(scale, originX, originY)
  1. Let other be the resulting matrix initialized to the values of the current matrix.
  2. Perform a scaleSelf() transformation on result with the arguments scale, originX, originY.
  3. Return result.

The current matrix is not modified.

scale3d(scale, originX, originY, originZ)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a scale3dSelf() transformation on result with the arguments scale, originX, originY, originZ.
  3. Return result.

The current matrix is not modified.

scaleNonUniform(scaleX, scaleY, scaleZ, originX, originY, originZ)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a scaleNonUniformSelf() transformation on result with the arguments scaleX, scaleY, scaleZ, originX, originY, originZ.
  3. Return result.

The current matrix is not modified.

rotate(angle, originX, originY)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a rotateSelf() transformation on result with the arguments angle, originX, originY.
  3. Return result.

The current matrix is not modified.

rotateFromVector(x, y)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a rotateFromVectorSelf() transformation on result with the arguments x, y.
  3. Return result.

The current matrix is not modified.

rotateAxisAngle(x, y, z, angle)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a rotateAxisAngleSelf() transformation on result with the arguments x, y, z, angle.
  3. Return result.

The current matrix is not modified.

skewX(sx)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a skewXSelf() transformation on result with the argument sx.
  3. Return result.

The current matrix is not modified.

skewY(sy)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a skewYSelf() transformation on result with the argument sy.
  3. Return result.

The current matrix is not modified.

multiply(other)
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a multiplySelf() transformation on result with the argument other.
  3. Return result.

The current matrix is not modified.

flipX()
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Post-multiply result with DOMMatrix(-1, 0, 0, 1, 0, 0).
  3. Return result.

The current matrix is not modified.

flipY()
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Post-multiply result with DOMMatrix(1, 0, 0, -1, 0, 0).
  3. Return result.

The current matrix is not modified.

inverse()
  1. Let result be the resulting matrix initialized to the values of the current matrix.
  2. Perform a invertSelf() transformation on result.
  3. Return result.

The current matrix is not modified.

The following methods do not modify the current matrix.

transformPoint(point)
Let point object be the result of invoking fromPoint() with point as the argument. Point object is post-multiplied to the current matrix and returns the resulting point. The passed argument does not get modified.

Note: Even if is2D of the current matrix may return true, a 4x4 matrix multiplication must be performed if the z attribute of point is not 0 or the w attribute of point is not 1.

toFloat32Array()
Returns the serialized 16 elements m11 to m44 of the current matrix in column-major order as Float32Array [typedarray].
toFloat64Array()
Returns the serialized 16 elements m11 to m44 of the current matrix in column-major order as Float64Array [typedarray].
stringifier()
If is2D is true
Return a DOMString in the form of a CSS Transforms <matrix()> function where a is a attribute, b is b attribute, c is c attribute, d is d attribute, e is e attribute, f is f attribute, [CSS3-TRANSFORMS].
Otherwise
Return a DOMString in the form of a CSS Transforms <matrix3d()> function where m11 to m44 are set to m11 to m44 attributes [CSS3-TRANSFORMS].

In this example, a matrix is created and several 2D transformation methods are called:

var matrix = new DOMMatrix();matrix.scaleSelf(2);
matrix.translateSelf(20,20);

Calling matrix.toString() returns the DOMString:

"matrix(2, 0, 0, 2, 20, 20)"

In the following example, a matrix is created and several 3D transformation methods are called:

var matrix = new DOMMatrix();matrix.scale3dSelf(2);

For 3D operations, the stringifier returns a DOMString representing a 3D matrix.

Calling matrix.toString() after the snippet above returns the DOMString:

"matrix3d(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1)"

6.5. Mutable transformation methods

The following methods modify the current matrix, so that each method returns the matrix where it was invoked on. The primary benefit of this is allowing content creators to chain method calls.

The following code example:

var matrix = new DOMMatrix();matrix.translateSelf(20, 20);
matrix.scaleSelf(2);
matrix.translateSelf(-20, -20);

is equivalent to:

var matrix = new DOMMatrix();matrix.translateSelf(20, 20).scaleSelf(2).translateSelf(-20, -20);

Note: Authors who use chained method calls are recommended to use mutable transformation methods to avoid unnecessary memory allocations due to creation of intermediate DOMMatrix objects in User Agents.

multiplySelf(other)
  1. Let other object be the result of invoking fromMatrix() with other as the argument.
  2. The other object matrix gets post-multiplied to the current matrix.
  3. If is2D of other object is false, set is2D of the current matrix to false.
  4. Return the current matrix.
preMultiplySelf(other)
  1. Let other object be the result of invoking fromMatrix() with other as the argument.
  2. The other object matrix gets pre-multiplied to the current matrix.
  3. If is2D of other object is false, set is2D of the current matrix to false.
  4. Return the current matrix.
translateSelf(tx, ty, tz)
  1. Post-multiply a translation transformation on the current matrix. The 3D translation matrix is described in CSS Transforms [CSS3-TRANSFORMS].

  2. If tz is specified and not 0, set is2D of the current matrix to false.

  3. Return the current matrix.
scaleSelf(scale, originX, originY)
  1. Apply a translateSelf(originX, originY) transformation to the current matrix.
  2. Post-multiply a uniform 2D scale transformation (m11 = m22 = scale) on the current matrix. The 2D scale matrix is described in CSS Transforms with sx = sy = scale. [CSS3-TRANSFORMS].
  3. Apply a translateSelf(-originX, -originY) transformation to the current matrix.
  4. Return the current matrix.
scale3dSelf(scale, originX, originY, originZ)
  1. Apply a translateSelf(originX, originY, originZ) transformation to the current matrix.
  2. Post-multiply a uniform 3D scale transformation (m11 = m22 = m33 = scale) on the current matrix. The 3D scale matrix is described in CSS Transforms with sx = sy = sz = scale. [CSS3-TRANSFORMS].
  3. Apply a translateSelf(-originX, -originY, -originZ) transformation to the current matrix.
  4. If scale is not 1, set is2D of the current matrix to false.
  5. Return the current matrix.
scaleNonUniformSelf(scaleX, scaleY, scaleZ, originX, originY, originZ)
  1. Apply a translateSelf(originX, originY, originZ) transformation to the current matrix.
  2. Post-multiply a non-uniform scale transformation on the current matrix. The 3D scale matrix is described in CSS Transforms with sx = scaleX, sy = scaleY and sz = scaleZ. [CSS3-TRANSFORMS].
  3. Apply a translateSelf(-originX, -originY, -originZ) transformation to the current matrix.
  4. If scaleZ is specified and not 1 or originZ is specified and not 0, set is2D of the current matrix to false.
  5. Return the current matrix.
rotateSelf(angle, originX, originY)
  1. Apply a translateSelf(originX, originY) transformation to the current matrix.
  2. Post-multiply a rotation transformation on the current matrix with the specified rotation angle in degrees. The 2D rotation matrix is described in CSS Transforms with alpha = angle in degrees. [CSS3-TRANSFORMS].
  3. Apply a translateSelf(-originX, -originY) transformation to the current matrix.
  4. Return the current matrix.
rotateFromVectorSelf(x, y)
  1. Post-multiply a rotation transformation on the current matrix. The rotation angle is determined by the angle between the vector (1,0)T and (x,y)T in the clockwise direction. If x and y should both be zero, the angle is specified as zero. The 2D rotation matrix is described in CSS Transforms where alpha is the angle between the vector (1,0)T and (x,y)T in degrees [CSS3-TRANSFORMS].
  2. Return the current matrix.
rotateAxisAngleSelf(x, y, z, angle)
  1. Post-multiply a rotation transformation on the current matrix around the specified vector x, y, z by the specified rotation angle in degrees. The 3D rotation matrix is described in CSS Transforms with alpha = angle in degrees [CSS3-TRANSFORMS].
  2. If x or y are not 0, set is2D of the current matrix to false.
  3. Return the current matrix.
skewXSelf(sx)
  1. Post-multiply a skewX transformation on the current matrix by the specified angle sx in degrees. The 2D skewX matrix is described in CSS Transforms with alpha = sx in degrees [CSS3-TRANSFORMS].
  2. Return the current matrix.
skewYSelf(sy)
  1. Post-multiply a skewX transformation on the current matrix by the specified angle sy in degrees. The 2D skewY matrix is described in CSS Transforms with beta = sy in degrees [CSS3-TRANSFORMS].
  2. Return the current matrix.
invertSelf()
  1. Invert the current matrix.
  2. If the current matrix is not invertible set all attributes to NaN and set is2D to false.
  3. Return the current matrix.
setMatrixValue(transformList)
  1. Parse transformList by following the syntax description in “Syntax of the SVG ‘transform’ attribute[CSS3-TRANSFORMS] to a <transform-list>. If parsing is not successful or any <transform-function> has <length> values without absolute length units, throw a SyntaxError exception.
  2. Set is2D to false if the <transform-list> consists of any 3D Transform functions. Otherwise set is2D to true.
  3. Transform all <transform-function>s to 4x4 matrices by following the “Mathematical Description of Transform Functions[CSS3-TRANSFORMS].
  4. Post-multiply all matrices from left to right to a combined 4x4 matrix.
  5. Set the m11 to m44 attributes to the element values of the 4x4 matrix in column-major order.
  6. Return the current matrix.

7. Cloning

When a user agent is asked to clone an DOMPointReadOnly, DOMPoint, DOMRectReadOnly, DOMRect, DOMQuad, DOMMatrixReadOnly or DOMMatrix object old, it must run the following steps, which return a new object of same type. These steps must be run atomically.

  1. Create a new object new of the same type as old. Copy all member variable values from old to new.
  2. Return new. It is the clone.

The above algorithm follows the “safe passing of structured data” [HTML5] definitions.

Changes since last publication

The following changes were made since the 18 September 2014 Working Draft.

The following changes were made since the 26 June 2014 Last Call Public Working Draft.

The following changes were made since the 22 May 2014 First Public Working Draft.

Acknowledgments

The editors would like to thank Robert O’Callahan for contributing to this specification. Many thanks to Dean Jackson for his initial proposal of DOMMatrix. Thanks to Brian Birtles, Benoit Jacob, Cameron McCormack, Kari Pihkala, Adenilson Cavalcanti, Boris Zbarsky and Max Vujovic for their careful reviews, comments, and corrections.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Experimental implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[HTML]
Ian Hickson. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[WebIDL]
Cameron McCormack. Web IDL. 19 April 2012. CR. URL: http://www.w3.org/TR/WebIDL/
[CSS-TRANSFORMS-1]
Simon Fraser; et al. CSS Transforms Module Level 1. 26 November 2013. WD. URL: http://www.w3.org/TR/css-transforms-1/
[CSS-VALUES-3]
CSS Values and Units Module Level 3 URL: http://www.w3.org/TR/css3-values/
[CSS3-TRANSFORMS]
Simon Fraser; et al. CSS Transforms Module Level 1. 26 November 2013. WD. URL: http://www.w3.org/TR/css-transforms-1/
[HTML5]
Ian Hickson; et al. HTML5. 28 October 2014. REC. URL: http://www.w3.org/TR/html5/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Informative References

[2DCONTEXT]
Rik Cabanier; et al. HTML Canvas 2D Context. 14 May 2015. LCWD. URL: http://www.w3.org/TR/2dcontext/
[SVG11]
Erik Dahlström; et al. Scalable Vector Graphics (SVG) 1.1 (Second Edition). 16 August 2011. REC. URL: http://www.w3.org/TR/SVG11/
[TYPEDARRAY]
David Herman; Kenneth Russell. Typed Array Specification. 26 June 2013. Khronos Working Draft. URL: https://www.khronos.org/registry/typedarray/specs/latest/

IDL Index

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double z = 0, optional unrestricted double w = 1),
 Exposed=(Window,Worker)]
interface DOMPointReadOnly {
    [NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit point);

    readonly attribute unrestricted double x;
    readonly attribute unrestricted double y;
    readonly attribute unrestricted double z;
    readonly attribute unrestricted double w;

    DOMPoint matrixTransform(optional DOMMatrixInit matrix);
};

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double z = 0, optional unrestricted double w = 1),
 Exposed=(Window,Worker)]
interface DOMPoint : DOMPointReadOnly {
    [NewObject] static DOMPoint fromPoint(optional DOMPointInit other);

    inherit attribute unrestricted double x;
    inherit attribute unrestricted double y;
    inherit attribute unrestricted double z;
    inherit attribute unrestricted double w;
};

dictionary DOMPointInit {
    unrestricted double x = 0;
    unrestricted double y = 0;
    unrestricted double z = 0;
    unrestricted double w = 1;
};

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double width = 0, optional unrestricted double height = 0),
 Exposed=(Window,Worker)]
interface DOMRectReadOnly {
    [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);

    readonly attribute unrestricted double x;
    readonly attribute unrestricted double y;
    readonly attribute unrestricted double width;
    readonly attribute unrestricted double height;
    readonly attribute unrestricted double top;
    readonly attribute unrestricted double right;
    readonly attribute unrestricted double bottom;
    readonly attribute unrestricted double left;
};

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
             optional unrestricted double width = 0, optional unrestricted double height = 0),
 Exposed=(Window,Worker)]
interface DOMRect : DOMRectReadOnly {
    [NewObject] static DOMRect fromRect(optional DOMRectInit other);

    inherit attribute unrestricted double x;
    inherit attribute unrestricted double y;
    inherit attribute unrestricted double width;
    inherit attribute unrestricted double height;
};

dictionary DOMRectInit {
    unrestricted double x = 0;
    unrestricted double y = 0;
    unrestricted double width = 0;
    unrestricted double height = 0;
};

[NoInterfaceObject,
 ArrayClass]
interface DOMRectList {
    readonly attribute unsigned long length;
    getter DOMRect? item(unsigned long index);
};

[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
             optional DOMPointInit p3, optional DOMPointInit p4),
 Exposed=(Window,Worker)]
interface DOMQuad {
    [NewObject] static DOMQuad fromRect(optional DOMRectInit other);
    [NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);

    [SameObject] readonly attribute DOMPoint p1;
    [SameObject] readonly attribute DOMPoint p2;
    [SameObject] readonly attribute DOMPoint p3;
    [SameObject] readonly attribute DOMPoint p4;
    [SameObject] readonly attribute DOMRectReadOnly bounds;
};

dictionary DOMQuadInit {
  DOMPointInit p1;
  DOMPointInit p2;
  DOMPointInit p3;
  DOMPointInit p4;
};

[Constructor(sequence<unrestricted double> numberSequence),
 Exposed=(Window,Worker)]
interface DOMMatrixReadOnly {
    [NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
    [NewObject] static DOMMatrixReadOnly fromString(DOMString transformList);
    [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
    [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);

    // These attributes are simple aliases for certain elements of the 4x4 matrix
    readonly attribute unrestricted double a;
    readonly attribute unrestricted double b;
    readonly attribute unrestricted double c;
    readonly attribute unrestricted double d;
    readonly attribute unrestricted double e;
    readonly attribute unrestricted double f;

    readonly attribute unrestricted double m11;
    readonly attribute unrestricted double m12;
    readonly attribute unrestricted double m13;
    readonly attribute unrestricted double m14;
    readonly attribute unrestricted double m21;
    readonly attribute unrestricted double m22;
    readonly attribute unrestricted double m23;
    readonly attribute unrestricted double m24;
    readonly attribute unrestricted double m31;
    readonly attribute unrestricted double m32;
    readonly attribute unrestricted double m33;
    readonly attribute unrestricted double m34;
    readonly attribute unrestricted double m41;
    readonly attribute unrestricted double m42;
    readonly attribute unrestricted double m43;
    readonly attribute unrestricted double m44;

    readonly attribute boolean is2D;
    readonly attribute boolean isIdentity;

    // Immutable transform methods
    DOMMatrix translate(unrestricted double tx,
                        unrestricted double ty,
                        optional unrestricted double tz = 0);
    DOMMatrix scale(unrestricted double scale,
                    optional unrestricted double originX = 0,
                    optional unrestricted double originY = 0);
    DOMMatrix scale3d(unrestricted double scale,
                      optional unrestricted double originX = 0,
                      optional unrestricted double originY = 0,
                      optional unrestricted double originZ = 0);
    DOMMatrix scaleNonUniform(unrestricted double scaleX,
                              optional unrestricted double scaleY = 1,
                              optional unrestricted double scaleZ = 1,
                              optional unrestricted double originX = 0,
                              optional unrestricted double originY = 0,
                              optional unrestricted double originZ = 0);
    DOMMatrix rotate(unrestricted double angle,
                     optional unrestricted double originX = 0,
                     optional unrestricted double originY = 0);
    DOMMatrix rotateFromVector(unrestricted double x,
                               unrestricted double y);
    DOMMatrix rotateAxisAngle(unrestricted double x,
                              unrestricted double y,
                              unrestricted double z,
                              unrestricted double angle);
    DOMMatrix skewX(unrestricted double sx);
    DOMMatrix skewY(unrestricted double sy);
    DOMMatrix multiply(optional DOMMatrixInit other);
    DOMMatrix flipX();
    DOMMatrix flipY();
    DOMMatrix inverse();

    DOMPoint            transformPoint(optional DOMPointInit point);
    Float32Array        toFloat32Array();
    Float64Array        toFloat64Array();
                        stringifier;
};

[Constructor(sequence<unrestricted double> numberSequence),
 Exposed=(Window,Worker)]
interface DOMMatrix : DOMMatrixReadOnly {
    [NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
    [NewObject] static DOMMatrix fromString(DOMString transformList);
    [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
    [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);

    // These attributes are simple aliases for certain elements of the 4x4 matrix
    inherit attribute unrestricted double a;
    inherit attribute unrestricted double b;
    inherit attribute unrestricted double c;
    inherit attribute unrestricted double d;
    inherit attribute unrestricted double e;
    inherit attribute unrestricted double f;

    inherit attribute unrestricted double m11;
    inherit attribute unrestricted double m12;
    inherit attribute unrestricted double m13;
    inherit attribute unrestricted double m14;
    inherit attribute unrestricted double m21;
    inherit attribute unrestricted double m22;
    inherit attribute unrestricted double m23;
    inherit attribute unrestricted double m24;
    inherit attribute unrestricted double m31;
    inherit attribute unrestricted double m32;
    inherit attribute unrestricted double m33;
    inherit attribute unrestricted double m34;
    inherit attribute unrestricted double m41;
    inherit attribute unrestricted double m42;
    inherit attribute unrestricted double m43;
    inherit attribute unrestricted double m44;

    // Mutable transform methods
    DOMMatrix multiplySelf(optional DOMMatrixInit other);
    DOMMatrix preMultiplySelf(optional DOMMatrixInit other);
    DOMMatrix translateSelf(unrestricted double tx,
                     unrestricted double ty,
                     optional unrestricted double tz = 0);
    DOMMatrix scaleSelf(unrestricted double scale,
                 optional unrestricted double originX = 0,
                 optional unrestricted double originY = 0);
    DOMMatrix scale3dSelf(unrestricted double scale,
                   optional unrestricted double originX = 0,
                   optional unrestricted double originY = 0,
                   optional unrestricted double originZ = 0);
    DOMMatrix scaleNonUniformSelf(unrestricted double scaleX,
                           optional unrestricted double scaleY = 1,
                           optional unrestricted double scaleZ = 1,
                           optional unrestricted double originX = 0,
                           optional unrestricted double originY = 0,
                           optional unrestricted double originZ = 0);
    DOMMatrix rotateSelf(unrestricted double angle,
                  optional unrestricted double originX = 0,
                  optional unrestricted double originY = 0);
    DOMMatrix rotateFromVectorSelf(unrestricted double x,
                            unrestricted double y);
    DOMMatrix rotateAxisAngleSelf(unrestricted double x,
                           unrestricted double y,
                           unrestricted double z,
                           unrestricted double angle);
    DOMMatrix skewXSelf(unrestricted double sx);
    DOMMatrix skewYSelf(unrestricted double sy);
    DOMMatrix invertSelf();

    DOMMatrix setMatrixValue(DOMString transformList);
};

dictionary DOMMatrixInit {
    unrestricted double a;
    unrestricted double b;
    unrestricted double c;
    unrestricted double d;
    unrestricted double e;
    unrestricted double f;
    unrestricted double m11;
    unrestricted double m12;
    unrestricted double m13 = 0;
    unrestricted double m14 = 0;
    unrestricted double m21;
    unrestricted double m22;
    unrestricted double m23 = 0;
    unrestricted double m24 = 0;
    unrestricted double m31 = 0;
    unrestricted double m32 = 0;
    unrestricted double m33 = 1;
    unrestricted double m34 = 0;
    unrestricted double m41;
    unrestricted double m42;
    unrestricted double m43 = 0;
    unrestricted double m44 = 1;
    boolean is2D;
};

Issues Index

The IDL in this specification is currently in an experimental state. An approach of avoiding overloading in constructors and instead using factory static methods, and supporting dictionary types everywhere, is explored. Readers interested in a specification that more closely matches implementations as of April 2015 are referred to an earlier revision of this specification.