LCOV - code coverage report
Current view: top level - dom/svg - SVGAnimatedPointList.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_SVGANIMATEDPOINTLIST_H__
       8             : #define MOZILLA_SVGANIMATEDPOINTLIST_H__
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "mozilla/UniquePtr.h"
      12             : #include "nsAutoPtr.h"
      13             : #include "nsISMILAttr.h"
      14             : #include "SVGPointList.h"
      15             : 
      16             : class nsSMILValue;
      17             : class nsSVGElement;
      18             : 
      19             : namespace mozilla {
      20             : 
      21             : namespace dom {
      22             : class SVGAnimationElement;
      23             : } // namespace dom
      24             : 
      25             : /**
      26             :  * Class SVGAnimatedPointList
      27             :  *
      28             :  * Despite the fact that no SVGAnimatedPointList interface or objects exist
      29             :  * in the SVG specification (unlike e.g. SVGAnimated*Length*List), we
      30             :  * nevertheless have this internal class. (Note that there is an
      31             :  * SVGAnimatedPoints interface, but that's quite different to
      32             :  * SVGAnimatedLengthList since it is inherited by elements, as opposed to
      33             :  * elements having members of that type.) The reason that we have this class is
      34             :  * to provide a single locked down point of entry to the SVGPointList objects,
      35             :  * which helps ensure that the DOM wrappers for SVGPointList objects' are
      36             :  * always kept in sync. This is vitally important (see the comment in
      37             :  * DOMSVGPointList::InternalListWillChangeTo) and frees consumers from having
      38             :  * to know or worry about wrappers (or forget about them!) for the most part.
      39             :  */
      40           0 : class SVGAnimatedPointList
      41             : {
      42             :   // friends so that they can get write access to mBaseVal and mAnimVal
      43             :   friend class DOMSVGPoint;
      44             :   friend class DOMSVGPointList;
      45             : 
      46             : public:
      47          14 :   SVGAnimatedPointList() {}
      48             : 
      49             :   /**
      50             :    * Because it's so important that mBaseVal and its DOMSVGPointList wrapper
      51             :    * (if any) be kept in sync (see the comment in
      52             :    * DOMSVGPointList::InternalListWillChangeTo), this method returns a const
      53             :    * reference. Only our friend classes may get mutable references to mBaseVal.
      54             :    */
      55          14 :   const SVGPointList& GetBaseValue() const {
      56          14 :     return mBaseVal;
      57             :   }
      58             : 
      59             :   nsresult SetBaseValueString(const nsAString& aValue);
      60             : 
      61             :   void ClearBaseValue();
      62             : 
      63             :   /**
      64             :    * const! See comment for GetBaseValue!
      65             :    */
      66          48 :   const SVGPointList& GetAnimValue() const {
      67          48 :     return mAnimVal ? *mAnimVal : mBaseVal;
      68             :   }
      69             : 
      70             :   nsresult SetAnimValue(const SVGPointList& aValue,
      71             :                         nsSVGElement *aElement);
      72             : 
      73             :   void ClearAnimValue(nsSVGElement *aElement);
      74             : 
      75             :   /**
      76             :    * Needed for correct DOM wrapper construction since GetAnimValue may
      77             :    * actually return the baseVal!
      78             :    */
      79          14 :   void *GetBaseValKey() const {
      80          14 :     return (void*)&mBaseVal;
      81             :   }
      82          14 :   void *GetAnimValKey() const {
      83          14 :     return (void*)&mAnimVal;
      84             :   }
      85             : 
      86          14 :   bool IsAnimating() const {
      87          14 :     return !!mAnimVal;
      88             :   }
      89             : 
      90             :   UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aElement);
      91             : 
      92             : private:
      93             : 
      94             :   // mAnimVal is a pointer to allow us to determine if we're being animated or
      95             :   // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
      96             :   // if we're animating is not an option, since that would break animation *to*
      97             :   // the empty string (<set to="">).
      98             : 
      99             :   SVGPointList mBaseVal;
     100             :   nsAutoPtr<SVGPointList> mAnimVal;
     101             : 
     102           0 :   struct SMILAnimatedPointList : public nsISMILAttr
     103             :   {
     104             :   public:
     105           0 :     SMILAnimatedPointList(SVGAnimatedPointList* aVal,
     106             :                           nsSVGElement* aElement)
     107           0 :       : mVal(aVal)
     108           0 :       , mElement(aElement)
     109           0 :     {}
     110             : 
     111             :     // These will stay alive because a nsISMILAttr only lives as long
     112             :     // as the Compositing step, and DOM elements don't get a chance to
     113             :     // die during that.
     114             :     SVGAnimatedPointList *mVal;
     115             :     nsSVGElement *mElement;
     116             : 
     117             :     // nsISMILAttr methods
     118             :     virtual nsresult ValueFromString(const nsAString& aStr,
     119             :                                      const dom::SVGAnimationElement* aSrcElement,
     120             :                                      nsSMILValue& aValue,
     121             :                                      bool& aPreventCachingOfSandwich) const override;
     122             :     virtual nsSMILValue GetBaseValue() const override;
     123             :     virtual void ClearAnimValue() override;
     124             :     virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
     125             :   };
     126             : };
     127             : 
     128             : } // namespace mozilla
     129             : 
     130             : #endif // MOZILLA_SVGANIMATEDPOINTLIST_H__

Generated by: LCOV version 1.13