2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
#ifndef MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
|
|
|
|
#define MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-03-30 07:10:07 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2011-09-26 01:04:31 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-20 07:20:38 +04:00
|
|
|
#include "nsISMILAttr.h"
|
|
|
|
#include "SVGTransformList.h"
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2013-03-20 07:20:38 +04:00
|
|
|
class nsSMILValue;
|
|
|
|
class nsSVGElement;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
namespace mozilla {
|
2013-03-20 06:31:44 +04:00
|
|
|
|
|
|
|
namespace dom {
|
2013-03-20 07:20:38 +04:00
|
|
|
class SVGAnimationElement;
|
2013-04-02 23:17:41 +04:00
|
|
|
class SVGTransform;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
/**
|
2013-04-15 02:56:34 +04:00
|
|
|
* Class nsSVGAnimatedTransformList
|
2011-09-26 01:04:31 +04:00
|
|
|
*
|
2013-03-20 07:20:38 +04:00
|
|
|
* This class is very different to the SVG DOM interface of the same name found
|
|
|
|
* in the SVG specification. This is a lightweight internal class - see
|
2013-04-15 02:56:34 +04:00
|
|
|
* SVGAnimatedTransformList for the heavier DOM class that wraps instances of
|
2013-03-20 07:20:38 +04:00
|
|
|
* this class and implements the SVG specification's SVGAnimatedTransformList
|
|
|
|
* DOM interface.
|
2011-09-26 01:04:31 +04:00
|
|
|
*
|
2013-03-20 07:20:38 +04:00
|
|
|
* Except where noted otherwise, this class' methods take care of keeping the
|
|
|
|
* appropriate DOM wrappers in sync (see the comment in
|
2013-04-15 02:56:34 +04:00
|
|
|
* SVGAnimatedTransformList::InternalBaseValListWillChangeTo) so that their
|
2013-03-20 07:20:38 +04:00
|
|
|
* consumers don't need to concern themselves with that.
|
2011-09-26 01:04:31 +04:00
|
|
|
*/
|
2013-04-15 02:56:34 +04:00
|
|
|
class nsSVGAnimatedTransformList
|
2011-09-26 01:04:31 +04:00
|
|
|
{
|
2013-03-20 07:20:38 +04:00
|
|
|
// friends so that they can get write access to mBaseVal
|
2013-04-02 23:17:41 +04:00
|
|
|
friend class dom::SVGTransform;
|
2011-09-26 01:04:31 +04:00
|
|
|
friend class DOMSVGTransformList;
|
|
|
|
|
|
|
|
public:
|
2016-03-15 03:37:36 +03:00
|
|
|
nsSVGAnimatedTransformList()
|
|
|
|
: mIsAttrSet(false),
|
|
|
|
mHadTransformBeforeLastBaseValChange(false) { }
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
/**
|
2013-03-20 07:20:38 +04:00
|
|
|
* Because it's so important that mBaseVal and its DOMSVGTransformList wrapper
|
|
|
|
* (if any) be kept in sync (see the comment in
|
2013-04-15 02:56:34 +04:00
|
|
|
* SVGAnimatedTransformList::InternalBaseValListWillChangeTo), this method
|
2013-03-20 07:20:38 +04:00
|
|
|
* returns a const reference. Only our friend classes may get mutable
|
|
|
|
* references to mBaseVal.
|
2011-09-26 01:04:31 +04:00
|
|
|
*/
|
2013-03-20 07:20:38 +04:00
|
|
|
const SVGTransformList& GetBaseValue() const {
|
|
|
|
return mBaseVal;
|
|
|
|
}
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2018-01-25 13:23:02 +03:00
|
|
|
nsresult SetBaseValue(const SVGTransformList& aValue);
|
2013-05-05 11:20:25 +04:00
|
|
|
|
2018-01-25 13:23:02 +03:00
|
|
|
nsresult SetBaseValueString(const nsAString& aValue);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
void ClearBaseValue();
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
const SVGTransformList& GetAnimValue() const {
|
|
|
|
return mAnimVal ? *mAnimVal : mBaseVal;
|
|
|
|
}
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
nsresult SetAnimValue(const SVGTransformList& aNewAnimValue,
|
|
|
|
nsSVGElement *aElement);
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
void ClearAnimValue(nsSVGElement *aElement);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-04-14 11:17:36 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the corresponding transform attribute is set (or animated)
|
|
|
|
* to a valid value. Unlike HasTransform it will return true for an empty
|
|
|
|
* transform.
|
|
|
|
*/
|
2013-03-20 07:20:38 +04:00
|
|
|
bool IsExplicitlySet() const;
|
|
|
|
|
2013-04-14 11:17:36 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the corresponding transform attribute is set (or animated)
|
|
|
|
* to a valid value, such that we have at least one transform in our list.
|
|
|
|
* Returns false otherwise (e.g. if the transform attribute is missing or empty
|
|
|
|
* or invalid).
|
|
|
|
*/
|
|
|
|
bool HasTransform() const
|
|
|
|
{ return (mAnimVal && !mAnimVal->IsEmpty()) || !mBaseVal.IsEmpty(); }
|
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
bool IsAnimating() const {
|
|
|
|
return !!mAnimVal;
|
2012-12-23 08:54:20 +04:00
|
|
|
}
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2016-03-15 03:37:36 +03:00
|
|
|
/**
|
|
|
|
* Returns true iff "HasTransform" returned true just before our most recent
|
|
|
|
* SetBaseValue/SetBaseValueString/ClearBaseValue change.
|
|
|
|
*
|
|
|
|
* (This is used as part of an optimization in
|
|
|
|
* SVGTransformableElement::GetAttributeChangeHint. That function reports an
|
|
|
|
* inexpensive nsChangeHint when a transform has just modified -- but this
|
|
|
|
* accessor lets it detect cases where the "modification" is actually adding
|
|
|
|
* a transform where we previously had none. These cases require a more
|
|
|
|
* thorough nsChangeHint.)
|
|
|
|
*/
|
|
|
|
bool HadTransformBeforeLastBaseValChange() const {
|
|
|
|
return mHadTransformBeforeLastBaseValChange;
|
|
|
|
}
|
|
|
|
|
2017-03-30 07:10:07 +03:00
|
|
|
mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
|
2013-03-20 07:20:38 +04:00
|
|
|
|
|
|
|
private:
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
// mAnimVal is a pointer to allow us to determine if we're being animated or
|
|
|
|
// not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
|
|
|
|
// if we're animating is not an option, since that would break animation *to*
|
|
|
|
// the empty string (<set to="">).
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
SVGTransformList mBaseVal;
|
|
|
|
nsAutoPtr<SVGTransformList> mAnimVal;
|
|
|
|
bool mIsAttrSet;
|
2016-03-15 03:37:36 +03:00
|
|
|
// (See documentation for accessor, HadTransformBeforeLastBaseValChange.)
|
|
|
|
bool mHadTransformBeforeLastBaseValChange;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
struct SMILAnimatedTransformList : public nsISMILAttr
|
|
|
|
{
|
|
|
|
public:
|
2013-04-15 02:56:34 +04:00
|
|
|
SMILAnimatedTransformList(nsSVGAnimatedTransformList* aVal,
|
2013-03-20 07:20:38 +04:00
|
|
|
nsSVGElement* aSVGElement)
|
|
|
|
: mVal(aVal)
|
|
|
|
, mElement(aSVGElement)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// nsISMILAttr methods
|
|
|
|
virtual nsresult ValueFromString(const nsAString& aStr,
|
|
|
|
const dom::SVGAnimationElement* aSrcElement,
|
|
|
|
nsSMILValue& aValue,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool& aPreventCachingOfSandwich) const override;
|
|
|
|
virtual nsSMILValue GetBaseValue() const override;
|
|
|
|
virtual void ClearAnimValue() override;
|
|
|
|
virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
|
2013-03-20 07:20:38 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void ParseValue(const nsAString& aSpec,
|
2017-10-03 01:05:19 +03:00
|
|
|
const nsAtom* aTransformType,
|
2013-03-20 07:20:38 +04:00
|
|
|
nsSMILValue& aResult);
|
|
|
|
static int32_t ParseParameterList(const nsAString& aSpec, float* aVars,
|
|
|
|
int32_t aNVars);
|
|
|
|
|
|
|
|
// These will stay alive because a nsISMILAttr only lives as long
|
|
|
|
// as the Compositing step, and DOM elements don't get a chance to
|
|
|
|
// die during that.
|
2013-04-15 02:56:34 +04:00
|
|
|
nsSVGAnimatedTransformList* mVal;
|
2013-03-20 07:20:38 +04:00
|
|
|
nsSVGElement* mElement;
|
|
|
|
};
|
2011-09-26 01:04:31 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-03-20 07:20:38 +04:00
|
|
|
#endif // MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
|