LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGBoolean.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 80 2 2.5 %
Date: 2012-06-02 Functions: 20 2 10.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 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 "nsSVGBoolean.h"
      38                 : #include "nsSMILValue.h"
      39                 : #include "SMILBoolType.h"
      40                 : 
      41                 : using namespace mozilla;
      42                 : 
      43            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean, mSVGElement)
      44                 : 
      45               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGBoolean::DOMAnimatedBoolean)
      46               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGBoolean::DOMAnimatedBoolean)
      47                 : 
      48                 : DOMCI_DATA(SVGAnimatedBoolean, nsSVGBoolean::DOMAnimatedBoolean)
      49                 : 
      50               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGBoolean::DOMAnimatedBoolean)
      51               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedBoolean)
      52               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      53               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedBoolean)
      54               0 : NS_INTERFACE_MAP_END
      55                 : 
      56                 : /* Implementation */
      57                 : 
      58                 : static nsresult
      59               0 : GetValueFromString(const nsAString &aValueAsString,
      60                 :                    bool *aValue)
      61                 : {
      62               0 :   if (aValueAsString.EqualsLiteral("true")) {
      63               0 :     *aValue = true;
      64               0 :     return NS_OK;
      65                 :   }
      66               0 :   if (aValueAsString.EqualsLiteral("false")) {
      67               0 :     *aValue = false;
      68               0 :     return NS_OK;
      69                 :   }
      70               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
      71                 : }
      72                 : 
      73                 : static nsresult
      74               0 : GetValueFromAtom(const nsIAtom* aValueAsAtom, bool *aValue)
      75                 : {
      76               0 :   if (aValueAsAtom == nsGkAtoms::_true) {
      77               0 :     *aValue = true;
      78               0 :     return NS_OK;
      79                 :   }
      80               0 :   if (aValueAsAtom == nsGkAtoms::_false) {
      81               0 :     *aValue = false;
      82               0 :     return NS_OK;
      83                 :   }
      84               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
      85                 : }
      86                 : 
      87                 : nsresult
      88               0 : nsSVGBoolean::SetBaseValueAtom(const nsIAtom* aValue, nsSVGElement *aSVGElement)
      89                 : {
      90                 :   bool val;
      91                 : 
      92               0 :   nsresult rv = GetValueFromAtom(aValue, &val);
      93               0 :   if (NS_FAILED(rv)) {
      94               0 :     return rv;
      95                 :   }
      96                 : 
      97               0 :   mBaseVal = val;
      98               0 :   if (!mIsAnimated) {
      99               0 :     mAnimVal = mBaseVal;
     100                 :   }
     101                 :   else {
     102               0 :     aSVGElement->AnimationNeedsResample();
     103                 :   }
     104                 : 
     105                 :   // We don't need to call DidChange* here - we're only called by
     106                 :   // nsSVGElement::ParseAttribute under nsGenericElement::SetAttr,
     107                 :   // which takes care of notifying.
     108               0 :   return NS_OK;
     109                 : }
     110                 : 
     111                 : nsIAtom*
     112               0 : nsSVGBoolean::GetBaseValueAtom() const
     113                 : {
     114               0 :   return mBaseVal ? nsGkAtoms::_true : nsGkAtoms::_false;
     115                 : }
     116                 : 
     117                 : void
     118               0 : nsSVGBoolean::SetBaseValue(bool aValue, nsSVGElement *aSVGElement)
     119                 : {
     120                 :   NS_PRECONDITION(aValue == true || aValue == false, "Boolean out of range");
     121                 : 
     122               0 :   if (aValue == mBaseVal) {
     123               0 :     return;
     124                 :   }
     125                 : 
     126               0 :   mBaseVal = aValue;
     127               0 :   if (!mIsAnimated) {
     128               0 :     mAnimVal = mBaseVal;
     129                 :   } else {
     130               0 :     aSVGElement->AnimationNeedsResample();
     131                 :   }
     132               0 :   aSVGElement->DidChangeBoolean(mAttrEnum);
     133                 : }
     134                 : 
     135                 : void
     136               0 : nsSVGBoolean::SetAnimValue(bool aValue, nsSVGElement *aSVGElement)
     137                 : {
     138               0 :   mAnimVal = aValue;
     139               0 :   mIsAnimated = true;
     140               0 :   aSVGElement->DidAnimateBoolean(mAttrEnum);
     141               0 : }
     142                 : 
     143                 : nsresult
     144               0 : nsSVGBoolean::ToDOMAnimatedBoolean(nsIDOMSVGAnimatedBoolean **aResult,
     145                 :                                    nsSVGElement *aSVGElement)
     146                 : {
     147               0 :   *aResult = new DOMAnimatedBoolean(this, aSVGElement);
     148               0 :   if (!*aResult)
     149               0 :     return NS_ERROR_OUT_OF_MEMORY;
     150                 : 
     151               0 :   NS_ADDREF(*aResult);
     152               0 :   return NS_OK;
     153                 : }
     154                 : 
     155                 : nsISMILAttr*
     156               0 : nsSVGBoolean::ToSMILAttr(nsSVGElement *aSVGElement)
     157                 : {
     158               0 :   return new SMILBool(this, aSVGElement);
     159                 : }
     160                 : 
     161                 : nsresult
     162               0 : nsSVGBoolean::SMILBool::ValueFromString(const nsAString& aStr,
     163                 :                                         const nsISMILAnimationElement* /*aSrcElement*/,
     164                 :                                         nsSMILValue& aValue,
     165                 :                                         bool& aPreventCachingOfSandwich) const
     166                 : {
     167                 :   bool value;
     168               0 :   nsresult rv = GetValueFromString(aStr, &value);
     169               0 :   if (NS_FAILED(rv)) {
     170               0 :     return rv;
     171                 :   }
     172                 : 
     173               0 :   nsSMILValue val(&SMILBoolType::sSingleton);
     174               0 :   val.mU.mBool = value;
     175               0 :   aValue = val;
     176               0 :   aPreventCachingOfSandwich = false;
     177                 : 
     178               0 :   return NS_OK;
     179                 : }
     180                 : 
     181                 : nsSMILValue
     182               0 : nsSVGBoolean::SMILBool::GetBaseValue() const
     183                 : {
     184               0 :   nsSMILValue val(&SMILBoolType::sSingleton);
     185               0 :   val.mU.mBool = mVal->mBaseVal;
     186                 :   return val;
     187                 : }
     188                 : 
     189                 : void
     190               0 : nsSVGBoolean::SMILBool::ClearAnimValue()
     191                 : {
     192               0 :   if (mVal->mIsAnimated) {
     193               0 :     mVal->mIsAnimated = false;
     194               0 :     mVal->mAnimVal = mVal->mBaseVal;
     195               0 :     mSVGElement->DidAnimateBoolean(mVal->mAttrEnum);
     196                 :   }
     197               0 : }
     198                 : 
     199                 : nsresult
     200               0 : nsSVGBoolean::SMILBool::SetAnimValue(const nsSMILValue& aValue)
     201                 : {
     202               0 :   NS_ASSERTION(aValue.mType == &SMILBoolType::sSingleton,
     203                 :                "Unexpected type to assign animated value");
     204               0 :   if (aValue.mType == &SMILBoolType::sSingleton) {
     205               0 :     mVal->SetAnimValue(PRUint16(aValue.mU.mBool), mSVGElement);
     206                 :   }
     207               0 :   return NS_OK;
     208            4392 : }

Generated by: LCOV version 1.7