LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGNumber2.h (source / functions) Found Hit Coverage
Test: app.info Lines: 31 1 3.2 %
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 IBM Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      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_SVGNUMBER2_H__
      38                 : #define __NS_SVGNUMBER2_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 nsSVGNumber2
      52                 : {
      53                 : 
      54                 : public:
      55               0 :   void Init(PRUint8 aAttrEnum = 0xff, float aValue = 0) {
      56               0 :     mAnimVal = mBaseVal = aValue;
      57               0 :     mAttrEnum = aAttrEnum;
      58               0 :     mIsAnimated = false;
      59               0 :     mIsBaseSet = false;
      60               0 :   }
      61                 : 
      62                 :   nsresult SetBaseValueString(const nsAString& aValue,
      63                 :                               nsSVGElement *aSVGElement);
      64                 :   void GetBaseValueString(nsAString& aValue);
      65                 : 
      66                 :   void SetBaseValue(float aValue, nsSVGElement *aSVGElement);
      67               0 :   float GetBaseValue() const
      68               0 :     { return mBaseVal; }
      69                 :   void SetAnimValue(float aValue, nsSVGElement *aSVGElement);
      70               0 :   float GetAnimValue() const
      71               0 :     { return mAnimVal; }
      72                 : 
      73                 :   // Returns true if the animated value of this number has been explicitly
      74                 :   // set (either by animation, or by taking on the base value which has been
      75                 :   // explicitly set by markup or a DOM call), false otherwise.
      76                 :   // If this returns false, the animated value is still valid, that is,
      77                 :   // useable, and represents the default base value of the attribute.
      78               0 :   bool IsExplicitlySet() const
      79               0 :     { return mIsAnimated || mIsBaseSet; }
      80                 : 
      81                 :   nsresult ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber **aResult,
      82                 :                                nsSVGElement* aSVGElement);
      83                 :   // Returns a new nsISMILAttr object that the caller must delete
      84                 :   nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
      85                 : 
      86                 : private:
      87                 : 
      88                 :   float mAnimVal;
      89                 :   float mBaseVal;
      90                 :   PRUint8 mAttrEnum; // element specified tracking for attribute
      91                 :   bool mIsAnimated;
      92                 :   bool mIsBaseSet;
      93                 : 
      94                 : public:
      95                 :   struct DOMAnimatedNumber : public nsIDOMSVGAnimatedNumber
      96               0 :   {
      97               0 :     NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      98            1464 :     NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedNumber)
      99                 : 
     100               0 :     DOMAnimatedNumber(nsSVGNumber2* aVal, nsSVGElement *aSVGElement)
     101               0 :       : mVal(aVal), mSVGElement(aSVGElement) {}
     102                 : 
     103                 :     nsSVGNumber2* mVal; // kept alive because it belongs to content
     104                 :     nsRefPtr<nsSVGElement> mSVGElement;
     105                 : 
     106               0 :     NS_IMETHOD GetBaseVal(float* aResult)
     107               0 :       { *aResult = mVal->GetBaseValue(); return NS_OK; }
     108               0 :     NS_IMETHOD SetBaseVal(float aValue)
     109                 :       {
     110               0 :         if (!NS_finite(aValue)) {
     111               0 :           return NS_ERROR_ILLEGAL_VALUE;
     112                 :         }
     113               0 :         mVal->SetBaseValue(aValue, mSVGElement);
     114               0 :         return NS_OK;
     115                 :       }
     116                 : 
     117                 :     // Script may have modified animation parameters or timeline -- DOM getters
     118                 :     // need to flush any resample requests to reflect these modifications.
     119               0 :     NS_IMETHOD GetAnimVal(float* aResult)
     120                 :     {
     121               0 :       mSVGElement->FlushAnimations();
     122               0 :       *aResult = mVal->GetAnimValue();
     123               0 :       return NS_OK;
     124                 :     }
     125                 :   };
     126                 : 
     127                 :   struct SMILNumber : public nsISMILAttr
     128               0 :   {
     129                 :   public:
     130               0 :     SMILNumber(nsSVGNumber2* aVal, nsSVGElement* aSVGElement)
     131               0 :     : mVal(aVal), mSVGElement(aSVGElement) {}
     132                 : 
     133                 :     // These will stay alive because a nsISMILAttr only lives as long
     134                 :     // as the Compositing step, and DOM elements don't get a chance to
     135                 :     // die during that.
     136                 :     nsSVGNumber2* mVal;
     137                 :     nsSVGElement* mSVGElement;
     138                 : 
     139                 :     // nsISMILAttr methods
     140                 :     virtual nsresult ValueFromString(const nsAString& aStr,
     141                 :                                      const nsISMILAnimationElement* aSrcElement,
     142                 :                                      nsSMILValue& aValue,
     143                 :                                      bool& aPreventCachingOfSandwich) const;
     144                 :     virtual nsSMILValue GetBaseValue() const;
     145                 :     virtual void ClearAnimValue();
     146                 :     virtual nsresult SetAnimValue(const nsSMILValue& aValue);
     147                 :   };
     148                 : };
     149                 : 
     150                 : #endif //__NS_SVGNUMBER2_H__

Generated by: LCOV version 1.7