LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGInteger.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 79 2 2.5 %
Date: 2012-06-02 Functions: 19 2 10.5 %

       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) 2007
      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 the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * 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 "nsSVGInteger.h"
      38                 : #include "nsSMILValue.h"
      39                 : #include "SMILIntegerType.h"
      40                 : 
      41                 : using namespace mozilla;
      42                 : 
      43            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGInteger::DOMAnimatedInteger, mSVGElement)
      44                 : 
      45               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGInteger::DOMAnimatedInteger)
      46               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGInteger::DOMAnimatedInteger)
      47                 : 
      48                 : DOMCI_DATA(SVGAnimatedInteger, nsSVGInteger::DOMAnimatedInteger)
      49                 : 
      50               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGInteger::DOMAnimatedInteger)
      51               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedInteger)
      52               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      53               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedInteger)
      54               0 : NS_INTERFACE_MAP_END
      55                 : 
      56                 : /* Implementation */
      57                 : 
      58                 : static nsresult
      59               0 : GetValueFromString(const nsAString &aValueAsString,
      60                 :                    PRInt32 *aValue)
      61                 : {
      62               0 :   NS_ConvertUTF16toUTF8 value(aValueAsString);
      63               0 :   const char *str = value.get();
      64                 : 
      65               0 :   if (NS_IsAsciiWhitespace(*str))
      66               0 :     return NS_ERROR_DOM_SYNTAX_ERR;
      67                 :   
      68                 :   char *rest;
      69               0 :   *aValue = strtol(str, &rest, 10);
      70               0 :   if (rest == str || *rest != '\0') {
      71               0 :     return NS_ERROR_DOM_SYNTAX_ERR;
      72                 :   }
      73               0 :   if (*rest == '\0') {
      74               0 :     return NS_OK;
      75                 :   }
      76               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
      77                 : }
      78                 : 
      79                 : nsresult
      80               0 : nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
      81                 :                                  nsSVGElement *aSVGElement)
      82                 : {
      83                 :   PRInt32 value;
      84                 : 
      85               0 :   nsresult rv = GetValueFromString(aValueAsString, &value);
      86               0 :   if (NS_FAILED(rv)) {
      87               0 :     return rv;
      88                 :   }
      89                 : 
      90               0 :   mIsBaseSet = true;
      91               0 :   mBaseVal = value;
      92               0 :   if (!mIsAnimated) {
      93               0 :     mAnimVal = mBaseVal;
      94                 :   }
      95                 :   else {
      96               0 :     aSVGElement->AnimationNeedsResample();
      97                 :   }
      98               0 :   return NS_OK;
      99                 : }
     100                 : 
     101                 : void
     102               0 : nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
     103                 : {
     104               0 :   aValueAsString.Truncate();
     105               0 :   aValueAsString.AppendInt(mBaseVal);
     106               0 : }
     107                 : 
     108                 : void
     109               0 : nsSVGInteger::SetBaseValue(int aValue, nsSVGElement *aSVGElement)
     110                 : {
     111                 :   // We can't just rely on SetParsedAttrValue (as called by DidChangeInteger)
     112                 :   // detecting redundant changes since it will compare false if the existing
     113                 :   // attribute value has an associated serialized version (a string value) even
     114                 :   // if the integers match due to the way integers are stored in nsAttrValue.
     115               0 :   if (aValue == mBaseVal && mIsBaseSet) {
     116               0 :     return;
     117                 :   }
     118                 : 
     119               0 :   mBaseVal = aValue;
     120               0 :   mIsBaseSet = true;
     121               0 :   if (!mIsAnimated) {
     122               0 :     mAnimVal = mBaseVal;
     123                 :   }
     124                 :   else {
     125               0 :     aSVGElement->AnimationNeedsResample();
     126                 :   }
     127               0 :   aSVGElement->DidChangeInteger(mAttrEnum);
     128                 : }
     129                 : 
     130                 : void
     131               0 : nsSVGInteger::SetAnimValue(int aValue, nsSVGElement *aSVGElement)
     132                 : {
     133               0 :   mAnimVal = aValue;
     134               0 :   mIsAnimated = true;
     135               0 :   aSVGElement->DidAnimateInteger(mAttrEnum);
     136               0 : }
     137                 : 
     138                 : nsresult
     139               0 : nsSVGInteger::ToDOMAnimatedInteger(nsIDOMSVGAnimatedInteger **aResult,
     140                 :                                    nsSVGElement *aSVGElement)
     141                 : {
     142               0 :   *aResult = new DOMAnimatedInteger(this, aSVGElement);
     143               0 :   if (!*aResult)
     144               0 :     return NS_ERROR_OUT_OF_MEMORY;
     145                 : 
     146               0 :   NS_ADDREF(*aResult);
     147               0 :   return NS_OK;
     148                 : }
     149                 : 
     150                 : nsISMILAttr*
     151               0 : nsSVGInteger::ToSMILAttr(nsSVGElement *aSVGElement)
     152                 : {
     153               0 :   return new SMILInteger(this, aSVGElement);
     154                 : }
     155                 : 
     156                 : nsresult
     157               0 : nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr,
     158                 :                                            const nsISMILAnimationElement* /*aSrcElement*/,
     159                 :                                            nsSMILValue& aValue,
     160                 :                                            bool& aPreventCachingOfSandwich) const
     161                 : {
     162                 :   PRInt32 val;
     163                 : 
     164               0 :   nsresult rv = GetValueFromString(aStr, &val);
     165               0 :   if (NS_FAILED(rv)) {
     166               0 :     return rv;
     167                 :   }
     168                 : 
     169               0 :   nsSMILValue smilVal(&SMILIntegerType::sSingleton);
     170               0 :   smilVal.mU.mInt = val;
     171               0 :   aValue = smilVal;
     172               0 :   aPreventCachingOfSandwich = false;
     173               0 :   return NS_OK;
     174                 : }
     175                 : 
     176                 : nsSMILValue
     177               0 : nsSVGInteger::SMILInteger::GetBaseValue() const
     178                 : {
     179               0 :   nsSMILValue val(&SMILIntegerType::sSingleton);
     180               0 :   val.mU.mInt = mVal->mBaseVal;
     181                 :   return val;
     182                 : }
     183                 : 
     184                 : void
     185               0 : nsSVGInteger::SMILInteger::ClearAnimValue()
     186                 : {
     187               0 :   if (mVal->mIsAnimated) {
     188               0 :     mVal->mIsAnimated = false;
     189               0 :     mVal->mAnimVal = mVal->mBaseVal;
     190               0 :     mSVGElement->DidAnimateInteger(mVal->mAttrEnum);
     191                 :   }
     192               0 : }
     193                 : 
     194                 : nsresult
     195               0 : nsSVGInteger::SMILInteger::SetAnimValue(const nsSMILValue& aValue)
     196                 : {
     197               0 :   NS_ASSERTION(aValue.mType == &SMILIntegerType::sSingleton,
     198                 :                "Unexpected type to assign animated value");
     199               0 :   if (aValue.mType == &SMILIntegerType::sSingleton) {
     200               0 :     mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement);
     201                 :   }
     202               0 :   return NS_OK;
     203            4392 : }

Generated by: LCOV version 1.7