2011-04-12 10:18:43 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_css_AnimationCommon_h
|
|
|
|
#define mozilla_css_AnimationCommon_h
|
|
|
|
|
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "prclist.h"
|
|
|
|
#include "nsStyleAnimation.h"
|
|
|
|
#include "nsCSSProperty.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsSMILKeySpline.h"
|
|
|
|
#include "nsStyleStruct.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
class nsPresContext;
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
bool IsGeometricProperty(nsCSSProperty aProperty);
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
struct CommonElementAnimationData;
|
|
|
|
|
|
|
|
class CommonAnimationManager : public nsIStyleRuleProcessor,
|
|
|
|
public nsARefreshObserver {
|
|
|
|
public:
|
|
|
|
CommonAnimationManager(nsPresContext *aPresContext);
|
|
|
|
virtual ~CommonAnimationManager();
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRuleProcessor (parts)
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
virtual nsRestyleHint
|
2012-09-14 20:10:08 +04:00
|
|
|
HasAttributeDependentStyle(AttributeRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) MOZ_OVERRIDE;
|
2013-03-24 06:14:43 +04:00
|
|
|
virtual size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
|
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify the manager that the pres context is going away.
|
|
|
|
*/
|
|
|
|
void Disconnect();
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
enum FlushFlags {
|
|
|
|
Can_Throttle,
|
|
|
|
Cannot_Throttle
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ExtractComputedValueForTransition(
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsStyleAnimation::Value& aComputedValue);
|
|
|
|
protected:
|
|
|
|
friend struct CommonElementAnimationData; // for ElementDataRemoved
|
|
|
|
|
|
|
|
void AddElementData(CommonElementAnimationData* aData);
|
|
|
|
void ElementDataRemoved();
|
|
|
|
void RemoveAllElementData();
|
|
|
|
|
|
|
|
PRCList mElementData;
|
|
|
|
nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A style rule that maps property-nsStyleAnimation::Value pairs.
|
|
|
|
*/
|
2012-06-19 06:30:09 +04:00
|
|
|
class AnimValuesStyleRule MOZ_FINAL : public nsIStyleRule
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports implementation
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIStyleRule implementation
|
2013-05-14 20:33:23 +04:00
|
|
|
virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
#ifdef DEBUG
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
|
2011-04-12 10:18:43 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void AddValue(nsCSSProperty aProperty, nsStyleAnimation::Value &aStartValue)
|
|
|
|
{
|
|
|
|
PropertyValuePair v = { aProperty, aStartValue };
|
|
|
|
mPropertyValuePairs.AppendElement(v);
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
// Caller must fill in returned value.
|
2011-04-12 10:18:43 +04:00
|
|
|
nsStyleAnimation::Value* AddEmptyValue(nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
PropertyValuePair *p = mPropertyValuePairs.AppendElement();
|
|
|
|
p->mProperty = aProperty;
|
|
|
|
return &p->mValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PropertyValuePair {
|
|
|
|
nsCSSProperty mProperty;
|
|
|
|
nsStyleAnimation::Value mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2011-04-12 10:18:43 +04:00
|
|
|
InfallibleTArray<PropertyValuePair> mPropertyValuePairs;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ComputedTimingFunction {
|
|
|
|
public:
|
|
|
|
typedef nsTimingFunction::Type Type;
|
|
|
|
void Init(const nsTimingFunction &aFunction);
|
|
|
|
double GetValue(double aPortion) const;
|
2012-07-31 21:28:21 +04:00
|
|
|
const nsSMILKeySpline* GetFunction() const {
|
|
|
|
NS_ASSERTION(mType == nsTimingFunction::Function, "Type mismatch");
|
|
|
|
return &mTimingFunction;
|
|
|
|
}
|
|
|
|
Type GetType() const { return mType; }
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetSteps() const { return mSteps; }
|
2011-04-12 10:18:43 +04:00
|
|
|
private:
|
|
|
|
Type mType;
|
|
|
|
nsSMILKeySpline mTimingFunction;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSteps;
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CommonElementAnimationData : public PRCList
|
|
|
|
{
|
|
|
|
CommonElementAnimationData(dom::Element *aElement, nsIAtom *aElementProperty,
|
|
|
|
CommonAnimationManager *aManager)
|
|
|
|
: mElement(aElement)
|
|
|
|
, mElementProperty(aElementProperty)
|
|
|
|
, mManager(aManager)
|
2013-02-26 10:21:26 +04:00
|
|
|
, mAnimationGeneration(0)
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mCalledPropertyDtor(false)
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(CommonElementAnimationData);
|
|
|
|
PR_INIT_CLIST(this);
|
|
|
|
}
|
|
|
|
~CommonElementAnimationData()
|
|
|
|
{
|
2011-05-01 02:16:19 +04:00
|
|
|
NS_ABORT_IF_FALSE(mCalledPropertyDtor,
|
|
|
|
"must call destructor through element property dtor");
|
2011-04-12 10:18:43 +04:00
|
|
|
MOZ_COUNT_DTOR(CommonElementAnimationData);
|
|
|
|
PR_REMOVE_LINK(this);
|
|
|
|
mManager->ElementDataRemoved();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
// This will call our destructor.
|
|
|
|
mElement->DeleteProperty(mElementProperty);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
bool CanThrottleTransformChanges(mozilla::TimeStamp aTime);
|
|
|
|
|
|
|
|
bool CanThrottleAnimation(mozilla::TimeStamp aTime);
|
|
|
|
|
|
|
|
enum CanAnimateFlags {
|
|
|
|
// Testing for width, height, top, right, bottom, or left.
|
|
|
|
CanAnimate_HasGeometricProperty = 1,
|
|
|
|
// Allow the case where OMTA is allowed in general, but not for the
|
|
|
|
// specified property.
|
|
|
|
CanAnimate_AllowPartial = 2
|
|
|
|
};
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
static bool
|
|
|
|
CanAnimatePropertyOnCompositor(const dom::Element *aElement,
|
2012-08-22 05:48:47 +04:00
|
|
|
nsCSSProperty aProperty,
|
2012-12-12 01:12:43 +04:00
|
|
|
CanAnimateFlags aFlags);
|
|
|
|
|
|
|
|
// True if this animation can be performed on the compositor thread.
|
|
|
|
// Do not pass CanAnimate_AllowPartial to make sure that all properties of this
|
|
|
|
// animation are supported by the compositor.
|
|
|
|
virtual bool CanPerformOnCompositorThread(CanAnimateFlags aFlags) const = 0;
|
|
|
|
virtual bool HasAnimationOfProperty(nsCSSProperty aProperty) const = 0;
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
static void LogAsyncAnimationFailure(nsCString& aMessage,
|
|
|
|
const nsIContent* aContent = nullptr);
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
dom::Element *mElement;
|
|
|
|
|
|
|
|
// the atom we use in mElement's prop table (must be a static atom,
|
|
|
|
// i.e., in an atom list)
|
|
|
|
nsIAtom *mElementProperty;
|
|
|
|
|
|
|
|
CommonAnimationManager *mManager;
|
2011-05-01 02:16:19 +04:00
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
// This style rule contains the style data for currently animating
|
|
|
|
// values. It only matches when styling with animation. When we
|
|
|
|
// style without animation, we need to not use it so that we can
|
|
|
|
// detect any new changes; if necessary we restyle immediately
|
|
|
|
// afterwards with animation.
|
|
|
|
// NOTE: If we don't need to apply any styles, mStyleRule will be
|
|
|
|
// null, but mStyleRuleRefreshTime will still be valid.
|
|
|
|
nsRefPtr<mozilla::css::AnimValuesStyleRule> mStyleRule;
|
2012-12-12 01:12:43 +04:00
|
|
|
|
|
|
|
// nsCSSFrameConstructor keeps track of the number of animation 'mini-flushes'
|
|
|
|
// (see nsTransitionManager::UpdateAllThrottledStyles()). mFlushCount is
|
|
|
|
// the last flush where a transition/animation changed. We keep a similar
|
|
|
|
// count on the corresponding layer so we can check that the layer is up to
|
|
|
|
// date with the animation manager.
|
|
|
|
uint64_t mAnimationGeneration;
|
|
|
|
// Update mFlushCount to nsCSSFrameConstructor's count
|
|
|
|
void UpdateAnimationGeneration(nsPresContext* aPresContext);
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
// The refresh time associated with mStyleRule.
|
|
|
|
TimeStamp mStyleRuleRefreshTime;
|
|
|
|
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mCalledPropertyDtor;
|
|
|
|
#endif
|
2011-04-12 10:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(mozilla_css_AnimationCommon_h) */
|