LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGEnum.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 90 2 2.2 %
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 IBM Corporation
      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 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 "nsSVGEnum.h"
      38                 : #include "nsIAtom.h"
      39                 : #include "nsSVGElement.h"
      40                 : #include "nsSMILValue.h"
      41                 : #include "SMILEnumType.h"
      42                 : 
      43                 : using namespace mozilla;
      44                 : 
      45            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGEnum::DOMAnimatedEnum, mSVGElement)
      46                 : 
      47               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGEnum::DOMAnimatedEnum)
      48               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGEnum::DOMAnimatedEnum)
      49                 : 
      50                 : DOMCI_DATA(SVGAnimatedEnumeration, nsSVGEnum::DOMAnimatedEnum)
      51                 : 
      52               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGEnum::DOMAnimatedEnum)
      53               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedEnumeration)
      54               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      55               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedEnumeration)
      56               0 : NS_INTERFACE_MAP_END
      57                 : 
      58                 : nsSVGEnumMapping *
      59               0 : nsSVGEnum::GetMapping(nsSVGElement *aSVGElement)
      60                 : {
      61               0 :   nsSVGElement::EnumAttributesInfo info = aSVGElement->GetEnumInfo();
      62                 : 
      63               0 :   NS_ASSERTION(info.mEnumCount > 0 && mAttrEnum < info.mEnumCount,
      64                 :                "mapping request for a non-attrib enum");
      65                 : 
      66               0 :   return info.mEnumInfo[mAttrEnum].mMapping;
      67                 : }
      68                 : 
      69                 : nsresult
      70               0 : nsSVGEnum::SetBaseValueAtom(const nsIAtom* aValue, nsSVGElement *aSVGElement)
      71                 : {
      72               0 :   nsSVGEnumMapping *mapping = GetMapping(aSVGElement);
      73                 : 
      74               0 :   while (mapping && mapping->mKey) {
      75               0 :     if (aValue == *(mapping->mKey)) {
      76               0 :       mIsBaseSet = true;
      77               0 :       if (mBaseVal != mapping->mVal) {
      78               0 :         mBaseVal = mapping->mVal;
      79               0 :         if (!mIsAnimated) {
      80               0 :           mAnimVal = mBaseVal;
      81                 :         }
      82                 :         else {
      83               0 :           aSVGElement->AnimationNeedsResample();
      84                 :         }
      85                 :         // We don't need to call DidChange* here - we're only called by
      86                 :         // nsSVGElement::ParseAttribute under nsGenericElement::SetAttr,
      87                 :         // which takes care of notifying.
      88                 :       }
      89               0 :       return NS_OK;
      90                 :     }
      91               0 :     mapping++;
      92                 :   }
      93                 : 
      94                 :   // only a warning since authors may mistype attribute values
      95               0 :   NS_WARNING("unknown enumeration key");
      96               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
      97                 : }
      98                 : 
      99                 : nsIAtom*
     100               0 : nsSVGEnum::GetBaseValueAtom(nsSVGElement *aSVGElement)
     101                 : {
     102               0 :   nsSVGEnumMapping *mapping = GetMapping(aSVGElement);
     103                 : 
     104               0 :   while (mapping && mapping->mKey) {
     105               0 :     if (mBaseVal == mapping->mVal) {
     106               0 :       return *mapping->mKey;
     107                 :     }
     108               0 :     mapping++;
     109                 :   }
     110               0 :   NS_ERROR("unknown enumeration value");
     111               0 :   return nsGkAtoms::_empty;
     112                 : }
     113                 : 
     114                 : nsresult
     115               0 : nsSVGEnum::SetBaseValue(PRUint16 aValue,
     116                 :                         nsSVGElement *aSVGElement)
     117                 : {
     118               0 :   nsSVGEnumMapping *mapping = GetMapping(aSVGElement);
     119                 : 
     120               0 :   while (mapping && mapping->mKey) {
     121               0 :     if (mapping->mVal == aValue) {
     122               0 :       mIsBaseSet = true;
     123               0 :       if (mBaseVal != PRUint8(aValue)) {
     124               0 :         mBaseVal = PRUint8(aValue);
     125               0 :         if (!mIsAnimated) {
     126               0 :           mAnimVal = mBaseVal;
     127                 :         }
     128                 :         else {
     129               0 :           aSVGElement->AnimationNeedsResample();
     130                 :         }
     131               0 :         aSVGElement->DidChangeEnum(mAttrEnum);
     132                 :       }
     133               0 :       return NS_OK;
     134                 :     }
     135               0 :     mapping++;
     136                 :   }
     137               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
     138                 : }
     139                 : 
     140                 : void
     141               0 : nsSVGEnum::SetAnimValue(PRUint16 aValue, nsSVGElement *aSVGElement)
     142                 : {
     143               0 :   mAnimVal = aValue;
     144               0 :   mIsAnimated = true;
     145               0 :   aSVGElement->DidAnimateEnum(mAttrEnum);
     146               0 : }
     147                 : 
     148                 : nsresult
     149               0 : nsSVGEnum::ToDOMAnimatedEnum(nsIDOMSVGAnimatedEnumeration **aResult,
     150                 :                              nsSVGElement *aSVGElement)
     151                 : {
     152               0 :   *aResult = new DOMAnimatedEnum(this, aSVGElement);
     153               0 :   if (!*aResult)
     154               0 :     return NS_ERROR_OUT_OF_MEMORY;
     155                 : 
     156               0 :   NS_ADDREF(*aResult);
     157               0 :   return NS_OK;
     158                 : }
     159                 : 
     160                 : nsISMILAttr*
     161               0 : nsSVGEnum::ToSMILAttr(nsSVGElement *aSVGElement)
     162                 : {
     163               0 :   return new SMILEnum(this, aSVGElement);
     164                 : }
     165                 : 
     166                 : nsresult
     167               0 : nsSVGEnum::SMILEnum::ValueFromString(const nsAString& aStr,
     168                 :                                      const nsISMILAnimationElement* /*aSrcElement*/,
     169                 :                                      nsSMILValue& aValue,
     170                 :                                      bool& aPreventCachingOfSandwich) const
     171                 : {
     172               0 :   nsCOMPtr<nsIAtom> valAtom = do_GetAtom(aStr);
     173               0 :   nsSVGEnumMapping *mapping = mVal->GetMapping(mSVGElement);
     174                 : 
     175               0 :   while (mapping && mapping->mKey) {
     176               0 :     if (valAtom == *(mapping->mKey)) {
     177               0 :       nsSMILValue val(&SMILEnumType::sSingleton);
     178               0 :       val.mU.mUint = mapping->mVal;
     179               0 :       aValue = val;
     180               0 :       aPreventCachingOfSandwich = false;
     181               0 :       return NS_OK;
     182                 :     }
     183               0 :     mapping++;
     184                 :   }
     185                 :   
     186                 :   // only a warning since authors may mistype attribute values
     187               0 :   NS_WARNING("unknown enumeration key");
     188               0 :   return NS_ERROR_FAILURE;
     189                 : }
     190                 : 
     191                 : nsSMILValue
     192               0 : nsSVGEnum::SMILEnum::GetBaseValue() const
     193                 : {
     194               0 :   nsSMILValue val(&SMILEnumType::sSingleton);
     195               0 :   val.mU.mUint = mVal->mBaseVal;
     196                 :   return val;
     197                 : }
     198                 : 
     199                 : void
     200               0 : nsSVGEnum::SMILEnum::ClearAnimValue()
     201                 : {
     202               0 :   if (mVal->mIsAnimated) {
     203               0 :     mVal->mIsAnimated = false;
     204               0 :     mVal->mAnimVal = mVal->mBaseVal;
     205               0 :     mSVGElement->DidAnimateEnum(mVal->mAttrEnum);
     206                 :   }
     207               0 : }
     208                 : 
     209                 : nsresult
     210               0 : nsSVGEnum::SMILEnum::SetAnimValue(const nsSMILValue& aValue)
     211                 : {
     212               0 :   NS_ASSERTION(aValue.mType == &SMILEnumType::sSingleton,
     213                 :                "Unexpected type to assign animated value");
     214               0 :   if (aValue.mType == &SMILEnumType::sSingleton) {
     215               0 :     NS_ABORT_IF_FALSE(aValue.mU.mUint <= USHRT_MAX,
     216                 :                       "Very large enumerated value - too big for PRUint16");
     217               0 :     mVal->SetAnimValue(PRUint16(aValue.mU.mUint), mSVGElement);
     218                 :   }
     219               0 :   return NS_OK;
     220            4392 : }

Generated by: LCOV version 1.7