2011-04-12 10:18:44 +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:44 +04:00
|
|
|
|
|
|
|
#include "nsAnimationManager.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2013-06-30 20:26:39 +04:00
|
|
|
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-06-30 20:26:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2013-06-30 20:26:39 +04:00
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleSet.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsStyleChangeList.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "nsCSSRules.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "RestyleManager.h"
|
2013-06-18 15:41:30 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-10-01 01:26:04 +04:00
|
|
|
#include "nsIFrame.h"
|
2013-10-03 00:09:18 +04:00
|
|
|
#include "nsIDocument.h"
|
2013-01-11 09:14:51 +04:00
|
|
|
#include <math.h>
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-08-22 05:48:47 +04:00
|
|
|
using namespace mozilla::css;
|
2014-08-10 11:06:47 +04:00
|
|
|
using mozilla::dom::Animation;
|
2014-08-10 11:06:44 +04:00
|
|
|
using mozilla::dom::AnimationPlayer;
|
2014-10-20 08:55:44 +04:00
|
|
|
using mozilla::CSSAnimationPlayer;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2014-12-18 02:42:41 +03:00
|
|
|
mozilla::dom::Promise*
|
|
|
|
CSSAnimationPlayer::GetReady(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
FlushStyle();
|
|
|
|
return AnimationPlayer::GetReady(aRv);
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:46 +04:00
|
|
|
void
|
2014-11-17 07:46:01 +03:00
|
|
|
CSSAnimationPlayer::Play()
|
2014-10-20 08:55:46 +04:00
|
|
|
{
|
|
|
|
mPauseShouldStick = false;
|
2014-11-17 07:46:01 +03:00
|
|
|
AnimationPlayer::Play();
|
2014-10-20 08:55:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-17 07:46:01 +03:00
|
|
|
CSSAnimationPlayer::Pause()
|
2014-10-20 08:55:46 +04:00
|
|
|
{
|
|
|
|
mPauseShouldStick = true;
|
2014-11-17 07:46:01 +03:00
|
|
|
AnimationPlayer::Pause();
|
2014-10-20 08:55:46 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 07:45:58 +03:00
|
|
|
mozilla::dom::AnimationPlayState
|
|
|
|
CSSAnimationPlayer::PlayStateFromJS() const
|
|
|
|
{
|
|
|
|
// Flush style to ensure that any properties controlling animation state
|
|
|
|
// (e.g. animation-play-state) are fully updated.
|
|
|
|
FlushStyle();
|
|
|
|
return AnimationPlayer::PlayStateFromJS();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSAnimationPlayer::PlayFromJS()
|
|
|
|
{
|
|
|
|
// Note that flushing style below might trigger calls to
|
|
|
|
// PlayFromStyle()/PauseFromStyle() on this object.
|
|
|
|
FlushStyle();
|
|
|
|
AnimationPlayer::PlayFromJS();
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:46 +04:00
|
|
|
void
|
|
|
|
CSSAnimationPlayer::PlayFromStyle()
|
|
|
|
{
|
|
|
|
mIsStylePaused = false;
|
|
|
|
if (!mPauseShouldStick) {
|
2014-11-17 07:46:01 +03:00
|
|
|
DoPlay();
|
2014-10-20 08:55:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSAnimationPlayer::PauseFromStyle()
|
|
|
|
{
|
|
|
|
// Check if the pause state is being overridden
|
|
|
|
if (mIsStylePaused) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsStylePaused = true;
|
2014-11-17 07:46:01 +03:00
|
|
|
DoPause();
|
2014-10-20 08:55:46 +04:00
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:47 +04:00
|
|
|
void
|
|
|
|
CSSAnimationPlayer::QueueEvents(EventArray& aEventsToDispatch)
|
|
|
|
{
|
|
|
|
if (!mSource) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ComputedTiming computedTiming = mSource->GetComputedTiming();
|
|
|
|
|
2015-02-13 18:58:33 +03:00
|
|
|
if (computedTiming.mPhase == ComputedTiming::AnimationPhase_Null) {
|
|
|
|
return; // do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that script can change the start time, so we have to handle moving
|
|
|
|
// backwards through the animation as well as forwards. An 'animationstart'
|
|
|
|
// is dispatched if we enter the active phase (regardless if that is from
|
|
|
|
// before or after the animation's active phase). An 'animationend' is
|
|
|
|
// dispatched if we leave the active phase (regardless if that is to before
|
|
|
|
// or after the animation's active phase).
|
|
|
|
|
|
|
|
bool wasActive = mPreviousPhaseOrIteration != PREVIOUS_PHASE_BEFORE &&
|
|
|
|
mPreviousPhaseOrIteration != PREVIOUS_PHASE_AFTER;
|
|
|
|
bool isActive =
|
|
|
|
computedTiming.mPhase == ComputedTiming::AnimationPhase_Active;
|
|
|
|
bool isSameIteration =
|
|
|
|
computedTiming.mCurrentIteration == mPreviousPhaseOrIteration;
|
|
|
|
bool skippedActivePhase =
|
|
|
|
(mPreviousPhaseOrIteration == PREVIOUS_PHASE_BEFORE &&
|
|
|
|
computedTiming.mPhase == ComputedTiming::AnimationPhase_After) ||
|
|
|
|
(mPreviousPhaseOrIteration == PREVIOUS_PHASE_AFTER &&
|
|
|
|
computedTiming.mPhase == ComputedTiming::AnimationPhase_Before);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!skippedActivePhase || (!isActive && !wasActive),
|
|
|
|
"skippedActivePhase only makes sense if we were & are inactive");
|
|
|
|
|
|
|
|
if (computedTiming.mPhase == ComputedTiming::AnimationPhase_Before) {
|
|
|
|
mPreviousPhaseOrIteration = PREVIOUS_PHASE_BEFORE;
|
|
|
|
} else if (computedTiming.mPhase == ComputedTiming::AnimationPhase_Active) {
|
|
|
|
mPreviousPhaseOrIteration = computedTiming.mCurrentIteration;
|
|
|
|
} else if (computedTiming.mPhase == ComputedTiming::AnimationPhase_After) {
|
|
|
|
mPreviousPhaseOrIteration = PREVIOUS_PHASE_AFTER;
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:47 +04:00
|
|
|
dom::Element* target;
|
|
|
|
nsCSSPseudoElements::Type targetPseudoType;
|
|
|
|
mSource->GetTarget(target, targetPseudoType);
|
|
|
|
|
2015-02-13 18:58:33 +03:00
|
|
|
uint32_t message;
|
|
|
|
|
|
|
|
if (!wasActive && isActive) {
|
|
|
|
message = NS_ANIMATION_START;
|
|
|
|
} else if (wasActive && !isActive) {
|
|
|
|
message = NS_ANIMATION_END;
|
|
|
|
} else if (wasActive && isActive && !isSameIteration) {
|
|
|
|
message = NS_ANIMATION_ITERATION;
|
|
|
|
} else if (skippedActivePhase) {
|
|
|
|
// First notifying for start of 0th iteration by appending an
|
|
|
|
// 'animationstart':
|
|
|
|
StickyTimeDuration elapsedTime =
|
|
|
|
std::min(StickyTimeDuration(mSource->InitialAdvance()),
|
|
|
|
computedTiming.mActiveDuration);
|
|
|
|
AnimationEventInfo ei(target, Name(), NS_ANIMATION_START,
|
|
|
|
elapsedTime,
|
|
|
|
PseudoTypeAsString(targetPseudoType));
|
|
|
|
aEventsToDispatch.AppendElement(ei);
|
|
|
|
// Then have the shared code below append an 'animationend':
|
|
|
|
message = NS_ANIMATION_END;
|
|
|
|
} else {
|
|
|
|
return; // No events need to be sent
|
2014-10-20 08:55:47 +04:00
|
|
|
}
|
2015-02-13 18:58:33 +03:00
|
|
|
|
|
|
|
StickyTimeDuration elapsedTime;
|
|
|
|
|
|
|
|
if (message == NS_ANIMATION_START ||
|
|
|
|
message == NS_ANIMATION_ITERATION) {
|
|
|
|
TimeDuration iterationStart = mSource->Timing().mIterationDuration *
|
|
|
|
computedTiming.mCurrentIteration;
|
|
|
|
elapsedTime = StickyTimeDuration(std::max(iterationStart,
|
|
|
|
mSource->InitialAdvance()));
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(message == NS_ANIMATION_END);
|
|
|
|
elapsedTime = computedTiming.mActiveDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationEventInfo ei(target, Name(), message, elapsedTime,
|
|
|
|
PseudoTypeAsString(targetPseudoType));
|
|
|
|
aEventsToDispatch.AppendElement(ei);
|
2014-10-20 08:55:47 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 07:45:58 +03:00
|
|
|
CommonAnimationManager*
|
|
|
|
CSSAnimationPlayer::GetAnimationManager() const
|
|
|
|
{
|
|
|
|
nsPresContext* context = GetPresContext();
|
|
|
|
if (!context) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return context->AnimationManager();
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:47 +04:00
|
|
|
/* static */ nsString
|
|
|
|
CSSAnimationPlayer::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:
|
|
|
|
return EmptyString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 11:51:48 +04:00
|
|
|
void
|
2014-08-10 11:06:46 +04:00
|
|
|
nsAnimationManager::UpdateStyleAndEvents(AnimationPlayerCollection*
|
2014-06-27 03:57:13 +04:00
|
|
|
aCollection,
|
2014-06-24 10:29:53 +04:00
|
|
|
TimeStamp aRefreshTime,
|
|
|
|
EnsureStyleRuleFlags aFlags)
|
|
|
|
{
|
2014-06-27 03:57:13 +04:00
|
|
|
aCollection->EnsureStyleRuleFor(aRefreshTime, aFlags);
|
2014-10-20 08:55:47 +04:00
|
|
|
QueueEvents(aCollection, mPendingEvents);
|
2014-06-24 10:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-20 08:55:47 +04:00
|
|
|
nsAnimationManager::QueueEvents(AnimationPlayerCollection* aCollection,
|
|
|
|
EventArray& aEventsToDispatch)
|
2014-05-28 11:51:48 +04:00
|
|
|
{
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = aCollection->mPlayers.Length(); playerIdx-- != 0; ) {
|
2014-10-20 08:55:47 +04:00
|
|
|
CSSAnimationPlayer* player =
|
|
|
|
aCollection->mPlayers[playerIdx]->AsCSSAnimationPlayer();
|
|
|
|
MOZ_ASSERT(player, "Expected a collection of CSS Animation players");
|
|
|
|
player->QueueEvents(aEventsToDispatch);
|
2014-05-28 11:51:48 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-21 08:06:47 +04:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsAnimationManager::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-09 09:01:52 +04:00
|
|
|
{
|
|
|
|
return CommonAnimationManager::SizeOfExcludingThis(aMallocSizeOf);
|
2012-01-03 06:19:14 +04:00
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mPendingEvents
|
2011-12-09 09:01:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsAnimationManager::SizeOfIncludingThis(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-12-09 09:01:52 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
nsIStyleRule*
|
|
|
|
nsAnimationManager::CheckAnimationRule(nsStyleContext* aStyleContext,
|
|
|
|
mozilla::dom::Element* aElement)
|
|
|
|
{
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore animations.
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
// Everything that causes our animation data to change triggers a
|
|
|
|
// style change, which in turn triggers a non-animation restyle.
|
|
|
|
// Likewise, when we initially construct frames, we're not in a
|
|
|
|
// style change, but also not in an animation restyle.
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
|
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
GetAnimationPlayers(aElement, aStyleContext->GetPseudoType(), false);
|
|
|
|
if (!collection &&
|
|
|
|
disp->mAnimationNameCount == 1 &&
|
|
|
|
disp->mAnimations[0].GetName().IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
// build the animations list
|
|
|
|
dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline();
|
|
|
|
AnimationPlayerPtrArray newPlayers;
|
|
|
|
BuildAnimations(aStyleContext, aElement, timeline, newPlayers);
|
2011-04-12 10:18:44 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
if (newPlayers.IsEmpty()) {
|
2014-06-27 03:57:13 +04:00
|
|
|
if (collection) {
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
collection->Destroy();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
if (collection) {
|
|
|
|
collection->mStyleRule = nullptr;
|
|
|
|
collection->mStyleRuleRefreshTime = TimeStamp();
|
|
|
|
collection->UpdateAnimationGeneration(mPresContext);
|
|
|
|
|
|
|
|
// Copy over the start times and (if still paused) pause starts
|
|
|
|
// for each animation (matching on name only) that was also in the
|
|
|
|
// old list of animations.
|
|
|
|
// This means that we honor dynamic changes, which isn't what the
|
|
|
|
// spec says to do, but WebKit seems to honor at least some of
|
|
|
|
// them. See
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2011Apr/0079.html
|
|
|
|
// In order to honor what the spec said, we'd copy more data over
|
|
|
|
// (or potentially optimize BuildAnimations to avoid rebuilding it
|
|
|
|
// in the first place).
|
|
|
|
if (!collection->mPlayers.IsEmpty()) {
|
|
|
|
|
|
|
|
for (size_t newIdx = newPlayers.Length(); newIdx-- != 0;) {
|
|
|
|
AnimationPlayer* newPlayer = newPlayers[newIdx];
|
|
|
|
|
|
|
|
// Find the matching animation with this name in the old list
|
|
|
|
// of animations. We iterate through both lists in a backwards
|
|
|
|
// direction which means that if there are more animations in
|
|
|
|
// the new list of animations with a given name than in the old
|
|
|
|
// list, it will be the animations towards the of the beginning of
|
|
|
|
// the list that do not match and are treated as new animations.
|
|
|
|
nsRefPtr<CSSAnimationPlayer> oldPlayer;
|
|
|
|
size_t oldIdx = collection->mPlayers.Length();
|
|
|
|
while (oldIdx-- != 0) {
|
|
|
|
CSSAnimationPlayer* a =
|
|
|
|
collection->mPlayers[oldIdx]->AsCSSAnimationPlayer();
|
|
|
|
MOZ_ASSERT(a, "All players in the CSS Animation collection should"
|
|
|
|
" be CSSAnimationPlayer objects");
|
|
|
|
if (a->Name() == newPlayer->Name()) {
|
|
|
|
oldPlayer = a;
|
|
|
|
break;
|
2014-08-10 11:06:49 +04:00
|
|
|
}
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
}
|
|
|
|
if (!oldPlayer) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-23 05:51:12 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
// Update the old from the new so we can keep the original object
|
|
|
|
// identity (and any expando properties attached to it).
|
|
|
|
if (oldPlayer->GetSource() && newPlayer->GetSource()) {
|
|
|
|
Animation* oldAnim = oldPlayer->GetSource();
|
|
|
|
Animation* newAnim = newPlayer->GetSource();
|
|
|
|
oldAnim->Timing() = newAnim->Timing();
|
|
|
|
oldAnim->Properties() = newAnim->Properties();
|
|
|
|
}
|
2014-07-23 05:51:12 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
// Reset compositor state so animation will be re-synchronized.
|
|
|
|
oldPlayer->ClearIsRunningOnCompositor();
|
|
|
|
|
|
|
|
// Handle changes in play state.
|
|
|
|
// CSSAnimationPlayer takes care of override behavior so that,
|
|
|
|
// for example, if the author has called pause(), that will
|
|
|
|
// override the animation-play-state.
|
|
|
|
// (We should check newPlayer->IsStylePaused() but that requires
|
|
|
|
// downcasting to CSSAnimationPlayer and we happen to know that
|
|
|
|
// newPlayer will only ever be paused by calling PauseFromStyle
|
|
|
|
// making IsPaused synonymous in this case.)
|
|
|
|
if (!oldPlayer->IsStylePaused() && newPlayer->IsPaused()) {
|
|
|
|
oldPlayer->PauseFromStyle();
|
|
|
|
} else if (oldPlayer->IsStylePaused() && !newPlayer->IsPaused()) {
|
|
|
|
oldPlayer->PlayFromStyle();
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
|
|
|
|
// Replace new animation with the (updated) old one and remove the
|
|
|
|
// old one from the array so we don't try to match it any more.
|
|
|
|
//
|
|
|
|
// Although we're doing this while iterating this is safe because
|
|
|
|
// we're not changing the length of newPlayers and we've finished
|
|
|
|
// iterating over the list of old iterations.
|
|
|
|
newPlayer->Cancel();
|
|
|
|
newPlayer = nullptr;
|
|
|
|
newPlayers.ReplaceElementAt(newIdx, oldPlayer);
|
|
|
|
collection->mPlayers.RemoveElementAt(oldIdx);
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
}
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
} else {
|
|
|
|
collection =
|
|
|
|
GetAnimationPlayers(aElement, aStyleContext->GetPseudoType(), true);
|
|
|
|
}
|
|
|
|
collection->mPlayers.SwapElements(newPlayers);
|
|
|
|
collection->mNeedsRefreshes = true;
|
|
|
|
collection->Tick();
|
2011-04-12 10:18:44 +04:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
// Cancel removed animations
|
|
|
|
for (size_t newPlayerIdx = newPlayers.Length(); newPlayerIdx-- != 0; ) {
|
|
|
|
newPlayers[newPlayerIdx]->Cancel();
|
|
|
|
}
|
2014-12-18 02:42:41 +03:00
|
|
|
|
Bug 960465 patch 17 - Remove separate animation and non-animation phases of restyling. r=birtles
Note that this means that when we start transitions, we post restyles
that are processed during the current restyling operation, rather than
in a later phase. This depends on patch 11, which makes the transition
manager skip style changes that it posts while starting transitions, to
ensure that this doesn't lead to an infinite loop. This also depends on
patch 16, which only consumes restyle data for the primary frame, to
ensure that the animation restyles posted are processed properly. It
also depends on patch 14, which makes us retain data on finished
transitions, to avoid triggering extra transitions on descendants when
both an ancestor and a descendant transition an inherited property, and
the descendant does so faster.
This fixes a known failure in layout/style/test/test_animations.html and
test_animations_omta.html (as visible in the patch). I believe this is
because this patch changes us to compute keyframe values for animations
on top of a style context *with* animation data rather than one without,
which means what we're computing them on top of changes each time. (The
purpose of patch 3 was to avoid this in the case where avoiding it
matters, i.e., implicit 0% and 100% keyframes.)
2015-02-17 01:15:05 +03:00
|
|
|
TimeStamp refreshTime = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
UpdateStyleAndEvents(collection, refreshTime,
|
|
|
|
EnsureStyleRule_IsNotThrottled);
|
|
|
|
// We don't actually dispatch the mPendingEvents now. We'll either
|
|
|
|
// dispatch them the next time we get a refresh driver notification
|
|
|
|
// or the next time somebody calls
|
|
|
|
// nsPresShell::FlushPendingNotifications.
|
|
|
|
if (!mPendingEvents.IsEmpty()) {
|
|
|
|
mPresContext->Document()->SetNeedStyleFlush();
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return GetAnimationRule(aElement, aStyleContext->GetPseudoType());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct KeyframeData {
|
|
|
|
float mKey;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mIndex; // store original order since sort algorithm is not stable
|
2011-04-12 10:18:44 +04:00
|
|
|
nsCSSKeyframeRule *mRule;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyframeDataComparator {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const KeyframeData& A, const KeyframeData& B) const {
|
2012-03-22 09:10:02 +04:00
|
|
|
return A.mKey == B.mKey && A.mIndex == B.mIndex;
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool LessThan(const KeyframeData& A, const KeyframeData& B) const {
|
2012-03-22 09:10:02 +04:00
|
|
|
return A.mKey < B.mKey || (A.mKey == B.mKey && A.mIndex < B.mIndex);
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ResolvedStyleCache {
|
|
|
|
public:
|
2014-08-06 17:31:21 +04:00
|
|
|
ResolvedStyleCache() : mCache() {}
|
2011-04-12 10:18:44 +04:00
|
|
|
nsStyleContext* Get(nsPresContext *aPresContext,
|
|
|
|
nsStyleContext *aParentStyleContext,
|
|
|
|
nsCSSKeyframeRule *aKeyframe);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<nsCSSKeyframeRule>, nsStyleContext> mCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsStyleContext*
|
|
|
|
ResolvedStyleCache::Get(nsPresContext *aPresContext,
|
|
|
|
nsStyleContext *aParentStyleContext,
|
|
|
|
nsCSSKeyframeRule *aKeyframe)
|
|
|
|
{
|
|
|
|
// FIXME (spec): The css3-animations spec isn't very clear about how
|
|
|
|
// properties are resolved when they have values that depend on other
|
|
|
|
// properties (e.g., values in 'em'). I presume that they're resolved
|
|
|
|
// relative to the other styles of the element. The question is
|
|
|
|
// whether they are resolved relative to other animations: I assume
|
|
|
|
// that they're not, since that would prevent us from caching a lot of
|
|
|
|
// data that we'd really like to cache (in particular, the
|
2014-06-24 10:29:54 +04:00
|
|
|
// StyleAnimationValue values in AnimationPropertySegment).
|
2011-04-12 10:18:44 +04:00
|
|
|
nsStyleContext *result = mCache.GetWeak(aKeyframe);
|
|
|
|
if (!result) {
|
|
|
|
nsCOMArray<nsIStyleRule> rules;
|
|
|
|
rules.AppendObject(aKeyframe);
|
|
|
|
nsRefPtr<nsStyleContext> resultStrong = aPresContext->StyleSet()->
|
|
|
|
ResolveStyleByAddingRules(aParentStyleContext, rules);
|
|
|
|
mCache.Put(aKeyframe, resultStrong);
|
|
|
|
result = resultStrong;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnimationManager::BuildAnimations(nsStyleContext* aStyleContext,
|
2014-10-02 10:14:15 +04:00
|
|
|
dom::Element* aTarget,
|
2014-07-16 04:02:30 +04:00
|
|
|
dom::AnimationTimeline* aTimeline,
|
2014-08-10 11:06:48 +04:00
|
|
|
AnimationPlayerPtrArray& aPlayers)
|
2011-04-12 10:18:44 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aPlayers.IsEmpty(), "expect empty array");
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
ResolvedStyleCache resolvedStyles;
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay *disp = aStyleContext->StyleDisplay();
|
2014-07-16 04:02:32 +04:00
|
|
|
|
2015-02-17 01:15:01 +03:00
|
|
|
nsRefPtr<nsStyleContext> styleWithoutAnimation;
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t animIdx = 0, animEnd = disp->mAnimationNameCount;
|
2011-04-23 05:36:23 +04:00
|
|
|
animIdx != animEnd; ++animIdx) {
|
2014-06-27 03:57:11 +04:00
|
|
|
const StyleAnimation& src = disp->mAnimations[animIdx];
|
2014-07-03 04:04:16 +04:00
|
|
|
|
2014-07-09 04:13:33 +04:00
|
|
|
// CSS Animations whose animation-name does not match a @keyframes rule do
|
|
|
|
// not generate animation events. This includes when the animation-name is
|
|
|
|
// "none" which is represented by an empty name in the StyleAnimation.
|
|
|
|
// Since such animations neither affect style nor dispatch events, we do
|
2014-08-10 11:06:44 +04:00
|
|
|
// not generate a corresponding AnimationPlayer for them.
|
2014-07-09 04:13:33 +04:00
|
|
|
nsCSSKeyframesRule* rule =
|
|
|
|
src.GetName().IsEmpty()
|
|
|
|
? nullptr
|
|
|
|
: mPresContext->StyleSet()->KeyframesRuleForName(mPresContext,
|
|
|
|
src.GetName());
|
|
|
|
if (!rule) {
|
2014-07-03 04:04:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-20 08:55:44 +04:00
|
|
|
nsRefPtr<CSSAnimationPlayer> dest = new CSSAnimationPlayer(aTimeline);
|
|
|
|
aPlayers.AppendElement(dest);
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2014-08-10 11:06:50 +04:00
|
|
|
AnimationTiming timing;
|
|
|
|
timing.mIterationDuration =
|
2014-05-28 11:51:49 +04:00
|
|
|
TimeDuration::FromMilliseconds(src.GetDuration());
|
2014-08-10 11:06:50 +04:00
|
|
|
timing.mDelay = TimeDuration::FromMilliseconds(src.GetDelay());
|
|
|
|
timing.mIterationCount = src.GetIterationCount();
|
|
|
|
timing.mDirection = src.GetDirection();
|
|
|
|
timing.mFillMode = src.GetFillMode();
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2014-08-10 11:06:47 +04:00
|
|
|
nsRefPtr<Animation> destAnim =
|
2014-10-02 10:14:15 +04:00
|
|
|
new Animation(mPresContext->Document(), aTarget,
|
|
|
|
aStyleContext->GetPseudoType(), timing, src.GetName());
|
2014-08-10 11:06:47 +04:00
|
|
|
dest->SetSource(destAnim);
|
|
|
|
|
2014-12-04 19:28:38 +03:00
|
|
|
// Even in the case where we call PauseFromStyle below, we still need to
|
|
|
|
// call PlayFromStyle first. This is because a newly-created player is idle
|
|
|
|
// and has no effect until it is played (or otherwise given a start time).
|
|
|
|
dest->PlayFromStyle();
|
|
|
|
|
2014-10-20 08:55:44 +04:00
|
|
|
if (src.GetPlayState() == NS_STYLE_ANIMATION_PLAY_STATE_PAUSED) {
|
|
|
|
dest->PauseFromStyle();
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
|
2012-03-22 09:10:02 +04:00
|
|
|
// While current drafts of css3-animations say that later keyframes
|
|
|
|
// with the same key entirely replace earlier ones (no cascading),
|
|
|
|
// this is a bad idea and contradictory to the rest of CSS. So
|
|
|
|
// we're going to keep all the keyframes for each key and then do
|
|
|
|
// the replacement on a per-property basis rather than a per-rule
|
|
|
|
// basis, just like everything else in CSS.
|
|
|
|
|
|
|
|
AutoInfallibleTArray<KeyframeData, 16> sortedKeyframes;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t ruleIdx = 0, ruleEnd = rule->StyleRuleCount();
|
2011-04-23 05:36:23 +04:00
|
|
|
ruleIdx != ruleEnd; ++ruleIdx) {
|
2011-04-08 05:23:46 +04:00
|
|
|
css::Rule* cssRule = rule->GetStyleRuleAt(ruleIdx);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(cssRule, "must have rule");
|
|
|
|
MOZ_ASSERT(cssRule->GetType() == css::Rule::KEYFRAME_RULE,
|
|
|
|
"must be keyframe rule");
|
2011-04-12 10:18:44 +04:00
|
|
|
nsCSSKeyframeRule *kfRule = static_cast<nsCSSKeyframeRule*>(cssRule);
|
|
|
|
|
|
|
|
const nsTArray<float> &keys = kfRule->GetKeys();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t keyIdx = 0, keyEnd = keys.Length();
|
2011-04-23 05:36:23 +04:00
|
|
|
keyIdx != keyEnd; ++keyIdx) {
|
|
|
|
float key = keys[keyIdx];
|
2011-04-12 10:18:44 +04:00
|
|
|
// FIXME (spec): The spec doesn't say what to do with
|
|
|
|
// out-of-range keyframes. We'll ignore them.
|
|
|
|
if (0.0f <= key && key <= 1.0f) {
|
2012-03-22 09:10:02 +04:00
|
|
|
KeyframeData *data = sortedKeyframes.AppendElement();
|
|
|
|
data->mKey = key;
|
|
|
|
data->mIndex = ruleIdx;
|
|
|
|
data->mRule = kfRule;
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sortedKeyframes.Sort(KeyframeDataComparator());
|
|
|
|
|
|
|
|
if (sortedKeyframes.Length() == 0) {
|
|
|
|
// no segments
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-23 05:36:23 +04:00
|
|
|
// Record the properties that are present in any keyframe rules we
|
|
|
|
// are using.
|
|
|
|
nsCSSPropertySet properties;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t kfIdx = 0, kfEnd = sortedKeyframes.Length();
|
2011-04-23 05:36:23 +04:00
|
|
|
kfIdx != kfEnd; ++kfIdx) {
|
2011-04-23 05:36:23 +04:00
|
|
|
css::Declaration *decl = sortedKeyframes[kfIdx].mRule->Declaration();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t propIdx = 0, propEnd = decl->Count();
|
2011-04-23 05:36:23 +04:00
|
|
|
propIdx != propEnd; ++propIdx) {
|
Bug 773296 - Part 2: Parse CSS variable declarations and store them on Declaration objects. p=ebassi,heycam r=dbaron
Patch co-authored by Emmanuele Bassi <ebassi@gmail.com>
This defines a CSSVariableDeclarations class that holds a set of
variable declarations. This is at the specified value stage, so values
can either be 'initial', 'inherit' or a token stream (which is what you
normally have). The variables are stored in a hash table. Although
it's a bit of a hack, we store 'initial' and 'inherit' using special
string values that can't be valid token streams (we use "!" and ";").
Declaration objects now can have two CSSVariableDeclarations objects
on them, to store normal and !important variable declarations. So that
we keep preserving the order of declarations on the object, we inflate
mOrder to store uint32_ts, where values from eCSSProperty_COUNT onwards
represent custom properties. mVariableOrder stores the names of the
variables corresponding to those entries in mOrder.
We also add a new nsCSSProperty value, eCSSPropertyExtra_variable, which
is used to represent any custom property name.
nsCSSProps::LookupProperty can return this value.
The changes to nsCSSParser are straightforward. Custom properties
are parsed and checked for syntactic validity (e.g. "var(a,)" being
invalid) and stored on the Declaration. We use nsCSSScanner's
recording ability to grab the unparsed CSS string corresponding to
the variable's value.
2013-12-12 06:09:40 +04:00
|
|
|
nsCSSProperty prop = decl->GetPropertyAt(propIdx);
|
|
|
|
if (prop != eCSSPropertyExtra_variable) {
|
|
|
|
// CSS Variables are not animatable
|
|
|
|
properties.AddProperty(prop);
|
|
|
|
}
|
2011-04-23 05:36:23 +04:00
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
|
2011-04-23 05:36:23 +04:00
|
|
|
for (nsCSSProperty prop = nsCSSProperty(0);
|
|
|
|
prop < eCSSProperty_COUNT_no_shorthands;
|
|
|
|
prop = nsCSSProperty(prop + 1)) {
|
|
|
|
if (!properties.HasProperty(prop) ||
|
|
|
|
nsCSSProps::kAnimTypeTable[prop] == eStyleAnimType_None) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-22 09:10:02 +04:00
|
|
|
// Build a list of the keyframes to use for this property. This
|
|
|
|
// means we need every keyframe with the property in it, except
|
|
|
|
// for those keyframes where a later keyframe with the *same key*
|
|
|
|
// also has the property.
|
2012-08-22 19:56:38 +04:00
|
|
|
AutoInfallibleTArray<uint32_t, 16> keyframesWithProperty;
|
2012-03-22 09:10:02 +04:00
|
|
|
float lastKey = 100.0f; // an invalid key
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t kfIdx = 0, kfEnd = sortedKeyframes.Length();
|
2012-03-22 09:10:02 +04:00
|
|
|
kfIdx != kfEnd; ++kfIdx) {
|
|
|
|
KeyframeData &kf = sortedKeyframes[kfIdx];
|
|
|
|
if (!kf.mRule->Declaration()->HasProperty(prop)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (kf.mKey == lastKey) {
|
|
|
|
// Replace previous occurrence of same key.
|
|
|
|
keyframesWithProperty[keyframesWithProperty.Length() - 1] = kfIdx;
|
|
|
|
} else {
|
|
|
|
keyframesWithProperty.AppendElement(kfIdx);
|
|
|
|
}
|
|
|
|
lastKey = kf.mKey;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
AnimationProperty &propData = *destAnim->Properties().AppendElement();
|
2011-04-23 05:36:23 +04:00
|
|
|
propData.mProperty = prop;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
KeyframeData *fromKeyframe = nullptr;
|
2011-04-23 05:36:23 +04:00
|
|
|
nsRefPtr<nsStyleContext> fromContext;
|
|
|
|
bool interpolated = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t wpIdx = 0, wpEnd = keyframesWithProperty.Length();
|
2012-03-22 09:10:02 +04:00
|
|
|
wpIdx != wpEnd; ++wpIdx) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t kfIdx = keyframesWithProperty[wpIdx];
|
2011-04-23 05:36:23 +04:00
|
|
|
KeyframeData &toKeyframe = sortedKeyframes[kfIdx];
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> toContext =
|
|
|
|
resolvedStyles.Get(mPresContext, aStyleContext, toKeyframe.mRule);
|
|
|
|
|
|
|
|
if (fromKeyframe) {
|
|
|
|
interpolated = interpolated &&
|
2014-05-15 03:38:37 +04:00
|
|
|
BuildSegment(propData.mSegments, prop, src,
|
2011-04-23 05:36:23 +04:00
|
|
|
fromKeyframe->mKey, fromContext,
|
|
|
|
fromKeyframe->mRule->Declaration(),
|
|
|
|
toKeyframe.mKey, toContext);
|
|
|
|
} else {
|
|
|
|
if (toKeyframe.mKey != 0.0f) {
|
|
|
|
// There's no data for this property at 0%, so use the
|
|
|
|
// cascaded value above us.
|
2015-02-17 01:15:01 +03:00
|
|
|
if (!styleWithoutAnimation) {
|
|
|
|
styleWithoutAnimation = mPresContext->StyleSet()->
|
|
|
|
ResolveStyleWithoutAnimation(aTarget, aStyleContext,
|
2015-02-17 01:15:06 +03:00
|
|
|
eRestyle_AllHintsWithAnimations);
|
2015-02-17 01:15:01 +03:00
|
|
|
}
|
2011-04-23 05:36:23 +04:00
|
|
|
interpolated = interpolated &&
|
2014-05-15 03:38:37 +04:00
|
|
|
BuildSegment(propData.mSegments, prop, src,
|
2015-02-17 01:15:01 +03:00
|
|
|
0.0f, styleWithoutAnimation, nullptr,
|
2011-04-23 05:36:23 +04:00
|
|
|
toKeyframe.mKey, toContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fromContext = toContext;
|
|
|
|
fromKeyframe = &toKeyframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fromKeyframe->mKey != 1.0f) {
|
|
|
|
// There's no data for this property at 100%, so use the
|
|
|
|
// cascaded value above us.
|
2015-02-17 01:15:01 +03:00
|
|
|
if (!styleWithoutAnimation) {
|
|
|
|
styleWithoutAnimation = mPresContext->StyleSet()->
|
|
|
|
ResolveStyleWithoutAnimation(aTarget, aStyleContext,
|
2015-02-17 01:15:06 +03:00
|
|
|
eRestyle_AllHintsWithAnimations);
|
2015-02-17 01:15:01 +03:00
|
|
|
}
|
2011-04-23 05:36:23 +04:00
|
|
|
interpolated = interpolated &&
|
2014-05-15 03:38:37 +04:00
|
|
|
BuildSegment(propData.mSegments, prop, src,
|
2011-04-23 05:36:23 +04:00
|
|
|
fromKeyframe->mKey, fromContext,
|
|
|
|
fromKeyframe->mRule->Declaration(),
|
2015-02-17 01:15:01 +03:00
|
|
|
1.0f, styleWithoutAnimation);
|
2011-04-23 05:36:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we failed to build any segments due to inability to
|
|
|
|
// interpolate, remove the property from the animation. (It's not
|
|
|
|
// clear if this is the right thing to do -- we could run some of
|
|
|
|
// the segments, but it's really not clear whether we should skip
|
|
|
|
// values (which?) or skip segments, so best to skip the whole
|
|
|
|
// thing for now.)
|
|
|
|
if (!interpolated) {
|
2014-08-10 11:06:49 +04:00
|
|
|
destAnim->Properties().RemoveElementAt(
|
|
|
|
destAnim->Properties().Length() - 1);
|
2011-04-23 05:36:23 +04:00
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 05:36:23 +04:00
|
|
|
bool
|
|
|
|
nsAnimationManager::BuildSegment(InfallibleTArray<AnimationPropertySegment>&
|
|
|
|
aSegments,
|
|
|
|
nsCSSProperty aProperty,
|
2014-06-27 03:57:11 +04:00
|
|
|
const StyleAnimation& aAnimation,
|
2011-04-12 10:18:44 +04:00
|
|
|
float aFromKey, nsStyleContext* aFromContext,
|
|
|
|
mozilla::css::Declaration* aFromDeclaration,
|
2011-04-23 05:36:23 +04:00
|
|
|
float aToKey, nsStyleContext* aToContext)
|
2011-04-12 10:18:44 +04:00
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue fromValue, toValue, dummyValue;
|
2011-04-23 05:36:23 +04:00
|
|
|
if (!ExtractComputedValueForTransition(aProperty, aFromContext, fromValue) ||
|
|
|
|
!ExtractComputedValueForTransition(aProperty, aToContext, toValue) ||
|
|
|
|
// Check that we can interpolate between these values
|
|
|
|
// (If this is ever a performance problem, we could add a
|
|
|
|
// CanInterpolate method, but it seems fine for now.)
|
2014-06-24 10:29:54 +04:00
|
|
|
!StyleAnimationValue::Interpolate(aProperty, fromValue, toValue,
|
|
|
|
0.5, dummyValue)) {
|
2011-04-23 05:36:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationPropertySegment &segment = *aSegments.AppendElement();
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2011-04-23 05:36:23 +04:00
|
|
|
segment.mFromValue = fromValue;
|
|
|
|
segment.mToValue = toValue;
|
2011-04-12 10:18:44 +04:00
|
|
|
segment.mFromKey = aFromKey;
|
|
|
|
segment.mToKey = aToKey;
|
|
|
|
const nsTimingFunction *tf;
|
|
|
|
if (aFromDeclaration &&
|
|
|
|
aFromDeclaration->HasProperty(eCSSProperty_animation_timing_function)) {
|
2013-02-17 01:51:02 +04:00
|
|
|
tf = &aFromContext->StyleDisplay()->mAnimations[0].GetTimingFunction();
|
2011-04-12 10:18:44 +04:00
|
|
|
} else {
|
|
|
|
tf = &aAnimation.GetTimingFunction();
|
|
|
|
}
|
|
|
|
segment.mTimingFunction.Init(*tf);
|
|
|
|
|
2011-04-23 05:36:23 +04:00
|
|
|
return true;
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsAnimationManager::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mPresContext,
|
|
|
|
"refresh driver should not notify additional observers "
|
|
|
|
"after pres context has been destroyed");
|
2011-04-12 10:18:44 +04:00
|
|
|
if (!mPresContext->GetPresShell()) {
|
|
|
|
// Someone might be keeping mPresContext alive past the point
|
|
|
|
// where it has been torn down; don't bother doing anything in
|
|
|
|
// this case. But do get rid of all our transitions so we stop
|
|
|
|
// triggering refreshes.
|
2014-06-27 03:57:13 +04:00
|
|
|
RemoveAllElementCollections();
|
2011-04-12 10:18:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
FlushAnimations(Can_Throttle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAnimationManager::FlushAnimations(FlushFlags aFlags)
|
|
|
|
{
|
2011-04-12 10:18:44 +04:00
|
|
|
// FIXME: check that there's at least one style rule that's not
|
|
|
|
// in its "done" state, and if there isn't, remove ourselves from
|
|
|
|
// the refresh driver (but leave the animations!).
|
2012-12-12 01:12:43 +04:00
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
bool didThrottle = false;
|
2014-06-27 03:57:13 +04:00
|
|
|
for (PRCList *l = PR_LIST_HEAD(&mElementCollections);
|
|
|
|
l != &mElementCollections;
|
2011-04-12 10:18:44 +04:00
|
|
|
l = PR_NEXT_LINK(l)) {
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
static_cast<AnimationPlayerCollection*>(l);
|
2014-08-10 11:06:48 +04:00
|
|
|
collection->Tick();
|
2012-12-12 01:12:43 +04:00
|
|
|
bool canThrottleTick = aFlags == Can_Throttle &&
|
2014-06-27 03:57:13 +04:00
|
|
|
collection->CanPerformOnCompositorThread(
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanAnimateFlags(0)) &&
|
2014-06-27 03:57:13 +04:00
|
|
|
collection->CanThrottleAnimation(now);
|
|
|
|
|
|
|
|
nsRefPtr<css::AnimValuesStyleRule> oldStyleRule = collection->mStyleRule;
|
|
|
|
UpdateStyleAndEvents(collection, now, canThrottleTick
|
|
|
|
? EnsureStyleRule_IsThrottled
|
|
|
|
: EnsureStyleRule_IsNotThrottled);
|
|
|
|
if (oldStyleRule != collection->mStyleRule) {
|
|
|
|
collection->PostRestyleForAnimation(mPresContext);
|
2012-12-12 01:12:43 +04:00
|
|
|
} else {
|
|
|
|
didThrottle = true;
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
if (didThrottle) {
|
|
|
|
mPresContext->Document()->SetNeedStyleFlush();
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
DispatchEvents(); // may destroy us
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-15 08:42:15 +04:00
|
|
|
nsAnimationManager::DoDispatchEvents()
|
2011-04-12 10:18:44 +04:00
|
|
|
{
|
|
|
|
EventArray events;
|
|
|
|
mPendingEvents.SwapElements(events);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = events.Length(); i < i_end; ++i) {
|
2011-04-12 10:18:44 +04:00
|
|
|
AnimationEventInfo &info = events[i];
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(info.mElement, mPresContext, &info.mEvent);
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
if (!mPresContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
}
|