LCOV - code coverage report
Current view: directory - content/svg/content/src - SVGOrientSMILType.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 57 2 3.5 %
Date: 2012-06-02 Functions: 10 2 20.0 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is the Mozilla SVG project.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is the Mozilla Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      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.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #include "SVGOrientSMILType.h"
      38                 : #include "nsSMILValue.h"
      39                 : #include "nsSVGViewBox.h"
      40                 : #include "nsSVGAngle.h"
      41                 : #include "nsIDOMSVGMarkerElement.h"
      42                 : #include "nsDebug.h"
      43                 : #include <math.h>
      44                 : 
      45                 : namespace mozilla {
      46                 : 
      47            1464 : /*static*/ SVGOrientSMILType SVGOrientSMILType::sSingleton;
      48                 : 
      49                 : void
      50               0 : SVGOrientSMILType::Init(nsSMILValue& aValue) const
      51                 : {
      52               0 :   NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type");
      53                 : 
      54               0 :   aValue.mU.mOrient.mAngle = 0.0f;
      55               0 :   aValue.mU.mOrient.mUnit = nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
      56               0 :   aValue.mU.mOrient.mOrientType = nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE;
      57               0 :   aValue.mType = this;
      58               0 : }
      59                 : 
      60                 : void
      61               0 : SVGOrientSMILType::Destroy(nsSMILValue& aValue) const
      62                 : {
      63               0 :   NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value.");
      64               0 :   aValue.mU.mPtr = nsnull;
      65               0 :   aValue.mType = &nsSMILNullType::sSingleton;
      66               0 : }
      67                 : 
      68                 : nsresult
      69               0 : SVGOrientSMILType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
      70                 : {
      71               0 :   NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types.");
      72               0 :   NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value.");
      73                 : 
      74               0 :   aDest.mU.mOrient.mAngle = aSrc.mU.mOrient.mAngle;
      75               0 :   aDest.mU.mOrient.mUnit = aSrc.mU.mOrient.mUnit;
      76               0 :   aDest.mU.mOrient.mOrientType = aSrc.mU.mOrient.mOrientType;
      77               0 :   return NS_OK;
      78                 : }
      79                 : 
      80                 : bool
      81               0 : SVGOrientSMILType::IsEqual(const nsSMILValue& aLeft,
      82                 :                            const nsSMILValue& aRight) const
      83                 : {
      84               0 :   NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types");
      85               0 :   NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value");
      86                 : 
      87                 :   return
      88                 :     aLeft.mU.mOrient.mAngle == aRight.mU.mOrient.mAngle &&
      89                 :     aLeft.mU.mOrient.mUnit == aRight.mU.mOrient.mUnit &&
      90               0 :     aLeft.mU.mOrient.mOrientType == aRight.mU.mOrient.mOrientType;
      91                 : }
      92                 : 
      93                 : nsresult
      94               0 : SVGOrientSMILType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
      95                 :                        PRUint32 aCount) const
      96                 : {
      97               0 :   NS_PRECONDITION(aValueToAdd.mType == aDest.mType,
      98                 :                   "Trying to add invalid types");
      99               0 :   NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type");
     100                 : 
     101               0 :   if (aDest.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE ||
     102                 :       aValueToAdd.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE) {
     103                 :     // TODO: it would be nice to be able to add to auto angles
     104               0 :     return NS_ERROR_FAILURE;
     105                 :   }
     106                 : 
     107                 :   // We may be dealing with two different angle units, so we normalize to
     108                 :   // degrees for the add:
     109                 :   float currentAngle = aDest.mU.mOrient.mAngle *
     110               0 :                        nsSVGAngle::GetDegreesPerUnit(aDest.mU.mOrient.mUnit);
     111                 :   float angleToAdd = aValueToAdd.mU.mOrient.mAngle *
     112               0 :                      nsSVGAngle::GetDegreesPerUnit(aValueToAdd.mU.mOrient.mUnit) *
     113               0 :                      aCount;
     114                 : 
     115                 :   // And then we give the resulting animated value the same units as the value
     116                 :   // that we're animating to/by (i.e. the same as aValueToAdd):
     117                 :   aDest.mU.mOrient.mAngle = (currentAngle + angleToAdd) /
     118               0 :                     nsSVGAngle::GetDegreesPerUnit(aValueToAdd.mU.mOrient.mUnit);
     119               0 :   aDest.mU.mOrient.mUnit = aValueToAdd.mU.mOrient.mUnit;
     120                 : 
     121               0 :   return NS_OK;
     122                 : }
     123                 : 
     124                 : nsresult
     125               0 : SVGOrientSMILType::ComputeDistance(const nsSMILValue& aFrom,
     126                 :                                    const nsSMILValue& aTo,
     127                 :                                    double& aDistance) const
     128                 : {
     129               0 :   NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types");
     130               0 :   NS_PRECONDITION(aFrom.mType == this, "Unexpected source type");
     131                 : 
     132               0 :   if (aFrom.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE ||
     133                 :       aTo.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE) {
     134                 :     // TODO: it would be nice to be able to compute distance with auto angles
     135               0 :     return NS_ERROR_FAILURE;
     136                 :   }
     137                 : 
     138                 :   // Normalize both to degrees in case they're different angle units:
     139                 :   double from = aFrom.mU.mOrient.mAngle *
     140               0 :                   nsSVGAngle::GetDegreesPerUnit(aFrom.mU.mOrient.mUnit);
     141                 :   double to   = aTo.mU.mOrient.mAngle *
     142               0 :                   nsSVGAngle::GetDegreesPerUnit(aTo.mU.mOrient.mUnit);
     143                 : 
     144               0 :   aDistance = fabs(to - from);
     145                 : 
     146               0 :   return NS_OK;
     147                 : }
     148                 : 
     149                 : nsresult
     150               0 : SVGOrientSMILType::Interpolate(const nsSMILValue& aStartVal,
     151                 :                                const nsSMILValue& aEndVal,
     152                 :                                double aUnitDistance,
     153                 :                                nsSMILValue& aResult) const
     154                 : {
     155               0 :   NS_PRECONDITION(aStartVal.mType == aEndVal.mType,
     156                 :                   "Trying to interpolate different types");
     157               0 :   NS_PRECONDITION(aStartVal.mType == this,
     158                 :                   "Unexpected types for interpolation.");
     159               0 :   NS_PRECONDITION(aResult.mType   == this, "Unexpected result type.");
     160                 : 
     161               0 :   if (aStartVal.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE ||
     162                 :       aEndVal.mU.mOrient.mOrientType != nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE) {
     163                 :     // TODO: it would be nice to be able to handle auto angles too.
     164               0 :     return NS_ERROR_FAILURE;
     165                 :   }
     166                 : 
     167                 :   float start  = aStartVal.mU.mOrient.mAngle *
     168               0 :                    nsSVGAngle::GetDegreesPerUnit(aStartVal.mU.mOrient.mUnit);
     169                 :   float end    = aEndVal.mU.mOrient.mAngle *
     170               0 :                    nsSVGAngle::GetDegreesPerUnit(aEndVal.mU.mOrient.mUnit);
     171               0 :   float result = (start + (end - start) * aUnitDistance);
     172                 : 
     173                 :   // Again, we use the unit of the to/by value for the result:
     174                 :   aResult.mU.mOrient.mAngle = result /
     175               0 :     nsSVGAngle::GetDegreesPerUnit(aEndVal.mU.mOrient.mUnit);
     176               0 :   aResult.mU.mOrient.mUnit = aEndVal.mU.mOrient.mUnit;
     177                 : 
     178               0 :   return NS_OK;
     179                 : }
     180                 : 
     181            4392 : } // namespace mozilla

Generated by: LCOV version 1.7