LCOV - code coverage report
Current view: directory - content/svg/content/src - SVGAnimatedPathSegList.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 75 0 0.0 %
Date: 2012-06-02 Functions: 9 0 0.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 Mozilla SVG Project code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      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 "SVGAnimatedPathSegList.h"
      38                 : #include "DOMSVGPathSegList.h"
      39                 : #include "nsSVGElement.h"
      40                 : #include "nsSVGAttrTearoffTable.h"
      41                 : #include "nsSMILValue.h"
      42                 : #include "SVGPathSegListSMILType.h"
      43                 : 
      44                 : // See the comments in this file's header!
      45                 : 
      46                 : namespace mozilla {
      47                 : 
      48                 : nsresult
      49               0 : SVGAnimatedPathSegList::SetBaseValueString(const nsAString& aValue)
      50                 : {
      51               0 :   SVGPathData newBaseValue;
      52                 : 
      53                 :   // The spec says that the path data is parsed and accepted up to the first
      54                 :   // error encountered, so we don't return early if an error occurs. However,
      55                 :   // we do want to throw any error code from setAttribute if there's a problem.
      56                 : 
      57               0 :   nsresult rv = newBaseValue.SetValueFromString(aValue);
      58                 : 
      59                 :   // We must send these notifications *before* changing mBaseVal! Our baseVal's
      60                 :   // DOM wrapper list may have to remove DOM items from itself, and any removed
      61                 :   // DOM items need to copy their internal counterpart's values *before* we
      62                 :   // change them. See the comments in
      63                 :   // DOMSVGPathSegList::InternalListWillChangeTo().
      64                 : 
      65                 :   DOMSVGPathSegList *baseValWrapper =
      66               0 :     DOMSVGPathSegList::GetDOMWrapperIfExists(GetBaseValKey());
      67               0 :   if (baseValWrapper) {
      68               0 :     baseValWrapper->InternalListWillChangeTo(newBaseValue);
      69                 :   }
      70                 : 
      71               0 :   DOMSVGPathSegList* animValWrapper = nsnull;
      72               0 :   if (!IsAnimating()) {  // DOM anim val wraps our base val too!
      73               0 :     animValWrapper = DOMSVGPathSegList::GetDOMWrapperIfExists(GetAnimValKey());
      74               0 :     if (animValWrapper) {
      75               0 :       animValWrapper->InternalListWillChangeTo(newBaseValue);
      76                 :     }
      77                 :   }
      78                 : 
      79                 :   // Only now may we modify mBaseVal!
      80                 : 
      81                 :   // We don't need to call DidChange* here - we're only called by
      82                 :   // nsSVGElement::ParseAttribute under nsGenericElement::SetAttr,
      83                 :   // which takes care of notifying.
      84                 : 
      85               0 :   nsresult rv2 = mBaseVal.CopyFrom(newBaseValue);
      86               0 :   if (NS_FAILED(rv2)) {
      87                 :     // Attempting to increase mBaseVal's length failed (mBaseVal is left
      88                 :     // unmodified). We MUST keep any DOM wrappers in sync:
      89               0 :     if (baseValWrapper) {
      90               0 :       baseValWrapper->InternalListWillChangeTo(mBaseVal);
      91                 :     }
      92               0 :     if (animValWrapper) {
      93               0 :       animValWrapper->InternalListWillChangeTo(mBaseVal);
      94                 :     }
      95               0 :     return rv2;
      96                 :   }
      97               0 :   return rv;
      98                 : }
      99                 : 
     100                 : void
     101               0 : SVGAnimatedPathSegList::ClearBaseValue()
     102                 : {
     103                 :   // We must send these notifications *before* changing mBaseVal! (See above.)
     104                 : 
     105                 :   DOMSVGPathSegList *baseValWrapper =
     106               0 :     DOMSVGPathSegList::GetDOMWrapperIfExists(GetBaseValKey());
     107               0 :   if (baseValWrapper) {
     108               0 :     baseValWrapper->InternalListWillChangeTo(SVGPathData());
     109                 :   }
     110                 : 
     111               0 :   if (!IsAnimating()) { // DOM anim val wraps our base val too!
     112                 :     DOMSVGPathSegList *animValWrapper =
     113               0 :       DOMSVGPathSegList::GetDOMWrapperIfExists(GetAnimValKey());
     114               0 :     if (animValWrapper) {
     115               0 :       animValWrapper->InternalListWillChangeTo(SVGPathData());
     116                 :     }
     117                 :   }
     118                 : 
     119               0 :   mBaseVal.Clear();
     120                 :   // Caller notifies
     121               0 : }
     122                 : 
     123                 : nsresult
     124               0 : SVGAnimatedPathSegList::SetAnimValue(const SVGPathData& aNewAnimValue,
     125                 :                                      nsSVGElement *aElement)
     126                 : {
     127                 :   // Note that a new animation may totally change the number of items in the
     128                 :   // animVal list, either replacing what was essentially a mirror of the
     129                 :   // baseVal list, or else replacing and overriding an existing animation.
     130                 :   // Unfortunately it is not possible for us to reliably distinguish between
     131                 :   // calls to this method that are setting a new sample for an existing
     132                 :   // animation, and calls that are setting the first sample of an animation
     133                 :   // that will override an existing animation. In the case of DOMSVGPathSegList
     134                 :   // the InternalListWillChangeTo method is not virtually free as it is for the
     135                 :   // other DOM list classes, so this is a shame. We'd quite like to be able to
     136                 :   // skip the call if possible.
     137                 : 
     138                 :   // We must send these notifications *before* changing mAnimVal! (See above.)
     139                 : 
     140                 :   DOMSVGPathSegList *domWrapper =
     141               0 :     DOMSVGPathSegList::GetDOMWrapperIfExists(GetAnimValKey());
     142               0 :   if (domWrapper) {
     143               0 :     domWrapper->InternalListWillChangeTo(aNewAnimValue);
     144                 :   }
     145               0 :   if (!mAnimVal) {
     146               0 :     mAnimVal = new SVGPathData();
     147                 :   }
     148               0 :   nsresult rv = mAnimVal->CopyFrom(aNewAnimValue);
     149               0 :   if (NS_FAILED(rv)) {
     150                 :     // OOM. We clear the animation and, importantly, ClearAnimValue() ensures
     151                 :     // that mAnimVal's DOM wrapper (if any) is kept in sync!
     152               0 :     ClearAnimValue(aElement);
     153                 :   }
     154               0 :   aElement->DidAnimatePathSegList();
     155               0 :   return rv;
     156                 : }
     157                 : 
     158                 : void
     159               0 : SVGAnimatedPathSegList::ClearAnimValue(nsSVGElement *aElement)
     160                 : {
     161                 :   // We must send these notifications *before* changing mAnimVal! (See above.)
     162                 : 
     163                 :   DOMSVGPathSegList *domWrapper =
     164               0 :     DOMSVGPathSegList::GetDOMWrapperIfExists(GetAnimValKey());
     165               0 :   if (domWrapper) {
     166                 :     // When all animation ends, animVal simply mirrors baseVal, which may have
     167                 :     // a different number of items to the last active animated value.
     168                 :     //
     169               0 :     domWrapper->InternalListWillChangeTo(mBaseVal);
     170                 :   }
     171               0 :   mAnimVal = nsnull;
     172               0 :   aElement->DidAnimatePathSegList();
     173               0 : }
     174                 : 
     175                 : nsISMILAttr*
     176               0 : SVGAnimatedPathSegList::ToSMILAttr(nsSVGElement *aElement)
     177                 : {
     178               0 :   return new SMILAnimatedPathSegList(this, aElement);
     179                 : }
     180                 : 
     181                 : nsresult
     182               0 : SVGAnimatedPathSegList::
     183                 :   SMILAnimatedPathSegList::ValueFromString(const nsAString& aStr,
     184                 :                                const nsISMILAnimationElement* /*aSrcElement*/,
     185                 :                                nsSMILValue& aValue,
     186                 :                                bool& aPreventCachingOfSandwich) const
     187                 : {
     188               0 :   nsSMILValue val(&SVGPathSegListSMILType::sSingleton);
     189               0 :   SVGPathDataAndOwner *list = static_cast<SVGPathDataAndOwner*>(val.mU.mPtr);
     190               0 :   nsresult rv = list->SetValueFromString(aStr);
     191               0 :   if (NS_SUCCEEDED(rv)) {
     192               0 :     list->SetElement(mElement);
     193               0 :     aValue.Swap(val);
     194                 :   }
     195               0 :   aPreventCachingOfSandwich = false;
     196               0 :   return rv;
     197                 : }
     198                 : 
     199                 : nsSMILValue
     200               0 : SVGAnimatedPathSegList::SMILAnimatedPathSegList::GetBaseValue() const
     201                 : {
     202                 :   // To benefit from Return Value Optimization and avoid copy constructor calls
     203                 :   // due to our use of return-by-value, we must return the exact same object
     204                 :   // from ALL return points. This function must only return THIS variable:
     205               0 :   nsSMILValue val;
     206                 : 
     207               0 :   nsSMILValue tmp(&SVGPathSegListSMILType::sSingleton);
     208               0 :   SVGPathDataAndOwner *list = static_cast<SVGPathDataAndOwner*>(tmp.mU.mPtr);
     209               0 :   nsresult rv = list->CopyFrom(mVal->mBaseVal);
     210               0 :   if (NS_SUCCEEDED(rv)) {
     211               0 :     list->SetElement(mElement);
     212               0 :     val.Swap(tmp);
     213                 :   }
     214                 :   return val;
     215                 : }
     216                 : 
     217                 : nsresult
     218               0 : SVGAnimatedPathSegList::SMILAnimatedPathSegList::SetAnimValue(const nsSMILValue& aValue)
     219                 : {
     220               0 :   NS_ASSERTION(aValue.mType == &SVGPathSegListSMILType::sSingleton,
     221                 :                "Unexpected type to assign animated value");
     222               0 :   if (aValue.mType == &SVGPathSegListSMILType::sSingleton) {
     223                 :     mVal->SetAnimValue(*static_cast<SVGPathDataAndOwner*>(aValue.mU.mPtr),
     224               0 :                        mElement);
     225                 :   }
     226               0 :   return NS_OK;
     227                 : }
     228                 : 
     229                 : void
     230               0 : SVGAnimatedPathSegList::SMILAnimatedPathSegList::ClearAnimValue()
     231                 : {
     232               0 :   if (mVal->mAnimVal) {
     233               0 :     mVal->ClearAnimValue(mElement);
     234                 :   }
     235               0 : }
     236                 : 
     237                 : } // namespace mozilla

Generated by: LCOV version 1.7