LCOV - code coverage report
Current view: directory - content/svg/content/src - SVGAnimatedPointList.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 76 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 "SVGAnimatedPointList.h"
      38                 : #include "DOMSVGPointList.h"
      39                 : #include "nsSVGElement.h"
      40                 : #include "nsSVGAttrTearoffTable.h"
      41                 : #include "nsSMILValue.h"
      42                 : #include "SVGPointListSMILType.h"
      43                 : 
      44                 : // See the comments in this file's header!
      45                 : 
      46                 : namespace mozilla {
      47                 : 
      48                 : nsresult
      49               0 : SVGAnimatedPointList::SetBaseValueString(const nsAString& aValue)
      50                 : {
      51               0 :   SVGPointList newBaseValue;
      52                 : 
      53                 :   // The spec says that the point 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                 :   // DOMSVGPointList::InternalListWillChangeTo().
      64                 : 
      65                 :   DOMSVGPointList *baseValWrapper =
      66               0 :     DOMSVGPointList::GetDOMWrapperIfExists(GetBaseValKey());
      67               0 :   if (baseValWrapper) {
      68               0 :     baseValWrapper->InternalListWillChangeTo(newBaseValue);
      69                 :   }
      70                 : 
      71               0 :   DOMSVGPointList* animValWrapper = nsnull;
      72               0 :   if (!IsAnimating()) {  // DOM anim val wraps our base val too!
      73               0 :     animValWrapper = DOMSVGPointList::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 : SVGAnimatedPointList::ClearBaseValue()
     102                 : {
     103                 :   // We must send these notifications *before* changing mBaseVal! (See above.)
     104                 : 
     105                 :   DOMSVGPointList *baseValWrapper =
     106               0 :     DOMSVGPointList::GetDOMWrapperIfExists(GetBaseValKey());
     107               0 :   if (baseValWrapper) {
     108               0 :     baseValWrapper->InternalListWillChangeTo(SVGPointList());
     109                 :   }
     110                 : 
     111               0 :   if (!IsAnimating()) { // DOM anim val wraps our base val too!
     112                 :     DOMSVGPointList *animValWrapper =
     113               0 :       DOMSVGPointList::GetDOMWrapperIfExists(GetAnimValKey());
     114               0 :     if (animValWrapper) {
     115               0 :       animValWrapper->InternalListWillChangeTo(SVGPointList());
     116                 :     }
     117                 :   }
     118                 : 
     119               0 :   mBaseVal.Clear();
     120                 :   // Caller notifies
     121               0 : }
     122                 : 
     123                 : nsresult
     124               0 : SVGAnimatedPointList::SetAnimValue(const SVGPointList& 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                 :   // It is not possible for us to reliably distinguish between calls to this
     131                 :   // method that are setting a new sample for an existing animation (in which
     132                 :   // case our list length isn't changing and we wouldn't need to notify our DOM
     133                 :   // wrapper to keep its length in sync), and calls to this method that are
     134                 :   // setting the first sample of a new animation that will override the base
     135                 :   // value/an existing animation (in which case our length may be changing and
     136                 :   // our DOM wrapper may need to be notified). Happily though, it's cheap to
     137                 :   // just blindly notify our animVal's DOM wrapper of our new value each time
     138                 :   // this method is called, so that's what we do.
     139                 : 
     140                 :   // We must send this notification *before* changing mAnimVal! (See above.)
     141                 : 
     142                 :   DOMSVGPointList *domWrapper =
     143               0 :     DOMSVGPointList::GetDOMWrapperIfExists(GetAnimValKey());
     144               0 :   if (domWrapper) {
     145               0 :     domWrapper->InternalListWillChangeTo(aNewAnimValue);
     146                 :   }
     147               0 :   if (!mAnimVal) {
     148               0 :     mAnimVal = new SVGPointList();
     149                 :   }
     150               0 :   nsresult rv = mAnimVal->CopyFrom(aNewAnimValue);
     151               0 :   if (NS_FAILED(rv)) {
     152                 :     // OOM. We clear the animation and, importantly, ClearAnimValue() ensures
     153                 :     // that mAnimVal's DOM wrapper (if any) is kept in sync!
     154               0 :     ClearAnimValue(aElement);
     155               0 :     return rv;
     156                 :   }
     157               0 :   aElement->DidAnimatePointList();
     158               0 :   return NS_OK;
     159                 : }
     160                 : 
     161                 : void
     162               0 : SVGAnimatedPointList::ClearAnimValue(nsSVGElement *aElement)
     163                 : {
     164                 :   // We must send these notifications *before* changing mAnimVal! (See above.)
     165                 : 
     166                 :   DOMSVGPointList *domWrapper =
     167               0 :     DOMSVGPointList::GetDOMWrapperIfExists(GetAnimValKey());
     168               0 :   if (domWrapper) {
     169                 :     // When all animation ends, animVal simply mirrors baseVal, which may have
     170                 :     // a different number of items to the last active animated value.
     171                 :     //
     172               0 :     domWrapper->InternalListWillChangeTo(mBaseVal);
     173                 :   }
     174               0 :   mAnimVal = nsnull;
     175               0 :   aElement->DidAnimatePointList();
     176               0 : }
     177                 : 
     178                 : nsISMILAttr*
     179               0 : SVGAnimatedPointList::ToSMILAttr(nsSVGElement *aElement)
     180                 : {
     181               0 :   return new SMILAnimatedPointList(this, aElement);
     182                 : }
     183                 : 
     184                 : nsresult
     185               0 : SVGAnimatedPointList::
     186                 :   SMILAnimatedPointList::ValueFromString(const nsAString& aStr,
     187                 :                                const nsISMILAnimationElement* /*aSrcElement*/,
     188                 :                                nsSMILValue& aValue,
     189                 :                                bool& aPreventCachingOfSandwich) const
     190                 : {
     191               0 :   nsSMILValue val(&SVGPointListSMILType::sSingleton);
     192               0 :   SVGPointListAndInfo *list = static_cast<SVGPointListAndInfo*>(val.mU.mPtr);
     193               0 :   nsresult rv = list->SetValueFromString(aStr);
     194               0 :   if (NS_SUCCEEDED(rv)) {
     195               0 :     list->SetInfo(mElement);
     196               0 :     aValue.Swap(val);
     197                 :   }
     198               0 :   aPreventCachingOfSandwich = false;
     199               0 :   return rv;
     200                 : }
     201                 : 
     202                 : nsSMILValue
     203               0 : SVGAnimatedPointList::SMILAnimatedPointList::GetBaseValue() const
     204                 : {
     205                 :   // To benefit from Return Value Optimization and avoid copy constructor calls
     206                 :   // due to our use of return-by-value, we must return the exact same object
     207                 :   // from ALL return points. This function must only return THIS variable:
     208               0 :   nsSMILValue val;
     209                 : 
     210               0 :   nsSMILValue tmp(&SVGPointListSMILType::sSingleton);
     211               0 :   SVGPointListAndInfo *list = static_cast<SVGPointListAndInfo*>(tmp.mU.mPtr);
     212               0 :   nsresult rv = list->CopyFrom(mVal->mBaseVal);
     213               0 :   if (NS_SUCCEEDED(rv)) {
     214               0 :     list->SetInfo(mElement);
     215               0 :     val.Swap(tmp);
     216                 :   }
     217                 :   return val;
     218                 : }
     219                 : 
     220                 : nsresult
     221               0 : SVGAnimatedPointList::SMILAnimatedPointList::SetAnimValue(const nsSMILValue& aValue)
     222                 : {
     223               0 :   NS_ASSERTION(aValue.mType == &SVGPointListSMILType::sSingleton,
     224                 :                "Unexpected type to assign animated value");
     225               0 :   if (aValue.mType == &SVGPointListSMILType::sSingleton) {
     226                 :     mVal->SetAnimValue(*static_cast<SVGPointListAndInfo*>(aValue.mU.mPtr),
     227               0 :                        mElement);
     228                 :   }
     229               0 :   return NS_OK;
     230                 : }
     231                 : 
     232                 : void
     233               0 : SVGAnimatedPointList::SMILAnimatedPointList::ClearAnimValue()
     234                 : {
     235               0 :   if (mVal->mAnimVal) {
     236               0 :     mVal->ClearAnimValue(mElement);
     237                 :   }
     238               0 : }
     239                 : 
     240                 : } // namespace mozilla

Generated by: LCOV version 1.7