2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#include "nsTransitionManager.h"
|
2012-12-12 01:12:43 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2015-06-30 04:00:39 +03:00
|
|
|
#include "mozilla/dom/CSSTransitionBinding.h"
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsIContent.h"
|
2017-03-05 11:28:49 +03:00
|
|
|
#include "nsContentUtils.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsStyleContext.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsRuleProcessorData.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2016-08-17 04:46:58 +03:00
|
|
|
#include "nsCSSPropertyIDSet.h"
|
2018-01-27 15:17:27 +03:00
|
|
|
#include "mozilla/AnimationEventDispatcher.h"
|
2016-01-06 05:04:05 +03:00
|
|
|
#include "mozilla/EffectCompositor.h"
|
2016-01-06 05:04:05 +03:00
|
|
|
#include "mozilla/EffectSet.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2017-05-07 17:36:47 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2014-06-24 10:29:54 +04:00
|
|
|
#include "mozilla/StyleAnimationValue.h"
|
2015-04-28 05:29:13 +03:00
|
|
|
#include "mozilla/dom/DocumentTimeline.h"
|
2010-05-14 21:04:51 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsIFrame.h"
|
2012-12-12 01:12:43 +04:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
2015-04-14 03:13:27 +03:00
|
|
|
#include "nsCSSProps.h"
|
2016-02-17 23:37:00 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2012-12-12 01:12:43 +04:00
|
|
|
#include "nsDisplayList.h"
|
2018-01-18 09:01:27 +03:00
|
|
|
#include "nsRFPService.h"
|
2013-01-09 08:37:29 +04:00
|
|
|
#include "nsStyleChangeList.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "nsStyleSet.h"
|
2017-02-13 06:21:33 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
|
|
|
#include "mozilla/RestyleManagerInlines.h"
|
2015-03-14 08:34:40 +03:00
|
|
|
#include "nsDOMMutationObserver.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
using mozilla::TimeStamp;
|
|
|
|
using mozilla::TimeDuration;
|
2015-04-21 04:22:09 +03:00
|
|
|
using mozilla::dom::Animation;
|
2016-07-08 00:05:28 +03:00
|
|
|
using mozilla::dom::AnimationPlayState;
|
|
|
|
using mozilla::dom::CSSTransition;
|
2015-04-30 16:06:43 +03:00
|
|
|
using mozilla::dom::KeyframeEffectReadOnly;
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::css;
|
2010-05-14 21:04:51 +04:00
|
|
|
|
2010-11-10 18:49:53 +03:00
|
|
|
double
|
2014-07-16 04:02:32 +04:00
|
|
|
ElementPropertyTransition::CurrentValuePortion() const
|
2010-11-10 18:49:53 +03:00
|
|
|
{
|
2014-08-10 11:06:52 +04:00
|
|
|
MOZ_ASSERT(!GetLocalTime().IsNull(),
|
2014-07-16 04:02:32 +04:00
|
|
|
"Getting the value portion of an animation that's not being "
|
|
|
|
"sampled");
|
2014-06-20 07:39:26 +04:00
|
|
|
|
2014-07-16 04:02:33 +04:00
|
|
|
// Transitions use a fill mode of 'backwards' so GetComputedTiming will
|
2015-05-13 07:57:35 +03:00
|
|
|
// never return a null time progress due to being *before* the animation
|
2014-06-20 07:39:26 +04:00
|
|
|
// interval. However, it might be possible that we're behind on flushing
|
|
|
|
// causing us to get called *after* the animation interval. So, just in
|
2015-05-13 07:57:35 +03:00
|
|
|
// case, we override the fill mode to 'both' to ensure the progress
|
2014-06-20 07:39:26 +04:00
|
|
|
// is never null.
|
2016-01-13 20:41:00 +03:00
|
|
|
TimingParams timingToUse = SpecifiedTiming();
|
2017-06-22 06:12:43 +03:00
|
|
|
timingToUse.SetFill(dom::FillMode::Both);
|
2014-08-10 11:06:52 +04:00
|
|
|
ComputedTiming computedTiming = GetComputedTiming(&timingToUse);
|
2014-06-20 07:39:26 +04:00
|
|
|
|
2015-10-19 01:38:00 +03:00
|
|
|
MOZ_ASSERT(!computedTiming.mProgress.IsNull(),
|
2015-05-13 07:57:35 +03:00
|
|
|
"Got a null progress for a fill mode of 'both'");
|
2016-05-13 03:40:52 +03:00
|
|
|
MOZ_ASSERT(mKeyframes.Length() == 2,
|
|
|
|
"Should have two animation keyframes for a transition");
|
|
|
|
return ComputedTimingFunction::GetPortion(mKeyframes[0].mTimingFunction,
|
2016-04-01 03:27:57 +03:00
|
|
|
computedTiming.mProgress.Value(),
|
|
|
|
computedTiming.mBeforeFlag);
|
2010-11-10 18:49:53 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 23:51:57 +03:00
|
|
|
void
|
|
|
|
ElementPropertyTransition::UpdateStartValueFromReplacedTransition()
|
|
|
|
{
|
|
|
|
if (!mReplacedTransition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(nsCSSProps::PropHasFlags(TransitionProperty(),
|
|
|
|
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR),
|
|
|
|
"The transition property should be able to be run on the "
|
|
|
|
"compositor");
|
|
|
|
MOZ_ASSERT(mTarget && mTarget->mElement->OwnerDoc(),
|
|
|
|
"We should have a valid document at this moment");
|
|
|
|
|
|
|
|
dom::DocumentTimeline* timeline = mTarget->mElement->OwnerDoc()->Timeline();
|
|
|
|
ComputedTiming computedTiming = GetComputedTimingAt(
|
|
|
|
dom::CSSTransition::GetCurrentTimeAt(*timeline,
|
|
|
|
TimeStamp::Now(),
|
|
|
|
mReplacedTransition->mStartTime,
|
|
|
|
mReplacedTransition->mPlaybackRate),
|
2016-08-17 02:28:41 +03:00
|
|
|
mReplacedTransition->mTiming,
|
|
|
|
mReplacedTransition->mPlaybackRate);
|
2016-05-24 23:51:57 +03:00
|
|
|
|
|
|
|
if (!computedTiming.mProgress.IsNull()) {
|
|
|
|
double valuePosition =
|
|
|
|
ComputedTimingFunction::GetPortion(mReplacedTransition->mTimingFunction,
|
|
|
|
computedTiming.mProgress.Value(),
|
|
|
|
computedTiming.mBeforeFlag);
|
2017-03-09 07:33:15 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mProperties.Length() == 1 &&
|
|
|
|
mProperties[0].mSegments.Length() == 1,
|
|
|
|
"The transition should have one property and one segment");
|
|
|
|
MOZ_ASSERT(mKeyframes.Length() == 2,
|
|
|
|
"Transitions should have exactly two animation keyframes");
|
|
|
|
MOZ_ASSERT(mKeyframes[0].mPropertyValues.Length() == 1,
|
|
|
|
"Transitions should have exactly one property in their first "
|
|
|
|
"frame");
|
|
|
|
|
|
|
|
const AnimationValue& replacedFrom = mReplacedTransition->mFromValue;
|
|
|
|
const AnimationValue& replacedTo = mReplacedTransition->mToValue;
|
|
|
|
AnimationValue startValue;
|
|
|
|
if (mDocument->IsStyledByServo()) {
|
|
|
|
startValue.mServo =
|
|
|
|
Servo_AnimationValues_Interpolate(replacedFrom.mServo,
|
|
|
|
replacedTo.mServo,
|
|
|
|
valuePosition).Consume();
|
|
|
|
if (startValue.mServo) {
|
|
|
|
mKeyframes[0].mPropertyValues[0].mServoDeclarationBlock =
|
|
|
|
Servo_AnimationValue_Uncompute(startValue.mServo).Consume();
|
|
|
|
mProperties[0].mSegments[0].mFromValue = Move(startValue);
|
|
|
|
}
|
|
|
|
} else if (StyleAnimationValue::Interpolate(mProperties[0].mProperty,
|
|
|
|
replacedFrom.mGecko,
|
|
|
|
replacedTo.mGecko,
|
|
|
|
valuePosition,
|
|
|
|
startValue.mGecko)) {
|
2016-06-08 00:25:46 +03:00
|
|
|
nsCSSValue cssValue;
|
|
|
|
DebugOnly<bool> uncomputeResult =
|
|
|
|
StyleAnimationValue::UncomputeValue(mProperties[0].mProperty,
|
2017-03-09 07:33:15 +03:00
|
|
|
startValue.mGecko,
|
2016-06-08 00:25:46 +03:00
|
|
|
cssValue);
|
|
|
|
MOZ_ASSERT(uncomputeResult, "UncomputeValue should not fail");
|
|
|
|
mKeyframes[0].mPropertyValues[0].mValue = cssValue;
|
2017-03-09 07:33:15 +03:00
|
|
|
|
|
|
|
mProperties[0].mSegments[0].mFromValue = Move(startValue);
|
2016-05-24 23:51:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mReplacedTransition.reset();
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
////////////////////////// CSSTransition ////////////////////////////
|
2014-11-17 07:45:58 +03:00
|
|
|
|
2015-06-30 04:00:39 +03:00
|
|
|
JSObject*
|
|
|
|
CSSTransition::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
|
|
{
|
|
|
|
return dom::CSSTransitionBinding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2015-07-01 09:19:04 +03:00
|
|
|
void
|
|
|
|
CSSTransition::GetTransitionProperty(nsString& aRetVal) const
|
|
|
|
{
|
2016-07-28 06:20:13 +03:00
|
|
|
MOZ_ASSERT(eCSSProperty_UNKNOWN != mTransitionProperty,
|
|
|
|
"Transition Property should be initialized");
|
|
|
|
aRetVal =
|
|
|
|
NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(mTransitionProperty));
|
2015-07-01 09:19:04 +03:00
|
|
|
}
|
|
|
|
|
2015-06-30 04:00:39 +03:00
|
|
|
AnimationPlayState
|
2015-04-21 04:22:10 +03:00
|
|
|
CSSTransition::PlayStateFromJS() const
|
2014-11-17 07:45:58 +03:00
|
|
|
{
|
|
|
|
FlushStyle();
|
2015-04-21 04:22:09 +03:00
|
|
|
return Animation::PlayStateFromJS();
|
2014-11-17 07:45:58 +03:00
|
|
|
}
|
|
|
|
|
2017-11-21 11:10:59 +03:00
|
|
|
bool
|
|
|
|
CSSTransition::PendingFromJS() const
|
|
|
|
{
|
|
|
|
// Transitions don't become pending again after they start running but, if
|
|
|
|
// while the transition is still pending, style is updated in such a way
|
|
|
|
// that the transition will be canceled, we need to report false here.
|
|
|
|
// Hence we need to flush, but only when we're pending.
|
|
|
|
if (Pending()) {
|
|
|
|
FlushStyle();
|
|
|
|
}
|
|
|
|
return Animation::PendingFromJS();
|
|
|
|
}
|
|
|
|
|
2014-11-17 07:45:58 +03:00
|
|
|
void
|
2015-05-19 08:00:48 +03:00
|
|
|
CSSTransition::PlayFromJS(ErrorResult& aRv)
|
2014-11-17 07:45:58 +03:00
|
|
|
{
|
|
|
|
FlushStyle();
|
2015-05-19 08:00:48 +03:00
|
|
|
Animation::PlayFromJS(aRv);
|
2014-11-17 07:45:58 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 05:20:56 +03:00
|
|
|
void
|
|
|
|
CSSTransition::UpdateTiming(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag)
|
|
|
|
{
|
|
|
|
if (mNeedsNewAnimationIndexWhenRun &&
|
|
|
|
PlayState() != AnimationPlayState::Idle) {
|
|
|
|
mAnimationIndex = sNextAnimationIndex++;
|
|
|
|
mNeedsNewAnimationIndexWhenRun = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation::UpdateTiming(aSeekFlag, aSyncNotifyFlag);
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:40 +03:00
|
|
|
void
|
2018-01-17 12:05:03 +03:00
|
|
|
CSSTransition::QueueEvents(const StickyTimeDuration& aActiveTime)
|
2015-07-29 04:57:40 +03:00
|
|
|
{
|
2016-12-20 10:03:29 +03:00
|
|
|
if (!mOwningElement.IsSet()) {
|
2015-07-29 04:57:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-17 02:13:01 +03:00
|
|
|
nsPresContext* presContext = mOwningElement.GetPresContext();
|
2015-07-29 04:57:40 +03:00
|
|
|
if (!presContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-18 09:01:24 +03:00
|
|
|
static constexpr StickyTimeDuration zeroDuration = StickyTimeDuration();
|
2016-12-20 10:03:29 +03:00
|
|
|
|
|
|
|
TransitionPhase currentPhase;
|
|
|
|
StickyTimeDuration intervalStartTime;
|
|
|
|
StickyTimeDuration intervalEndTime;
|
|
|
|
|
|
|
|
if (!mEffect) {
|
2017-02-10 06:32:44 +03:00
|
|
|
currentPhase = GetAnimationPhaseWithoutEffect<TransitionPhase>(*this);
|
2016-12-20 10:03:29 +03:00
|
|
|
} else {
|
|
|
|
ComputedTiming computedTiming = mEffect->GetComputedTiming();
|
|
|
|
|
|
|
|
currentPhase = static_cast<TransitionPhase>(computedTiming.mPhase);
|
|
|
|
intervalStartTime =
|
2017-06-22 06:12:43 +03:00
|
|
|
std::max(std::min(StickyTimeDuration(-mEffect->SpecifiedTiming().Delay()),
|
2016-12-20 10:03:29 +03:00
|
|
|
computedTiming.mActiveDuration), zeroDuration);
|
|
|
|
intervalEndTime =
|
2017-06-22 06:12:43 +03:00
|
|
|
std::max(std::min((EffectEnd() - mEffect->SpecifiedTiming().Delay()),
|
2016-12-20 10:03:29 +03:00
|
|
|
computedTiming.mActiveDuration), zeroDuration);
|
|
|
|
}
|
2016-10-19 09:16:51 +03:00
|
|
|
|
|
|
|
// TimeStamps to use for ordering the events when they are dispatched. We
|
|
|
|
// use a TimeStamp so we can compare events produced by different elements,
|
|
|
|
// perhaps even with different timelines.
|
|
|
|
// The zero timestamp is for transitionrun events where we ignore the delay
|
|
|
|
// for the purpose of ordering events.
|
2017-02-06 10:21:01 +03:00
|
|
|
TimeStamp zeroTimeStamp = AnimationTimeToTimeStamp(zeroDuration);
|
|
|
|
TimeStamp startTimeStamp = ElapsedTimeToTimeStamp(intervalStartTime);
|
|
|
|
TimeStamp endTimeStamp = ElapsedTimeToTimeStamp(intervalEndTime);
|
2016-10-19 09:16:51 +03:00
|
|
|
|
|
|
|
if (mPendingState != PendingState::NotPending &&
|
|
|
|
(mPreviousTransitionPhase == TransitionPhase::Idle ||
|
|
|
|
mPreviousTransitionPhase == TransitionPhase::Pending))
|
|
|
|
{
|
|
|
|
currentPhase = TransitionPhase::Pending;
|
|
|
|
}
|
|
|
|
|
2018-01-27 15:17:27 +03:00
|
|
|
AutoTArray<AnimationEventInfo, 3> events;
|
2018-01-17 02:13:01 +03:00
|
|
|
|
|
|
|
auto appendTransitionEvent = [&](EventMessage aMessage,
|
2018-01-17 12:05:03 +03:00
|
|
|
const StickyTimeDuration& aElapsedTime,
|
|
|
|
const TimeStamp& aTimeStamp) {
|
2018-01-18 09:01:27 +03:00
|
|
|
double elapsedTime = aElapsedTime.ToSeconds();
|
|
|
|
if (aMessage == eTransitionCancel) {
|
|
|
|
elapsedTime = nsRFPService::ReduceTimePrecisionAsSecs(elapsedTime);
|
|
|
|
}
|
2018-01-27 15:17:27 +03:00
|
|
|
events.AppendElement(AnimationEventInfo(TransitionProperty(),
|
|
|
|
mOwningElement.Target(),
|
|
|
|
aMessage,
|
|
|
|
elapsedTime,
|
|
|
|
aTimeStamp,
|
|
|
|
this));
|
2018-01-17 02:13:01 +03:00
|
|
|
};
|
2016-12-20 10:03:29 +03:00
|
|
|
|
2017-02-06 10:21:01 +03:00
|
|
|
// Handle cancel events first
|
|
|
|
if ((mPreviousTransitionPhase != TransitionPhase::Idle &&
|
|
|
|
mPreviousTransitionPhase != TransitionPhase::After) &&
|
2016-12-20 10:03:29 +03:00
|
|
|
currentPhase == TransitionPhase::Idle) {
|
2016-12-20 10:03:29 +03:00
|
|
|
TimeStamp activeTimeStamp = ElapsedTimeToTimeStamp(aActiveTime);
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionCancel, aActiveTime, activeTimeStamp);
|
2016-12-20 10:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// All other events
|
2016-10-19 09:16:51 +03:00
|
|
|
switch (mPreviousTransitionPhase) {
|
|
|
|
case TransitionPhase::Idle:
|
|
|
|
if (currentPhase == TransitionPhase::Pending ||
|
|
|
|
currentPhase == TransitionPhase::Before) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionRun, intervalStartTime, zeroTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
} else if (currentPhase == TransitionPhase::Active) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionRun, intervalStartTime, zeroTimeStamp);
|
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalStartTime,
|
|
|
|
startTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
} else if (currentPhase == TransitionPhase::After) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionRun, intervalStartTime, zeroTimeStamp);
|
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalStartTime,
|
|
|
|
startTimeStamp);
|
|
|
|
appendTransitionEvent(eTransitionEnd, intervalEndTime, endTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TransitionPhase::Pending:
|
|
|
|
case TransitionPhase::Before:
|
|
|
|
if (currentPhase == TransitionPhase::Active) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalStartTime,
|
|
|
|
startTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
} else if (currentPhase == TransitionPhase::After) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalStartTime,
|
|
|
|
startTimeStamp);
|
|
|
|
appendTransitionEvent(eTransitionEnd, intervalEndTime, endTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TransitionPhase::Active:
|
|
|
|
if (currentPhase == TransitionPhase::After) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionEnd, intervalEndTime, endTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
} else if (currentPhase == TransitionPhase::Before) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionEnd,
|
|
|
|
intervalStartTime,
|
|
|
|
startTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TransitionPhase::After:
|
|
|
|
if (currentPhase == TransitionPhase::Active) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalEndTime,
|
|
|
|
startTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
} else if (currentPhase == TransitionPhase::Before) {
|
2018-01-17 02:13:01 +03:00
|
|
|
appendTransitionEvent(eTransitionStart,
|
|
|
|
intervalEndTime,
|
|
|
|
startTimeStamp);
|
|
|
|
appendTransitionEvent(eTransitionEnd,
|
|
|
|
intervalStartTime,
|
|
|
|
endTimeStamp);
|
2016-10-19 09:16:51 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mPreviousTransitionPhase = currentPhase;
|
|
|
|
|
2018-01-17 02:13:01 +03:00
|
|
|
if (!events.IsEmpty()) {
|
2018-01-27 15:17:27 +03:00
|
|
|
presContext->AnimationEventDispatcher()->QueueEvents(Move(events));
|
2016-10-19 09:16:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:40 +03:00
|
|
|
void
|
|
|
|
CSSTransition::Tick()
|
|
|
|
{
|
|
|
|
Animation::Tick();
|
|
|
|
QueueEvents();
|
|
|
|
}
|
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID
|
2015-06-09 05:13:54 +03:00
|
|
|
CSSTransition::TransitionProperty() const
|
|
|
|
{
|
2016-07-28 06:20:13 +03:00
|
|
|
MOZ_ASSERT(eCSSProperty_UNKNOWN != mTransitionProperty,
|
|
|
|
"Transition property should be initialized");
|
|
|
|
return mTransitionProperty;
|
2015-06-09 05:13:54 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 07:33:15 +03:00
|
|
|
AnimationValue
|
2016-04-01 03:28:35 +03:00
|
|
|
CSSTransition::ToValue() const
|
|
|
|
{
|
2016-07-28 06:20:13 +03:00
|
|
|
MOZ_ASSERT(!mTransitionToValue.IsNull(),
|
|
|
|
"Transition ToValue should be initialized");
|
|
|
|
return mTransitionToValue;
|
2016-04-01 03:28:35 +03:00
|
|
|
}
|
|
|
|
|
2015-06-09 05:13:54 +03:00
|
|
|
bool
|
2016-01-14 04:24:24 +03:00
|
|
|
CSSTransition::HasLowerCompositeOrderThan(const CSSTransition& aOther) const
|
2015-06-09 05:13:54 +03:00
|
|
|
{
|
2016-01-14 04:24:24 +03:00
|
|
|
MOZ_ASSERT(IsTiedToMarkup() && aOther.IsTiedToMarkup(),
|
|
|
|
"Should only be called for CSS transitions that are sorted "
|
|
|
|
"as CSS transitions (i.e. tied to CSS markup)");
|
|
|
|
|
2015-06-09 05:13:54 +03:00
|
|
|
// 0. Object-equality case
|
|
|
|
if (&aOther == this) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-14 04:24:24 +03:00
|
|
|
// 1. Sort by document order
|
|
|
|
if (!mOwningElement.Equals(aOther.mOwningElement)) {
|
|
|
|
return mOwningElement.LessThan(aOther.mOwningElement);
|
2015-06-09 05:13:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-14 04:24:24 +03:00
|
|
|
// 2. (Same element and pseudo): Sort by transition generation
|
|
|
|
if (mAnimationIndex != aOther.mAnimationIndex) {
|
|
|
|
return mAnimationIndex < aOther.mAnimationIndex;
|
2015-06-09 05:13:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-14 04:24:24 +03:00
|
|
|
// 3. (Same transition generation): Sort by transition property
|
2015-06-09 05:13:54 +03:00
|
|
|
return nsCSSProps::GetStringValue(TransitionProperty()) <
|
2016-01-14 04:24:24 +03:00
|
|
|
nsCSSProps::GetStringValue(aOther.TransitionProperty());
|
2015-06-09 05:13:54 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 23:51:57 +03:00
|
|
|
/* static */ Nullable<TimeDuration>
|
2016-11-23 02:26:20 +03:00
|
|
|
CSSTransition::GetCurrentTimeAt(const dom::DocumentTimeline& aTimeline,
|
2016-05-24 23:51:57 +03:00
|
|
|
const TimeStamp& aBaseTime,
|
|
|
|
const TimeDuration& aStartTime,
|
|
|
|
double aPlaybackRate)
|
|
|
|
{
|
|
|
|
Nullable<TimeDuration> result;
|
|
|
|
|
|
|
|
Nullable<TimeDuration> timelineTime = aTimeline.ToTimelineTime(aBaseTime);
|
|
|
|
if (!timelineTime.IsNull()) {
|
|
|
|
result.SetValue((timelineTime.Value() - aStartTime)
|
|
|
|
.MultDouble(aPlaybackRate));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-28 06:20:13 +03:00
|
|
|
void
|
2016-11-23 02:26:20 +03:00
|
|
|
CSSTransition::SetEffectFromStyle(dom::AnimationEffectReadOnly* aEffect)
|
2016-07-28 06:20:13 +03:00
|
|
|
{
|
2016-08-24 09:36:14 +03:00
|
|
|
Animation::SetEffectNoUpdate(aEffect);
|
2016-07-28 06:20:13 +03:00
|
|
|
|
|
|
|
// Initialize transition property.
|
|
|
|
ElementPropertyTransition* pt = aEffect ? aEffect->AsTransition() : nullptr;
|
|
|
|
if (eCSSProperty_UNKNOWN == mTransitionProperty && pt) {
|
|
|
|
mTransitionProperty = pt->TransitionProperty();
|
|
|
|
mTransitionToValue = pt->ToValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
////////////////////////// nsTransitionManager ////////////////////////////
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2016-08-16 08:29:21 +03:00
|
|
|
static inline bool
|
2016-08-17 04:37:48 +03:00
|
|
|
ExtractNonDiscreteComputedValue(nsCSSPropertyID aProperty,
|
2017-07-21 04:22:00 +03:00
|
|
|
GeckoStyleContext* aStyleContext,
|
2017-04-12 11:31:12 +03:00
|
|
|
AnimationValue& aAnimationValue)
|
2016-08-16 08:29:21 +03:00
|
|
|
{
|
|
|
|
return (nsCSSProps::kAnimTypeTable[aProperty] != eStyleAnimType_Discrete ||
|
|
|
|
aProperty == eCSSProperty_visibility) &&
|
|
|
|
StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext,
|
2017-04-12 11:31:12 +03:00
|
|
|
aAnimationValue.mGecko);
|
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2017-04-12 11:31:12 +03:00
|
|
|
|
|
|
|
static inline bool
|
|
|
|
ExtractNonDiscreteComputedValue(nsCSSPropertyID aProperty,
|
2017-07-17 21:42:00 +03:00
|
|
|
const ServoStyleContext* aComputedStyle,
|
2017-04-12 11:31:12 +03:00
|
|
|
AnimationValue& aAnimationValue)
|
|
|
|
{
|
|
|
|
if (Servo_Property_IsDiscreteAnimatable(aProperty) &&
|
|
|
|
aProperty != eCSSProperty_visibility) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aAnimationValue.mServo =
|
2017-07-18 17:47:13 +03:00
|
|
|
Servo_ComputedValues_ExtractAnimationValue(aComputedStyle,
|
2017-04-12 11:31:12 +03:00
|
|
|
aProperty).Consume();
|
|
|
|
return !!aAnimationValue.mServo;
|
2016-08-16 08:29:21 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
2015-02-17 01:15:02 +03:00
|
|
|
void
|
2010-05-14 21:04:51 +04:00
|
|
|
nsTransitionManager::StyleContextChanged(dom::Element *aElement,
|
2017-07-21 04:22:00 +03:00
|
|
|
GeckoStyleContext* aOldStyleContext,
|
|
|
|
RefPtr<GeckoStyleContext>* aNewStyleContext /* inout */)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
2017-07-21 04:22:00 +03:00
|
|
|
GeckoStyleContext* newStyleContext = *aNewStyleContext;
|
2015-02-17 01:15:02 +03:00
|
|
|
|
|
|
|
NS_PRECONDITION(aOldStyleContext->GetPseudo() == newStyleContext->GetPseudo(),
|
2009-10-08 07:22:42 +04:00
|
|
|
"pseudo type mismatch");
|
|
|
|
|
2014-08-07 09:58:44 +04: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.
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2014-08-07 09:58:44 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 10:36:39 +04:00
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore transitions.
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2013-05-29 10:36:39 +04:00
|
|
|
}
|
|
|
|
|
2014-08-14 02:39:02 +04:00
|
|
|
if (aOldStyleContext->HasPseudoElementData() !=
|
2015-02-17 01:15:02 +03:00
|
|
|
newStyleContext->HasPseudoElementData()) {
|
2014-08-14 02:39:02 +04:00
|
|
|
// 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.
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2014-08-14 02:39:02 +04:00
|
|
|
}
|
|
|
|
|
2016-10-19 09:16:52 +03:00
|
|
|
// NOTE: Things in this function (and ConsiderInitiatingTransition)
|
2009-12-11 19:13:19 +03:00
|
|
|
// should never call PeekStyleData because we don't preserve gotten
|
|
|
|
// structs across reframes.
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
// Return sooner (before the startedAny check below) for the most
|
2009-12-22 00:46:25 +03:00
|
|
|
// common case: no transitions specified or running.
|
2018-01-05 00:24:07 +03:00
|
|
|
const nsStyleDisplay* disp = newStyleContext->StyleDisplay();
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType pseudoType = newStyleContext->GetPseudoType();
|
2016-02-17 01:07:00 +03:00
|
|
|
if (pseudoType != CSSPseudoElementType::NotPseudo) {
|
|
|
|
if (pseudoType != CSSPseudoElementType::before &&
|
|
|
|
pseudoType != CSSPseudoElementType::after) {
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2010-07-01 05:54:29 +04:00
|
|
|
}
|
|
|
|
|
2016-02-17 01:07:00 +03:00
|
|
|
NS_ASSERTION((pseudoType == CSSPseudoElementType::before &&
|
2016-08-19 06:46:46 +03:00
|
|
|
aElement->IsGeneratedContentContainerForBefore()) ||
|
2016-02-17 01:07:00 +03:00
|
|
|
(pseudoType == CSSPseudoElementType::after &&
|
2016-08-19 06:46:46 +03:00
|
|
|
aElement->IsGeneratedContentContainerForAfter()),
|
2010-07-01 05:54:29 +04:00
|
|
|
"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();
|
|
|
|
}
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection* collection =
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection::GetAnimationCollection(aElement, pseudoType);
|
2014-06-27 03:57:13 +04:00
|
|
|
if (!collection &&
|
2009-12-22 00:46:25 +03:00
|
|
|
disp->mTransitionPropertyCount == 1 &&
|
2018-01-05 00:24:09 +03:00
|
|
|
disp->GetTransitionCombinedDuration(0) <= 0.0f) {
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-07-30 22:36:12 +04:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
|
|
|
|
"ServoRestyleManager should not use nsTransitionManager "
|
|
|
|
"for transitions");
|
2015-02-17 01:15:03 +03:00
|
|
|
if (collection &&
|
|
|
|
collection->mCheckGeneration ==
|
2017-03-09 12:15:08 +03:00
|
|
|
mPresContext->RestyleManager()->GetAnimationGeneration()) {
|
2015-02-17 01:15:03 +03:00
|
|
|
// When we start a new transition, we immediately post a restyle.
|
|
|
|
// If the animation generation on the collection is current, that
|
|
|
|
// means *this* is that restyle, since we bump the animation
|
|
|
|
// generation on the restyle manager whenever there's a real style
|
|
|
|
// change (i.e., one where mInAnimationOnlyStyleUpdate isn't true,
|
|
|
|
// which causes us to return above). Thus we shouldn't do anything.
|
|
|
|
return;
|
|
|
|
}
|
2015-02-17 01:15:02 +03:00
|
|
|
if (newStyleContext->GetParent() &&
|
|
|
|
newStyleContext->GetParent()->HasPseudoElementData()) {
|
2009-10-08 07:22:42 +04:00
|
|
|
// Ignore transitions on things that inherit properties from
|
|
|
|
// pseudo-elements.
|
2009-10-16 04:23:19 +04:00
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
2015-02-17 01:15:02 +03:00
|
|
|
return;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
!mPresContext->EffectCompositor()->HasThrottledStyleUpdates(),
|
|
|
|
"throttled animations not up to date");
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2015-02-17 01:15:02 +03:00
|
|
|
// Compute what the css-transitions spec calls the "after-change
|
|
|
|
// style", which is the new style without any data from transitions,
|
|
|
|
// but still inheriting from data that contains transitions that are
|
|
|
|
// not stopping or starting right now.
|
2017-07-21 04:22:00 +03:00
|
|
|
RefPtr<GeckoStyleContext> afterChangeStyle;
|
2015-02-17 01:15:02 +03:00
|
|
|
if (collection) {
|
2016-02-24 10:01:11 +03:00
|
|
|
MOZ_ASSERT(mPresContext->StyleSet()->IsGecko(),
|
|
|
|
"ServoStyleSets should not use nsTransitionManager "
|
|
|
|
"for transitions");
|
|
|
|
nsStyleSet* styleSet = mPresContext->StyleSet()->AsGecko();
|
2015-02-17 01:15:02 +03:00
|
|
|
afterChangeStyle =
|
2017-01-16 10:57:13 +03:00
|
|
|
styleSet->ResolveStyleByRemovingAnimation(aElement, newStyleContext,
|
|
|
|
eRestyle_CSSTransitions);
|
2015-02-17 01:15:02 +03:00
|
|
|
} else {
|
2015-02-17 01:15:02 +03:00
|
|
|
afterChangeStyle = newStyleContext;
|
2015-02-17 01:15:02 +03:00
|
|
|
}
|
|
|
|
|
2015-08-31 10:21:49 +03:00
|
|
|
nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
|
2015-03-14 08:34:40 +03:00
|
|
|
|
2016-04-12 02:55:00 +03:00
|
|
|
DebugOnly<bool> startedAny = false;
|
|
|
|
// We don't have to update transitions if display:none, although we will
|
|
|
|
// cancel them after restyling.
|
|
|
|
if (!afterChangeStyle->IsInDisplayNoneSubtree()) {
|
2018-01-05 00:24:07 +03:00
|
|
|
startedAny = DoUpdateTransitions(*disp,
|
2017-04-12 11:33:44 +03:00
|
|
|
aElement,
|
|
|
|
afterChangeStyle->GetPseudoType(),
|
|
|
|
collection,
|
2017-07-17 21:42:00 +03:00
|
|
|
aOldStyleContext->AsGecko(),
|
|
|
|
afterChangeStyle->AsGecko());
|
2016-04-12 02:55:00 +03:00
|
|
|
}
|
2016-04-12 02:53:00 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!startedAny || collection,
|
|
|
|
"must have element transitions if we started any transitions");
|
|
|
|
|
|
|
|
EffectCompositor::CascadeLevel cascadeLevel =
|
|
|
|
EffectCompositor::CascadeLevel::Transitions;
|
|
|
|
|
|
|
|
if (collection) {
|
|
|
|
collection->UpdateCheckGeneration(mPresContext);
|
|
|
|
mPresContext->EffectCompositor()->MaybeUpdateAnimationRule(aElement,
|
|
|
|
pseudoType,
|
2016-07-11 11:28:14 +03:00
|
|
|
cascadeLevel,
|
|
|
|
newStyleContext);
|
2016-04-12 02:53:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We want to replace the new style context with the after-change style.
|
|
|
|
*aNewStyleContext = afterChangeStyle;
|
|
|
|
if (collection) {
|
|
|
|
// Since we have transition styles, we have to undo this replacement.
|
|
|
|
// The check of collection->mCheckGeneration against the restyle
|
|
|
|
// manager's GetAnimationGeneration() will ensure that we don't go
|
|
|
|
// through the rest of this function again when we do.
|
|
|
|
mPresContext->EffectCompositor()->PostRestyleForAnimation(aElement,
|
|
|
|
pseudoType,
|
|
|
|
cascadeLevel);
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|
2016-04-12 02:53:00 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsTransitionManager::UpdateTransitions(
|
2017-04-12 11:33:44 +03:00
|
|
|
dom::Element *aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
2017-07-17 21:42:00 +03:00
|
|
|
const ServoStyleContext* aOldStyle,
|
|
|
|
const ServoStyleContext* aNewStyle)
|
2017-04-12 11:33:44 +03:00
|
|
|
{
|
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore transitions.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSTransitionCollection* collection =
|
|
|
|
CSSTransitionCollection::GetAnimationCollection(aElement, aPseudoType);
|
2018-01-05 00:24:07 +03:00
|
|
|
const nsStyleDisplay* disp =
|
2017-07-21 07:44:02 +03:00
|
|
|
aNewStyle->ComputedData()->GetStyleDisplay();
|
2018-01-05 00:24:07 +03:00
|
|
|
return DoUpdateTransitions(*disp,
|
2017-04-12 11:33:44 +03:00
|
|
|
aElement, aPseudoType,
|
|
|
|
collection,
|
|
|
|
aOldStyle, aNewStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StyleType>
|
|
|
|
bool
|
|
|
|
nsTransitionManager::DoUpdateTransitions(
|
2018-01-05 00:24:07 +03:00
|
|
|
const nsStyleDisplay& aDisp,
|
2016-04-12 02:53:00 +03:00
|
|
|
dom::Element* aElement,
|
2017-03-09 10:37:17 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2016-04-12 02:53:00 +03:00
|
|
|
CSSTransitionCollection*& aElementTransitions,
|
2017-03-09 10:37:17 +03:00
|
|
|
StyleType aOldStyle,
|
|
|
|
StyleType aNewStyle)
|
2016-04-12 02:53:00 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aElementTransitions ||
|
|
|
|
aElementTransitions->mElement == aElement, "Element mismatch");
|
|
|
|
|
2009-10-08 07:22:42 +04: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 10:19:26 +04:00
|
|
|
bool startedAny = false;
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyIDSet whichStarted;
|
2018-01-05 00:24:07 +03:00
|
|
|
for (uint32_t i = aDisp.mTransitionPropertyCount; i-- != 0; ) {
|
2015-02-19 03:49:51 +03:00
|
|
|
// Check the combined duration (combination of delay and duration)
|
|
|
|
// first, since it defaults to zero, which means we can ignore the
|
|
|
|
// transition.
|
2018-01-05 00:24:09 +03:00
|
|
|
if (aDisp.GetTransitionCombinedDuration(i) > 0.0f) {
|
2009-10-08 07:22:42 +04:00
|
|
|
// We might have something to transition. See if any of the
|
|
|
|
// properties in question changed and are animatable.
|
2009-12-11 19:13:19 +03:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one below.
|
2018-01-05 00:24:09 +03:00
|
|
|
nsCSSPropertyID property = aDisp.GetTransitionProperty(i);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
2014-04-13 05:44:31 +04:00
|
|
|
property == eCSSPropertyExtra_variable ||
|
2009-10-08 07:22:42 +04:00
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2016-08-17 04:37:48 +03:00
|
|
|
for (nsCSSPropertyID p = nsCSSPropertyID(0);
|
2009-10-08 07:22:42 +04:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
2016-08-17 04:37:48 +03:00
|
|
|
p = nsCSSPropertyID(p + 1)) {
|
2018-01-05 00:24:09 +03:00
|
|
|
ConsiderInitiatingTransition(p, aDisp, i, aElement, aPseudoType,
|
2017-03-09 10:37:17 +03:00
|
|
|
aElementTransitions,
|
|
|
|
aOldStyle, aNewStyle,
|
2016-10-19 09:16:52 +03:00
|
|
|
&startedAny, &whichStarted);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
2016-04-12 02:53:00 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property,
|
2016-05-10 11:44:05 +03:00
|
|
|
CSSEnabledState::eForAllContent)
|
2016-04-12 02:53:00 +03:00
|
|
|
{
|
2018-01-05 00:24:09 +03:00
|
|
|
ConsiderInitiatingTransition(*subprop, aDisp, i, aElement, aPseudoType,
|
2016-10-19 09:16:52 +03:00
|
|
|
aElementTransitions,
|
2017-03-09 10:37:17 +03:00
|
|
|
aOldStyle, aNewStyle,
|
2016-10-19 09:16:52 +03:00
|
|
|
&startedAny, &whichStarted);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-05 00:24:09 +03:00
|
|
|
ConsiderInitiatingTransition(property, aDisp, i, aElement, aPseudoType,
|
2017-03-09 10:37:17 +03:00
|
|
|
aElementTransitions,
|
|
|
|
aOldStyle, aNewStyle,
|
2016-10-19 09:16:52 +03:00
|
|
|
&startedAny, &whichStarted);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
// Stop any transitions for properties that are no longer in
|
2015-02-17 01:15:04 +03:00
|
|
|
// 'transition-property', including finished transitions.
|
|
|
|
// Also stop any transitions (and remove any finished transitions)
|
|
|
|
// for properties that just changed (and are still in the set of
|
|
|
|
// properties to transition), but for which we didn't just start the
|
|
|
|
// transition. This can happen delay and duration are both zero, or
|
|
|
|
// because the new value is not interpolable.
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
// Note that we also do the latter set of work in
|
|
|
|
// nsTransitionManager::PruneCompletedTransitions.
|
2016-04-12 02:53:00 +03:00
|
|
|
if (aElementTransitions) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool checkProperties =
|
2018-01-05 00:24:09 +03:00
|
|
|
aDisp.GetTransitionProperty(0) != eCSSPropertyExtra_all_properties;
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyIDSet allTransitionProperties;
|
2009-12-22 00:46:25 +03:00
|
|
|
if (checkProperties) {
|
2018-01-05 00:24:07 +03:00
|
|
|
for (uint32_t i = aDisp.mTransitionPropertyCount; i-- != 0; ) {
|
2009-12-22 00:46:25 +03:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one above.
|
2018-01-05 00:24:09 +03:00
|
|
|
nsCSSPropertyID property = aDisp.GetTransitionProperty(i);
|
2009-12-22 00:46:25 +03:00
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
2014-04-13 05:44:31 +04:00
|
|
|
property == eCSSPropertyExtra_variable ||
|
2009-12-22 00:46:25 +03:00
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2016-08-17 04:37:48 +03:00
|
|
|
for (nsCSSPropertyID p = nsCSSPropertyID(0);
|
2009-12-22 00:46:25 +03:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
2016-08-17 04:37:48 +03:00
|
|
|
p = nsCSSPropertyID(p + 1)) {
|
2009-12-22 00:46:25 +03:00
|
|
|
allTransitionProperties.AddProperty(p);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
2015-01-17 07:55:07 +03:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
|
2016-05-10 11:44:05 +03:00
|
|
|
subprop, property, CSSEnabledState::eForAllContent) {
|
2009-12-22 00:46:25 +03:00
|
|
|
allTransitionProperties.AddProperty(*subprop);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allTransitionProperties.AddProperty(property);
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 02:53:00 +03:00
|
|
|
OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
|
2015-04-21 04:22:10 +03:00
|
|
|
size_t i = animations.Length();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(i != 0, "empty transitions list?");
|
2017-04-12 11:31:12 +03:00
|
|
|
AnimationValue currentValue;
|
2009-12-11 19:13:19 +03:00
|
|
|
do {
|
|
|
|
--i;
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransition* anim = animations[i];
|
2009-12-22 00:46:25 +03:00
|
|
|
// properties no longer in 'transition-property'
|
|
|
|
if ((checkProperties &&
|
2016-04-01 03:28:35 +03:00
|
|
|
!allTransitionProperties.HasProperty(anim->TransitionProperty())) ||
|
2015-02-17 01:15:04 +03:00
|
|
|
// properties whose computed values changed but for which we
|
|
|
|
// did not start a new transition (because delay and
|
|
|
|
// duration are both zero, or because the new value is not
|
2016-04-01 03:28:35 +03:00
|
|
|
// interpolable); a new transition would have anim->ToValue()
|
2015-02-17 01:15:04 +03:00
|
|
|
// matching currentValue
|
2016-08-16 08:29:21 +03:00
|
|
|
!ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
|
2017-03-09 10:37:17 +03:00
|
|
|
aNewStyle, currentValue) ||
|
2017-04-12 11:31:12 +03:00
|
|
|
currentValue != anim->ToValue()) {
|
2009-12-22 00:46:25 +03:00
|
|
|
// stop the transition
|
2015-08-07 06:29:36 +03:00
|
|
|
if (anim->HasCurrentEffect()) {
|
2016-04-12 02:53:00 +03:00
|
|
|
EffectSet* effectSet =
|
2017-03-09 10:37:17 +03:00
|
|
|
EffectSet::GetEffectSet(aElement, aPseudoType);
|
2016-01-06 05:04:05 +03:00
|
|
|
if (effectSet) {
|
|
|
|
effectSet->UpdateAnimationGeneration(mPresContext);
|
|
|
|
}
|
2015-02-17 01:15:04 +03:00
|
|
|
}
|
2015-07-09 02:05:16 +03:00
|
|
|
anim->CancelFromStyle();
|
2015-04-21 04:22:10 +03:00
|
|
|
animations.RemoveElementAt(i);
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
if (animations.IsEmpty()) {
|
2016-04-12 02:53:00 +03:00
|
|
|
aElementTransitions->Destroy();
|
|
|
|
aElementTransitions = nullptr;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 02:53:00 +03:00
|
|
|
return startedAny;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 08:35:43 +03:00
|
|
|
static Keyframe&
|
|
|
|
AppendKeyframe(double aOffset,
|
|
|
|
nsCSSPropertyID aProperty,
|
2017-04-12 10:51:55 +03:00
|
|
|
AnimationValue&& aValue,
|
2017-03-09 08:35:43 +03:00
|
|
|
nsTArray<Keyframe>& aKeyframes)
|
|
|
|
{
|
|
|
|
Keyframe& frame = *aKeyframes.AppendElement();
|
|
|
|
frame.mOffset.emplace(aOffset);
|
2017-04-12 10:51:55 +03:00
|
|
|
|
|
|
|
if (aValue.mServo) {
|
2017-06-14 06:43:47 +03:00
|
|
|
RefPtr<RawServoDeclarationBlock> decl =
|
2017-04-12 10:51:55 +03:00
|
|
|
Servo_AnimationValue_Uncompute(aValue.mServo).Consume();
|
2017-06-14 06:43:47 +03:00
|
|
|
frame.mPropertyValues.AppendElement(
|
|
|
|
Move(PropertyValuePair(aProperty, Move(decl))));
|
2017-04-12 10:51:55 +03:00
|
|
|
} else {
|
2017-06-14 06:43:47 +03:00
|
|
|
nsCSSValue propertyValue;
|
2017-04-12 10:51:55 +03:00
|
|
|
DebugOnly<bool> uncomputeResult =
|
|
|
|
StyleAnimationValue::UncomputeValue(aProperty, Move(aValue.mGecko),
|
2017-06-14 06:43:47 +03:00
|
|
|
propertyValue);
|
2017-04-12 10:51:55 +03:00
|
|
|
MOZ_ASSERT(uncomputeResult,
|
|
|
|
"Unable to get specified value from computed value");
|
2017-06-14 06:43:47 +03:00
|
|
|
frame.mPropertyValues.AppendElement(
|
|
|
|
Move(PropertyValuePair(aProperty, Move(propertyValue))));
|
2017-04-12 10:51:55 +03:00
|
|
|
}
|
2017-03-09 08:35:43 +03:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsTArray<Keyframe>
|
|
|
|
GetTransitionKeyframes(nsCSSPropertyID aProperty,
|
2017-04-12 10:51:55 +03:00
|
|
|
AnimationValue&& aStartValue,
|
|
|
|
AnimationValue&& aEndValue,
|
2017-03-09 08:35:43 +03:00
|
|
|
const nsTimingFunction& aTimingFunction)
|
|
|
|
{
|
|
|
|
nsTArray<Keyframe> keyframes(2);
|
|
|
|
|
|
|
|
Keyframe& fromFrame = AppendKeyframe(0.0, aProperty, Move(aStartValue),
|
|
|
|
keyframes);
|
|
|
|
if (aTimingFunction.mType != nsTimingFunction::Type::Linear) {
|
|
|
|
fromFrame.mTimingFunction.emplace();
|
|
|
|
fromFrame.mTimingFunction->Init(aTimingFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendKeyframe(1.0, aProperty, Move(aEndValue), keyframes);
|
|
|
|
|
|
|
|
return keyframes;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:37:09 +03:00
|
|
|
static bool
|
2017-06-15 03:54:06 +03:00
|
|
|
IsTransitionable(nsCSSPropertyID aProperty, bool aIsServo)
|
2017-04-12 11:37:09 +03:00
|
|
|
{
|
|
|
|
if (aIsServo) {
|
2017-06-15 03:54:06 +03:00
|
|
|
return Servo_Property_IsTransitionable(aProperty);
|
2017-04-12 11:37:09 +03:00
|
|
|
}
|
|
|
|
|
2017-06-15 03:54:06 +03:00
|
|
|
// FIXME: This should also exclude discretely-animated properties.
|
2017-04-12 11:37:09 +03:00
|
|
|
return nsCSSProps::kAnimTypeTable[aProperty] != eStyleAnimType_None;
|
|
|
|
}
|
|
|
|
|
2017-03-09 10:37:17 +03:00
|
|
|
template<typename StyleType>
|
2009-10-08 07:22:42 +04:00
|
|
|
void
|
2016-10-19 09:16:52 +03:00
|
|
|
nsTransitionManager::ConsiderInitiatingTransition(
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID aProperty,
|
2018-01-05 00:24:09 +03:00
|
|
|
const nsStyleDisplay& aStyleDisplay,
|
|
|
|
uint32_t transitionIdx,
|
2014-06-27 03:57:12 +04:00
|
|
|
dom::Element* aElement,
|
2017-03-09 10:37:17 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection*& aElementTransitions,
|
2017-03-09 10:37:17 +03:00
|
|
|
StyleType aOldStyle,
|
|
|
|
StyleType aNewStyle,
|
2014-06-27 03:57:12 +04:00
|
|
|
bool* aStartedAny,
|
2016-08-17 04:46:58 +03:00
|
|
|
nsCSSPropertyIDSet* aWhichStarted)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
|
|
|
// IsShorthand itself will assert if aProperty is not a property.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
2012-12-12 01:12:43 +04:00
|
|
|
NS_ASSERTION(!aElementTransitions ||
|
|
|
|
aElementTransitions->mElement == aElement, "Element mismatch");
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2016-04-21 11:05:46 +03:00
|
|
|
// Ignore disabled properties. We can arrive here if the transition-property
|
|
|
|
// is 'all' and the disabled property has a default value which derives value
|
|
|
|
// from another property, e.g. color.
|
2016-05-10 11:44:05 +03:00
|
|
|
if (!nsCSSProps::IsEnabled(aProperty, CSSEnabledState::eForAllContent)) {
|
2016-04-21 11:05:46 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04: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;
|
|
|
|
}
|
|
|
|
|
2017-06-15 03:54:06 +03:00
|
|
|
if (!IsTransitionable(aProperty, aElement->IsStyledByServo())) {
|
2009-10-08 07:22:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-10 04:34:22 +03:00
|
|
|
dom::DocumentTimeline* timeline = aElement->OwnerDoc()->Timeline();
|
2014-04-03 09:57:27 +04:00
|
|
|
|
2017-04-12 11:26:59 +03:00
|
|
|
AnimationValue startValue, endValue;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveValues =
|
2017-03-09 10:37:17 +03:00
|
|
|
ExtractNonDiscreteComputedValue(aProperty, aOldStyle, startValue) &&
|
|
|
|
ExtractNonDiscreteComputedValue(aProperty, aNewStyle, endValue);
|
2012-07-31 21:28:22 +04:00
|
|
|
|
2017-03-09 07:33:15 +03:00
|
|
|
bool haveChange = startValue != endValue;
|
2014-05-15 03:38:37 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldAnimate =
|
2011-01-15 06:57:53 +03:00
|
|
|
haveValues &&
|
2012-12-12 01:12:43 +04:00
|
|
|
haveChange &&
|
2017-04-12 11:26:59 +03:00
|
|
|
startValue.IsInterpolableWith(aProperty, endValue);
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2013-06-05 04:35:52 +04:00
|
|
|
bool haveCurrentTransition = false;
|
2014-05-09 05:03:35 +04:00
|
|
|
size_t currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
|
2013-06-05 04:35:52 +04:00
|
|
|
const ElementPropertyTransition *oldPT = nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
if (aElementTransitions) {
|
2016-03-09 06:55:39 +03:00
|
|
|
OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
|
2015-04-21 04:22:10 +03:00
|
|
|
for (size_t i = 0, i_end = animations.Length(); i < i_end; ++i) {
|
2016-07-28 06:20:13 +03:00
|
|
|
if (animations[i]->TransitionProperty() == aProperty) {
|
2013-06-05 04:35:52 +04:00
|
|
|
haveCurrentTransition = true;
|
2009-10-08 07:22:42 +04:00
|
|
|
currentIndex = i;
|
2016-07-28 06:20:13 +03:00
|
|
|
oldPT = animations[i]->GetEffect()
|
|
|
|
? animations[i]->GetEffect()->AsTransition()
|
|
|
|
: nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 04:35:52 +04: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!
|
2015-02-17 01:15:04 +03:00
|
|
|
//
|
|
|
|
// Likewise, if we got a style change that changed the value to the
|
|
|
|
// endpoint of our finished transition, we also don't want to start
|
|
|
|
// a new transition for the reasons described in
|
|
|
|
// https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html .
|
2016-07-28 06:20:13 +03:00
|
|
|
if (haveCurrentTransition && haveValues &&
|
2017-03-09 07:33:15 +03:00
|
|
|
aElementTransitions->mAnimations[currentIndex]->ToValue() == endValue) {
|
2014-11-20 05:48:41 +03:00
|
|
|
// GetAnimationRule already called RestyleForAnimation.
|
2013-06-05 04:35:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!shouldAnimate) {
|
2015-08-07 06:29:36 +03:00
|
|
|
if (haveCurrentTransition) {
|
2013-06-12 09:43:17 +04: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.
|
2016-03-09 06:55:39 +03:00
|
|
|
OwningCSSTransitionPtrArray& animations =
|
|
|
|
aElementTransitions->mAnimations;
|
2015-04-27 02:53:19 +03:00
|
|
|
animations[currentIndex]->CancelFromStyle();
|
2014-08-10 11:06:52 +04:00
|
|
|
oldPT = nullptr; // Clear pointer so it doesn't dangle
|
2015-04-21 04:22:10 +03:00
|
|
|
animations.RemoveElementAt(currentIndex);
|
2017-03-09 10:37:17 +03:00
|
|
|
EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType);
|
2016-01-06 05:04:05 +03:00
|
|
|
if (effectSet) {
|
|
|
|
effectSet->UpdateAnimationGeneration(mPresContext);
|
|
|
|
}
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2015-04-21 04:22:10 +03:00
|
|
|
if (animations.IsEmpty()) {
|
2009-10-08 07:22:42 +04:00
|
|
|
aElementTransitions->Destroy();
|
|
|
|
// |aElementTransitions| is now a dangling pointer!
|
2012-07-30 18:20:58 +04:00
|
|
|
aElementTransitions = nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2014-11-20 05:48:41 +03:00
|
|
|
// GetAnimationRule already called RestyleForAnimation.
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-05 00:24:09 +03:00
|
|
|
const nsTimingFunction &tf =
|
|
|
|
aStyleDisplay.GetTransitionTimingFunction(transitionIdx);
|
|
|
|
float delay = aStyleDisplay.GetTransitionDelay(transitionIdx);
|
|
|
|
float duration = aStyleDisplay.GetTransitionDuration(transitionIdx);
|
2010-11-10 18:49:53 +03:00
|
|
|
if (duration < 0.0) {
|
|
|
|
// The spec says a negative duration is treated as zero.
|
|
|
|
duration = 0.0;
|
|
|
|
}
|
2014-08-10 11:06:52 +04:00
|
|
|
|
2017-04-12 10:51:55 +03:00
|
|
|
AnimationValue startForReversingTest = startValue;
|
2014-08-10 11:06:52 +04:00
|
|
|
double reversePortion = 1.0;
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2013-06-05 04:35:52 +04:00
|
|
|
// If the new transition reverses an existing one, we'll need to
|
|
|
|
// handle the timing differently.
|
2016-07-28 06:20:13 +03:00
|
|
|
// FIXME: Move mStartForReversingTest, mReversePortion to CSSTransition,
|
|
|
|
// and set the timing function on transitions as an effect-level
|
|
|
|
// easing (rather than keyframe-level easing). (Bug 1292001)
|
2013-06-05 04:35:52 +04:00
|
|
|
if (haveCurrentTransition &&
|
2015-08-07 06:29:36 +03:00
|
|
|
aElementTransitions->mAnimations[currentIndex]->HasCurrentEffect() &&
|
2016-07-28 06:20:13 +03:00
|
|
|
oldPT &&
|
2017-03-09 07:33:15 +03:00
|
|
|
oldPT->mStartForReversingTest == endValue) {
|
2013-06-05 04:35:52 +04:00
|
|
|
// Compute the appropriate negative transition-delay such that right
|
|
|
|
// now we'd end up at the current position.
|
|
|
|
double valuePortion =
|
2014-07-16 04:02:32 +04:00
|
|
|
oldPT->CurrentValuePortion() * oldPT->mReversePortion +
|
2013-06-05 04:35:52 +04: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 07:22:42 +04:00
|
|
|
}
|
2013-06-05 04:35:52 +04: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;
|
|
|
|
|
2017-03-09 07:33:15 +03:00
|
|
|
startForReversingTest = oldPT->ToValue();
|
2014-08-10 11:06:52 +04:00
|
|
|
reversePortion = valuePortion;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2017-02-20 05:02:52 +03:00
|
|
|
TimingParams timing =
|
|
|
|
TimingParamsFromCSSParams(duration, delay,
|
|
|
|
1.0 /* iteration count */,
|
|
|
|
dom::PlaybackDirection::Normal,
|
|
|
|
dom::FillMode::Backwards);
|
2014-08-10 11:06:50 +04:00
|
|
|
|
2016-04-28 18:22:44 +03:00
|
|
|
// aElement is non-null here, so we emplace it directly.
|
|
|
|
Maybe<OwningAnimationTarget> target;
|
2017-03-09 10:37:17 +03:00
|
|
|
target.emplace(aElement, aPseudoType);
|
2016-05-05 10:41:03 +03:00
|
|
|
KeyframeEffectParams effectOptions;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ElementPropertyTransition> pt =
|
2016-04-28 18:22:44 +03:00
|
|
|
new ElementPropertyTransition(aElement->OwnerDoc(), target, timing,
|
2017-03-09 07:33:15 +03:00
|
|
|
startForReversingTest, reversePortion,
|
2016-05-05 10:41:03 +03:00
|
|
|
effectOptions);
|
2014-08-10 11:06:47 +04:00
|
|
|
|
2017-04-12 10:51:55 +03:00
|
|
|
pt->SetKeyframes(GetTransitionKeyframes(aProperty,
|
2016-05-13 03:40:52 +03:00
|
|
|
Move(startValue), Move(endValue), tf),
|
2017-03-09 10:37:17 +03:00
|
|
|
aNewStyle);
|
2016-02-24 10:01:12 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CSSTransition> animation =
|
2015-04-28 11:21:58 +03:00
|
|
|
new CSSTransition(mPresContext->Document()->GetScopeObject());
|
2017-03-09 10:37:17 +03:00
|
|
|
animation->SetOwningElement(OwningElementRef(*aElement, aPseudoType));
|
2016-05-31 03:42:37 +03:00
|
|
|
animation->SetTimelineNoUpdate(timeline);
|
2015-06-09 05:13:54 +03:00
|
|
|
animation->SetCreationSequence(
|
2017-03-09 12:15:08 +03:00
|
|
|
mPresContext->RestyleManager()->GetAnimationGeneration());
|
2016-08-24 09:36:14 +03:00
|
|
|
animation->SetEffectFromStyle(pt);
|
2015-04-21 04:22:10 +03:00
|
|
|
animation->PlayFromStyle();
|
2014-04-03 09:57:27 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!aElementTransitions) {
|
2016-03-09 06:55:39 +03:00
|
|
|
bool createdCollection = false;
|
2009-10-08 07:22:42 +04:00
|
|
|
aElementTransitions =
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection::GetOrCreateAnimationCollection(
|
2017-03-09 10:37:17 +03:00
|
|
|
aElement, aPseudoType, &createdCollection);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!aElementTransitions) {
|
2016-03-09 06:55:39 +03:00
|
|
|
MOZ_ASSERT(!createdCollection, "outparam should agree with return value");
|
|
|
|
NS_WARNING("allocating collection failed");
|
2009-10-08 07:22:42 +04:00
|
|
|
return;
|
|
|
|
}
|
2016-03-09 06:55:39 +03:00
|
|
|
|
|
|
|
if (createdCollection) {
|
|
|
|
AddElementCollection(aElementTransitions);
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
|
2009-10-08 07:22:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-04-21 04:22:10 +03:00
|
|
|
for (size_t i = 0, i_end = animations.Length(); i < i_end; ++i) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(
|
2016-07-28 06:20:13 +03:00
|
|
|
i == currentIndex || animations[i]->TransitionProperty() != aProperty,
|
2015-02-10 01:34:50 +03:00
|
|
|
"duplicate transitions for property");
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-05 04:35:52 +04:00
|
|
|
if (haveCurrentTransition) {
|
2016-05-24 23:51:57 +03:00
|
|
|
// If this new transition is replacing an existing transition that is running
|
|
|
|
// on the compositor, we store select parameters from the replaced transition
|
|
|
|
// so that later, once all scripts have run, we can update the start value
|
|
|
|
// of the transition using TimeStamp::Now(). This allows us to avoid a
|
|
|
|
// large jump when starting a new transition when the main thread lags behind
|
|
|
|
// the compositor.
|
2016-07-28 06:20:13 +03:00
|
|
|
if (oldPT &&
|
|
|
|
oldPT->IsCurrent() &&
|
2016-05-24 23:51:57 +03:00
|
|
|
oldPT->IsRunningOnCompositor() &&
|
|
|
|
!oldPT->GetAnimation()->GetStartTime().IsNull() &&
|
|
|
|
timeline == oldPT->GetAnimation()->GetTimeline()) {
|
|
|
|
const AnimationPropertySegment& segment =
|
|
|
|
oldPT->Properties()[0].mSegments[0];
|
|
|
|
pt->mReplacedTransition.emplace(
|
|
|
|
ElementPropertyTransition::ReplacedTransitionProperties({
|
|
|
|
oldPT->GetAnimation()->GetStartTime().Value(),
|
|
|
|
oldPT->GetAnimation()->PlaybackRate(),
|
|
|
|
oldPT->SpecifiedTiming(),
|
|
|
|
segment.mTimingFunction,
|
2017-03-09 07:33:15 +03:00
|
|
|
segment.mFromValue,
|
|
|
|
segment.mToValue
|
2016-05-24 23:51:57 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2015-04-27 02:53:19 +03:00
|
|
|
animations[currentIndex]->CancelFromStyle();
|
2015-02-19 03:52:36 +03:00
|
|
|
oldPT = nullptr; // Clear pointer so it doesn't dangle
|
2015-04-21 04:22:10 +03:00
|
|
|
animations[currentIndex] = animation;
|
2009-10-08 07:22:42 +04:00
|
|
|
} else {
|
2015-04-21 04:22:10 +03:00
|
|
|
if (!animations.AppendElement(animation)) {
|
2009-10-08 07:22:42 +04:00
|
|
|
NS_WARNING("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2017-03-09 10:37:17 +03:00
|
|
|
EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType);
|
2016-01-06 05:04:05 +03:00
|
|
|
if (effectSet) {
|
|
|
|
effectSet->UpdateAnimationGeneration(mPresContext);
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aStartedAny = true;
|
2009-10-08 07:22:42 +04:00
|
|
|
aWhichStarted->AddProperty(aProperty);
|
|
|
|
}
|
|
|
|
|
2018-02-01 07:04:04 +03:00
|
|
|
#ifdef MOZ_OLD_STYLE
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
void
|
|
|
|
nsTransitionManager::PruneCompletedTransitions(mozilla::dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType,
|
2017-07-21 04:22:00 +03:00
|
|
|
GeckoStyleContext* aNewStyleContext)
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
{
|
2017-04-21 17:53:21 +03:00
|
|
|
MOZ_ASSERT(!aElement->IsGeneratedContentContainerForBefore() &&
|
|
|
|
!aElement->IsGeneratedContentContainerForAfter());
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection* collection =
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransitionCollection::GetAnimationCollection(aElement, aPseudoType);
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
if (!collection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any finished transitions whose style doesn't match the new
|
|
|
|
// style.
|
|
|
|
// This is similar to some of the work that happens near the end of
|
|
|
|
// nsTransitionManager::StyleContextChanged.
|
|
|
|
// FIXME (bug 1158431): Really, we should also cancel running
|
|
|
|
// transitions whose destination doesn't match as well.
|
2016-03-09 06:55:39 +03:00
|
|
|
OwningCSSTransitionPtrArray& animations = collection->mAnimations;
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
size_t i = animations.Length();
|
|
|
|
MOZ_ASSERT(i != 0, "empty transitions list?");
|
|
|
|
do {
|
|
|
|
--i;
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSTransition* anim = animations[i];
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
|
2015-08-07 06:29:36 +03:00
|
|
|
if (anim->HasCurrentEffect()) {
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since effect is a finished transition, we know it didn't
|
|
|
|
// influence style.
|
2017-03-09 07:33:15 +03:00
|
|
|
AnimationValue currentValue;
|
2016-08-16 08:29:21 +03:00
|
|
|
if (!ExtractNonDiscreteComputedValue(anim->TransitionProperty(),
|
2017-04-12 11:31:12 +03:00
|
|
|
aNewStyleContext, currentValue) ||
|
2016-04-01 03:28:35 +03:00
|
|
|
currentValue != anim->ToValue()) {
|
2015-07-09 02:05:16 +03:00
|
|
|
anim->CancelFromStyle();
|
Bug 1144410 - Remove finished transitions when a frame transitions away from being display:none. r=birtles
Since bug 960465 patch 14, we've retained finished transitions in order
to handle the issues described in
https://lists.w3.org/Archives/Public/www-style/2015Jan/0444.html . The
code that did this made the assumption that the transition manager is
notified of the full sequence of style changes that happen to an
element. However, when an element becomes part of a display:none
subtree and then later becomes displayed again, the transition manager
is not notified of a style change when it becomes displayed again (when
we do not have the old style context).
This patch introduces code to prune the finished transitions when that
happens.
This really fixes only part of the set of problems described in bug
1158431, which also affect running transitions. However, it's the part
of that set that was a regression from bug 960465, which introduced the
retention of finished transitions, and which makes these issues
substantially easier to hit.
I'd like to fix this part quickly because it's a regression and we
should backport the fix.
Without the patch, I confirmed that the following two tests fail:
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity after starting second transition - got 0, expected 1
INFO TEST-UNEXPECTED-FAIL | layout/style/test/test_transitions_dynamic_changes.html | bug 1144410 test - opacity during second transition - got 0, expected 0.5
With the patch, all the added tests pass.
--HG--
extra : transplant_source : %B4%A5%5Ck%E1%B7%F5Et%CF%9B%9F%40%97c%C5NM%D3%A8
2015-04-27 05:20:19 +03:00
|
|
|
animations.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
|
|
|
if (collection->mAnimations.IsEmpty()) {
|
|
|
|
collection->Destroy();
|
|
|
|
// |collection| is now a dangling pointer!
|
|
|
|
collection = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
#endif
|