LCOV - code coverage report
Current view: directory - content/svg/content/src - SVGTransform.h (source / functions) Found Hit Coverage
Test: app.info Lines: 42 0 0.0 %
Date: 2012-06-02 Functions: 13 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla SVG Project code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Brian Birtles <birtles@gmail.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef MOZILLA_SVGTRANSFORM_H__
      40                 : #define MOZILLA_SVGTRANSFORM_H__
      41                 : 
      42                 : #include "gfxMatrix.h"
      43                 : #include "nsDebug.h"
      44                 : #include "nsIDOMSVGTransform.h"
      45                 : 
      46                 : namespace mozilla {
      47                 : 
      48                 : /*
      49                 :  * The DOM wrapper class for this class is DOMSVGTransformMatrix.
      50                 :  */
      51                 : class SVGTransform
      52               0 : {
      53                 : public:
      54                 :   // Default ctor initialises to matrix type with identity matrix
      55               0 :   SVGTransform()
      56                 :     : mMatrix() // Initialises to identity
      57                 :     , mAngle(0.f)
      58                 :     , mOriginX(0.f)
      59                 :     , mOriginY(0.f)
      60               0 :     , mType(nsIDOMSVGTransform::SVG_TRANSFORM_MATRIX)
      61               0 :   { }
      62                 : 
      63               0 :   SVGTransform(const gfxMatrix& aMatrix)
      64                 :     : mMatrix(aMatrix)
      65                 :     , mAngle(0.f)
      66                 :     , mOriginX(0.f)
      67                 :     , mOriginY(0.f)
      68               0 :     , mType(nsIDOMSVGTransform::SVG_TRANSFORM_MATRIX)
      69               0 :   { }
      70                 : 
      71                 :   bool operator==(const SVGTransform& rhs) const {
      72                 :     return mType == rhs.mType &&
      73                 :       MatricesEqual(mMatrix, rhs.mMatrix) &&
      74                 :       mAngle == rhs.mAngle &&
      75                 :       mOriginX == rhs.mOriginX &&
      76                 :       mOriginY == rhs.mOriginY;
      77                 :   }
      78                 : 
      79                 :   void GetValueAsString(nsAString& aValue) const;
      80                 : 
      81               0 :   float Angle() const {
      82               0 :     return mAngle;
      83                 :   }
      84               0 :   void GetRotationOrigin(float& aOriginX, float& aOriginY) const {
      85               0 :     aOriginX = mOriginX;
      86               0 :     aOriginY = mOriginY;
      87               0 :   }
      88               0 :   PRUint16 Type() const {
      89               0 :     return mType;
      90                 :   }
      91                 : 
      92               0 :   const gfxMatrix& Matrix() const { return mMatrix; }
      93                 :   void SetMatrix(const gfxMatrix& aMatrix);
      94                 :   void SetTranslate(float aTx, float aTy);
      95                 :   void SetScale(float aSx, float aSy);
      96                 :   void SetRotate(float aAngle, float aCx, float aCy);
      97                 :   nsresult SetSkewX(float aAngle);
      98                 :   nsresult SetSkewY(float aAngle);
      99                 : 
     100               0 :   static bool MatricesEqual(const gfxMatrix& a, const gfxMatrix& b)
     101                 :   {
     102                 :     return a.xx == b.xx &&
     103                 :            a.yx == b.yx &&
     104                 :            a.xy == b.xy &&
     105                 :            a.yy == b.yy &&
     106                 :            a.x0 == b.x0 &&
     107               0 :            a.y0 == b.y0;
     108                 :   }
     109                 : 
     110                 : protected:
     111                 :   gfxMatrix mMatrix;
     112                 :   float mAngle, mOriginX, mOriginY;
     113                 :   PRUint16 mType;
     114                 : };
     115                 : 
     116                 : /*
     117                 :  * A slightly more light-weight version of SVGTransform for SMIL animation.
     118                 :  *
     119                 :  * Storing the parameters in an array (rather than a matrix) also allows simpler
     120                 :  * (transform type-agnostic) interpolation and addition.
     121                 :  *
     122                 :  * The meaning of the mParams array depends on the transform type as follows:
     123                 :  *
     124                 :  * Type                | mParams[0], mParams[1], mParams[2], ...
     125                 :  * --------------------+-----------------------------------------
     126                 :  * translate           | tx, ty
     127                 :  * scale               | sx, sy
     128                 :  * rotate              | rotation-angle (in degrees), cx, cy
     129                 :  * skewX               | skew-angle (in degrees)
     130                 :  * skewY               | skew-angle (in degrees)
     131                 :  * matrix              | a, b, c, d, e, f
     132                 :  *
     133                 :  * The matrix type is never generated by animation code (it is only produced
     134                 :  * when the user inserts one via the DOM) and often requires special handling
     135                 :  * when we do encounter it. Therefore many users of this class are only
     136                 :  * interested in the first three parameters and so we provide a special
     137                 :  * constructor for setting those parameters only.
     138                 :  */
     139                 : class SVGTransformSMILData
     140               0 : {
     141                 : public:
     142                 :   // Number of float-params required in constructor, if constructing one of the
     143                 :   // 'simple' transform types (all but matrix type)
     144                 :   static const PRUint32 NUM_SIMPLE_PARAMS = 3;
     145                 : 
     146                 :   // Number of float-params required in constructor for matrix type.
     147                 :   // This is also the number of params we actually store, regardless of type.
     148                 :   static const PRUint32 NUM_STORED_PARAMS = 6;
     149                 : 
     150               0 :   explicit SVGTransformSMILData(PRUint16 aType)
     151               0 :   : mTransformType(aType)
     152                 :   {
     153               0 :     NS_ABORT_IF_FALSE(aType >= nsIDOMSVGTransform::SVG_TRANSFORM_MATRIX &&
     154                 :                       aType <= nsIDOMSVGTransform::SVG_TRANSFORM_SKEWY,
     155                 :                       "Unexpected transform type");
     156               0 :     for (PRUint32 i = 0; i < NUM_STORED_PARAMS; ++i) {
     157               0 :       mParams[i] = 0.f;
     158                 :     }
     159               0 :   }
     160                 : 
     161               0 :   SVGTransformSMILData(PRUint16 aType, float (&aParams)[NUM_SIMPLE_PARAMS])
     162               0 :   : mTransformType(aType)
     163                 :   {
     164               0 :     NS_ABORT_IF_FALSE(aType >= nsIDOMSVGTransform::SVG_TRANSFORM_TRANSLATE &&
     165                 :                       aType <= nsIDOMSVGTransform::SVG_TRANSFORM_SKEWY,
     166                 :                       "Expected 'simple' transform type");
     167               0 :     for (PRUint32 i = 0; i < NUM_SIMPLE_PARAMS; ++i) {
     168               0 :       mParams[i] = aParams[i];
     169                 :     }
     170               0 :     for (PRUint32 i = NUM_SIMPLE_PARAMS; i < NUM_STORED_PARAMS; ++i) {
     171               0 :       mParams[i] = 0.f;
     172                 :     }
     173               0 :   }
     174                 : 
     175                 :   // Conversion to/from a fully-fledged SVGTransform
     176                 :   SVGTransformSMILData(const SVGTransform& aTransform);
     177                 :   SVGTransform ToSVGTransform() const;
     178                 : 
     179               0 :   bool operator==(const SVGTransformSMILData& aOther) const
     180                 :   {
     181               0 :     if (mTransformType != aOther.mTransformType)
     182               0 :       return false;
     183                 : 
     184               0 :     for (PRUint32 i = 0; i < NUM_STORED_PARAMS; ++i) {
     185               0 :       if (mParams[i] != aOther.mParams[i]) {
     186               0 :         return false;
     187                 :       }
     188                 :     }
     189                 : 
     190               0 :     return true;
     191                 :   }
     192                 : 
     193               0 :   bool operator!=(const SVGTransformSMILData& aOther) const
     194                 :   {
     195               0 :     return !(*this == aOther);
     196                 :   }
     197                 : 
     198                 :   PRUint16 mTransformType;
     199                 :   float    mParams[NUM_STORED_PARAMS];
     200                 : };
     201                 : 
     202                 : } // namespace mozilla
     203                 : 
     204                 : #endif // MOZILLA_SVGTRANSFORM_H__

Generated by: LCOV version 1.7