LCOV - code coverage report
Current view: directory - content/svg/content/src - nsSVGAngle.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 250 4 1.6 %
Date: 2012-06-02 Functions: 54 2 3.7 %

       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) 2004
      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 "mozilla/Util.h"
      38                 : 
      39                 : #include "nsSVGAngle.h"
      40                 : #include "prdtoa.h"
      41                 : #include "nsTextFormatter.h"
      42                 : #include "nsSVGUtils.h"
      43                 : #include "nsSVGMarkerElement.h"
      44                 : #include "nsMathUtils.h"
      45                 : #include "nsContentUtils.h" // NS_ENSURE_FINITE
      46                 : #include "nsSMILValue.h"
      47                 : #include "SVGOrientSMILType.h"
      48                 : 
      49                 : using namespace mozilla;
      50                 : 
      51                 : /**
      52                 :  * Mutable SVGAngle class for SVGSVGElement.createSVGAngle().
      53                 :  *
      54                 :  * Note that this class holds its own nsSVGAngle, which therefore can't be
      55                 :  * animated. This means SVGMarkerElement::setOrientToAngle(angle) must copy
      56                 :  * any DOMSVGAngle passed in. Perhaps this is wrong and inconsistent with
      57                 :  * other parts of SVG, but it's how the code works for now.
      58                 :  */
      59                 : class DOMSVGAngle : public nsIDOMSVGAngle
      60                 : {
      61                 : public:
      62                 :   NS_DECL_ISUPPORTS
      63                 : 
      64               0 :   DOMSVGAngle()
      65               0 :     { mVal.Init(); }
      66                 :     
      67               0 :   NS_IMETHOD GetUnitType(PRUint16* aResult)
      68               0 :     { *aResult = mVal.mBaseValUnit; return NS_OK; }
      69                 : 
      70               0 :   NS_IMETHOD GetValue(float* aResult)
      71               0 :     { *aResult = mVal.GetBaseValue(); return NS_OK; }
      72               0 :   NS_IMETHOD SetValue(float aValue)
      73                 :     {
      74               0 :       NS_ENSURE_FINITE(aValue, NS_ERROR_ILLEGAL_VALUE);
      75               0 :       mVal.SetBaseValue(aValue, nsnull, false);
      76               0 :       return NS_OK;
      77                 :     }
      78                 : 
      79               0 :   NS_IMETHOD GetValueInSpecifiedUnits(float* aResult)
      80               0 :     { *aResult = mVal.mBaseVal; return NS_OK; }
      81               0 :   NS_IMETHOD SetValueInSpecifiedUnits(float aValue)
      82                 :     {
      83               0 :       NS_ENSURE_FINITE(aValue, NS_ERROR_ILLEGAL_VALUE);
      84               0 :       mVal.mBaseVal = aValue;
      85               0 :       return NS_OK;
      86                 :     }
      87                 : 
      88               0 :   NS_IMETHOD SetValueAsString(const nsAString& aValue)
      89               0 :     { return mVal.SetBaseValueString(aValue, nsnull, false); }
      90               0 :   NS_IMETHOD GetValueAsString(nsAString& aValue)
      91               0 :     { mVal.GetBaseValueString(aValue); return NS_OK; }
      92                 : 
      93               0 :   NS_IMETHOD NewValueSpecifiedUnits(PRUint16 unitType,
      94                 :                                     float valueInSpecifiedUnits)
      95                 :     {
      96               0 :       return mVal.NewValueSpecifiedUnits(unitType, valueInSpecifiedUnits, nsnull);
      97                 :     }
      98                 : 
      99               0 :   NS_IMETHOD ConvertToSpecifiedUnits(PRUint16 unitType)
     100               0 :     { return mVal.ConvertToSpecifiedUnits(unitType, nsnull); }
     101                 : 
     102                 : private:
     103                 :   nsSVGAngle mVal;
     104                 : };
     105                 : 
     106            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGAngle::DOMBaseVal, mSVGElement)
     107                 : 
     108            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGAngle::DOMAnimVal, mSVGElement)
     109                 : 
     110            1464 : NS_SVG_VAL_IMPL_CYCLE_COLLECTION(nsSVGAngle::DOMAnimatedAngle, mSVGElement)
     111                 : 
     112               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGAngle::DOMBaseVal)
     113               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGAngle::DOMBaseVal)
     114                 : 
     115               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGAngle::DOMAnimVal)
     116               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGAngle::DOMAnimVal)
     117                 : 
     118               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsSVGAngle::DOMAnimatedAngle)
     119               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGAngle::DOMAnimatedAngle)
     120                 : 
     121               0 : NS_IMPL_ADDREF(DOMSVGAngle)
     122               0 : NS_IMPL_RELEASE(DOMSVGAngle)
     123                 : 
     124                 : DOMCI_DATA(SVGAngle, nsSVGAngle::DOMBaseVal)
     125                 : DOMCI_DATA(SVGAnimatedAngle, nsSVGAngle::DOMAnimatedAngle)
     126                 : 
     127               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGAngle::DOMBaseVal)
     128               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAngle)
     129               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     130               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAngle)
     131               0 : NS_INTERFACE_MAP_END
     132                 : 
     133               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGAngle::DOMAnimVal)
     134               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAngle)
     135               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     136               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAngle)
     137               0 : NS_INTERFACE_MAP_END
     138                 : 
     139               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGAngle::DOMAnimatedAngle)
     140               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedAngle)
     141               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     142               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAnimatedAngle)
     143               0 : NS_INTERFACE_MAP_END
     144                 : 
     145               0 : NS_INTERFACE_MAP_BEGIN(DOMSVGAngle)
     146               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAngle)
     147               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
     148               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGAngle)
     149               0 : NS_INTERFACE_MAP_END
     150                 : 
     151                 : static nsIAtom** const unitMap[] =
     152                 : {
     153                 :   nsnull, /* SVG_ANGLETYPE_UNKNOWN */
     154                 :   nsnull, /* SVG_ANGLETYPE_UNSPECIFIED */
     155                 :   &nsGkAtoms::deg,
     156                 :   &nsGkAtoms::rad,
     157                 :   &nsGkAtoms::grad
     158                 : };
     159                 : 
     160                 : /* Helper functions */
     161                 : 
     162                 : static bool
     163               0 : IsValidUnitType(PRUint16 unit)
     164                 : {
     165               0 :   if (unit > nsIDOMSVGAngle::SVG_ANGLETYPE_UNKNOWN &&
     166                 :       unit <= nsIDOMSVGAngle::SVG_ANGLETYPE_GRAD)
     167               0 :     return true;
     168                 : 
     169               0 :   return false;
     170                 : }
     171                 : 
     172                 : static void 
     173               0 : GetUnitString(nsAString& unit, PRUint16 unitType)
     174                 : {
     175               0 :   if (IsValidUnitType(unitType)) {
     176               0 :     if (unitMap[unitType]) {
     177               0 :       (*unitMap[unitType])->ToString(unit);
     178                 :     }
     179               0 :     return;
     180                 :   }
     181                 : 
     182               0 :   NS_NOTREACHED("Unknown unit type");
     183               0 :   return;
     184                 : }
     185                 : 
     186                 : static PRUint16
     187               0 : GetUnitTypeForString(const char* unitStr)
     188                 : {
     189               0 :   if (!unitStr || *unitStr == '\0') 
     190               0 :     return nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED;
     191                 :                    
     192               0 :   nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
     193                 : 
     194               0 :   for (PRUint32 i = 0 ; i < ArrayLength(unitMap) ; i++) {
     195               0 :     if (unitMap[i] && *unitMap[i] == unitAtom) {
     196               0 :       return i;
     197                 :     }
     198                 :   }
     199                 : 
     200               0 :   return nsIDOMSVGAngle::SVG_ANGLETYPE_UNKNOWN;
     201                 : }
     202                 : 
     203                 : static void
     204               0 : GetValueString(nsAString &aValueAsString, float aValue, PRUint16 aUnitType)
     205                 : {
     206                 :   PRUnichar buf[24];
     207                 :   nsTextFormatter::snprintf(buf, sizeof(buf)/sizeof(PRUnichar),
     208               0 :                             NS_LITERAL_STRING("%g").get(),
     209               0 :                             (double)aValue);
     210               0 :   aValueAsString.Assign(buf);
     211                 : 
     212               0 :   nsAutoString unitString;
     213               0 :   GetUnitString(unitString, aUnitType);
     214               0 :   aValueAsString.Append(unitString);
     215               0 : }
     216                 : 
     217                 : static nsresult
     218               0 : GetValueFromString(const nsAString &aValueAsString,
     219                 :                    float *aValue,
     220                 :                    PRUint16 *aUnitType)
     221                 : {
     222               0 :   NS_ConvertUTF16toUTF8 value(aValueAsString);
     223               0 :   const char *str = value.get();
     224                 : 
     225               0 :   if (NS_IsAsciiWhitespace(*str))
     226               0 :     return NS_ERROR_DOM_SYNTAX_ERR;
     227                 :   
     228                 :   char *rest;
     229               0 :   *aValue = float(PR_strtod(str, &rest));
     230               0 :   if (rest != str && NS_finite(*aValue)) {
     231               0 :     *aUnitType = GetUnitTypeForString(rest);
     232               0 :     if (IsValidUnitType(*aUnitType)) {
     233               0 :       return NS_OK;
     234                 :     }
     235                 :   }
     236                 :   
     237               0 :   return NS_ERROR_DOM_SYNTAX_ERR;
     238                 : }
     239                 : 
     240                 : /* static */ float
     241               0 : nsSVGAngle::GetDegreesPerUnit(PRUint8 aUnit)
     242                 : {
     243               0 :   switch (aUnit) {
     244                 :   case nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED:
     245                 :   case nsIDOMSVGAngle::SVG_ANGLETYPE_DEG:
     246               0 :     return 1;
     247                 :   case nsIDOMSVGAngle::SVG_ANGLETYPE_RAD:
     248               0 :     return static_cast<float>(180.0 / M_PI);
     249                 :   case nsIDOMSVGAngle::SVG_ANGLETYPE_GRAD:
     250               0 :     return 90.0f / 100.0f;
     251                 :   default:
     252               0 :     NS_NOTREACHED("Unknown unit type");
     253               0 :     return 0;
     254                 :   }
     255                 : }
     256                 : 
     257                 : void
     258               0 : nsSVGAngle::SetBaseValueInSpecifiedUnits(float aValue,
     259                 :                                          nsSVGElement *aSVGElement)
     260                 : {
     261               0 :   if (mBaseVal == aValue) {
     262               0 :     return;
     263                 :   }
     264                 : 
     265               0 :   nsAttrValue emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
     266               0 :   mBaseVal = aValue;
     267               0 :   if (!mIsAnimated) {
     268               0 :     mAnimVal = mBaseVal;
     269                 :   }
     270                 :   else {
     271               0 :     aSVGElement->AnimationNeedsResample();
     272                 :   }
     273               0 :   aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
     274                 : }
     275                 : 
     276                 : nsresult
     277               0 : nsSVGAngle::ConvertToSpecifiedUnits(PRUint16 unitType,
     278                 :                                     nsSVGElement *aSVGElement)
     279                 : {
     280               0 :   if (!IsValidUnitType(unitType))
     281               0 :     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     282                 : 
     283               0 :   if (mBaseValUnit == PRUint8(unitType))
     284               0 :     return NS_OK;
     285                 : 
     286               0 :   nsAttrValue emptyOrOldValue;
     287               0 :   if (aSVGElement) {
     288               0 :     emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
     289                 :   }
     290                 : 
     291               0 :   float valueInUserUnits = mBaseVal * GetDegreesPerUnit(mBaseValUnit);
     292               0 :   mBaseValUnit = PRUint8(unitType);
     293                 :   // Setting aDoSetAttr to false here will ensure we don't call
     294                 :   // Will/DidChangeAngle a second time (and dispatch duplicate notifications).
     295               0 :   SetBaseValue(valueInUserUnits, aSVGElement, false);
     296                 : 
     297               0 :   if (aSVGElement) {
     298               0 :     aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
     299                 :   }
     300                 : 
     301               0 :   return NS_OK;
     302                 : }
     303                 : 
     304                 : nsresult
     305               0 : nsSVGAngle::NewValueSpecifiedUnits(PRUint16 unitType,
     306                 :                                    float valueInSpecifiedUnits,
     307                 :                                    nsSVGElement *aSVGElement)
     308                 : {
     309               0 :   NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
     310                 : 
     311               0 :   if (!IsValidUnitType(unitType))
     312               0 :     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
     313                 : 
     314               0 :   if (mBaseVal == valueInSpecifiedUnits && mBaseValUnit == PRUint8(unitType))
     315               0 :     return NS_OK;
     316                 : 
     317               0 :   nsAttrValue emptyOrOldValue;
     318               0 :   if (aSVGElement) {
     319               0 :     emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
     320                 :   }
     321               0 :   mBaseVal = valueInSpecifiedUnits;
     322               0 :   mBaseValUnit = PRUint8(unitType);
     323               0 :   if (!mIsAnimated) {
     324               0 :     mAnimVal = mBaseVal;
     325               0 :     mAnimValUnit = mBaseValUnit;
     326                 :   }
     327                 :   else {
     328               0 :     aSVGElement->AnimationNeedsResample();
     329                 :   }
     330               0 :   if (aSVGElement) {
     331               0 :     aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
     332                 :   }
     333               0 :   return NS_OK;
     334                 : }
     335                 : 
     336                 : nsresult
     337               0 : nsSVGAngle::ToDOMBaseVal(nsIDOMSVGAngle **aResult, nsSVGElement *aSVGElement)
     338                 : {
     339               0 :   *aResult = new DOMBaseVal(this, aSVGElement);
     340               0 :   if (!*aResult)
     341               0 :     return NS_ERROR_OUT_OF_MEMORY;
     342                 : 
     343               0 :   NS_ADDREF(*aResult);
     344               0 :   return NS_OK;
     345                 : }
     346                 : 
     347                 : nsresult
     348               0 : nsSVGAngle::ToDOMAnimVal(nsIDOMSVGAngle **aResult, nsSVGElement *aSVGElement)
     349                 : {
     350               0 :   *aResult = new DOMAnimVal(this, aSVGElement);
     351               0 :   if (!*aResult)
     352               0 :     return NS_ERROR_OUT_OF_MEMORY;
     353                 : 
     354               0 :   NS_ADDREF(*aResult);
     355               0 :   return NS_OK;
     356                 : }
     357                 : 
     358                 : /* Implementation */
     359                 : 
     360                 : nsresult
     361               0 : nsSVGAngle::SetBaseValueString(const nsAString &aValueAsString,
     362                 :                                nsSVGElement *aSVGElement,
     363                 :                                bool aDoSetAttr)
     364                 : {
     365               0 :   float value = 0;
     366               0 :   PRUint16 unitType = 0;
     367                 :   
     368               0 :   nsresult rv = GetValueFromString(aValueAsString, &value, &unitType);
     369               0 :   if (NS_FAILED(rv)) {
     370               0 :     return rv;
     371                 :   }
     372               0 :   if (mBaseVal == value && mBaseValUnit == PRUint8(unitType)) {
     373               0 :     return NS_OK;
     374                 :   }
     375                 : 
     376               0 :   nsAttrValue emptyOrOldValue;
     377               0 :   if (aDoSetAttr) {
     378               0 :     emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
     379                 :   }
     380               0 :   mBaseVal = value;
     381               0 :   mBaseValUnit = PRUint8(unitType);
     382               0 :   if (!mIsAnimated) {
     383               0 :     mAnimVal = mBaseVal;
     384               0 :     mAnimValUnit = mBaseValUnit;
     385                 :   }
     386                 :   else {
     387               0 :     aSVGElement->AnimationNeedsResample();
     388                 :   }
     389                 : 
     390               0 :   if (aDoSetAttr) {
     391               0 :     aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
     392                 :   }
     393               0 :   return NS_OK;
     394                 : }
     395                 : 
     396                 : void
     397               0 : nsSVGAngle::GetBaseValueString(nsAString & aValueAsString) const
     398                 : {
     399               0 :   GetValueString(aValueAsString, mBaseVal, mBaseValUnit);
     400               0 : }
     401                 : 
     402                 : void
     403               0 : nsSVGAngle::GetAnimValueString(nsAString & aValueAsString) const
     404                 : {
     405               0 :   GetValueString(aValueAsString, mAnimVal, mAnimValUnit);
     406               0 : }
     407                 : 
     408                 : void
     409               0 : nsSVGAngle::SetBaseValue(float aValue, nsSVGElement *aSVGElement,
     410                 :                          bool aDoSetAttr)
     411                 : {
     412               0 :   if (mBaseVal == aValue * GetDegreesPerUnit(mBaseValUnit)) {
     413               0 :     return;
     414                 :   }
     415               0 :   nsAttrValue emptyOrOldValue;
     416               0 :   if (aSVGElement && aDoSetAttr) {
     417               0 :     emptyOrOldValue = aSVGElement->WillChangeAngle(mAttrEnum);
     418                 :   }
     419                 : 
     420               0 :   mBaseVal = aValue / GetDegreesPerUnit(mBaseValUnit);
     421               0 :   if (!mIsAnimated) {
     422               0 :     mAnimVal = mBaseVal;
     423                 :   }
     424                 :   else {
     425               0 :     aSVGElement->AnimationNeedsResample();
     426                 :   }
     427               0 :   if (aSVGElement && aDoSetAttr) {
     428               0 :     aSVGElement->DidChangeAngle(mAttrEnum, emptyOrOldValue);
     429                 :   }
     430                 : }
     431                 : 
     432                 : void
     433               0 : nsSVGAngle::SetAnimValue(float aValue, PRUint8 aUnit, nsSVGElement *aSVGElement)
     434                 : {
     435               0 :   mAnimVal = aValue;
     436               0 :   mAnimValUnit = aUnit;
     437               0 :   mIsAnimated = true;
     438               0 :   aSVGElement->DidAnimateAngle(mAttrEnum);
     439               0 : }
     440                 : 
     441                 : nsresult
     442               0 : nsSVGAngle::ToDOMAnimatedAngle(nsIDOMSVGAnimatedAngle **aResult,
     443                 :                                nsSVGElement *aSVGElement)
     444                 : {
     445               0 :   *aResult = new DOMAnimatedAngle(this, aSVGElement);
     446               0 :   if (!*aResult)
     447               0 :     return NS_ERROR_OUT_OF_MEMORY;
     448                 : 
     449               0 :   NS_ADDREF(*aResult);
     450               0 :   return NS_OK;
     451                 : }
     452                 : 
     453                 : nsresult
     454               0 : NS_NewDOMSVGAngle(nsIDOMSVGAngle** aResult)
     455                 : {
     456               0 :   *aResult = new DOMSVGAngle;
     457               0 :   if (!*aResult)
     458               0 :     return NS_ERROR_OUT_OF_MEMORY;
     459                 : 
     460               0 :   NS_ADDREF(*aResult);
     461               0 :   return NS_OK;
     462                 : }
     463                 : 
     464                 : nsISMILAttr*
     465               0 : nsSVGAngle::ToSMILAttr(nsSVGElement *aSVGElement)
     466                 : {
     467               0 :   if (aSVGElement->NodeInfo()->Equals(nsGkAtoms::marker, kNameSpaceID_SVG)) {
     468               0 :     nsSVGMarkerElement *marker = static_cast<nsSVGMarkerElement*>(aSVGElement);
     469               0 :     return new SMILOrient(marker->GetOrientType(), this, aSVGElement);
     470                 :   }
     471                 :   // SMILOrient would not be useful for general angle attributes (also,
     472                 :   // "orient" is the only animatable <angle>-valued attribute in SVG 1.1).
     473               0 :   NS_NOTREACHED("Trying to animate unknown angle attribute.");
     474               0 :   return nsnull;
     475                 : }
     476                 : 
     477                 : nsresult
     478               0 : nsSVGAngle::SMILOrient::ValueFromString(const nsAString& aStr,
     479                 :                                         const nsISMILAnimationElement* /*aSrcElement*/,
     480                 :                                         nsSMILValue& aValue,
     481                 :                                         bool& aPreventCachingOfSandwich) const
     482                 : {
     483               0 :   nsSMILValue val(&SVGOrientSMILType::sSingleton);
     484               0 :   if (aStr.EqualsLiteral("auto")) {
     485               0 :     val.mU.mOrient.mOrientType = nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_AUTO;
     486                 :   } else {
     487                 :     float value;
     488                 :     PRUint16 unitType;
     489               0 :     nsresult rv = GetValueFromString(aStr, &value, &unitType);
     490               0 :     if (NS_FAILED(rv)) {
     491               0 :       return rv;
     492                 :     }
     493               0 :     val.mU.mOrient.mAngle = value;
     494               0 :     val.mU.mOrient.mUnit = unitType;
     495               0 :     val.mU.mOrient.mOrientType = nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE;
     496                 :   }
     497               0 :   aValue.Swap(val);
     498               0 :   aPreventCachingOfSandwich = false;
     499                 : 
     500               0 :   return NS_OK;
     501                 : }
     502                 : 
     503                 : nsSMILValue
     504               0 : nsSVGAngle::SMILOrient::GetBaseValue() const
     505                 : {
     506               0 :   nsSMILValue val(&SVGOrientSMILType::sSingleton);
     507               0 :   val.mU.mOrient.mAngle = mAngle->GetBaseValInSpecifiedUnits();
     508               0 :   val.mU.mOrient.mUnit = mAngle->GetBaseValueUnit();
     509               0 :   val.mU.mOrient.mOrientType = mOrientType->GetBaseValue();
     510                 :   return val;
     511                 : }
     512                 : 
     513                 : void
     514               0 : nsSVGAngle::SMILOrient::ClearAnimValue()
     515                 : {
     516               0 :   if (mAngle->mIsAnimated) {
     517               0 :     mOrientType->SetAnimValue(mOrientType->GetBaseValue());
     518               0 :     mAngle->mIsAnimated = false;
     519               0 :     mAngle->mAnimVal = mAngle->mBaseVal;
     520               0 :     mAngle->mAnimValUnit = mAngle->mBaseValUnit;
     521               0 :     mSVGElement->DidAnimateAngle(mAngle->mAttrEnum);
     522                 :   }
     523               0 : }
     524                 : 
     525                 : nsresult
     526               0 : nsSVGAngle::SMILOrient::SetAnimValue(const nsSMILValue& aValue)
     527                 : {
     528               0 :   NS_ASSERTION(aValue.mType == &SVGOrientSMILType::sSingleton,
     529                 :                "Unexpected type to assign animated value");
     530                 : 
     531               0 :   if (aValue.mType == &SVGOrientSMILType::sSingleton) {
     532               0 :     mOrientType->SetAnimValue(aValue.mU.mOrient.mOrientType);
     533               0 :     if (aValue.mU.mOrient.mOrientType == nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_AUTO) {
     534               0 :       mAngle->SetAnimValue(0.0f, nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED, mSVGElement);
     535                 :     } else {
     536               0 :       mAngle->SetAnimValue(aValue.mU.mOrient.mAngle, aValue.mU.mOrient.mUnit, mSVGElement);
     537                 :     }
     538                 :   }
     539               0 :   return NS_OK;
     540            4392 : }

Generated by: LCOV version 1.7