2011-04-11 23:18:43 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07: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-11 23:18:43 -07:00
|
|
|
|
2013-10-22 13:55:14 -07:00
|
|
|
#include "AnimationCommon.h"
|
2013-10-22 05:14:41 -07:00
|
|
|
#include "nsTransitionManager.h"
|
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
|
2014-06-19 20:39:25 -07:00
|
|
|
#include "ActiveLayerTracker.h"
|
2013-10-22 05:14:41 -07:00
|
|
|
#include "gfxPlatform.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsRuleData.h"
|
2014-06-19 20:39:24 -07:00
|
|
|
#include "nsCSSPropertySet.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsCSSValue.h"
|
2014-07-15 17:02:30 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsStyleContext.h"
|
2012-07-31 10:28:21 -07:00
|
|
|
#include "nsIFrame.h"
|
2012-07-31 10:28:22 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-12-11 13:12:43 -08:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
|
|
|
#include "Layers.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsDisplayList.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "RestyleManager.h"
|
2013-10-22 05:14:41 -07:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2014-04-02 22:57:28 -07:00
|
|
|
using mozilla::layers::Layer;
|
2014-08-10 00:06:44 -07:00
|
|
|
using mozilla::dom::AnimationPlayer;
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-21 18:48:47 -07: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 16:57:12 -07:00
|
|
|
namespace css {
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
2014-06-26 16:57:13 -07:00
|
|
|
PR_INIT_CLIST(&mElementCollections);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CommonAnimationManager::~CommonAnimationManager()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mPresContext, "Disconnect should have been called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::Disconnect()
|
|
|
|
{
|
|
|
|
// Content nodes might outlive the transition or animation manager.
|
2014-06-26 16:57:13 -07:00
|
|
|
RemoveAllElementCollections();
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresContext = nullptr;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-26 16:57:13 -07:00
|
|
|
CommonAnimationManager::RemoveAllElementCollections()
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2014-06-26 16:57:13 -07:00
|
|
|
while (!PR_CLIST_IS_EMPTY(&mElementCollections)) {
|
|
|
|
ElementAnimationCollection* head =
|
|
|
|
static_cast<ElementAnimationCollection*>(
|
|
|
|
PR_LIST_HEAD(&mElementCollections));
|
2011-04-11 23:18:43 -07:00
|
|
|
head->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection*
|
2014-06-19 20:39:25 -07:00
|
|
|
CommonAnimationManager::GetAnimationsForCompositor(nsIContent* aContent,
|
|
|
|
nsIAtom* aElementProperty,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
if (!aContent->MayHaveAnimations())
|
|
|
|
return nullptr;
|
2014-06-26 16:57:13 -07:00
|
|
|
ElementAnimationCollection* collection =
|
2014-06-26 16:57:12 -07:00
|
|
|
static_cast<ElementAnimationCollection*>(
|
2014-06-19 20:39:25 -07:00
|
|
|
aContent->GetProperty(aElementProperty));
|
2014-06-26 16:57:13 -07:00
|
|
|
if (!collection ||
|
|
|
|
!collection->HasAnimationOfProperty(aProperty) ||
|
|
|
|
!collection->CanPerformOnCompositorThread(
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::CanAnimate_AllowPartial)) {
|
2014-06-19 20:39:25 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-19 20:39:26 -07:00
|
|
|
|
|
|
|
// This animation can be done on the compositor.
|
|
|
|
// Mark the frame as active, in case we are able to throttle this animation.
|
2014-06-26 16:57:13 -07:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(collection->mElement);
|
2014-06-19 20:39:26 -07:00
|
|
|
if (frame) {
|
|
|
|
if (aProperty == eCSSProperty_opacity) {
|
|
|
|
ActiveLayerTracker::NotifyAnimated(frame, eCSSProperty_opacity);
|
|
|
|
} else if (aProperty == eCSSProperty_transform) {
|
|
|
|
ActiveLayerTracker::NotifyAnimated(frame, eCSSProperty_transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 16:57:13 -07:00
|
|
|
return collection;
|
2014-06-19 20:39:25 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
/*
|
|
|
|
* nsISupports implementation
|
|
|
|
*/
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(CommonAnimationManager, nsIStyleRuleProcessor)
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2013-11-27 22:46:39 -08:00
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-11 23:18:43 -07:00
|
|
|
CommonAnimationManager::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2011-04-11 23:18:43 -07:00
|
|
|
CommonAnimationManager::MediumFeaturesChanged(nsPresContext* aPresContext)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
CommonAnimationManager::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-08-01 11:25:20 -07:00
|
|
|
{
|
2012-01-02 18:19:14 -08:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
2014-06-26 16:57:13 -07:00
|
|
|
// - mElementCollections
|
2012-01-02 18:19:14 -08:00
|
|
|
//
|
|
|
|
// The following members are not measured
|
|
|
|
// - mPresContext, because it's non-owning
|
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
CommonAnimationManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-01 11:25:20 -07:00
|
|
|
}
|
|
|
|
|
2014-08-06 22:58:44 -07:00
|
|
|
void
|
|
|
|
CommonAnimationManager::AddStyleUpdatesTo(RestyleTracker& aTracker)
|
|
|
|
{
|
|
|
|
PRCList* next = PR_LIST_HEAD(&mElementCollections);
|
|
|
|
while (next != &mElementCollections) {
|
|
|
|
ElementAnimationCollection* collection = static_cast<ElementAnimationCollection*>(next);
|
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
|
|
|
if (!collection->IsForElement()) {
|
|
|
|
// We don't support compositor-driven animation of :before/:after
|
|
|
|
// transitions or animations, so at least skip those.
|
|
|
|
// FIXME: We'll need to handle this before using this for the
|
|
|
|
// transitions redesign.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint rshint = collection->IsForTransitions()
|
|
|
|
? eRestyle_CSSTransitions : eRestyle_CSSAnimations;
|
|
|
|
aTracker.AddPendingRestyle(collection->mElement, rshint, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2011-04-11 23:18:43 -07:00
|
|
|
CommonAnimationManager::ExtractComputedValueForTransition(
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue& aComputedValue)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2014-06-23 23:29:54 -07:00
|
|
|
bool result = StyleAnimationValue::ExtractComputedValue(aProperty,
|
|
|
|
aStyleContext,
|
|
|
|
aComputedValue);
|
2011-04-11 23:18:43 -07:00
|
|
|
if (aProperty == eCSSProperty_visibility) {
|
|
|
|
NS_ABORT_IF_FALSE(aComputedValue.GetUnit() ==
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue::eUnit_Enumerated,
|
2011-04-11 23:18:43 -07:00
|
|
|
"unexpected unit");
|
|
|
|
aComputedValue.SetIntValue(aComputedValue.GetIntValue(),
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue::eUnit_Visibility);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
/* 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 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
2011-04-11 23:18:43 -07: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-28 23:19:26 -07:00
|
|
|
bool ok =
|
2011-04-11 23:18:43 -07:00
|
|
|
#endif
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue::UncomputeValue(cv.mProperty, cv.mValue, *prop);
|
2011-04-11 23:18:43 -07:00
|
|
|
NS_ABORT_IF_FALSE(ok, "could not store computed value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-20 13:22:35 -08:00
|
|
|
fputs("[anim values] { ", out);
|
2012-11-20 11:55:14 -08:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
|
|
|
const PropertyValuePair &pair = mPropertyValuePairs[i];
|
|
|
|
nsAutoString value;
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
|
2012-11-20 13:22:35 -08:00
|
|
|
fprintf(out, "%s: %s; ", nsCSSProps::GetStringValue(pair.mProperty).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(value).get());
|
2012-11-20 11:55:14 -08:00
|
|
|
}
|
2012-11-20 13:22:35 -08:00
|
|
|
fputs("}\n", out);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-02 22:57:28 -07:00
|
|
|
} /* end sub-namespace css */
|
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::CanAnimatePropertyOnCompositor(
|
|
|
|
const dom::Element *aElement,
|
2014-06-26 16:57:13 -07:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
CanAnimateFlags aFlags)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2012-08-06 13:33:23 -07:00
|
|
|
bool shouldLog = nsLayoutUtils::IsAnimationLoggingEnabled();
|
2014-03-04 20:13:22 -08:00
|
|
|
if (!gfxPlatform::OffMainThreadCompositingEnabled()) {
|
|
|
|
if (shouldLog) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Compositor disabled");
|
|
|
|
LogAsyncAnimationFailure(message);
|
|
|
|
}
|
2012-08-25 18:27:28 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
|
2012-08-21 18:48:47 -07:00
|
|
|
if (IsGeometricProperty(aProperty)) {
|
|
|
|
if (shouldLog) {
|
2012-08-25 18:27:28 -07:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation of geometric property '");
|
2012-12-11 13:12:47 -08:00
|
|
|
message.Append(nsCSSProps::GetStringValue(aProperty));
|
|
|
|
message.AppendLiteral("' is disabled");
|
2012-08-25 18:27:28 -07:00
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-21 18:48:47 -07:00
|
|
|
}
|
|
|
|
return false;
|
2012-08-05 10:03:43 -07:00
|
|
|
}
|
2012-08-02 23:32:13 -07:00
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2012-08-21 18:48:47 -07:00
|
|
|
if (frame->Preserves3D() &&
|
2012-08-02 23:32:13 -07:00
|
|
|
frame->Preserves3DChildren()) {
|
2012-08-06 13:33:23 -07:00
|
|
|
if (shouldLog) {
|
2012-08-25 18:27:28 -07:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async animation of 'preserve-3d' transforms is not supported. See bug 779598");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-02 23:32:13 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-21 18:48:47 -07:00
|
|
|
if (frame->IsSVGTransformed()) {
|
2012-08-06 13:33:23 -07:00
|
|
|
if (shouldLog) {
|
2012-08-25 18:27:28 -07:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async 'transform' animations of frames with SVG transforms is not supported. See bug 779599");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-02 23:32:13 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
if (aFlags & CanAnimate_HasGeometricProperty) {
|
2012-08-21 18:48:47 -07:00
|
|
|
if (shouldLog) {
|
2012-08-25 18:27:28 -07:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation of 'transform' not possible due to presence of geometric properties");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-21 18:48:47 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-02 23:32:13 -07:00
|
|
|
}
|
2013-05-23 00:09:26 -07:00
|
|
|
bool enabled = nsLayoutUtils::AreAsyncAnimationsEnabled();
|
|
|
|
if (!enabled && shouldLog) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animations are disabled");
|
|
|
|
LogAsyncAnimationFailure(message);
|
|
|
|
}
|
2013-06-18 01:03:20 -07:00
|
|
|
bool propertyAllowed = (aProperty == eCSSProperty_transform) ||
|
|
|
|
(aProperty == eCSSProperty_opacity) ||
|
|
|
|
(aFlags & CanAnimate_AllowPartial);
|
|
|
|
return enabled && propertyAllowed;
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
|
|
|
|
2013-10-22 03:30:45 -07:00
|
|
|
/* static */ bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::IsCompositorAnimationDisabledForFrame(
|
|
|
|
nsIFrame* aFrame)
|
2013-10-22 03:30:45 -07:00
|
|
|
{
|
|
|
|
void* prop = aFrame->Properties().Get(nsIFrame::RefusedAsyncAnimation());
|
|
|
|
return bool(reinterpret_cast<intptr_t>(prop));
|
|
|
|
}
|
|
|
|
|
2014-06-19 20:39:25 -07:00
|
|
|
bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::CanPerformOnCompositorThread(
|
2014-06-19 20:39:25 -07:00
|
|
|
CanAnimateFlags aFlags) const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(mElement);
|
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mElementProperty != nsGkAtoms::transitionsProperty &&
|
|
|
|
mElementProperty != nsGkAtoms::animationsProperty) {
|
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async animation of pseudoelements"
|
|
|
|
" not supported. See bug 771367 (");
|
|
|
|
message.Append(nsAtomCString(mElementProperty));
|
|
|
|
message.Append(")");
|
|
|
|
LogAsyncAnimationFailure(message, mElement);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-08-10 00:06:44 -07:00
|
|
|
const AnimationPlayer* anim = mAnimations[animIdx];
|
2014-07-15 17:02:33 -07:00
|
|
|
bool isRunning = anim->IsRunning();
|
2014-06-19 20:39:25 -07:00
|
|
|
for (uint32_t propIdx = 0, propEnd = anim->mProperties.Length();
|
|
|
|
propIdx != propEnd; ++propIdx) {
|
|
|
|
if (IsGeometricProperty(anim->mProperties[propIdx].mProperty) &&
|
|
|
|
isRunning) {
|
|
|
|
aFlags = CanAnimateFlags(aFlags | CanAnimate_HasGeometricProperty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool existsProperty = false;
|
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-08-10 00:06:44 -07:00
|
|
|
const AnimationPlayer* anim = mAnimations[animIdx];
|
2014-07-15 17:02:33 -07:00
|
|
|
if (!anim->IsRunning()) {
|
2014-06-19 20:39:25 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
existsProperty = true;
|
|
|
|
|
|
|
|
for (uint32_t propIdx = 0, propEnd = anim->mProperties.Length();
|
|
|
|
propIdx != propEnd; ++propIdx) {
|
|
|
|
const AnimationProperty& prop = anim->mProperties[propIdx];
|
|
|
|
if (!CanAnimatePropertyOnCompositor(mElement,
|
|
|
|
prop.mProperty,
|
|
|
|
aFlags) ||
|
|
|
|
IsCompositorAnimationDisabledForFrame(frame)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No properties to animate
|
|
|
|
if (!existsProperty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-19 20:39:25 -07:00
|
|
|
bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::HasAnimationOfProperty(
|
2014-06-19 20:39:25 -07:00
|
|
|
nsCSSProperty aProperty) const
|
|
|
|
{
|
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-08-10 00:06:44 -07:00
|
|
|
const AnimationPlayer* anim = mAnimations[animIdx];
|
2014-06-19 20:39:25 -07:00
|
|
|
if (anim->HasAnimationOfProperty(aProperty) &&
|
|
|
|
!anim->IsFinishedTransition()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-25 18:27:28 -07:00
|
|
|
/* static */ void
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::LogAsyncAnimationFailure(nsCString& aMessage,
|
2012-08-25 18:27:28 -07:00
|
|
|
const nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
aMessage.AppendLiteral(" [");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->Tag()));
|
|
|
|
|
|
|
|
nsIAtom* id = aContent->GetID();
|
|
|
|
if (id) {
|
|
|
|
aMessage.AppendLiteral(" with id '");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->GetID()));
|
2014-05-21 20:48:51 -07:00
|
|
|
aMessage.Append('\'');
|
2012-08-25 18:27:28 -07:00
|
|
|
}
|
2014-05-21 20:48:51 -07:00
|
|
|
aMessage.Append(']');
|
2012-08-25 18:27:28 -07:00
|
|
|
}
|
2014-05-21 20:48:51 -07:00
|
|
|
aMessage.Append('\n');
|
2012-08-25 18:27:28 -07:00
|
|
|
printf_stderr(aMessage.get());
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2014-06-23 23:29:53 -07:00
|
|
|
/*static*/ void
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName,
|
2014-06-23 23:29:53 -07:00
|
|
|
void *aPropertyValue, void *aData)
|
|
|
|
{
|
2014-06-26 16:57:13 -07:00
|
|
|
ElementAnimationCollection* collection =
|
2014-06-26 16:57:12 -07:00
|
|
|
static_cast<ElementAnimationCollection*>(aPropertyValue);
|
2014-06-23 23:29:53 -07:00
|
|
|
#ifdef DEBUG
|
2014-06-26 16:57:13 -07:00
|
|
|
NS_ABORT_IF_FALSE(!collection->mCalledPropertyDtor, "can't call dtor twice");
|
|
|
|
collection->mCalledPropertyDtor = true;
|
2014-06-23 23:29:53 -07:00
|
|
|
#endif
|
2014-06-26 16:57:13 -07:00
|
|
|
delete collection;
|
2014-06-23 23:29:53 -07:00
|
|
|
}
|
|
|
|
|
2014-06-19 20:39:24 -07:00
|
|
|
void
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::EnsureStyleRuleFor(TimeStamp aRefreshTime,
|
2014-06-19 20:39:25 -07:00
|
|
|
EnsureStyleRuleFlags aFlags)
|
2014-06-19 20:39:24 -07:00
|
|
|
{
|
|
|
|
if (!mNeedsRefreshes) {
|
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're performing animations on the compositor thread, then we can skip
|
|
|
|
// most of the work in this method. But even if we are throttled, then we
|
|
|
|
// have to do the work if an animation is ending in order to get correct end
|
|
|
|
// of animation behaviour (the styles of the animation disappear, or the fill
|
|
|
|
// mode behaviour). This loop checks for any finishing animations and forces
|
|
|
|
// the style recalculation if we find any.
|
2014-06-19 20:39:25 -07:00
|
|
|
if (aFlags == EnsureStyleRule_IsThrottled) {
|
2014-06-19 20:39:24 -07:00
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-08-10 00:06:44 -07:00
|
|
|
AnimationPlayer* anim = mAnimations[animIdx];
|
2014-06-19 20:39:24 -07:00
|
|
|
|
|
|
|
// Skip finished transitions or animations whose @keyframes rule
|
|
|
|
// is empty.
|
|
|
|
if (anim->IsFinishedTransition() || anim->mProperties.IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-15 17:02:32 -07:00
|
|
|
// The GetLocalTime() call here handles pausing. But:
|
2014-06-19 20:39:24 -07:00
|
|
|
// FIXME: avoid recalculating every time when paused.
|
2014-07-15 17:02:33 -07:00
|
|
|
ComputedTiming computedTiming = anim->GetComputedTiming(anim->mTiming);
|
2014-06-19 20:39:24 -07:00
|
|
|
|
|
|
|
// XXX We shouldn't really be using mLastNotification as a general
|
|
|
|
// indicator that the animation has finished, it should be reserved for
|
|
|
|
// events. If we use it differently in the future this use might need
|
|
|
|
// changing.
|
|
|
|
if (!anim->mIsRunningOnCompositor ||
|
|
|
|
(computedTiming.mPhase == ComputedTiming::AnimationPhase_After &&
|
2014-08-10 00:06:44 -07:00
|
|
|
anim->mLastNotification != AnimationPlayer::LAST_NOTIFICATION_END))
|
2014-06-19 20:39:24 -07:00
|
|
|
{
|
2014-06-19 20:39:25 -07:00
|
|
|
aFlags = EnsureStyleRule_IsNotThrottled;
|
2014-06-19 20:39:24 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 20:39:25 -07:00
|
|
|
if (aFlags == EnsureStyleRule_IsThrottled) {
|
2014-06-19 20:39:24 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mStyleRule may be null and valid, if we have no style to apply.
|
|
|
|
if (mStyleRuleRefreshTime.IsNull() ||
|
|
|
|
mStyleRuleRefreshTime != aRefreshTime) {
|
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
mStyleRule = nullptr;
|
|
|
|
// We'll set mNeedsRefreshes to true below in all cases where we need them.
|
|
|
|
mNeedsRefreshes = false;
|
|
|
|
|
|
|
|
// FIXME(spec): assume that properties in higher animations override
|
|
|
|
// those in lower ones.
|
|
|
|
// Therefore, we iterate from last animation to first.
|
|
|
|
nsCSSPropertySet properties;
|
|
|
|
|
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-08-10 00:06:44 -07:00
|
|
|
AnimationPlayer* anim = mAnimations[animIdx];
|
2014-06-19 20:39:24 -07:00
|
|
|
|
|
|
|
if (anim->IsFinishedTransition()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-15 17:02:32 -07:00
|
|
|
// The GetLocalTime() call here handles pausing. But:
|
2014-06-19 20:39:24 -07:00
|
|
|
// FIXME: avoid recalculating every time when paused.
|
2014-07-15 17:02:33 -07:00
|
|
|
ComputedTiming computedTiming = anim->GetComputedTiming(anim->mTiming);
|
2014-06-19 20:39:24 -07:00
|
|
|
|
|
|
|
if ((computedTiming.mPhase == ComputedTiming::AnimationPhase_Before ||
|
|
|
|
computedTiming.mPhase == ComputedTiming::AnimationPhase_Active) &&
|
|
|
|
!anim->IsPaused()) {
|
|
|
|
mNeedsRefreshes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the time fraction is null, we don't have fill data for the current
|
|
|
|
// time so we shouldn't animate.
|
|
|
|
if (computedTiming.mTimeFraction == ComputedTiming::kNullTimeFraction) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(0.0 <= computedTiming.mTimeFraction &&
|
|
|
|
computedTiming.mTimeFraction <= 1.0,
|
|
|
|
"timing fraction should be in [0-1]");
|
|
|
|
|
|
|
|
for (uint32_t propIdx = 0, propEnd = anim->mProperties.Length();
|
|
|
|
propIdx != propEnd; ++propIdx)
|
|
|
|
{
|
|
|
|
const AnimationProperty &prop = anim->mProperties[propIdx];
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments[0].mFromKey == 0.0,
|
|
|
|
"incorrect first from key");
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments[prop.mSegments.Length() - 1].mToKey
|
|
|
|
== 1.0,
|
|
|
|
"incorrect last to key");
|
|
|
|
|
|
|
|
if (properties.HasProperty(prop.mProperty)) {
|
|
|
|
// A later animation already set this property.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
properties.AddProperty(prop.mProperty);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments.Length() > 0,
|
|
|
|
"property should not be in animations if it "
|
|
|
|
"has no segments");
|
|
|
|
|
|
|
|
// FIXME: Maybe cache the current segment?
|
|
|
|
const AnimationPropertySegment *segment = prop.mSegments.Elements(),
|
|
|
|
*segmentEnd = segment + prop.mSegments.Length();
|
|
|
|
while (segment->mToKey < computedTiming.mTimeFraction) {
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey < segment->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
++segment;
|
|
|
|
if (segment == segmentEnd) {
|
|
|
|
NS_ABORT_IF_FALSE(false, "incorrect time fraction");
|
|
|
|
break; // in order to continue in outer loop (just below)
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey == (segment-1)->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
}
|
|
|
|
if (segment == segmentEnd) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey < segment->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
NS_ABORT_IF_FALSE(segment >= prop.mSegments.Elements() &&
|
|
|
|
size_t(segment - prop.mSegments.Elements()) <
|
|
|
|
prop.mSegments.Length(),
|
|
|
|
"out of array bounds");
|
|
|
|
|
|
|
|
if (!mStyleRule) {
|
|
|
|
// Allocate the style rule now that we know we have animation data.
|
|
|
|
mStyleRule = new css::AnimValuesStyleRule();
|
|
|
|
}
|
|
|
|
|
|
|
|
double positionInSegment =
|
|
|
|
(computedTiming.mTimeFraction - segment->mFromKey) /
|
|
|
|
(segment->mToKey - segment->mFromKey);
|
|
|
|
double valuePosition =
|
|
|
|
segment->mTimingFunction.GetValue(positionInSegment);
|
|
|
|
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue *val =
|
2014-06-19 20:39:24 -07:00
|
|
|
mStyleRule->AddEmptyValue(prop.mProperty);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool result =
|
|
|
|
#endif
|
2014-06-23 23:29:54 -07:00
|
|
|
StyleAnimationValue::Interpolate(prop.mProperty,
|
|
|
|
segment->mFromValue,
|
|
|
|
segment->mToValue,
|
|
|
|
valuePosition, *val);
|
2014-06-19 20:39:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(result, "interpolate must succeed now");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::CanThrottleTransformChanges(TimeStamp aTime)
|
2012-12-11 13:12:43 -08:00
|
|
|
{
|
2013-05-22 03:31:03 -07:00
|
|
|
if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) {
|
2012-12-11 13:12:43 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we know that the animation cannot cause overflow,
|
|
|
|
// we can just disable flushes for this animation.
|
|
|
|
|
|
|
|
// If we don't show scrollbars, we don't care about overflow.
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this animation can cause overflow, we can throttle some of the ticks.
|
|
|
|
if ((aTime - mStyleRuleRefreshTime) < TimeDuration::FromMilliseconds(200)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the nearest scrollable ancestor has overflow:hidden,
|
|
|
|
// we don't care about overflow.
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIScrollableFrame* scrollable = nsLayoutUtils::GetNearestScrollableFrame(
|
|
|
|
nsLayoutUtils::GetStyleFrame(mElement));
|
2012-12-11 13:12:43 -08:00
|
|
|
if (!scrollable) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-23 13:20:07 -07:00
|
|
|
ScrollbarStyles ss = scrollable->GetScrollbarStyles();
|
2012-12-11 13:12:43 -08:00
|
|
|
if (ss.mVertical == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
ss.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
scrollable->GetLogicalScrollPosition() == nsPoint(0, 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-06-26 16:57:12 -07:00
|
|
|
ElementAnimationCollection::CanThrottleAnimation(TimeStamp aTime)
|
2012-12-11 13:12:43 -08:00
|
|
|
{
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(mElement);
|
2012-12-11 13:12:43 -08:00
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasTransform = HasAnimationOfProperty(eCSSProperty_transform);
|
|
|
|
bool hasOpacity = HasAnimationOfProperty(eCSSProperty_opacity);
|
|
|
|
if (hasOpacity) {
|
|
|
|
Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
frame, nsDisplayItem::TYPE_OPACITY);
|
|
|
|
if (!layer || mAnimationGeneration > layer->GetAnimationGeneration()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasTransform) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
frame, nsDisplayItem::TYPE_TRANSFORM);
|
|
|
|
if (!layer || mAnimationGeneration > layer->GetAnimationGeneration()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CanThrottleTransformChanges(aTime);
|
|
|
|
}
|
|
|
|
|
2014-06-26 16:57:12 -07:00
|
|
|
void
|
|
|
|
ElementAnimationCollection::UpdateAnimationGeneration(
|
|
|
|
nsPresContext* aPresContext)
|
2012-12-11 13:12:43 -08:00
|
|
|
{
|
|
|
|
mAnimationGeneration =
|
2013-07-20 12:14:25 -07:00
|
|
|
aPresContext->RestyleManager()->GetAnimationGeneration();
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
|
2014-06-16 11:43:04 -07:00
|
|
|
bool
|
2014-07-15 17:02:33 -07:00
|
|
|
ElementAnimationCollection::HasCurrentAnimations()
|
2014-06-16 11:43:04 -07:00
|
|
|
{
|
|
|
|
for (uint32_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2014-07-15 17:02:33 -07:00
|
|
|
if (mAnimations[animIdx]->IsCurrent()) {
|
2014-06-16 11:43:04 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|