LCOV - code coverage report
Current view: top level - dom/svg - SVGAnimatedPathSegList.h (source / functions) Hit Total Coverage
Test: output.info Lines: 11 17 64.7 %
Date: 2017-07-14 16:53:18 Functions: 6 10 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef MOZILLA_SVGANIMATEDPATHSEGLIST_H__
       8             : #define MOZILLA_SVGANIMATEDPATHSEGLIST_H__
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "mozilla/MemoryReporting.h"
      12             : #include "mozilla/UniquePtr.h"
      13             : #include "nsAutoPtr.h"
      14             : #include "nsISMILAttr.h"
      15             : #include "SVGPathData.h"
      16             : 
      17             : class nsSMILValue;
      18             : class nsSVGElement;
      19             : 
      20             : namespace mozilla {
      21             : 
      22             : namespace dom {
      23             : class SVGAnimationElement;
      24             : } // namespace dom
      25             : 
      26             : /**
      27             :  * Class SVGAnimatedPathSegList
      28             :  *
      29             :  * Despite the fact that no SVGAnimatedPathSegList interface or objects exist
      30             :  * in the SVG specification (unlike e.g. SVGAnimated*Length*List), we
      31             :  * nevertheless have this internal class. (Note that there is an
      32             :  * SVGAnimatedPathData interface, but that's quite different to
      33             :  * SVGAnimatedLengthList since it is inherited by elements, as opposed to
      34             :  * elements having members of that type.) The reason that we have this class is
      35             :  * to provide a single locked down point of entry to the SVGPathData objects,
      36             :  * which helps ensure that the DOM wrappers for SVGPathData objects' are always
      37             :  * kept in sync. This is vitally important (see the comment in
      38             :  * DOMSVGPathSegList::InternalListWillChangeTo) and frees consumers from having
      39             :  * to know or worry about wrappers (or forget about them!) for the most part.
      40             :  */
      41           0 : class SVGAnimatedPathSegList final
      42             : {
      43             :   // friends so that they can get write access to mBaseVal and mAnimVal
      44             :   friend class DOMSVGPathSeg;
      45             :   friend class DOMSVGPathSegList;
      46             : 
      47             : public:
      48          44 :   SVGAnimatedPathSegList() {}
      49             : 
      50             :   /**
      51             :    * Because it's so important that mBaseVal and its DOMSVGPathSegList wrapper
      52             :    * (if any) be kept in sync (see the comment in
      53             :    * DOMSVGPathSegList::InternalListWillChangeTo), this method returns a const
      54             :    * reference. Only our friend classes may get mutable references to mBaseVal.
      55             :    */
      56          44 :   const SVGPathData& GetBaseValue() const {
      57          44 :     return mBaseVal;
      58             :   }
      59             : 
      60             :   nsresult SetBaseValueString(const nsAString& aValue);
      61             : 
      62             :   void ClearBaseValue();
      63             : 
      64             :   /**
      65             :    * const! See comment for GetBaseValue!
      66             :    */
      67          42 :   const SVGPathData& GetAnimValue() const {
      68          42 :     return mAnimVal ? *mAnimVal : mBaseVal;
      69             :   }
      70             : 
      71             :   nsresult SetAnimValue(const SVGPathData& aValue,
      72             :                         nsSVGElement *aElement);
      73             : 
      74             :   void ClearAnimValue(nsSVGElement *aElement);
      75             : 
      76             :   /**
      77             :    * Needed for correct DOM wrapper construction since GetAnimValue may
      78             :    * actually return the baseVal!
      79             :    */
      80          44 :   void *GetBaseValKey() const {
      81          44 :     return (void*)&mBaseVal;
      82             :   }
      83          44 :   void *GetAnimValKey() const {
      84          44 :     return (void*)&mAnimVal;
      85             :   }
      86             : 
      87          44 :   bool IsAnimating() const {
      88          44 :     return !!mAnimVal;
      89             :   }
      90             : 
      91             :   UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aElement);
      92             : 
      93             :   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
      94             : 
      95             : private:
      96             : 
      97             :   // mAnimVal is a pointer to allow us to determine if we're being animated or
      98             :   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
      99             :   // if we're animating is not an option, since that would break animation *to*
     100             :   // the empty string (<set to="">).
     101             : 
     102             :   SVGPathData mBaseVal;
     103             :   nsAutoPtr<SVGPathData> mAnimVal;
     104             : 
     105           0 :   struct SMILAnimatedPathSegList : public nsISMILAttr
     106             :   {
     107             :   public:
     108           0 :     SMILAnimatedPathSegList(SVGAnimatedPathSegList* aVal,
     109             :                             nsSVGElement* aElement)
     110           0 :       : mVal(aVal)
     111           0 :       , mElement(aElement)
     112           0 :     {}
     113             : 
     114             :     // These will stay alive because a nsISMILAttr only lives as long
     115             :     // as the Compositing step, and DOM elements don't get a chance to
     116             :     // die during that.
     117             :     SVGAnimatedPathSegList *mVal;
     118             :     nsSVGElement *mElement;
     119             : 
     120             :     // nsISMILAttr methods
     121             :     virtual nsresult ValueFromString(const nsAString& aStr,
     122             :                                      const dom::SVGAnimationElement* aSrcElement,
     123             :                                      nsSMILValue& aValue,
     124             :                                      bool& aPreventCachingOfSandwich) const override;
     125             :     virtual nsSMILValue GetBaseValue() const override;
     126             :     virtual void ClearAnimValue() override;
     127             :     virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
     128             :   };
     129             : };
     130             : 
     131             : } // namespace mozilla
     132             : 
     133             : #endif // MOZILLA_SVGANIMATEDPATHSEGLIST_H__

Generated by: LCOV version 1.13