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
|
|
|
|
2013-10-23 00:55:14 +04:00
|
|
|
#include "AnimationCommon.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsTransitionManager.h"
|
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
#include "ActiveLayerTracker.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "gfxPlatform.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsRuleData.h"
|
2014-06-20 07:39:24 +04:00
|
|
|
#include "nsCSSPropertySet.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCSSValue.h"
|
2014-07-16 04:02:30 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-06-09 05:13:53 +03:00
|
|
|
#include "nsDOMMutationObserver.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsStyleContext.h"
|
2012-07-31 21:28:21 +04:00
|
|
|
#include "nsIFrame.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2015-09-03 23:59:00 +03:00
|
|
|
#include "LayerAnimationInfo.h" // For LayerAnimationInfo::sRecords
|
2012-12-12 01:12:43 +04:00
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsDisplayList.h"
|
2015-12-04 02:32:53 +03:00
|
|
|
#include "mozilla/EffectSet.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-04-15 02:48:21 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "RestyleManager.h"
|
2014-11-20 05:48:41 +03:00
|
|
|
#include "nsRuleProcessorData.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
using mozilla::dom::Animation;
|
2015-04-30 16:06:43 +03:00
|
|
|
using mozilla::dom::KeyframeEffectReadOnly;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CommonAnimationManager::~CommonAnimationManager()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mPresContext, "Disconnect should have been called");
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::Disconnect()
|
|
|
|
{
|
|
|
|
// Content nodes might outlive the transition or animation manager.
|
2014-06-27 03:57:13 +04:00
|
|
|
RemoveAllElementCollections();
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPresContext = nullptr;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 07:45:56 +03:00
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
CommonAnimationManager::AddElementCollection(AnimationCollection* aCollection)
|
2014-11-17 07:45:56 +03:00
|
|
|
{
|
2015-08-18 07:13:14 +03:00
|
|
|
mElementCollections.insertBack(aCollection);
|
2014-11-17 07:45:56 +03:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
void
|
2014-06-27 03:57:13 +04:00
|
|
|
CommonAnimationManager::RemoveAllElementCollections()
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2015-08-18 07:13:14 +03:00
|
|
|
while (AnimationCollection* head = mElementCollections.getFirst()) {
|
|
|
|
head->Destroy(); // Note: this removes 'head' from mElementCollections.
|
|
|
|
}
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection*
|
2015-07-01 21:43:13 +03:00
|
|
|
CommonAnimationManager::GetAnimationCollection(const nsIFrame* aFrame)
|
2014-06-20 07:39:25 +04:00
|
|
|
{
|
2015-07-01 21:43:13 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return nullptr;
|
2015-07-01 18:55:51 +03:00
|
|
|
}
|
2015-07-01 21:43:13 +03:00
|
|
|
nsIAtom* animProp;
|
|
|
|
if (aFrame->IsGeneratedContentFrame()) {
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (parent->IsGeneratedContentFrame()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIAtom* name = content->NodeInfo()->NameAtom();
|
|
|
|
if (name == nsGkAtoms::mozgeneratedcontentbefore) {
|
|
|
|
animProp = GetAnimationsBeforeAtom();
|
|
|
|
} else if (name == nsGkAtoms::mozgeneratedcontentafter) {
|
|
|
|
animProp = GetAnimationsAfterAtom();
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
content = content->GetParent();
|
|
|
|
if (!content) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-01 18:55:51 +03:00
|
|
|
} else {
|
2015-07-01 21:43:13 +03:00
|
|
|
if (!content->MayHaveAnimations()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
animProp = GetAnimationsAtom();
|
2015-07-01 18:55:51 +03:00
|
|
|
}
|
2015-04-01 06:23:24 +03:00
|
|
|
|
2015-07-01 21:43:13 +03:00
|
|
|
return static_cast<AnimationCollection*>(content->GetProperty(animProp));
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationCollection*
|
|
|
|
CommonAnimationManager::GetAnimationsForCompositor(const nsIFrame* aFrame,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
AnimationCollection* collection = GetAnimationCollection(aFrame);
|
2014-06-27 03:57:13 +04:00
|
|
|
if (!collection ||
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
!collection->HasCurrentAnimationOfProperty(aProperty) ||
|
2015-11-06 04:47:00 +03:00
|
|
|
!collection->CanPerformOnCompositorThread(aFrame)) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-20 07:39:26 +04:00
|
|
|
|
|
|
|
// This animation can be done on the compositor.
|
2014-06-27 03:57:13 +04:00
|
|
|
return collection;
|
2014-06-20 07:39:25 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(PseudoElementStateRuleProcessorData* 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
|
2015-08-05 15:42:21 +03:00
|
|
|
CommonAnimationManager::HasAttributeDependentStyle(
|
|
|
|
AttributeRuleProcessorData* aData,
|
|
|
|
RestyleHintData& aRestyleHintDataResult)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-20 05:48:41 +03:00
|
|
|
/* virtual */ void
|
|
|
|
CommonAnimationManager::RulesMatching(ElementRuleProcessorData* aData)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2014-11-20 05:48:41 +03:00
|
|
|
nsIStyleRule *rule =
|
|
|
|
GetAnimationRule(aData->mElement,
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
|
|
|
if (rule) {
|
|
|
|
aData->mRuleWalker->Forward(rule);
|
2015-07-27 09:43:44 +03:00
|
|
|
aData->mRuleWalker->CurrentNode()->SetIsAnimationRule();
|
2014-11-20 05:48:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
CommonAnimationManager::RulesMatching(PseudoElementRuleProcessorData* aData)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2014-11-20 05:48:41 +03:00
|
|
|
if (aData->mPseudoType != nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
aData->mPseudoType != nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Do we really want to be the only thing keeping a
|
|
|
|
// pseudo-element alive? I *think* the non-animation restyle should
|
|
|
|
// handle that, but should add a test.
|
|
|
|
nsIStyleRule *rule = GetAnimationRule(aData->mElement, aData->mPseudoType);
|
|
|
|
if (rule) {
|
|
|
|
aData->mRuleWalker->Forward(rule);
|
2015-07-27 09:43:44 +03:00
|
|
|
aData->mRuleWalker->CurrentNode()->SetIsAnimationRule();
|
2014-11-20 05:48:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
CommonAnimationManager::RulesMatching(AnonBoxRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
/* virtual */ void
|
|
|
|
CommonAnimationManager::RulesMatching(XULTreeRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
CommonAnimationManager::SizeOfExcludingThis(mozilla::MallocSizeOf 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:
|
2014-06-27 03:57:13 +04:00
|
|
|
// - mElementCollections
|
2012-01-03 06:19:14 +04:00
|
|
|
//
|
|
|
|
// 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
|
2013-06-23 16:03:39 +04:00
|
|
|
CommonAnimationManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-09 09:01:52 +04:00
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-01 22:25:20 +04:00
|
|
|
}
|
|
|
|
|
2014-08-07 09:58:44 +04:00
|
|
|
void
|
|
|
|
CommonAnimationManager::AddStyleUpdatesTo(RestyleTracker& aTracker)
|
|
|
|
{
|
2014-11-12 02:42:57 +03:00
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
2015-08-18 07:13:14 +03:00
|
|
|
for (AnimationCollection* collection = mElementCollections.getFirst();
|
|
|
|
collection; collection = collection->getNext()) {
|
2015-08-18 10:11:55 +03:00
|
|
|
collection->EnsureStyleRuleFor(now);
|
2014-11-12 02:42:57 +03:00
|
|
|
|
2014-08-25 08:48:22 +04:00
|
|
|
dom::Element* elementToRestyle = collection->GetElementToRestyle();
|
|
|
|
if (elementToRestyle) {
|
|
|
|
nsRestyleHint rshint = collection->IsForTransitions()
|
|
|
|
? eRestyle_CSSTransitions : eRestyle_CSSAnimations;
|
|
|
|
aTracker.AddPendingRestyle(elementToRestyle, rshint, nsChangeHint(0));
|
2014-08-07 09:58:44 +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,
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue& aComputedValue)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
bool result = StyleAnimationValue::ExtractComputedValue(aProperty,
|
|
|
|
aStyleContext,
|
|
|
|
aComputedValue);
|
2011-04-12 10:18:43 +04:00
|
|
|
if (aProperty == eCSSProperty_visibility) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aComputedValue.GetUnit() ==
|
|
|
|
StyleAnimationValue::eUnit_Enumerated,
|
|
|
|
"unexpected unit");
|
2011-04-12 10:18:43 +04:00
|
|
|
aComputedValue.SetIntValue(aComputedValue.GetIntValue(),
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::eUnit_Visibility);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection*
|
2015-03-20 21:20:49 +03:00
|
|
|
CommonAnimationManager::GetAnimations(dom::Element *aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
bool aCreateIfNeeded)
|
2014-11-20 05:48:41 +03:00
|
|
|
{
|
2015-08-18 07:13:14 +03:00
|
|
|
if (!aCreateIfNeeded && mElementCollections.isEmpty()) {
|
2014-11-20 05:48:41 +03:00
|
|
|
// Early return for the most common case.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *propName;
|
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
propName = GetAnimationsAtom();
|
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_before) {
|
|
|
|
propName = GetAnimationsBeforeAtom();
|
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_after) {
|
|
|
|
propName = GetAnimationsAfterAtom();
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!aCreateIfNeeded,
|
|
|
|
"should never try to create transitions for pseudo "
|
|
|
|
"other than :before or :after");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection* collection =
|
|
|
|
static_cast<AnimationCollection*>(aElement->GetProperty(propName));
|
2014-11-20 05:48:41 +03:00
|
|
|
if (!collection && aCreateIfNeeded) {
|
|
|
|
// FIXME: Consider arena-allocating?
|
2015-04-21 04:22:10 +03:00
|
|
|
collection = new AnimationCollection(aElement, propName, this);
|
2014-11-20 05:48:41 +03:00
|
|
|
nsresult rv =
|
|
|
|
aElement->SetProperty(propName, collection,
|
2015-04-21 04:22:10 +03:00
|
|
|
&AnimationCollection::PropertyDtor, false);
|
2014-11-20 05:48:41 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("SetProperty failed");
|
2015-07-01 18:55:51 +03:00
|
|
|
// The collection must be destroyed via PropertyDtor, otherwise
|
|
|
|
// mCalledPropertyDtor assertion is triggered in destructor.
|
|
|
|
AnimationCollection::PropertyDtor(aElement, propName, collection, nullptr);
|
2014-11-20 05:48:41 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-01 18:55:51 +03:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
2014-11-20 05:48:41 +03:00
|
|
|
aElement->SetMayHaveAnimations();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddElementCollection(collection);
|
|
|
|
}
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
void
|
2015-08-31 10:21:55 +03:00
|
|
|
CommonAnimationManager::FlushAnimations()
|
2015-08-17 07:59:44 +03:00
|
|
|
{
|
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
2015-08-18 07:13:14 +03:00
|
|
|
for (AnimationCollection* collection = mElementCollections.getFirst();
|
|
|
|
collection; collection = collection->getNext()) {
|
2015-08-17 07:59:44 +03:00
|
|
|
if (collection->mStyleRuleRefreshTime == now) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-09-09 04:10:41 +03:00
|
|
|
MOZ_ASSERT(collection->mElement->GetComposedDoc() ==
|
|
|
|
mPresContext->Document(),
|
2015-09-15 08:05:49 +03:00
|
|
|
"Should not have a transition/animation collection for an "
|
2015-09-09 04:10:41 +03:00
|
|
|
"element that is not part of the document tree");
|
|
|
|
|
2015-08-31 10:21:55 +03:00
|
|
|
collection->RequestRestyle(AnimationCollection::RestyleType::Standard);
|
2015-08-17 07:59:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 05:48:41 +03:00
|
|
|
nsIStyleRule*
|
|
|
|
CommonAnimationManager::GetAnimationRule(mozilla::dom::Element* aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(
|
2014-11-20 05:48:41 +03:00
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_before ||
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_after,
|
|
|
|
"forbidden pseudo type");
|
|
|
|
|
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore animations.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection* collection =
|
2015-03-20 21:20:49 +03:00
|
|
|
GetAnimations(aElement, aPseudoType, false);
|
2014-11-20 05:48:41 +03:00
|
|
|
if (!collection) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RestyleManager* restyleManager = mPresContext->RestyleManager();
|
|
|
|
if (restyleManager->SkipAnimationRules()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-24 03:06:06 +03:00
|
|
|
collection->EnsureStyleRuleFor(
|
2015-08-18 10:11:55 +03:00
|
|
|
mPresContext->RefreshDriver()->MostRecentRefresh());
|
2014-11-20 05:48:41 +03:00
|
|
|
|
|
|
|
return collection->mStyleRule;
|
|
|
|
}
|
|
|
|
|
2015-09-16 17:05:00 +03:00
|
|
|
void
|
|
|
|
CommonAnimationManager::ClearIsRunningOnCompositor(const nsIFrame* aFrame,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
2015-12-04 02:32:53 +03:00
|
|
|
EffectSet* effects = EffectSet::GetEffectSet(aFrame);
|
|
|
|
if (!effects) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (KeyframeEffectReadOnly* effect : *effects) {
|
|
|
|
effect->SetIsRunningOnCompositor(aProperty, false);
|
2015-09-16 17:05:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
|
2011-04-12 10:18:43 +04: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.
|
2015-07-27 09:43:44 +03:00
|
|
|
|
|
|
|
// Prevent structs from being cached on the rule node since we're inside
|
|
|
|
// a pseudo-element, as we could determine cacheability differently
|
|
|
|
// when walking the rule tree for a style context that is not inside
|
|
|
|
// a pseudo-element. Note that nsRuleNode::GetStyle##name_ and GetStyleData
|
|
|
|
// will never look at cached structs when we're animating things inside
|
|
|
|
// a pseduo-element, so that we don't incorrectly return a struct that
|
|
|
|
// is only appropriate for non-pseudo-elements.
|
|
|
|
aRuleData->mConditions.SetUncacheable();
|
2011-04-12 10:18:43 +04:00
|
|
|
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
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::UncomputeValue(cv.mProperty, cv.mValue, *prop);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(ok, "could not store computed value");
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 07:09:55 +03:00
|
|
|
/* virtual */ bool
|
|
|
|
AnimValuesStyleRule::MightMapInheritedStyleData()
|
|
|
|
{
|
|
|
|
return mStyleBits & NS_STYLE_INHERITED_STRUCT_MASK;
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
#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
|
|
|
{
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString str;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral("[anim values] { ");
|
2012-11-20 23:55:14 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
|
|
|
const PropertyValuePair &pair = mPropertyValuePairs[i];
|
2014-11-27 09:29:44 +03:00
|
|
|
str.Append(nsCSSProps::GetStringValue(pair.mProperty));
|
|
|
|
str.AppendLiteral(": ");
|
2012-11-20 23:55:14 +04:00
|
|
|
nsAutoString value;
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
|
2014-11-27 09:29:44 +03:00
|
|
|
AppendUTF16toUTF8(value, str);
|
|
|
|
str.AppendLiteral("; ");
|
2012-11-20 23:55:14 +04:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral("}\n");
|
|
|
|
fprintf_stderr(out, "%s", str.get());
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
bool
|
2015-11-06 04:47:00 +03:00
|
|
|
AnimationCollection::CanPerformOnCompositorThread(const nsIFrame* aFrame) const
|
2014-06-20 07:39:25 +04:00
|
|
|
{
|
2015-11-06 04:34:00 +03:00
|
|
|
if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) {
|
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animations are disabled");
|
|
|
|
LogAsyncAnimationFailure(message);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-06 04:47:00 +03:00
|
|
|
if (aFrame->RefusedAsyncAnimation()) {
|
2015-11-06 04:35:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
for (size_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
|
|
|
const Animation* anim = mAnimations[animIdx];
|
|
|
|
if (!anim->IsPlaying()) {
|
2014-06-20 07:39:25 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-30 16:06:43 +03:00
|
|
|
const KeyframeEffectReadOnly* effect = anim->GetEffect();
|
2015-04-21 04:22:10 +03:00
|
|
|
MOZ_ASSERT(effect, "A playing animation should have an effect");
|
2015-03-27 12:01:00 +03:00
|
|
|
|
2015-04-15 02:48:21 +03:00
|
|
|
for (size_t propIdx = 0, propEnd = effect->Properties().Length();
|
2014-06-20 07:39:25 +04:00
|
|
|
propIdx != propEnd; ++propIdx) {
|
2015-04-15 02:48:21 +03:00
|
|
|
const AnimationProperty& prop = effect->Properties()[propIdx];
|
2015-11-06 04:45:00 +03:00
|
|
|
if (!KeyframeEffectReadOnly::CanAnimatePropertyOnCompositor(
|
2015-11-06 04:47:00 +03:00
|
|
|
aFrame,
|
2015-11-06 04:45:00 +03:00
|
|
|
prop.mProperty)) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
bool
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
AnimationCollection::HasCurrentAnimationOfProperty(nsCSSProperty
|
|
|
|
aProperty) const
|
2014-06-20 07:39:25 +04:00
|
|
|
{
|
Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron
AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:
1. nsLayoutUtils::HasAnimations
The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
there are any opacity animations
For this case, simply returning *current* animations would be sufficient
(since finished but filling animations should have already filled in the
display opacity)
2. CommonAnimationManager::GetAnimationsForCompositor
This should really only return *current* animations--that is, animations that
are running or scheduled to run. Finished animations never run on the
compositor. Indeed, only *playing* animations run on the compositor but, as
we will see in some of the cases below, it is sometimes useful to know that
an animation *will* run on the compositor in the near future (e.g. so we can
pre-render content).
The places where GetAnimationsForCompositor is used are:
- When building layers to add animations to layers in nsDisplayList--in this
case we skip any animations that aren't playing so if
GetAnimationsForCompositor only returned current animations that would be
more than sufficient.
- In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:
- In ChooseScaleAndSetTransform to see if the transform is being animated
on the compositor. If so, it calls
nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
GetAnimationsForCompositor) and passes the result to
GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
part 4 of this patch series to only deal with *relevant* animations
Relevant animations include both current animations and in effect
animations but we don't run forwards-filling animations on the compositor
so GetAnimationsForCompositor should NOT return them. Current animations
should be enough. In fact, playing animations should be enough but we
might want to pre-render layers at a suitable size during their delay
phase so returning current animations is probably ok.
- In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
factor to the overflow rect for frames undergoing a transform animation
on the compositor. In this case too current animations should be
sufficient.
- In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
opacity on the compositor. Presumably in this case it would be good to
say "yes" if the animation is in the delay phase too (as it currently
does). After the animation is finished, we should drop the layer, i.e.
current animations should be sufficient.
- In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
transformed content for animations that are current.
- In nsDisplayTransform::GetLayerState. As with
nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
for current animations.
- In nsIFrame::IsTransformed. Here we test the display style to see if
there is a transform and also check if transform is being animated on the
compositor. As a result, we really only need HasAnimationsForCompositor
to return true for animations that are playing--otherwise the display
style will tell us if we're transformed or not. Returning true for all
current compositor animations (which is a superset of playing), however,
should not cause problems (we already return true for even more than
that).
- In nsIFrame::HasOpacityInternal which is much the same as
nsIFrame::IsTransformed and hence current should be fine.
3. AnimationCollection::CanThrottleAnimation
Here, HasAnimationOfProperty is used when looking for animations that would
disqualify us from throttling the animation by having an out-of-date layer
generation or being a transform animation that affects scroll and so requires
that we do the occasional main thread sample to update scrollbars.
It would seem like current animations are enough here too. One interesting
case is where we *had* a compositor animation but it has finished or been
cancelled. In that case, the animation won't be current and we should not
throttle the animation since we need to take it off its layer.
It turns out checking for current animations is still ok in this case too.
The reasoning is as follows:
- If the animation is newly-finished, we'll pick that up in
Animation::CanThrottle and return false then.
- If the animation is newly-idle then there are two cases:
If the cancelled animation was the only compositor animation then
AnimationCollection::CanPerformOnCompositorThread will notice that there
are no playing compositor animations and return false and
AnimationCollection::CanThrottleAnimation will never be called.
If there are other compositor animations running, then
AnimationCollection::CanThrottleAnimation will still return false because
whatever cancelled the animation will update the animation generation and
we'll notice the mismatch between the layer animation generation and the
animation generation on the collection.
Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.
This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
2015-08-07 06:29:36 +03:00
|
|
|
for (Animation* animation : mAnimations) {
|
|
|
|
if (animation->HasCurrentEffect() &&
|
|
|
|
animation->GetEffect()->HasAnimationOfProperty(aProperty)) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:40 +03:00
|
|
|
/*static*/ nsString
|
|
|
|
AnimationCollection::PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType)
|
|
|
|
{
|
|
|
|
switch (aPseudoType) {
|
|
|
|
case nsCSSPseudoElements::ePseudo_before:
|
|
|
|
return NS_LITERAL_STRING("::before");
|
|
|
|
case nsCSSPseudoElements::ePseudo_after:
|
|
|
|
return NS_LITERAL_STRING("::after");
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
"Unexpected pseudo type");
|
|
|
|
return EmptyString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-25 08:48:22 +04:00
|
|
|
mozilla::dom::Element*
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::GetElementToRestyle() const
|
2014-08-25 08:48:22 +04:00
|
|
|
{
|
|
|
|
if (IsForElement()) {
|
|
|
|
return mElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* primaryFrame = mElement->GetPrimaryFrame();
|
|
|
|
if (!primaryFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIFrame* pseudoFrame;
|
|
|
|
if (IsForBeforePseudo()) {
|
|
|
|
pseudoFrame = nsLayoutUtils::GetBeforeFrame(primaryFrame);
|
|
|
|
} else if (IsForAfterPseudo()) {
|
|
|
|
pseudoFrame = nsLayoutUtils::GetAfterFrame(primaryFrame);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "unknown mElementProperty");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!pseudoFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return pseudoFrame->GetContent()->AsElement();
|
|
|
|
}
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
/* static */ void
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::LogAsyncAnimationFailure(nsCString& aMessage,
|
2012-08-26 05:27:28 +04:00
|
|
|
const nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
aMessage.AppendLiteral(" [");
|
2015-03-03 14:09:00 +03:00
|
|
|
aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom()));
|
2012-08-26 05:27:28 +04:00
|
|
|
|
|
|
|
nsIAtom* id = aContent->GetID();
|
|
|
|
if (id) {
|
|
|
|
aMessage.AppendLiteral(" with id '");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->GetID()));
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append('\'');
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append(']');
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append('\n');
|
2014-08-27 01:14:51 +04:00
|
|
|
printf_stderr("%s", aMessage.get());
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-06-24 10:29:53 +04:00
|
|
|
/*static*/ void
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue, void *aData)
|
2014-06-24 10:29:53 +04:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection* collection =
|
|
|
|
static_cast<AnimationCollection*>(aPropertyValue);
|
2014-06-24 10:29:53 +04:00
|
|
|
#ifdef DEBUG
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!collection->mCalledPropertyDtor, "can't call dtor twice");
|
2014-06-27 03:57:13 +04:00
|
|
|
collection->mCalledPropertyDtor = true;
|
2014-06-24 10:29:53 +04:00
|
|
|
#endif
|
2015-06-09 05:13:53 +03:00
|
|
|
{
|
2015-08-31 10:21:49 +03:00
|
|
|
nsAutoAnimationMutationBatch mb(collection->mElement->OwnerDoc());
|
2015-06-09 05:13:53 +03:00
|
|
|
|
|
|
|
for (size_t animIdx = collection->mAnimations.Length(); animIdx-- != 0; ) {
|
|
|
|
collection->mAnimations[animIdx]->CancelFromStyle();
|
|
|
|
}
|
|
|
|
}
|
2014-06-27 03:57:13 +04:00
|
|
|
delete collection;
|
2014-06-24 10:29:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::Tick()
|
2014-08-10 11:06:48 +04:00
|
|
|
{
|
2015-04-21 04:22:10 +03:00
|
|
|
for (size_t animIdx = 0, animEnd = mAnimations.Length();
|
|
|
|
animIdx != animEnd; animIdx++) {
|
|
|
|
mAnimations[animIdx]->Tick();
|
2014-08-10 11:06:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:24 +04:00
|
|
|
void
|
2015-08-18 10:11:55 +03:00
|
|
|
AnimationCollection::EnsureStyleRuleFor(TimeStamp aRefreshTime)
|
2014-06-20 07:39:24 +04:00
|
|
|
{
|
2015-08-17 07:59:44 +03:00
|
|
|
mHasPendingAnimationRestyle = false;
|
|
|
|
|
2015-09-17 09:43:15 +03:00
|
|
|
if (!mStyleChanging) {
|
2014-06-20 07:39:24 +04:00
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
if (!mStyleRuleRefreshTime.IsNull() &&
|
|
|
|
mStyleRuleRefreshTime == aRefreshTime) {
|
|
|
|
// mStyleRule may be null and valid, if we have no style to apply.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mManager->IsAnimationManager()) {
|
|
|
|
// Update cascade results before updating the style rule, since the
|
|
|
|
// cascade results can influence the style rule.
|
|
|
|
static_cast<nsAnimationManager*>(mManager)->MaybeUpdateCascadeResults(this);
|
|
|
|
}
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
mStyleRule = nullptr;
|
2015-09-17 09:43:15 +03:00
|
|
|
// We'll set mStyleChanging to true below if necessary.
|
|
|
|
mStyleChanging = false;
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
// If multiple animations specify behavior for the same property the
|
|
|
|
// animation which occurs last in the value of animation-name wins.
|
|
|
|
// As a result, we iterate from last animation to first and, if a
|
|
|
|
// property has already been set, we don't leave it.
|
|
|
|
nsCSSPropertySet properties;
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
for (size_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
|
2015-09-17 09:43:15 +03:00
|
|
|
mAnimations[animIdx]->ComposeStyle(mStyleRule, properties, mStyleChanging);
|
2015-04-01 01:05:55 +03:00
|
|
|
}
|
2014-11-17 07:45:56 +03:00
|
|
|
}
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
void
|
|
|
|
AnimationCollection::RequestRestyle(RestyleType aRestyleType)
|
|
|
|
{
|
2015-08-17 07:59:44 +03:00
|
|
|
MOZ_ASSERT(IsForElement() || IsForBeforePseudo() || IsForAfterPseudo(),
|
|
|
|
"Unexpected mElementProperty; might restyle too much");
|
|
|
|
|
2015-08-17 07:59:44 +03:00
|
|
|
nsPresContext* presContext = mManager->PresContext();
|
|
|
|
if (!presContext) {
|
|
|
|
// Pres context will be null after the manager is disconnected.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:11:55 +03:00
|
|
|
// Steps for Restyle::Layer:
|
|
|
|
|
|
|
|
if (aRestyleType == RestyleType::Layer) {
|
|
|
|
mStyleRuleRefreshTime = TimeStamp();
|
2015-09-17 09:43:15 +03:00
|
|
|
mStyleChanging = true;
|
2015-08-18 10:11:55 +03:00
|
|
|
|
|
|
|
// Prompt layers to re-sync their animations.
|
|
|
|
presContext->ClearLastStyleUpdateForAllAnimations();
|
|
|
|
presContext->RestyleManager()->IncrementAnimationGeneration();
|
|
|
|
UpdateAnimationGeneration(presContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Steps for RestyleType::Standard and above:
|
2015-08-17 07:59:44 +03:00
|
|
|
|
|
|
|
if (mHasPendingAnimationRestyle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:11:55 +03:00
|
|
|
if (aRestyleType >= RestyleType::Standard) {
|
2015-08-17 07:59:44 +03:00
|
|
|
mHasPendingAnimationRestyle = true;
|
|
|
|
PostRestyleForAnimation(presContext);
|
2015-08-18 10:11:55 +03:00
|
|
|
return;
|
2015-08-17 07:59:44 +03:00
|
|
|
}
|
2015-08-18 10:11:55 +03:00
|
|
|
|
|
|
|
// Steps for RestyleType::Throttled:
|
|
|
|
|
|
|
|
MOZ_ASSERT(aRestyleType == RestyleType::Throttled,
|
|
|
|
"Should have already handled all non-throttled restyles");
|
|
|
|
presContext->Document()->SetNeedStyleFlush();
|
2015-08-17 07:59:44 +03:00
|
|
|
}
|
|
|
|
|
2014-06-27 03:57:12 +04:00
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::UpdateAnimationGeneration(nsPresContext* aPresContext)
|
2012-12-12 01:12:43 +04:00
|
|
|
{
|
|
|
|
mAnimationGeneration =
|
2013-07-20 23:14:25 +04:00
|
|
|
aPresContext->RestyleManager()->GetAnimationGeneration();
|
2012-12-12 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
2015-02-17 01:15:03 +03:00
|
|
|
void
|
2015-04-21 04:22:10 +03:00
|
|
|
AnimationCollection::UpdateCheckGeneration(
|
2015-02-17 01:15:03 +03:00
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
mCheckGeneration =
|
|
|
|
aPresContext->RestyleManager()->GetAnimationGeneration();
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
nsPresContext*
|
|
|
|
OwningElementRef::GetRenderedPresContext() const
|
|
|
|
{
|
|
|
|
if (!mElement) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = mElement->GetComposedDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* shell = doc->GetShell();
|
|
|
|
if (!shell) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shell->GetPresContext();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|