2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-05-13 11:22:12 +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/. */
|
|
|
|
|
|
|
|
#include "AnimationTimeline.h"
|
2015-06-15 05:05:43 +03:00
|
|
|
#include "mozilla/AnimationComparator.h"
|
2014-05-13 11:22:12 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-09-28 06:38:41 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mWindow,
|
|
|
|
mAnimationOrder)
|
2014-05-13 11:22:12 +04:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(AnimationTimeline)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(AnimationTimeline)
|
2014-05-13 11:22:12 +04:00
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AnimationTimeline)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2014-12-18 02:42:41 +03:00
|
|
|
|
2015-06-15 05:05:43 +03:00
|
|
|
void
|
|
|
|
AnimationTimeline::GetAnimations(AnimationSequence& aAnimations)
|
|
|
|
{
|
2015-06-15 05:05:43 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mWindow);
|
|
|
|
if (mWindow) {
|
|
|
|
nsIDocument* doc = window->GetDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->FlushPendingNotifications(Flush_Style);
|
|
|
|
}
|
|
|
|
}
|
2015-06-15 05:05:43 +03:00
|
|
|
|
2015-09-28 06:38:41 +03:00
|
|
|
aAnimations.SetCapacity(mAnimationOrder.Length());
|
|
|
|
|
|
|
|
for (Animation* animation : mAnimationOrder) {
|
2015-07-21 04:47:23 +03:00
|
|
|
|
Bug 1195180 part 6 - Lazily remove animations from timelines; r=heycam
Now that DocumentTimeline observes the refresh driver we can use regular
ticks to remove unnecessary animations.
We do this because in a subsequent patch, in order to provide deterministic
enumeration order when ticking animations, we will store animations in an array.
Removing an arbitrary element from an nsTArray is O(n) since we have to search
for the array index first, or O(log n) if we keep the array sorted. If we
destroy a subtree containing n animations, the operation effectively becomes
O(n^2), or, if we keep the array sorted, O(n log n). By destroying during a
tick when we are already iterating over the array, however, we will be able
to do this much more efficiently.
Whether an animation is newly associated with a timeline, or is disassociated
from a timeline, or if it merely has its timing updated, the behavior
implemented in this patch is to simply make sure we are observing the refresh
driver and deal with the animation on the next tick.
It might seem that we could be a lot more clever about this and, for example, if
an animation reports NeedsTicks() == false, not start observing the refresh
driver. There are various edge cases however that need to be taken into account.
For example, if a CSS animation is finished (IsRelevant() == false so that
animation will have been removed from the timeline), and paused
(NeedsTicks() == false), and we seek it back to the point where it is relevant
again, we actually need to observe the refresh driver so that it can dispatch an
animationstart event on the next tick. A test case in a subsequent patch tests
this specific situation.
We could possibly add logic to detect if we need to fire events on the next tick
but the complexity does not seem warranted given that even if we unnecessarily
start observing the refresh driver, we will stop watching it on the next tick.
This patch removes some rather lengthy comments from
AnimationTiming::UpdateTiming. This is, in part, because of the behavior
described above that makes these comments no longer relevant. Other parts are
removed because the Web Animations specification has been updated such that a
timeline becoming inactive now pauses the animation[1] so that the issue
regarding detecting timelines becoming active/inactive no longer applies
since animations attached to an inactive timeline remain "relevant".
[1] https://w3c.github.io/web-animations/#responding-to-a-newly-inactive-timeline
2015-09-28 06:38:41 +03:00
|
|
|
// Skip animations which are no longer relevant or which have been
|
|
|
|
// associated with another timeline. These animations will be removed
|
|
|
|
// on the next tick.
|
|
|
|
if (!animation->IsRelevant() || animation->GetTimeline() != this) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-21 04:47:23 +03:00
|
|
|
|
|
|
|
// Bug 1174575: Until we implement a suitable PseudoElement interface we
|
|
|
|
// don't have anything to return for the |target| attribute of
|
|
|
|
// KeyframeEffect(ReadOnly) objects that refer to pseudo-elements.
|
|
|
|
// Rather than return some half-baked version of these objects (e.g.
|
|
|
|
// we a null effect attribute) we simply don't provide access to animations
|
|
|
|
// whose effect refers to a pseudo-element until we can support them
|
|
|
|
// properly.
|
|
|
|
Element* target;
|
|
|
|
nsCSSPseudoElements::Type pseudoType;
|
|
|
|
animation->GetEffect()->GetTarget(target, pseudoType);
|
|
|
|
if (pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
aAnimations.AppendElement(animation);
|
|
|
|
}
|
|
|
|
}
|
2015-06-15 05:05:43 +03:00
|
|
|
|
|
|
|
// Sort animations by priority
|
2015-10-18 08:24:48 +03:00
|
|
|
aAnimations.Sort(AnimationPtrComparator<RefPtr<Animation>>());
|
2015-06-15 05:05:43 +03:00
|
|
|
}
|
|
|
|
|
2015-04-28 10:41:09 +03:00
|
|
|
void
|
Bug 1195180 part 6 - Lazily remove animations from timelines; r=heycam
Now that DocumentTimeline observes the refresh driver we can use regular
ticks to remove unnecessary animations.
We do this because in a subsequent patch, in order to provide deterministic
enumeration order when ticking animations, we will store animations in an array.
Removing an arbitrary element from an nsTArray is O(n) since we have to search
for the array index first, or O(log n) if we keep the array sorted. If we
destroy a subtree containing n animations, the operation effectively becomes
O(n^2), or, if we keep the array sorted, O(n log n). By destroying during a
tick when we are already iterating over the array, however, we will be able
to do this much more efficiently.
Whether an animation is newly associated with a timeline, or is disassociated
from a timeline, or if it merely has its timing updated, the behavior
implemented in this patch is to simply make sure we are observing the refresh
driver and deal with the animation on the next tick.
It might seem that we could be a lot more clever about this and, for example, if
an animation reports NeedsTicks() == false, not start observing the refresh
driver. There are various edge cases however that need to be taken into account.
For example, if a CSS animation is finished (IsRelevant() == false so that
animation will have been removed from the timeline), and paused
(NeedsTicks() == false), and we seek it back to the point where it is relevant
again, we actually need to observe the refresh driver so that it can dispatch an
animationstart event on the next tick. A test case in a subsequent patch tests
this specific situation.
We could possibly add logic to detect if we need to fire events on the next tick
but the complexity does not seem warranted given that even if we unnecessarily
start observing the refresh driver, we will stop watching it on the next tick.
This patch removes some rather lengthy comments from
AnimationTiming::UpdateTiming. This is, in part, because of the behavior
described above that makes these comments no longer relevant. Other parts are
removed because the Web Animations specification has been updated such that a
timeline becoming inactive now pauses the animation[1] so that the issue
regarding detecting timelines becoming active/inactive no longer applies
since animations attached to an inactive timeline remain "relevant".
[1] https://w3c.github.io/web-animations/#responding-to-a-newly-inactive-timeline
2015-09-28 06:38:41 +03:00
|
|
|
AnimationTimeline::NotifyAnimationUpdated(Animation& aAnimation)
|
2015-04-28 10:41:09 +03:00
|
|
|
{
|
2015-09-28 06:38:41 +03:00
|
|
|
if (mAnimations.Contains(&aAnimation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-28 10:41:09 +03:00
|
|
|
mAnimations.PutEntry(&aAnimation);
|
2015-09-28 06:38:41 +03:00
|
|
|
mAnimationOrder.AppendElement(&aAnimation);
|
2015-04-28 10:41:09 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 11:22:12 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|