2011-04-12 06:18:43 +00:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 11:12:37 +00: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 06:18:43 +00:00
|
|
|
|
|
|
|
#include "AnimationCommon.h"
|
|
|
|
#include "nsRuleData.h"
|
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
|
|
|
PR_INIT_CLIST(&mElementData);
|
|
|
|
}
|
|
|
|
|
|
|
|
CommonAnimationManager::~CommonAnimationManager()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mPresContext, "Disconnect should have been called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::Disconnect()
|
|
|
|
{
|
|
|
|
// Content nodes might outlive the transition or animation manager.
|
|
|
|
RemoveAllElementData();
|
|
|
|
|
|
|
|
mPresContext = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::AddElementData(CommonElementAnimationData* aData)
|
|
|
|
{
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
// We need to observe the refresh driver.
|
|
|
|
nsRefreshDriver *rd = mPresContext->RefreshDriver();
|
|
|
|
rd->AddRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_INSERT_BEFORE(aData, &mElementData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::ElementDataRemoved()
|
|
|
|
{
|
|
|
|
// If we have no transitions or animations left, remove ourselves from
|
|
|
|
// the refresh driver.
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::RemoveAllElementData()
|
|
|
|
{
|
|
|
|
while (!PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
CommonElementAnimationData *head =
|
|
|
|
static_cast<CommonElementAnimationData*>(PR_LIST_HEAD(&mElementData));
|
|
|
|
head->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsISupports implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(CommonAnimationManager, nsIStyleRuleProcessor)
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-04-12 06:18:43 +00:00
|
|
|
CommonAnimationManager::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-04-12 06:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2011-04-12 06:18:43 +00:00
|
|
|
CommonAnimationManager::MediumFeaturesChanged(nsPresContext* aPresContext)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-04-12 06:18:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-09 05:01:52 +00:00
|
|
|
/* virtual */ size_t
|
|
|
|
CommonAnimationManager::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-01 18:25:20 +00:00
|
|
|
{
|
2012-01-03 02:19:14 +00:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mElementData
|
|
|
|
//
|
|
|
|
// The following members are not measured
|
|
|
|
// - mPresContext, because it's non-owning
|
|
|
|
|
2011-12-09 05:01:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
CommonAnimationManager::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 08:52:51 +00:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-01 18:25:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* static */ bool
|
2011-04-12 06:18:43 +00:00
|
|
|
CommonAnimationManager::ExtractComputedValueForTransition(
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsStyleAnimation::Value& aComputedValue)
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool result =
|
2011-04-12 06:18:43 +00:00
|
|
|
nsStyleAnimation::ExtractComputedValue(aProperty, aStyleContext,
|
|
|
|
aComputedValue);
|
|
|
|
if (aProperty == eCSSProperty_visibility) {
|
|
|
|
NS_ABORT_IF_FALSE(aComputedValue.GetUnit() ==
|
|
|
|
nsStyleAnimation::eUnit_Enumerated,
|
|
|
|
"unexpected unit");
|
|
|
|
aComputedValue.SetIntValue(aComputedValue.GetIntValue(),
|
|
|
|
nsStyleAnimation::eUnit_Visibility);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(AnimValuesStyleRule, nsIStyleRule)
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
nsStyleContext *contextParent = aRuleData->mStyleContext->GetParent();
|
|
|
|
if (contextParent && contextParent->HasPseudoElementData()) {
|
|
|
|
// Don't apply transitions or animations to things inside of
|
|
|
|
// pseudo-elements.
|
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
|
|
|
PropertyValuePair &cv = mPropertyValuePairs[i];
|
|
|
|
if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
|
|
|
|
nsCSSProps::kSIDTable[cv.mProperty]))
|
|
|
|
{
|
|
|
|
nsCSSValue *prop = aRuleData->ValueFor(cv.mProperty);
|
|
|
|
if (prop->GetUnit() == eCSSUnit_Null) {
|
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool ok =
|
2011-04-12 06:18:43 +00:00
|
|
|
#endif
|
|
|
|
nsStyleAnimation::UncomputeValue(cv.mProperty,
|
|
|
|
aRuleData->mPresContext,
|
|
|
|
cv.mValue, *prop);
|
|
|
|
NS_ABORT_IF_FALSE(ok, "could not store computed value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
|
|
|
AnimValuesStyleRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// WRITE ME?
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
ComputedTimingFunction::Init(const nsTimingFunction &aFunction)
|
|
|
|
{
|
|
|
|
mType = aFunction.mType;
|
|
|
|
if (mType == nsTimingFunction::Function) {
|
|
|
|
mTimingFunction.Init(aFunction.mFunc.mX1, aFunction.mFunc.mY1,
|
|
|
|
aFunction.mFunc.mX2, aFunction.mFunc.mY2);
|
|
|
|
} else {
|
|
|
|
mSteps = aFunction.mSteps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline double
|
|
|
|
StepEnd(PRUint32 aSteps, double aPortion)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(0.0 <= aPortion && aPortion <= 1.0, "out of range");
|
|
|
|
PRUint32 step = PRUint32(aPortion * aSteps); // floor
|
|
|
|
return double(step) / double(aSteps);
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
ComputedTimingFunction::GetValue(double aPortion) const
|
|
|
|
{
|
|
|
|
switch (mType) {
|
|
|
|
case nsTimingFunction::Function:
|
|
|
|
return mTimingFunction.GetSplineValue(aPortion);
|
|
|
|
case nsTimingFunction::StepStart:
|
|
|
|
// There are diagrams in the spec that seem to suggest this check
|
|
|
|
// and the bounds point should not be symmetric with StepEnd, but
|
|
|
|
// should actually step up at rather than immediately after the
|
|
|
|
// fraction points. However, we rely on rounding negative values
|
|
|
|
// up to zero, so we can't do that. And it's not clear the spec
|
|
|
|
// really meant it.
|
|
|
|
return 1.0 - StepEnd(mSteps, 1.0 - aPortion);
|
|
|
|
default:
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_ABORT_IF_FALSE(false, "bad type");
|
2011-04-12 06:18:43 +00:00
|
|
|
// fall through
|
|
|
|
case nsTimingFunction::StepEnd:
|
|
|
|
return StepEnd(mSteps, aPortion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|