LCOV - code coverage report
Current view: top level - dom/svg - nsSVGTransform.h (source / functions) Hit Total Coverage
Test: output.info Lines: 5 47 10.6 %
Date: 2017-07-14 16:53:18 Functions: 2 11 18.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef MOZILLA_SVGTRANSFORM_H__
       8             : #define MOZILLA_SVGTRANSFORM_H__
       9             : 
      10             : #include "gfxMatrix.h"
      11             : #include "mozilla/gfx/Matrix.h"
      12             : #include "nsDebug.h"
      13             : 
      14             : namespace mozilla {
      15             : 
      16             : // Transform Types
      17             : static const unsigned short SVG_TRANSFORM_UNKNOWN = 0;
      18             : static const unsigned short SVG_TRANSFORM_MATRIX = 1;
      19             : static const unsigned short SVG_TRANSFORM_TRANSLATE = 2;
      20             : static const unsigned short SVG_TRANSFORM_SCALE = 3;
      21             : static const unsigned short SVG_TRANSFORM_ROTATE = 4;
      22             : static const unsigned short SVG_TRANSFORM_SKEWX = 5;
      23             : static const unsigned short SVG_TRANSFORM_SKEWY = 6;
      24             : 
      25             : /*
      26             :  * The DOM wrapper class for this class is DOMSVGTransformMatrix.
      27             :  */
      28             : class nsSVGTransform
      29             : {
      30             : public:
      31             :   // Default ctor initialises to matrix type with identity matrix
      32           7 :   nsSVGTransform()
      33           7 :     : mMatrix() // Initialises to identity
      34             :     , mAngle(0.f)
      35             :     , mOriginX(0.f)
      36             :     , mOriginY(0.f)
      37           7 :     , mType(SVG_TRANSFORM_MATRIX)
      38           7 :   { }
      39             : 
      40           0 :   explicit nsSVGTransform(const gfxMatrix& aMatrix)
      41           0 :     : mMatrix(aMatrix)
      42             :     , mAngle(0.f)
      43             :     , mOriginX(0.f)
      44             :     , mOriginY(0.f)
      45           0 :     , mType(SVG_TRANSFORM_MATRIX)
      46           0 :   { }
      47             : 
      48             :   bool operator==(const nsSVGTransform& rhs) const {
      49             :     return mType == rhs.mType &&
      50             :       MatricesEqual(mMatrix, rhs.mMatrix) &&
      51             :       mAngle == rhs.mAngle &&
      52             :       mOriginX == rhs.mOriginX &&
      53             :       mOriginY == rhs.mOriginY;
      54             :   }
      55             : 
      56             :   void GetValueAsString(nsAString& aValue) const;
      57             : 
      58           0 :   float Angle() const {
      59           0 :     return mAngle;
      60             :   }
      61           0 :   void GetRotationOrigin(float& aOriginX, float& aOriginY) const {
      62           0 :     aOriginX = mOriginX;
      63           0 :     aOriginY = mOriginY;
      64           0 :   }
      65           0 :   uint16_t Type() const {
      66           0 :     return mType;
      67             :   }
      68             : 
      69          42 :   const gfxMatrix& GetMatrix() const { return mMatrix; }
      70             :   void SetMatrix(const gfxMatrix& aMatrix);
      71             :   void SetTranslate(float aTx, float aTy);
      72             :   void SetScale(float aSx, float aSy);
      73             :   void SetRotate(float aAngle, float aCx, float aCy);
      74             :   nsresult SetSkewX(float aAngle);
      75             :   nsresult SetSkewY(float aAngle);
      76             : 
      77           0 :   static bool MatricesEqual(const gfxMatrix& a, const gfxMatrix& b)
      78             :   {
      79           0 :     return a._11 == b._11 &&
      80           0 :            a._12 == b._12 &&
      81           0 :            a._21 == b._21 &&
      82           0 :            a._22 == b._22 &&
      83           0 :            a._31 == b._31 &&
      84           0 :            a._32 == b._32;
      85             :   }
      86             : 
      87             : protected:
      88             :   gfxMatrix mMatrix;
      89             :   float mAngle, mOriginX, mOriginY;
      90             :   uint16_t mType;
      91             : };
      92             : 
      93             : /*
      94             :  * A slightly more light-weight version of nsSVGTransform for SMIL animation.
      95             :  *
      96             :  * Storing the parameters in an array (rather than a matrix) also allows simpler
      97             :  * (transform type-agnostic) interpolation and addition.
      98             :  *
      99             :  * The meaning of the mParams array depends on the transform type as follows:
     100             :  *
     101             :  * Type                | mParams[0], mParams[1], mParams[2], ...
     102             :  * --------------------+-----------------------------------------
     103             :  * translate           | tx, ty
     104             :  * scale               | sx, sy
     105             :  * rotate              | rotation-angle (in degrees), cx, cy
     106             :  * skewX               | skew-angle (in degrees)
     107             :  * skewY               | skew-angle (in degrees)
     108             :  * matrix              | a, b, c, d, e, f
     109             :  *
     110             :  * The matrix type is never generated by animation code (it is only produced
     111             :  * when the user inserts one via the DOM) and often requires special handling
     112             :  * when we do encounter it. Therefore many users of this class are only
     113             :  * interested in the first three parameters and so we provide a special
     114             :  * constructor for setting those parameters only.
     115             :  */
     116             : class SVGTransformSMILData
     117             : {
     118             : public:
     119             :   // Number of float-params required in constructor, if constructing one of the
     120             :   // 'simple' transform types (all but matrix type)
     121             :   static const uint32_t NUM_SIMPLE_PARAMS = 3;
     122             : 
     123             :   // Number of float-params required in constructor for matrix type.
     124             :   // This is also the number of params we actually store, regardless of type.
     125             :   static const uint32_t NUM_STORED_PARAMS = 6;
     126             : 
     127           0 :   explicit SVGTransformSMILData(uint16_t aType)
     128           0 :   : mTransformType(aType)
     129             :   {
     130           0 :     MOZ_ASSERT(aType >= SVG_TRANSFORM_MATRIX && aType <= SVG_TRANSFORM_SKEWY,
     131             :                "Unexpected transform type");
     132           0 :     for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
     133           0 :       mParams[i] = 0.f;
     134             :     }
     135           0 :   }
     136             : 
     137           0 :   SVGTransformSMILData(uint16_t aType, float (&aParams)[NUM_SIMPLE_PARAMS])
     138           0 :   : mTransformType(aType)
     139             :   {
     140           0 :     MOZ_ASSERT(aType >= SVG_TRANSFORM_TRANSLATE && aType <= SVG_TRANSFORM_SKEWY,
     141             :                "Expected 'simple' transform type");
     142           0 :     for (uint32_t i = 0; i < NUM_SIMPLE_PARAMS; ++i) {
     143           0 :       mParams[i] = aParams[i];
     144             :     }
     145           0 :     for (uint32_t i = NUM_SIMPLE_PARAMS; i < NUM_STORED_PARAMS; ++i) {
     146           0 :       mParams[i] = 0.f;
     147             :     }
     148           0 :   }
     149             : 
     150             :   // Conversion to/from a fully-fledged nsSVGTransform
     151             :   explicit SVGTransformSMILData(const nsSVGTransform& aTransform);
     152             :   nsSVGTransform ToSVGTransform() const;
     153             : 
     154           0 :   bool operator==(const SVGTransformSMILData& aOther) const
     155             :   {
     156           0 :     if (mTransformType != aOther.mTransformType)
     157           0 :       return false;
     158             : 
     159           0 :     for (uint32_t i = 0; i < NUM_STORED_PARAMS; ++i) {
     160           0 :       if (mParams[i] != aOther.mParams[i]) {
     161           0 :         return false;
     162             :       }
     163             :     }
     164             : 
     165           0 :     return true;
     166             :   }
     167             : 
     168           0 :   bool operator!=(const SVGTransformSMILData& aOther) const
     169             :   {
     170           0 :     return !(*this == aOther);
     171             :   }
     172             : 
     173             :   uint16_t mTransformType;
     174             :   float    mParams[NUM_STORED_PARAMS];
     175             : };
     176             : 
     177             : } // namespace mozilla
     178             : 
     179             : #endif // MOZILLA_SVGTRANSFORM_H__

Generated by: LCOV version 1.13