LCOV - code coverage report
Current view: top level - dom/svg - nsSVGNumberPair.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 29 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 11 0.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 __NS_SVGNUMBERPAIR_H__
       8             : #define __NS_SVGNUMBERPAIR_H__
       9             : 
      10             : #include "nsCycleCollectionParticipant.h"
      11             : #include "nsError.h"
      12             : #include "nsISMILAttr.h"
      13             : #include "nsMathUtils.h"
      14             : #include "nsSVGElement.h"
      15             : #include "mozilla/Attributes.h"
      16             : #include "mozilla/dom/SVGAnimatedNumber.h"
      17             : #include "mozilla/FloatingPoint.h"
      18             : #include "mozilla/UniquePtr.h"
      19             : 
      20             : 
      21             : class nsSMILValue;
      22             : 
      23             : namespace mozilla {
      24             : namespace dom {
      25             : class SVGAnimationElement;
      26             : } // namespace dom
      27             : } // namespace mozilla
      28             : 
      29             : class nsSVGNumberPair
      30             : {
      31             : 
      32             : public:
      33             :   enum PairIndex {
      34             :     eFirst,
      35             :     eSecond
      36             :   };
      37             : 
      38           0 :   void Init(uint8_t aAttrEnum = 0xff, float aValue1 = 0, float aValue2 = 0) {
      39           0 :     mAnimVal[0] = mBaseVal[0] = aValue1;
      40           0 :     mAnimVal[1] = mBaseVal[1] = aValue2;
      41           0 :     mAttrEnum = aAttrEnum;
      42           0 :     mIsAnimated = false;
      43           0 :     mIsBaseSet = false;
      44           0 :   }
      45             : 
      46             :   nsresult SetBaseValueString(const nsAString& aValue,
      47             :                               nsSVGElement *aSVGElement);
      48             :   void GetBaseValueString(nsAString& aValue) const;
      49             : 
      50             :   void SetBaseValue(float aValue, PairIndex aIndex, nsSVGElement *aSVGElement);
      51             :   void SetBaseValues(float aValue1, float aValue2, nsSVGElement *aSVGElement);
      52           0 :   float GetBaseValue(PairIndex aIndex) const
      53           0 :     { return mBaseVal[aIndex == eFirst ? 0 : 1]; }
      54             :   void SetAnimValue(const float aValue[2], nsSVGElement *aSVGElement);
      55           0 :   float GetAnimValue(PairIndex aIndex) const
      56           0 :     { return mAnimVal[aIndex == eFirst ? 0 : 1]; }
      57             : 
      58             :   // Returns true if the animated value of this number has been explicitly
      59             :   // set (either by animation, or by taking on the base value which has been
      60             :   // explicitly set by markup or a DOM call), false otherwise.
      61             :   // If this returns false, the animated value is still valid, that is,
      62             :   // useable, and represents the default base value of the attribute.
      63           0 :   bool IsExplicitlySet() const
      64           0 :     { return mIsAnimated || mIsBaseSet; }
      65             : 
      66             :   already_AddRefed<mozilla::dom::SVGAnimatedNumber>
      67             :     ToDOMAnimatedNumber(PairIndex aIndex,
      68             :                         nsSVGElement* aSVGElement);
      69             :   mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
      70             : 
      71             : private:
      72             :   float mAnimVal[2];
      73             :   float mBaseVal[2];
      74             :   uint8_t mAttrEnum; // element specified tracking for attribute
      75             :   bool mIsAnimated;
      76             :   bool mIsBaseSet;
      77             : 
      78             : public:
      79             :   struct DOMAnimatedNumber final : public mozilla::dom::SVGAnimatedNumber
      80             :   {
      81           0 :     DOMAnimatedNumber(nsSVGNumberPair* aVal, PairIndex aIndex, nsSVGElement *aSVGElement)
      82           0 :       : mozilla::dom::SVGAnimatedNumber(aSVGElement)
      83             :       , mVal(aVal)
      84           0 :       , mIndex(aIndex)
      85           0 :     {}
      86             :     virtual ~DOMAnimatedNumber();
      87             : 
      88             :     nsSVGNumberPair* mVal; // kept alive because it belongs to content
      89             :     PairIndex mIndex; // are we the first or second number
      90             : 
      91           0 :     virtual float BaseVal() override
      92             :     {
      93           0 :       return mVal->GetBaseValue(mIndex);
      94             :     }
      95           0 :     virtual void SetBaseVal(float aValue) override
      96             :     {
      97           0 :       MOZ_ASSERT(mozilla::IsFinite(aValue));
      98           0 :       mVal->SetBaseValue(aValue, mIndex, mSVGElement);
      99           0 :     }
     100             : 
     101             :     // Script may have modified animation parameters or timeline -- DOM getters
     102             :     // need to flush any resample requests to reflect these modifications.
     103           0 :     virtual float AnimVal() override
     104             :     {
     105           0 :       mSVGElement->FlushAnimations();
     106           0 :       return mVal->GetAnimValue(mIndex);
     107             :     }
     108             :   };
     109             : 
     110           0 :   struct SMILNumberPair : public nsISMILAttr
     111             :   {
     112             :   public:
     113           0 :     SMILNumberPair(nsSVGNumberPair* aVal, nsSVGElement* aSVGElement)
     114           0 :       : mVal(aVal), mSVGElement(aSVGElement) {}
     115             : 
     116             :     // These will stay alive because a nsISMILAttr only lives as long
     117             :     // as the Compositing step, and DOM elements don't get a chance to
     118             :     // die during that.
     119             :     nsSVGNumberPair* mVal;
     120             :     nsSVGElement* mSVGElement;
     121             : 
     122             :     // nsISMILAttr methods
     123             :     virtual nsresult ValueFromString(const nsAString& aStr,
     124             :                                      const mozilla::dom::SVGAnimationElement* aSrcElement,
     125             :                                      nsSMILValue& aValue,
     126             :                                      bool& aPreventCachingOfSandwich) const override;
     127             :     virtual nsSMILValue GetBaseValue() const override;
     128             :     virtual void ClearAnimValue() override;
     129             :     virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
     130             :   };
     131             : };
     132             : 
     133             : #endif //__NS_SVGNUMBERPAIR_H__

Generated by: LCOV version 1.13