WebCore/css/WebKitCSSMatrix.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  * 1. Redistributions of source code must retain the above copyright
       
     8  *    notice, this list of conditions and the following disclaimer.
       
     9  * 2. Redistributions in binary form must reproduce the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer in the
       
    11  *    documentation and/or other materials provided with the distribution.
       
    12  *
       
    13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
       
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
       
    17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    24  */
       
    25 
       
    26 #ifndef WebKitCSSMatrix_h
       
    27 #define WebKitCSSMatrix_h
       
    28 
       
    29 #include "ExceptionCode.h"
       
    30 #include "PlatformString.h"
       
    31 #include "StyleBase.h"
       
    32 #include "TransformationMatrix.h"
       
    33 #include <wtf/PassRefPtr.h>
       
    34 #include <wtf/RefPtr.h>
       
    35 
       
    36 namespace WebCore {
       
    37 
       
    38 class WebKitCSSMatrix : public StyleBase {
       
    39 public:
       
    40     static PassRefPtr<WebKitCSSMatrix> create()
       
    41     {
       
    42         return adoptRef(new WebKitCSSMatrix());
       
    43     }
       
    44     static PassRefPtr<WebKitCSSMatrix> create(const WebKitCSSMatrix& m)
       
    45     {
       
    46         return adoptRef(new WebKitCSSMatrix(m));
       
    47     }
       
    48     static PassRefPtr<WebKitCSSMatrix> create(const TransformationMatrix& m)
       
    49     {
       
    50         return adoptRef(new WebKitCSSMatrix(m));
       
    51     }
       
    52     static PassRefPtr<WebKitCSSMatrix> create(const String& s, ExceptionCode& ec)
       
    53     {
       
    54         return adoptRef(new WebKitCSSMatrix(s, ec));
       
    55     }
       
    56     
       
    57     virtual ~WebKitCSSMatrix();
       
    58 
       
    59     double a() const { return m_matrix.a(); }
       
    60     double b() const { return m_matrix.b(); }
       
    61     double c() const { return m_matrix.c(); }
       
    62     double d() const { return m_matrix.d(); }
       
    63     double e() const { return m_matrix.e(); }
       
    64     double f() const { return m_matrix.f(); }
       
    65     
       
    66     void setA(double f) { m_matrix.setA(f); }
       
    67     void setB(double f) { m_matrix.setB(f); }
       
    68     void setC(double f) { m_matrix.setC(f); }
       
    69     void setD(double f) { m_matrix.setD(f); }
       
    70     void setE(double f) { m_matrix.setE(f); }
       
    71     void setF(double f) { m_matrix.setF(f); }
       
    72  
       
    73     double m11() const { return m_matrix.m11(); }
       
    74     double m12() const { return m_matrix.m12(); }
       
    75     double m13() const { return m_matrix.m13(); }
       
    76     double m14() const { return m_matrix.m14(); }
       
    77     double m21() const { return m_matrix.m21(); }
       
    78     double m22() const { return m_matrix.m22(); }
       
    79     double m23() const { return m_matrix.m23(); }
       
    80     double m24() const { return m_matrix.m24(); }
       
    81     double m31() const { return m_matrix.m31(); }
       
    82     double m32() const { return m_matrix.m32(); }
       
    83     double m33() const { return m_matrix.m33(); }
       
    84     double m34() const { return m_matrix.m34(); }
       
    85     double m41() const { return m_matrix.m41(); }
       
    86     double m42() const { return m_matrix.m42(); }
       
    87     double m43() const { return m_matrix.m43(); }
       
    88     double m44() const { return m_matrix.m44(); }
       
    89     
       
    90     void setM11(double f) { m_matrix.setM11(f); }
       
    91     void setM12(double f) { m_matrix.setM12(f); }
       
    92     void setM13(double f) { m_matrix.setM13(f); }
       
    93     void setM14(double f) { m_matrix.setM14(f); }
       
    94     void setM21(double f) { m_matrix.setM21(f); }
       
    95     void setM22(double f) { m_matrix.setM22(f); }
       
    96     void setM23(double f) { m_matrix.setM23(f); }
       
    97     void setM24(double f) { m_matrix.setM24(f); }
       
    98     void setM31(double f) { m_matrix.setM31(f); }
       
    99     void setM32(double f) { m_matrix.setM32(f); }
       
   100     void setM33(double f) { m_matrix.setM33(f); }
       
   101     void setM34(double f) { m_matrix.setM34(f); }
       
   102     void setM41(double f) { m_matrix.setM41(f); }
       
   103     void setM42(double f) { m_matrix.setM42(f); }
       
   104     void setM43(double f) { m_matrix.setM43(f); }
       
   105     void setM44(double f) { m_matrix.setM44(f); }
       
   106  
       
   107     void setMatrixValue(const String& string, ExceptionCode&);
       
   108     
       
   109     // The following math function return a new matrix with the 
       
   110     // specified operation applied. The this value is not modified.
       
   111     
       
   112     // Multiply this matrix by secondMatrix, on the right (result = this * secondMatrix)
       
   113     PassRefPtr<WebKitCSSMatrix> multiply(WebKitCSSMatrix* secondMatrix) const;
       
   114     
       
   115     // Return the inverse of this matrix. Throw an exception if the matrix is not invertible
       
   116     PassRefPtr<WebKitCSSMatrix> inverse(ExceptionCode&) const;
       
   117     
       
   118     // Return this matrix translated by the passed values.
       
   119     // Passing a NaN will use a value of 0. This allows the 3D form to used for 2D operations
       
   120     // Operation is performed as though the this matrix is multiplied by a matrix with
       
   121     // the translation values on the left (result = translation(x,y,z) * this)
       
   122     PassRefPtr<WebKitCSSMatrix> translate(double x, double y, double z) const;
       
   123     
       
   124     // Returns this matrix scaled by the passed values.
       
   125     // Passing scaleX or scaleZ as NaN uses a value of 1, but passing scaleY of NaN 
       
   126     // makes it the same as scaleX. This allows the 3D form to used for 2D operations
       
   127     // Operation is performed as though the this matrix is multiplied by a matrix with
       
   128     // the scale values on the left (result = scale(x,y,z) * this)
       
   129     PassRefPtr<WebKitCSSMatrix> scale(double scaleX, double scaleY, double scaleZ) const;
       
   130 
       
   131     // Returns this matrix rotated by the passed values.
       
   132     // If rotY and rotZ are NaN, rotate about Z (rotX=0, rotateY=0, rotateZ=rotX).
       
   133     // Otherwise use a rotation value of 0 for any passed NaN.    
       
   134     // Operation is performed as though the this matrix is multiplied by a matrix with
       
   135     // the rotation values on the left (result = rotation(x,y,z) * this)
       
   136     PassRefPtr<WebKitCSSMatrix> rotate(double rotX, double rotY, double rotZ) const;
       
   137     
       
   138     // Returns this matrix rotated about the passed axis by the passed angle.
       
   139     // Passing a NaN will use a value of 0. If the axis is (0,0,0) use a value
       
   140     // Operation is performed as though the this matrix is multiplied by a matrix with
       
   141     // the rotation values on the left (result = rotation(x,y,z,angle) * this)
       
   142     PassRefPtr<WebKitCSSMatrix> rotateAxisAngle(double x, double y, double z, double angle) const;
       
   143     
       
   144     const TransformationMatrix& transform() const { return m_matrix; }
       
   145     
       
   146     String toString() const;
       
   147     
       
   148 protected:
       
   149     WebKitCSSMatrix();
       
   150     WebKitCSSMatrix(const WebKitCSSMatrix&);
       
   151     WebKitCSSMatrix(const TransformationMatrix&);
       
   152     WebKitCSSMatrix(const String&, ExceptionCode&);
       
   153 
       
   154     TransformationMatrix m_matrix;
       
   155 };
       
   156 
       
   157 } // namespace WebCore
       
   158 
       
   159 #endif // WebKitCSSMatrix_h