1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
21 * Keith Schwarz <kschwarz@mozilla.com> (original author)
23 * Alternatively, the contents of this file may be used under the terms of
24 * either of the GNU General Public License Version 2 or later (the "GPL"),
25 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
38 * A class representing three matrices that can be used for style transforms.
41 #ifndef nsStyleTransformMatrix_h_
42 #define nsStyleTransformMatrix_h_
44 #include "nsCSSValue.h"
45 #include "gfxMatrix.h"
49 * A class representing a style transformation matrix. The class actually
50 * wraps three different matrices, a constant matrix and two matrices
51 * whose values are scaled by the width and the height of the bounding
52 * rectangle for the object to transform. Thus, given a frame rectangle
53 * of dimensions (width, height) and a point (x, y) to transform, the matrix
54 * corresponds to the transform operation
56 * | a c e | |0 0 dX1| |0 0 dY1| | x |
57 *(| b d f | + |0 0 dX2| (width) + |0 0 dY2| (height)) | y |
58 * | 0 0 1 | |0 0 0| |0 0 0| | 1 |
60 * Note that unlike the Thebes gfxMatrix, vectors are column vectors and
61 * consequently the multiplication of a matrix A and a vector x is Ax, not xA.
65 class nsStyleTransformMatrix
69 * Constructor sets the matrix to the identity.
71 nsStyleTransformMatrix();
74 * Given a frame's bounding rectangle, returns a gfxMatrix
75 * corresponding to the transformation represented by this
76 * matrix. The transformation takes points in the frame's
77 * local space and converts them to points in the frame's
80 * @param aBounds The frame's bounding rectangle.
81 * @param aFactor The number of app units per device pixel.
82 * @return A Thebes matrix corresponding to the transform.
84 gfxMatrix
GetThebesMatrix(const nsRect
& aBounds
, float aFactor
) const;
87 * Multiplies this matrix by another matrix, in that order. If A'
88 * is the value of A after A *= B, then for any vector x, the
89 * equivalence A'(x) == A(B(x)) holds.
91 * @param aOther The matrix to multiply this matrix by.
92 * @return A reference to this matrix.
94 nsStyleTransformMatrix
& operator *= (const nsStyleTransformMatrix
&aOther
);
97 * Returns a new nsStyleTransformMatrix that is equal to one matrix
98 * multiplied by another matrix, in that order. If C is the result of
99 * A * B, then for any vector x, the equivalence C(x) = A(B(x)).
101 * @param aOther The matrix to multiply this matrix by.
102 * @return A new nsStyleTransformMatrix equal to this matrix multiplied
103 * by the other matrix.
105 const nsStyleTransformMatrix
106 operator * (const nsStyleTransformMatrix
&aOther
) const;
109 * Given an nsCSSValue::Array* containing a -moz-transform function,
110 * updates this matrix to hold the value of that function.
112 * @param aData The nsCSSValue::Array* containing the transform function.
113 * @param aContext The style context, used for unit conversion.
114 * @param aPresContext The presentation context, used for unit conversion.
115 * @param aInherited Set to true if the result cannot be cached in the rule
116 * tree, otherwise untouched.
118 void SetToTransformFunction(const nsCSSValue::Array
* aData
,
119 nsStyleContext
* aContext
,
120 nsPresContext
* aPresContext
,
124 * Sets this matrix to be the identity matrix.
126 void SetToIdentity();
129 * Returns the value of the entry at the 2x2 submatrix of the
130 * transform matrix that defines the non-affine linear transform.
131 * The order is given as
135 * @param aIndex The element index.
136 * @return The value of the element at that index.
138 float GetMainMatrixEntry(PRInt32 aIndex
) const
140 NS_PRECONDITION(aIndex
>= 0 && aIndex
< 4, "Index out of bounds!");
141 return mMain
[aIndex
];
145 * Returns the value of the X or Y translation component of the matrix,
146 * given the specified bounds.
148 * @param aBounds The bounds of the element.
149 * @return The value of the X or Ytranslation component.
151 nscoord
GetXTranslation(const nsRect
& aBounds
) const;
152 nscoord
GetYTranslation(const nsRect
& aBounds
) const;
155 * Returns whether the two matrices are equal or not.
157 * @param aOther The matrix to compare to.
158 * @return Whether the two matrices are equal.
160 PRBool
operator== (const nsStyleTransformMatrix
& aOther
) const;
161 PRBool
operator!= (const nsStyleTransformMatrix
& aOther
) const
163 return !(*this == aOther
);
167 /* The three matrices look like this:
168 * |mMain[0] mMain[2] mDelta[0]|
169 * |mMain[1] mMain[3] mDelta[1]| <-- Constant matrix
173 * | 0 0 mX[1]| <-- Scaled by width of element
177 * | 0 0 mY[1]| <-- Scaled by height of element