2010-07-01 01:54:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2009-10-08 03:22:42 +00:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 11:12:37 +00: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/. */
|
2009-10-08 03:22:42 +00:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#include "nsTransitionManager.h"
|
2012-12-11 21:12:43 +00:00
|
|
|
#include "nsAnimationManager.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSProps.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsRuleProcessorData.h"
|
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsCSSPropertySet.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-09-25 11:21:20 +00:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-06-24 06:29:54 +00:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2010-05-14 17:04:51 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-31 17:28:22 +00:00
|
|
|
#include "nsIFrame.h"
|
2012-12-11 21:12:43 +00:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsDisplayList.h"
|
2013-01-09 04:37:29 +00:00
|
|
|
#include "nsStyleChangeList.h"
|
2013-08-19 22:55:18 +00:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "RestyleManager.h"
|
2009-10-08 03:22:42 +00:00
|
|
|
|
|
|
|
using mozilla::TimeStamp;
|
|
|
|
using mozilla::TimeDuration;
|
2014-08-10 07:06:49 +00:00
|
|
|
using mozilla::dom::AnimationPlayer;
|
|
|
|
using mozilla::dom::Animation;
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2012-12-11 21:12:43 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::css;
|
2010-05-14 17:04:51 +00:00
|
|
|
|
2010-11-10 15:49:53 +00:00
|
|
|
double
|
2014-07-16 00:02:32 +00:00
|
|
|
ElementPropertyTransition::CurrentValuePortion() const
|
2010-11-10 15:49:53 +00:00
|
|
|
{
|
2014-06-20 03:39:26 +00:00
|
|
|
// It would be easy enough to handle finished transitions by using a time
|
|
|
|
// fraction of 1 but currently we should not be called for finished
|
|
|
|
// transitions.
|
2014-08-10 07:06:52 +00:00
|
|
|
MOZ_ASSERT(!IsFinishedTransition(),
|
2014-06-20 03:39:26 +00:00
|
|
|
"Getting the value portion of a finished transition");
|
2014-08-10 07:06:52 +00:00
|
|
|
MOZ_ASSERT(!GetLocalTime().IsNull(),
|
2014-07-16 00:02:32 +00:00
|
|
|
"Getting the value portion of an animation that's not being "
|
|
|
|
"sampled");
|
2014-06-20 03:39:26 +00:00
|
|
|
|
2014-07-16 00:02:33 +00:00
|
|
|
// Transitions use a fill mode of 'backwards' so GetComputedTiming will
|
2014-06-20 03:39:26 +00:00
|
|
|
// never return a null time fraction due to being *before* the animation
|
|
|
|
// interval. However, it might be possible that we're behind on flushing
|
|
|
|
// causing us to get called *after* the animation interval. So, just in
|
|
|
|
// case, we override the fill mode to 'both' to ensure the time fraction
|
|
|
|
// is never null.
|
2014-08-10 07:06:52 +00:00
|
|
|
AnimationTiming timingToUse = mTiming;
|
2014-06-20 03:39:26 +00:00
|
|
|
timingToUse.mFillMode = NS_STYLE_ANIMATION_FILL_MODE_BOTH;
|
2014-08-10 07:06:52 +00:00
|
|
|
ComputedTiming computedTiming = GetComputedTiming(&timingToUse);
|
2014-06-20 03:39:26 +00:00
|
|
|
|
|
|
|
MOZ_ASSERT(computedTiming.mTimeFraction != ComputedTiming::kNullTimeFraction,
|
|
|
|
"Got a null time fraction for a fill mode of 'both'");
|
2014-08-10 07:06:52 +00:00
|
|
|
MOZ_ASSERT(mProperties.Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property for a transition");
|
2014-08-10 07:06:52 +00:00
|
|
|
MOZ_ASSERT(mProperties[0].mSegments.Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Animation property should have one segment for a transition");
|
2014-08-10 07:06:52 +00:00
|
|
|
return mProperties[0].mSegments[0].mTimingFunction
|
|
|
|
.GetValue(computedTiming.mTimeFraction);
|
2010-11-10 15:49:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 04:45:58 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* CSSTransitionPlayer *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
mozilla::dom::AnimationPlayState
|
|
|
|
CSSTransitionPlayer::PlayStateFromJS() const
|
|
|
|
{
|
|
|
|
FlushStyle();
|
|
|
|
return AnimationPlayer::PlayStateFromJS();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSTransitionPlayer::PlayFromJS()
|
|
|
|
{
|
|
|
|
FlushStyle();
|
|
|
|
AnimationPlayer::PlayFromJS();
|
|
|
|
}
|
|
|
|
|
2014-11-17 04:45:58 +00:00
|
|
|
CommonAnimationManager*
|
|
|
|
CSSTransitionPlayer::GetAnimationManager() const
|
|
|
|
{
|
|
|
|
nsPresContext* context = GetPresContext();
|
|
|
|
if (!context) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return context->TransitionManager();
|
|
|
|
}
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* nsTransitionManager *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
already_AddRefed<nsIStyleRule>
|
2010-05-14 17:04:51 +00:00
|
|
|
nsTransitionManager::StyleContextChanged(dom::Element *aElement,
|
2009-10-08 03:22:42 +00:00
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext)
|
|
|
|
{
|
2009-10-29 21:17:56 +00:00
|
|
|
NS_PRECONDITION(aOldStyleContext->GetPseudo() ==
|
|
|
|
aNewStyleContext->GetPseudo(),
|
2009-10-08 03:22:42 +00:00
|
|
|
"pseudo type mismatch");
|
|
|
|
|
2014-08-07 05:58:44 +00:00
|
|
|
if (mInAnimationOnlyStyleUpdate) {
|
|
|
|
// If we're doing an animation-only style update, return, since the
|
|
|
|
// purpose of an animation-only style update is to update only the
|
|
|
|
// animation styles so that we don't consider style changes
|
|
|
|
// resulting from changes in the animation time for starting a
|
|
|
|
// transition.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-29 06:36:39 +00:00
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore transitions.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-13 22:39:02 +00:00
|
|
|
if (aOldStyleContext->HasPseudoElementData() !=
|
|
|
|
aNewStyleContext->HasPseudoElementData()) {
|
|
|
|
// If the old style context and new style context differ in terms of
|
|
|
|
// whether they're inside ::first-letter, ::first-line, or similar,
|
|
|
|
// bail. We can't hit this codepath for normal style changes
|
|
|
|
// involving moving frames around the boundaries of these
|
|
|
|
// pseudo-elements since we don't call StyleContextChanged from
|
|
|
|
// ReparentStyleContext. However, we can hit this codepath during
|
|
|
|
// the handling of transitions that start across reframes.
|
|
|
|
//
|
|
|
|
// While there isn't an easy *perfect* way to handle this case, err
|
|
|
|
// on the side of missing some transitions that we ought to have
|
|
|
|
// rather than having bogus transitions that we shouldn't.
|
|
|
|
//
|
|
|
|
// We could consider changing this handling, although it's worth
|
|
|
|
// thinking about whether the code below could do anything weird in
|
|
|
|
// this case.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2009-12-11 16:13:19 +00:00
|
|
|
// NOTE: Things in this function (and ConsiderStartingTransition)
|
|
|
|
// should never call PeekStyleData because we don't preserve gotten
|
|
|
|
// structs across reframes.
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
// Return sooner (before the startedAny check below) for the most
|
2009-12-21 21:46:25 +00:00
|
|
|
// common case: no transitions specified or running.
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleDisplay *disp = aNewStyleContext->StyleDisplay();
|
2009-12-21 21:46:25 +00:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aNewStyleContext->GetPseudoType();
|
2010-07-01 01:54:29 +00:00
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
pseudoType != nsCSSPseudoElements::ePseudo_after) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-01 01:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION((pseudoType == nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
aElement->Tag() == nsGkAtoms::mozgeneratedcontentbefore) ||
|
|
|
|
(pseudoType == nsCSSPseudoElements::ePseudo_after &&
|
|
|
|
aElement->Tag() == nsGkAtoms::mozgeneratedcontentafter),
|
|
|
|
"Unexpected aElement coming through");
|
|
|
|
|
|
|
|
// Else the element we want to use from now on is the element the
|
|
|
|
// :before or :after is attached to.
|
|
|
|
aElement = aElement->GetParent()->AsElement();
|
|
|
|
}
|
|
|
|
|
2014-08-10 07:06:46 +00:00
|
|
|
AnimationPlayerCollection* collection =
|
2014-11-17 04:45:59 +00:00
|
|
|
GetAnimationPlayers(aElement, pseudoType, false);
|
2014-06-26 23:57:13 +00:00
|
|
|
if (!collection &&
|
2009-12-21 21:46:25 +00:00
|
|
|
disp->mTransitionPropertyCount == 1 &&
|
2009-10-08 03:22:42 +00:00
|
|
|
disp->mTransitions[0].GetDelay() == 0.0f &&
|
2009-12-21 21:46:25 +00:00
|
|
|
disp->mTransitions[0].GetDuration() == 0.0f) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-07-31 17:28:21 +00:00
|
|
|
}
|
2012-07-30 18:36:12 +00:00
|
|
|
|
2012-07-25 15:37:04 +00:00
|
|
|
|
2014-10-03 04:53:24 +00:00
|
|
|
// FIXME (bug 960465): This test should go away.
|
|
|
|
if (aNewStyleContext->PresContext()->RestyleManager()->
|
|
|
|
IsProcessingAnimationStyleChange()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
2012-07-31 17:28:21 +00:00
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
if (aNewStyleContext->GetParent() &&
|
|
|
|
aNewStyleContext->GetParent()->HasPseudoElementData()) {
|
|
|
|
// Ignore transitions on things that inherit properties from
|
|
|
|
// pseudo-elements.
|
2009-10-16 00:23:19 +00:00
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 10:31:03 +00:00
|
|
|
NS_WARN_IF_FALSE(!nsLayoutUtils::AreAsyncAnimationsEnabled() ||
|
2014-07-25 04:35:34 +00:00
|
|
|
mPresContext->RestyleManager()->
|
|
|
|
ThrottledAnimationStyleIsUpToDate(),
|
2012-12-11 21:12:43 +00:00
|
|
|
"throttled animations not up to date");
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
// Per http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html
|
|
|
|
// I'll consider only the transitions from the number of items in
|
|
|
|
// 'transition-property' on down, and later ones will override earlier
|
|
|
|
// ones (tracked using |whichStarted|).
|
2011-09-29 06:19:26 +00:00
|
|
|
bool startedAny = false;
|
2009-10-08 03:22:42 +00:00
|
|
|
nsCSSPropertySet whichStarted;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2014-06-26 23:57:12 +00:00
|
|
|
const StyleTransition& t = disp->mTransitions[i];
|
2009-10-08 03:22:42 +00:00
|
|
|
// Check delay and duration first, since they default to zero, and
|
|
|
|
// when they're both zero, we can ignore the transition.
|
|
|
|
if (t.GetDelay() != 0.0f || t.GetDuration() != 0.0f) {
|
|
|
|
// We might have something to transition. See if any of the
|
|
|
|
// properties in question changed and are animatable.
|
2009-12-11 16:13:19 +00:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one below.
|
2009-10-08 03:22:42 +00:00
|
|
|
nsCSSProperty property = t.GetProperty();
|
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
2014-04-13 01:44:31 +00:00
|
|
|
property == eCSSPropertyExtra_variable ||
|
2009-10-08 03:22:42 +00:00
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2012-07-31 17:28:21 +00:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-10-08 03:22:42 +00:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
|
|
|
p = nsCSSProperty(p + 1)) {
|
2014-06-26 23:57:13 +00:00
|
|
|
ConsiderStartingTransition(p, t, aElement, collection,
|
2009-10-08 03:22:42 +00:00
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
|
2014-06-26 23:57:13 +00:00
|
|
|
ConsiderStartingTransition(*subprop, t, aElement, collection,
|
2009-10-08 03:22:42 +00:00
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-26 23:57:13 +00:00
|
|
|
ConsiderStartingTransition(property, t, aElement, collection,
|
2009-10-08 03:22:42 +00:00
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 16:13:19 +00:00
|
|
|
// Stop any transitions for properties that are no longer in
|
|
|
|
// 'transition-property'.
|
2009-12-21 21:46:25 +00:00
|
|
|
// Also stop any transitions for properties that just changed (and are
|
|
|
|
// still in the set of properties to transition), but we didn't just
|
|
|
|
// start the transition because delay and duration are both zero.
|
2014-06-26 23:57:13 +00:00
|
|
|
if (collection) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool checkProperties =
|
2009-12-21 21:46:25 +00:00
|
|
|
disp->mTransitions[0].GetProperty() != eCSSPropertyExtra_all_properties;
|
2009-12-11 16:13:19 +00:00
|
|
|
nsCSSPropertySet allTransitionProperties;
|
2009-12-21 21:46:25 +00:00
|
|
|
if (checkProperties) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2014-06-26 23:57:12 +00:00
|
|
|
const StyleTransition& t = disp->mTransitions[i];
|
2009-12-21 21:46:25 +00:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one above.
|
|
|
|
nsCSSProperty property = t.GetProperty();
|
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
2014-04-13 01:44:31 +00:00
|
|
|
property == eCSSPropertyExtra_variable ||
|
2009-12-21 21:46:25 +00:00
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2012-07-31 17:28:21 +00:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-12-21 21:46:25 +00:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
|
|
|
p = nsCSSProperty(p + 1)) {
|
|
|
|
allTransitionProperties.AddProperty(p);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
|
|
|
|
allTransitionProperties.AddProperty(*subprop);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allTransitionProperties.AddProperty(property);
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayerPtrArray& players = collection->mPlayers;
|
|
|
|
size_t i = players.Length();
|
2009-12-11 16:13:19 +00:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
2014-06-24 06:29:54 +00:00
|
|
|
StyleAnimationValue currentValue;
|
2009-12-11 16:13:19 +00:00
|
|
|
do {
|
|
|
|
--i;
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayer* player = players[i];
|
2014-08-10 07:06:49 +00:00
|
|
|
dom::Animation* anim = player->GetSource();
|
|
|
|
MOZ_ASSERT(anim && anim->Properties().Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
MOZ_ASSERT(anim && anim->Properties()[0].mSegments.Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Animation property should have one segment for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
const AnimationProperty& prop = anim->Properties()[0];
|
2014-04-03 05:57:27 +00:00
|
|
|
const AnimationPropertySegment& segment = prop.mSegments[0];
|
2009-12-21 21:46:25 +00:00
|
|
|
// properties no longer in 'transition-property'
|
|
|
|
if ((checkProperties &&
|
2014-04-03 05:57:27 +00:00
|
|
|
!allTransitionProperties.HasProperty(prop.mProperty)) ||
|
2009-12-21 21:46:25 +00:00
|
|
|
// properties whose computed values changed but delay and
|
|
|
|
// duration are both zero
|
2014-04-03 05:57:27 +00:00
|
|
|
!ExtractComputedValueForTransition(prop.mProperty, aNewStyleContext,
|
2011-04-12 06:18:43 +00:00
|
|
|
currentValue) ||
|
2014-04-03 05:57:27 +00:00
|
|
|
currentValue != segment.mToValue) {
|
2009-12-21 21:46:25 +00:00
|
|
|
// stop the transition
|
2014-12-17 23:42:41 +00:00
|
|
|
player->Cancel();
|
2014-08-10 07:06:48 +00:00
|
|
|
players.RemoveElementAt(i);
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->UpdateAnimationGeneration(mPresContext);
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
if (players.IsEmpty()) {
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->Destroy();
|
|
|
|
collection = nullptr;
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
if (!startedAny) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 23:57:13 +00:00
|
|
|
NS_ABORT_IF_FALSE(collection, "must have element transitions if we started "
|
|
|
|
"any transitions");
|
2009-10-08 03:22:42 +00:00
|
|
|
|
|
|
|
// In the CSS working group discussion (2009 Jul 15 telecon,
|
|
|
|
// http://www.w3.org/mid/4A5E1470.4030904@inkedblade.net ) of
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2009Jun/0121.html ,
|
|
|
|
// the working group decided that a transition property on an
|
|
|
|
// element should not cause any transitions if the property change
|
|
|
|
// is itself inheriting a value that is transitioning on an
|
|
|
|
// ancestor. So, to get the correct behavior, we continue the
|
|
|
|
// restyle that caused this transition using a "covering" rule that
|
|
|
|
// covers up any changes on which we started transitions, so that
|
|
|
|
// descendants don't start their own transitions. (In the case of
|
|
|
|
// negative transition delay, this covering rule produces different
|
|
|
|
// results than applying the transition rule immediately would).
|
|
|
|
// Our caller is responsible for restyling again using this covering
|
|
|
|
// rule.
|
|
|
|
|
2011-04-12 06:18:43 +00:00
|
|
|
nsRefPtr<css::AnimValuesStyleRule> coverRule = new css::AnimValuesStyleRule;
|
2012-07-31 17:28:21 +00:00
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayerPtrArray& players = collection->mPlayers;
|
|
|
|
for (size_t i = 0, i_end = players.Length(); i < i_end; ++i) {
|
2014-08-10 07:06:49 +00:00
|
|
|
dom::Animation* anim = players[i]->GetSource();
|
|
|
|
MOZ_ASSERT(anim && anim->Properties().Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
MOZ_ASSERT(anim && anim->Properties()[0].mSegments.Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Animation property should have one segment for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
AnimationProperty& prop = anim->Properties()[0];
|
2014-04-03 05:57:27 +00:00
|
|
|
AnimationPropertySegment& segment = prop.mSegments[0];
|
|
|
|
if (whichStarted.HasProperty(prop.mProperty)) {
|
|
|
|
coverRule->AddValue(prop.mProperty, segment.mFromValue);
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 07:57:21 +00:00
|
|
|
// Set the style rule refresh time to null so that EnsureStyleRuleFor
|
|
|
|
// creates a new style rule.
|
|
|
|
collection->mStyleRuleRefreshTime = TimeStamp();
|
2013-06-18 02:18:55 +00:00
|
|
|
|
2010-07-28 23:43:53 +00:00
|
|
|
return coverRule.forget();
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-26 23:57:12 +00:00
|
|
|
nsTransitionManager::ConsiderStartingTransition(
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
const StyleTransition& aTransition,
|
|
|
|
dom::Element* aElement,
|
2014-08-10 07:06:46 +00:00
|
|
|
AnimationPlayerCollection*& aElementTransitions,
|
2014-06-26 23:57:12 +00:00
|
|
|
nsStyleContext* aOldStyleContext,
|
|
|
|
nsStyleContext* aNewStyleContext,
|
|
|
|
bool* aStartedAny,
|
|
|
|
nsCSSPropertySet* aWhichStarted)
|
2009-10-08 03:22:42 +00:00
|
|
|
{
|
|
|
|
// IsShorthand itself will assert if aProperty is not a property.
|
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
2012-12-11 21:12:43 +00:00
|
|
|
NS_ASSERTION(!aElementTransitions ||
|
|
|
|
aElementTransitions->mElement == aElement, "Element mismatch");
|
2009-10-08 03:22:42 +00:00
|
|
|
|
|
|
|
if (aWhichStarted->HasProperty(aProperty)) {
|
|
|
|
// A later item in transition-property already started a
|
|
|
|
// transition for this property, so we ignore this one.
|
|
|
|
// See comment above and
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html .
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-16 00:02:30 +00:00
|
|
|
dom::AnimationTimeline* timeline = aElement->OwnerDoc()->Timeline();
|
2014-04-03 05:57:27 +00:00
|
|
|
|
2014-06-24 06:29:54 +00:00
|
|
|
StyleAnimationValue startValue, endValue, dummyValue;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool haveValues =
|
2011-04-12 06:18:43 +00:00
|
|
|
ExtractComputedValueForTransition(aProperty, aOldStyleContext,
|
2014-04-03 05:57:27 +00:00
|
|
|
startValue) &&
|
2011-04-12 06:18:43 +00:00
|
|
|
ExtractComputedValueForTransition(aProperty, aNewStyleContext,
|
2014-04-03 05:57:27 +00:00
|
|
|
endValue);
|
2012-07-31 17:28:22 +00:00
|
|
|
|
2014-04-03 05:57:27 +00:00
|
|
|
bool haveChange = startValue != endValue;
|
2014-05-14 23:38:37 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool shouldAnimate =
|
2011-01-15 03:57:53 +00:00
|
|
|
haveValues &&
|
2012-12-11 21:12:43 +00:00
|
|
|
haveChange &&
|
2009-10-08 03:22:42 +00:00
|
|
|
// 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 06:29:54 +00:00
|
|
|
StyleAnimationValue::Interpolate(aProperty, startValue, endValue,
|
|
|
|
0.5, dummyValue);
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2013-06-05 00:35:52 +00:00
|
|
|
bool haveCurrentTransition = false;
|
2014-05-09 01:03:35 +00:00
|
|
|
size_t currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
|
2013-06-05 00:35:52 +00:00
|
|
|
const ElementPropertyTransition *oldPT = nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
if (aElementTransitions) {
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayerPtrArray& players = aElementTransitions->mPlayers;
|
|
|
|
for (size_t i = 0, i_end = players.Length(); i < i_end; ++i) {
|
2014-08-10 07:06:49 +00:00
|
|
|
MOZ_ASSERT(players[i]->GetSource() &&
|
|
|
|
players[i]->GetSource()->Properties().Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
if (players[i]->GetSource()->Properties()[0].mProperty == aProperty) {
|
2013-06-05 00:35:52 +00:00
|
|
|
haveCurrentTransition = true;
|
2009-10-08 03:22:42 +00:00
|
|
|
currentIndex = i;
|
2014-08-10 07:06:52 +00:00
|
|
|
oldPT = players[currentIndex]->GetSource()->AsTransition();
|
2009-10-08 03:22:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 00:35:52 +00:00
|
|
|
// If we got a style change that changed the value to the endpoint
|
|
|
|
// of the currently running transition, we don't want to interrupt
|
|
|
|
// its timing function.
|
|
|
|
// This needs to be before the !shouldAnimate && haveCurrentTransition
|
|
|
|
// case below because we might be close enough to the end of the
|
|
|
|
// transition that the current value rounds to the final value. In
|
|
|
|
// this case, we'll end up with shouldAnimate as false (because
|
|
|
|
// there's no value change), but we need to return early here rather
|
|
|
|
// than cancel the running transition because shouldAnimate is false!
|
2014-08-10 07:06:52 +00:00
|
|
|
MOZ_ASSERT(!oldPT || oldPT->Properties()[0].mSegments.Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property segment for a transition");
|
|
|
|
if (haveCurrentTransition && haveValues &&
|
2014-08-10 07:06:52 +00:00
|
|
|
oldPT->Properties()[0].mSegments[0].mToValue == endValue) {
|
2014-11-20 02:48:41 +00:00
|
|
|
// GetAnimationRule already called RestyleForAnimation.
|
2013-06-05 00:35:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
nsPresContext *presContext = aNewStyleContext->PresContext();
|
|
|
|
|
|
|
|
if (!shouldAnimate) {
|
2013-06-05 00:35:52 +00:00
|
|
|
if (haveCurrentTransition) {
|
2013-06-12 05:43:17 +00:00
|
|
|
// We're in the middle of a transition, and just got a non-transition
|
|
|
|
// style change to something that we can't animate. This might happen
|
|
|
|
// because we got a non-transition style change changing to the current
|
|
|
|
// in-progress value (which is particularly easy to cause when we're
|
|
|
|
// currently in the 'transition-delay'). It also might happen because we
|
|
|
|
// just got a style change to a value that can't be interpolated.
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayerPtrArray& players = aElementTransitions->mPlayers;
|
2014-08-10 07:06:52 +00:00
|
|
|
oldPT = nullptr; // Clear pointer so it doesn't dangle
|
2014-08-10 07:06:48 +00:00
|
|
|
players.RemoveElementAt(currentIndex);
|
2012-12-11 21:12:43 +00:00
|
|
|
aElementTransitions->UpdateAnimationGeneration(mPresContext);
|
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
if (players.IsEmpty()) {
|
2009-10-08 03:22:42 +00:00
|
|
|
aElementTransitions->Destroy();
|
|
|
|
// |aElementTransitions| is now a dangling pointer!
|
2012-07-30 14:20:58 +00:00
|
|
|
aElementTransitions = nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
2014-11-20 02:48:41 +00:00
|
|
|
// GetAnimationRule already called RestyleForAnimation.
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:49:53 +00:00
|
|
|
const nsTimingFunction &tf = aTransition.GetTimingFunction();
|
|
|
|
float delay = aTransition.GetDelay();
|
|
|
|
float duration = aTransition.GetDuration();
|
|
|
|
if (duration < 0.0) {
|
|
|
|
// The spec says a negative duration is treated as zero.
|
|
|
|
duration = 0.0;
|
|
|
|
}
|
2014-08-10 07:06:52 +00:00
|
|
|
|
|
|
|
StyleAnimationValue startForReversingTest = startValue;
|
|
|
|
double reversePortion = 1.0;
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2013-06-05 00:35:52 +00:00
|
|
|
// If the new transition reverses an existing one, we'll need to
|
|
|
|
// handle the timing differently.
|
2013-06-05 00:35:52 +00:00
|
|
|
if (haveCurrentTransition &&
|
2014-08-10 07:06:52 +00:00
|
|
|
!oldPT->IsFinishedTransition() &&
|
2014-04-03 05:57:27 +00:00
|
|
|
oldPT->mStartForReversingTest == endValue) {
|
2013-06-05 00:35:52 +00:00
|
|
|
// Compute the appropriate negative transition-delay such that right
|
|
|
|
// now we'd end up at the current position.
|
|
|
|
double valuePortion =
|
2014-07-16 00:02:32 +00:00
|
|
|
oldPT->CurrentValuePortion() * oldPT->mReversePortion +
|
2013-06-05 00:35:52 +00:00
|
|
|
(1.0 - oldPT->mReversePortion);
|
|
|
|
// A timing function with negative y1 (or y2!) might make
|
|
|
|
// valuePortion negative. In this case, we still want to apply our
|
|
|
|
// reversing logic based on relative distances, not make duration
|
|
|
|
// negative.
|
|
|
|
if (valuePortion < 0.0) {
|
|
|
|
valuePortion = -valuePortion;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
2013-06-05 00:35:52 +00:00
|
|
|
// A timing function with y2 (or y1!) greater than one might
|
|
|
|
// advance past its terminal value. It's probably a good idea to
|
|
|
|
// clamp valuePortion to be at most one to preserve the invariant
|
|
|
|
// that a transition will complete within at most its specified
|
|
|
|
// time.
|
|
|
|
if (valuePortion > 1.0) {
|
|
|
|
valuePortion = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Negative delays are essentially part of the transition
|
|
|
|
// function, so reduce them along with the duration, but don't
|
|
|
|
// reduce positive delays.
|
|
|
|
if (delay < 0.0f) {
|
|
|
|
delay *= valuePortion;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration *= valuePortion;
|
|
|
|
|
2014-08-10 07:06:52 +00:00
|
|
|
startForReversingTest = oldPT->Properties()[0].mSegments[0].mToValue;
|
|
|
|
reversePortion = valuePortion;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
|
2014-08-10 07:06:50 +00:00
|
|
|
AnimationTiming timing;
|
|
|
|
timing.mIterationDuration = TimeDuration::FromMilliseconds(duration);
|
|
|
|
timing.mDelay = TimeDuration::FromMilliseconds(delay);
|
|
|
|
timing.mIterationCount = 1;
|
|
|
|
timing.mDirection = NS_STYLE_ANIMATION_DIRECTION_NORMAL;
|
|
|
|
timing.mFillMode = NS_STYLE_ANIMATION_FILL_MODE_BACKWARDS;
|
|
|
|
|
2014-08-10 07:06:52 +00:00
|
|
|
nsRefPtr<ElementPropertyTransition> pt =
|
2014-10-02 06:14:15 +00:00
|
|
|
new ElementPropertyTransition(aElement->OwnerDoc(), aElement,
|
|
|
|
aNewStyleContext->GetPseudoType(), timing);
|
2014-08-10 07:06:52 +00:00
|
|
|
pt->mStartForReversingTest = startForReversingTest;
|
|
|
|
pt->mReversePortion = reversePortion;
|
2014-08-10 07:06:47 +00:00
|
|
|
|
2014-08-10 07:06:52 +00:00
|
|
|
AnimationProperty& prop = *pt->Properties().AppendElement();
|
2014-04-03 05:57:27 +00:00
|
|
|
prop.mProperty = aProperty;
|
|
|
|
|
|
|
|
AnimationPropertySegment& segment = *prop.mSegments.AppendElement();
|
|
|
|
segment.mFromValue = startValue;
|
|
|
|
segment.mToValue = endValue;
|
|
|
|
segment.mFromKey = 0;
|
|
|
|
segment.mToKey = 1;
|
|
|
|
segment.mTimingFunction.Init(tf);
|
|
|
|
|
2014-11-17 04:45:57 +00:00
|
|
|
nsRefPtr<CSSTransitionPlayer> player = new CSSTransitionPlayer(timeline);
|
2014-12-25 23:49:20 +00:00
|
|
|
// The order of the following two calls is important since PlayFromStyle
|
|
|
|
// will add the player to the PendingPlayerTracker of its source content's
|
|
|
|
// document. When we come to make source writeable (bug 1049975) we should
|
|
|
|
// remove this dependency.
|
2014-12-25 07:31:55 +00:00
|
|
|
player->SetSource(pt);
|
2014-12-25 23:49:20 +00:00
|
|
|
player->PlayFromStyle();
|
2014-04-03 05:57:27 +00:00
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
if (!aElementTransitions) {
|
|
|
|
aElementTransitions =
|
2014-11-17 04:45:59 +00:00
|
|
|
GetAnimationPlayers(aElement, aNewStyleContext->GetPseudoType(), true);
|
2009-10-08 03:22:42 +00:00
|
|
|
if (!aElementTransitions) {
|
2014-06-20 03:39:26 +00:00
|
|
|
NS_WARNING("allocating CommonAnimationManager failed");
|
2009-10-08 03:22:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 17:28:21 +00:00
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayerPtrArray& players = aElementTransitions->mPlayers;
|
2009-10-08 03:22:42 +00:00
|
|
|
#ifdef DEBUG
|
2014-08-10 07:06:48 +00:00
|
|
|
for (size_t i = 0, i_end = players.Length(); i < i_end; ++i) {
|
2014-08-10 07:06:49 +00:00
|
|
|
NS_ABORT_IF_FALSE(players[i]->GetSource() &&
|
|
|
|
players[i]->GetSource()->Properties().Length() == 1,
|
2014-04-03 05:57:27 +00:00
|
|
|
"Should have one animation property for a transition");
|
2009-10-08 03:22:42 +00:00
|
|
|
NS_ABORT_IF_FALSE(i == currentIndex ||
|
2014-08-10 07:06:49 +00:00
|
|
|
(players[i]->GetSource() &&
|
|
|
|
players[i]->GetSource()->Properties()[0].mProperty
|
|
|
|
!= aProperty),
|
2009-10-08 03:22:42 +00:00
|
|
|
"duplicate transitions for property");
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-05 00:35:52 +00:00
|
|
|
if (haveCurrentTransition) {
|
2014-08-10 07:06:52 +00:00
|
|
|
players[currentIndex] = player;
|
2009-10-08 03:22:42 +00:00
|
|
|
} else {
|
2014-08-10 07:06:52 +00:00
|
|
|
if (!players.AppendElement(player)) {
|
2009-10-08 03:22:42 +00:00
|
|
|
NS_WARNING("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-12-11 21:12:43 +00:00
|
|
|
aElementTransitions->UpdateAnimationGeneration(mPresContext);
|
2014-06-23 05:10:19 +00:00
|
|
|
aElementTransitions->PostRestyleForAnimation(presContext);
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aStartedAny = true;
|
2009-10-08 03:22:42 +00:00
|
|
|
aWhichStarted->AddProperty(aProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsIStyleRuleProcessor implementation
|
|
|
|
*/
|
|
|
|
|
2011-12-09 05:01:52 +00:00
|
|
|
/* virtual */ size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsTransitionManager::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-09 05:01:52 +00:00
|
|
|
{
|
|
|
|
return CommonAnimationManager::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsTransitionManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-09 05:01:52 +00:00
|
|
|
{
|
2012-01-25 08:52:51 +00:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-09 05:01:52 +00:00
|
|
|
}
|
|
|
|
|
2009-12-23 19:10:31 +00:00
|
|
|
struct TransitionEventInfo {
|
|
|
|
nsCOMPtr<nsIContent> mElement;
|
2013-09-27 06:20:55 +00:00
|
|
|
InternalTransitionEvent mEvent;
|
2009-12-23 19:10:31 +00:00
|
|
|
|
|
|
|
TransitionEventInfo(nsIContent *aElement, nsCSSProperty aProperty,
|
2013-05-04 14:41:20 +00:00
|
|
|
TimeDuration aDuration, const nsAString& aPseudoElement)
|
2014-02-11 05:35:25 +00:00
|
|
|
: mElement(aElement)
|
|
|
|
, mEvent(true, NS_TRANSITION_END)
|
2009-12-23 19:10:31 +00:00
|
|
|
{
|
2014-02-11 05:35:25 +00:00
|
|
|
// XXX Looks like nobody initialize WidgetEvent::time
|
|
|
|
mEvent.propertyName =
|
|
|
|
NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aProperty));
|
|
|
|
mEvent.elapsedTime = aDuration.ToSeconds();
|
|
|
|
mEvent.pseudoElement = aPseudoElement;
|
2009-12-23 19:10:31 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 06:20:55 +00:00
|
|
|
// InternalTransitionEvent doesn't support copy-construction, so we need
|
2009-12-23 19:10:31 +00:00
|
|
|
// to ourselves in order to work with nsTArray
|
|
|
|
TransitionEventInfo(const TransitionEventInfo &aOther)
|
2014-02-11 05:35:25 +00:00
|
|
|
: mElement(aOther.mElement)
|
|
|
|
, mEvent(true, NS_TRANSITION_END)
|
2009-12-23 19:10:31 +00:00
|
|
|
{
|
2014-02-11 05:35:25 +00:00
|
|
|
mEvent.AssignTransitionEventData(aOther.mEvent, false);
|
2009-12-23 19:10:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-08 03:22:42 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsTransitionManager::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
2009-12-23 19:10:31 +00:00
|
|
|
NS_ABORT_IF_FALSE(mPresContext,
|
|
|
|
"refresh driver should not notify additional observers "
|
|
|
|
"after pres context has been destroyed");
|
2010-09-15 19:40:11 +00: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-26 23:57:13 +00:00
|
|
|
RemoveAllElementCollections();
|
2010-09-15 19:40:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-12-23 19:10:31 +00:00
|
|
|
|
2012-12-11 21:12:43 +00:00
|
|
|
FlushTransitions(Can_Throttle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::FlushTransitions(FlushFlags aFlags)
|
2014-06-25 00:42:19 +00:00
|
|
|
{
|
2014-06-26 23:57:13 +00:00
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementCollections)) {
|
2012-12-11 21:12:43 +00:00
|
|
|
// no transitions, leave early
|
|
|
|
return;
|
|
|
|
}
|
2009-12-23 19:10:31 +00:00
|
|
|
|
2012-12-11 21:12:43 +00:00
|
|
|
nsTArray<TransitionEventInfo> events;
|
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
bool didThrottle = false;
|
2012-12-23 04:52:13 +00:00
|
|
|
// Trim transitions that have completed, post restyle events for frames that
|
|
|
|
// are still transitioning, and start transitions with delays.
|
2009-10-08 03:22:42 +00:00
|
|
|
{
|
2014-06-26 23:57:13 +00:00
|
|
|
PRCList *next = PR_LIST_HEAD(&mElementCollections);
|
|
|
|
while (next != &mElementCollections) {
|
2014-08-10 07:06:46 +00:00
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
static_cast<AnimationPlayerCollection*>(next);
|
2009-10-08 03:22:42 +00:00
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
collection->Tick();
|
2012-12-11 21:12:43 +00:00
|
|
|
bool canThrottleTick = aFlags == Can_Throttle &&
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->CanPerformOnCompositorThread(
|
2014-08-10 07:06:46 +00:00
|
|
|
AnimationPlayerCollection::CanAnimateFlags(0)) &&
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->CanThrottleAnimation(now);
|
2012-12-11 21:12:43 +00:00
|
|
|
|
2014-06-26 23:57:13 +00:00
|
|
|
NS_ABORT_IF_FALSE(collection->mElement->GetCrossShadowCurrentDoc() ==
|
2009-10-08 03:22:42 +00:00
|
|
|
mPresContext->Document(),
|
2012-11-14 22:10:08 +00:00
|
|
|
"Element::UnbindFromTree should have "
|
2009-10-08 03:22:42 +00:00
|
|
|
"destroyed the element transitions object");
|
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
size_t i = collection->mPlayers.Length();
|
2009-10-08 03:22:42 +00:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
2012-12-23 04:52:13 +00:00
|
|
|
bool transitionStartedOrEnded = false;
|
2009-10-08 03:22:42 +00:00
|
|
|
do {
|
|
|
|
--i;
|
2014-08-10 07:06:48 +00:00
|
|
|
AnimationPlayer* player = collection->mPlayers[i];
|
2014-08-10 07:06:51 +00:00
|
|
|
if (player->GetSource()->IsFinishedTransition()) {
|
2012-12-11 21:12:43 +00:00
|
|
|
// Actually remove transitions one throttle-able cycle after their
|
|
|
|
// completion. We only clear on a throttle-able cycle because that
|
|
|
|
// means it is a regular restyle tick and thus it is safe to discard
|
|
|
|
// the transition. If the flush is not throttle-able, we might still
|
|
|
|
// have new transitions left to process. See comment below.
|
|
|
|
if (aFlags == Can_Throttle) {
|
2014-08-10 07:06:48 +00:00
|
|
|
collection->mPlayers.RemoveElementAt(i);
|
2012-12-11 21:12:43 +00:00
|
|
|
}
|
2014-06-25 00:42:19 +00:00
|
|
|
} else {
|
2014-08-10 07:06:50 +00:00
|
|
|
MOZ_ASSERT(player->GetSource(),
|
|
|
|
"Transitions should have source content");
|
2014-06-25 00:42:19 +00:00
|
|
|
ComputedTiming computedTiming =
|
2014-08-10 07:06:50 +00:00
|
|
|
player->GetSource()->GetComputedTiming();
|
2014-06-25 00:42:19 +00:00
|
|
|
if (computedTiming.mPhase == ComputedTiming::AnimationPhase_After) {
|
2014-08-10 07:06:50 +00:00
|
|
|
MOZ_ASSERT(player->GetSource()->Properties().Length() == 1,
|
2014-06-25 00:42:19 +00:00
|
|
|
"Should have one animation property for a transition");
|
2014-08-10 07:06:49 +00:00
|
|
|
nsCSSProperty prop = player->GetSource()->Properties()[0].mProperty;
|
2014-06-25 00:42:19 +00:00
|
|
|
if (nsCSSProps::PropHasFlags(prop, CSS_PROPERTY_REPORT_OTHER_NAME))
|
|
|
|
{
|
|
|
|
prop = nsCSSProps::OtherNameFor(prop);
|
|
|
|
}
|
2014-08-10 07:06:50 +00:00
|
|
|
TimeDuration duration =
|
|
|
|
player->GetSource()->Timing().mIterationDuration;
|
2014-06-25 00:42:19 +00:00
|
|
|
events.AppendElement(
|
2014-06-26 23:57:13 +00:00
|
|
|
TransitionEventInfo(collection->mElement, prop,
|
2014-08-10 07:06:50 +00:00
|
|
|
duration,
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->PseudoElement()));
|
2014-06-25 00:42:19 +00:00
|
|
|
|
|
|
|
// Leave this transition in the list for one more refresh
|
|
|
|
// cycle, since we haven't yet processed its style change, and
|
|
|
|
// if we also have (already, or will have from processing
|
|
|
|
// transitionend events or other refresh driver notifications)
|
|
|
|
// a non-animation style change that would affect it, we need
|
|
|
|
// to know not to start a new transition for the transition
|
|
|
|
// from the almost-completed value to the final value.
|
2014-08-10 07:06:51 +00:00
|
|
|
player->GetSource()->SetIsFinishedTransition();
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->UpdateAnimationGeneration(mPresContext);
|
2014-06-25 00:42:19 +00:00
|
|
|
transitionStartedOrEnded = true;
|
|
|
|
} else if ((computedTiming.mPhase ==
|
|
|
|
ComputedTiming::AnimationPhase_Active) &&
|
|
|
|
canThrottleTick &&
|
2014-10-20 04:55:46 +00:00
|
|
|
!player->IsRunningOnCompositor()) {
|
2014-06-25 00:42:19 +00:00
|
|
|
// Start a transition with a delay where we should start the
|
|
|
|
// transition proper.
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->UpdateAnimationGeneration(mPresContext);
|
2014-06-25 00:42:19 +00:00
|
|
|
transitionStartedOrEnded = true;
|
2009-12-23 19:10:31 +00:00
|
|
|
}
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
|
|
|
// We need to restyle even if the transition rule no longer
|
|
|
|
// applies (in which case we just made it not apply).
|
2014-07-03 00:04:35 +00:00
|
|
|
MOZ_ASSERT(collection->mElementProperty ==
|
|
|
|
nsGkAtoms::transitionsProperty ||
|
|
|
|
collection->mElementProperty ==
|
|
|
|
nsGkAtoms::transitionsOfBeforeProperty ||
|
|
|
|
collection->mElementProperty ==
|
|
|
|
nsGkAtoms::transitionsOfAfterProperty,
|
|
|
|
"Unexpected element property; might restyle too much");
|
2012-12-23 04:52:13 +00:00
|
|
|
if (!canThrottleTick || transitionStartedOrEnded) {
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->PostRestyleForAnimation(mPresContext);
|
2012-12-11 21:12:43 +00:00
|
|
|
} else {
|
|
|
|
didThrottle = true;
|
|
|
|
}
|
2009-10-08 03:22:42 +00:00
|
|
|
|
2014-08-10 07:06:48 +00:00
|
|
|
if (collection->mPlayers.IsEmpty()) {
|
2014-06-26 23:57:13 +00:00
|
|
|
collection->Destroy();
|
|
|
|
// |collection| is now a dangling pointer!
|
|
|
|
collection = nullptr;
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 21:12:43 +00:00
|
|
|
if (didThrottle) {
|
|
|
|
mPresContext->Document()->SetNeedStyleFlush();
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0, i_end = events.Length(); i < i_end; ++i) {
|
2009-12-23 19:10:31 +00:00
|
|
|
TransitionEventInfo &info = events[i];
|
2014-03-18 04:48:21 +00:00
|
|
|
EventDispatcher::Dispatch(info.mElement, mPresContext, &info.mEvent);
|
2009-12-23 19:10:31 +00:00
|
|
|
|
|
|
|
if (!mPresContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 03:22:42 +00:00
|
|
|
}
|