LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGNumberPair.h (source / functions) Found Hit Coverage
Test: app.info Lines: 32 1 3.1 %
Date: 2012-06-02 Functions: 17 1 5.9 %

       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 Robert Longson.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      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                 : #ifndef __NS_SVGNUMBERPAIR_H__
      38                 : #define __NS_SVGNUMBERPAIR_H__
      39                 : 
      40                 : #include "nsAutoPtr.h"
      41                 : #include "nsCycleCollectionParticipant.h"
      42                 : #include "nsError.h"
      43                 : #include "nsIDOMSVGAnimatedNumber.h"
      44                 : #include "nsISMILAttr.h"
      45                 : #include "nsMathUtils.h"
      46                 : #include "nsSVGElement.h"
      47                 : 
      48                 : class nsISMILAnimationElement;
      49                 : class nsSMILValue;
      50                 : 
      51                 : class nsSVGNumberPair
      52                 : {
      53                 : 
      54                 : public:
      55                 :   enum PairIndex {
      56                 :     eFirst,
      57                 :     eSecond
      58                 :   };
      59                 : 
      60               0 :   void Init(PRUint8 aAttrEnum = 0xff, float aValue1 = 0, float aValue2 = 0) {
      61               0 :     mAnimVal[0] = mBaseVal[0] = aValue1;
      62               0 :     mAnimVal[1] = mBaseVal[1] = aValue2;
      63               0 :     mAttrEnum = aAttrEnum;
      64               0 :     mIsAnimated = false;
      65               0 :     mIsBaseSet = false;
      66               0 :   }
      67                 : 
      68                 :   nsresult SetBaseValueString(const nsAString& aValue,
      69                 :                               nsSVGElement *aSVGElement);
      70                 :   void GetBaseValueString(nsAString& aValue) const;
      71                 : 
      72                 :   void SetBaseValue(float aValue, PairIndex aIndex, nsSVGElement *aSVGElement);
      73                 :   void SetBaseValues(float aValue1, float aValue2, nsSVGElement *aSVGElement);
      74               0 :   float GetBaseValue(PairIndex aIndex) const
      75               0 :     { return mBaseVal[aIndex == eFirst ? 0 : 1]; }
      76                 :   void SetAnimValue(const float aValue[2], nsSVGElement *aSVGElement);
      77               0 :   float GetAnimValue(PairIndex aIndex) const
      78               0 :     { return mAnimVal[aIndex == eFirst ? 0 : 1]; }
      79                 : 
      80                 :   // Returns true if the animated value of this number has been explicitly
      81                 :   // set (either by animation, or by taking on the base value which has been
      82                 :   // explicitly set by markup or a DOM call), false otherwise.
      83                 :   // If this returns false, the animated value is still valid, that is,
      84                 :   // useable, and represents the default base value of the attribute.
      85               0 :   bool IsExplicitlySet() const
      86               0 :     { return mIsAnimated || mIsBaseSet; }
      87                 : 
      88                 :   nsresult ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber **aResult,
      89                 :                                PairIndex aIndex,
      90                 :                                nsSVGElement* aSVGElement);
      91                 :   // Returns a new nsISMILAttr object that the caller must delete
      92                 :   nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
      93                 : 
      94                 : private:
      95                 : 
      96                 :   float mAnimVal[2];
      97                 :   float mBaseVal[2];
      98                 :   PRUint8 mAttrEnum; // element specified tracking for attribute
      99                 :   bool mIsAnimated;
     100                 :   bool mIsBaseSet;
     101                 : 
     102                 : public:
     103                 :   struct DOMAnimatedNumber : public nsIDOMSVGAnimatedNumber
     104               0 :   {
     105               0 :     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     106            1464 :     NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedNumber)
     107                 : 
     108               0 :     DOMAnimatedNumber(nsSVGNumberPair* aVal, PairIndex aIndex, nsSVGElement *aSVGElement)
     109               0 :       : mVal(aVal), mSVGElement(aSVGElement), mIndex(aIndex) {}
     110                 : 
     111                 :     nsSVGNumberPair* mVal; // kept alive because it belongs to content
     112                 :     nsRefPtr<nsSVGElement> mSVGElement;
     113                 :     PairIndex mIndex; // are we the first or second number
     114                 : 
     115               0 :     NS_IMETHOD GetBaseVal(float* aResult)
     116               0 :       { *aResult = mVal->GetBaseValue(mIndex); return NS_OK; }
     117               0 :     NS_IMETHOD SetBaseVal(float aValue)
     118                 :       {
     119               0 :         if (!NS_finite(aValue)) {
     120               0 :           return NS_ERROR_ILLEGAL_VALUE;
     121                 :         }
     122               0 :         mVal->SetBaseValue(aValue, mIndex, mSVGElement);
     123               0 :         return NS_OK;
     124                 :       }
     125                 : 
     126                 :     // Script may have modified animation parameters or timeline -- DOM getters
     127                 :     // need to flush any resample requests to reflect these modifications.
     128               0 :     NS_IMETHOD GetAnimVal(float* aResult)
     129                 :     {
     130               0 :       mSVGElement->FlushAnimations();
     131               0 :       *aResult = mVal->GetAnimValue(mIndex);
     132               0 :       return NS_OK;
     133                 :     }
     134                 :   };
     135                 : 
     136                 :   struct SMILNumberPair : public nsISMILAttr
     137               0 :   {
     138                 :   public:
     139               0 :     SMILNumberPair(nsSVGNumberPair* aVal, nsSVGElement* aSVGElement)
     140               0 :       : mVal(aVal), mSVGElement(aSVGElement) {}
     141                 : 
     142                 :     // These will stay alive because a nsISMILAttr only lives as long
     143                 :     // as the Compositing step, and DOM elements don't get a chance to
     144                 :     // die during that.
     145                 :     nsSVGNumberPair* mVal;
     146                 :     nsSVGElement* mSVGElement;
     147                 : 
     148                 :     // nsISMILAttr methods
     149                 :     virtual nsresult ValueFromString(const nsAString& aStr,
     150                 :                                      const nsISMILAnimationElement* aSrcElement,
     151                 :                                      nsSMILValue& aValue,
     152                 :                                      bool& aPreventCachingOfSandwich) const;
     153                 :     virtual nsSMILValue GetBaseValue() const;
     154                 :     virtual void ClearAnimValue();
     155                 :     virtual nsresult SetAnimValue(const nsSMILValue& aValue);
     156                 :   };
     157                 : };
     158                 : 
     159                 : #endif //__NS_SVGNUMBERPAIR_H__

Generated by: LCOV version 1.7