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
|
|
|
|
|
|
|
#include "AnimationCommon.h"
|
|
|
|
#include "nsRuleData.h"
|
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsStyleContext.h"
|
2012-07-31 21:28:21 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsAnimationManager.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
/* static */ bool
|
|
|
|
IsGeometricProperty(nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_height:
|
|
|
|
case eCSSProperty_left:
|
|
|
|
case eCSSProperty_right:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_width:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
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();
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPresContext = nullptr;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
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 10:19:26 +04:00
|
|
|
bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::MediumFeaturesChanged(nsPresContext* aPresContext)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
|
|
|
CommonAnimationManager::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
2011-08-01 22:25:20 +04:00
|
|
|
{
|
2012-01-03 06:19:14 +04: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 09:01:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
CommonAnimationManager::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-01 22:25:20 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::ExtractComputedValueForTransition(
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsStyleAnimation::Value& aComputedValue)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool result =
|
2011-04-12 10:18:43 +04: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;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
2011-04-12 10:18:43 +04:00
|
|
|
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 10:19:26 +04:00
|
|
|
bool ok =
|
2011-04-12 10:18:43 +04: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
|
2012-08-22 19:56:38 +04:00
|
|
|
AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
// 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
|
2012-08-22 19:56:38 +04:00
|
|
|
StepEnd(uint32_t aSteps, double aPortion)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(0.0 <= aPortion && aPortion <= 1.0, "out of range");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t step = uint32_t(aPortion * aSteps); // floor
|
2011-04-12 10:18:43 +04:00
|
|
|
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 18:59:28 +04:00
|
|
|
NS_ABORT_IF_FALSE(false, "bad type");
|
2011-04-12 10:18:43 +04:00
|
|
|
// fall through
|
|
|
|
case nsTimingFunction::StepEnd:
|
|
|
|
return StepEnd(mSteps, aPortion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
bool
|
|
|
|
CommonElementAnimationData::CanAnimatePropertyOnCompositor(const dom::Element *aElement,
|
2012-08-22 05:48:47 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
bool aHasGeometricProperties)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2012-08-07 00:33:23 +04:00
|
|
|
bool shouldLog = nsLayoutUtils::IsAnimationLoggingEnabled();
|
2012-07-31 21:28:21 +04:00
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
2012-08-22 05:48:47 +04:00
|
|
|
if (IsGeometricProperty(aProperty)) {
|
|
|
|
if (shouldLog) {
|
|
|
|
printf_stderr("Performance warning: Async animation of geometric property '%s' is disabled\n", aProperty);
|
|
|
|
}
|
|
|
|
return false;
|
2012-08-05 21:03:43 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
if (aProperty == eCSSProperty_opacity) {
|
2012-08-03 10:32:13 +04:00
|
|
|
bool enabled = nsLayoutUtils::AreOpacityAnimationsEnabled();
|
2012-08-07 00:33:23 +04:00
|
|
|
if (!enabled && shouldLog) {
|
2012-08-03 10:32:13 +04:00
|
|
|
printf_stderr("Performance warning: Async animation of 'opacity' is disabled\n");
|
|
|
|
}
|
|
|
|
return enabled;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-08-03 10:32:13 +04:00
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2012-08-22 05:48:47 +04:00
|
|
|
if (frame->Preserves3D() &&
|
2012-08-03 10:32:13 +04:00
|
|
|
frame->Preserves3DChildren()) {
|
2012-08-07 00:33:23 +04:00
|
|
|
if (shouldLog) {
|
2012-08-03 10:32:13 +04:00
|
|
|
printf_stderr("Gecko bug: Async animation of 'preserve-3d' transforms is not supported. See bug 779598\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 05:48:47 +04:00
|
|
|
if (frame->IsSVGTransformed()) {
|
2012-08-07 00:33:23 +04:00
|
|
|
if (shouldLog) {
|
2012-08-03 10:32:13 +04:00
|
|
|
printf_stderr("Gecko bug: Async 'transform' animations of frames with SVG transforms is not supported. See bug 779599\n");
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 05:48:47 +04:00
|
|
|
if (aHasGeometricProperties) {
|
|
|
|
if (shouldLog) {
|
|
|
|
printf_stderr("Performance warning: Async animation of 'transform' not possible due to presence of geometric properties\n");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-03 10:32:13 +04:00
|
|
|
bool enabled = nsLayoutUtils::AreTransformAnimationsEnabled();
|
2012-08-07 00:33:23 +04:00
|
|
|
if (!enabled && shouldLog) {
|
2012-08-03 10:32:13 +04:00
|
|
|
printf_stderr("Performance warning: Async animation of 'transform' is disabled\n");
|
|
|
|
}
|
|
|
|
return enabled;
|
|
|
|
}
|
2012-08-22 05:48:47 +04:00
|
|
|
return true;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
}
|