gecko-dev/layout/style/nsTransitionManager.cpp

803 строки
31 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Code to start and animate CSS transitions. */
#include "nsTransitionManager.h"
#include "nsAnimationManager.h"
#include "mozilla/dom/CSSTransitionBinding.h"
#include "nsIContent.h"
#include "nsStyleContext.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/TimeStamp.h"
#include "nsRefreshDriver.h"
#include "nsRuleProcessorData.h"
#include "nsRuleWalker.h"
#include "nsCSSPropertySet.h"
#include "mozilla/EffectCompositor.h"
#include "mozilla/EffectSet.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/DocumentTimeline.h"
#include "mozilla/dom/Element.h"
#include "nsIFrame.h"
#include "Layers.h"
#include "FrameLayerBuilder.h"
#include "nsCSSProps.h"
#include "nsCSSPseudoElements.h"
#include "nsDisplayList.h"
#include "nsStyleChangeList.h"
#include "nsStyleSet.h"
#include "mozilla/RestyleManagerHandle.h"
#include "mozilla/RestyleManagerHandleInlines.h"
#include "nsDOMMutationObserver.h"
using mozilla::TimeStamp;
using mozilla::TimeDuration;
using mozilla::dom::Animation;
using mozilla::dom::KeyframeEffectReadOnly;
using namespace mozilla;
using namespace mozilla::css;
double
ElementPropertyTransition::CurrentValuePortion() const
{
MOZ_ASSERT(!GetLocalTime().IsNull(),
"Getting the value portion of an animation that's not being "
"sampled");
// Transitions use a fill mode of 'backwards' so GetComputedTiming will
// never return a null time progress 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 progress
// is never null.
TimingParams timingToUse = SpecifiedTiming();
timingToUse.mFill = dom::FillMode::Both;
ComputedTiming computedTiming = GetComputedTiming(&timingToUse);
MOZ_ASSERT(!computedTiming.mProgress.IsNull(),
"Got a null progress for a fill mode of 'both'");
MOZ_ASSERT(mProperties.Length() == 1,
"Should have one animation property for a transition");
MOZ_ASSERT(mProperties[0].mSegments.Length() == 1,
"Animation property should have one segment for a transition");
return ComputedTimingFunction::GetPortion(
mProperties[0].mSegments[0].mTimingFunction,
computedTiming.mProgress.Value());
}
////////////////////////// CSSTransition ////////////////////////////
JSObject*
CSSTransition::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return dom::CSSTransitionBinding::Wrap(aCx, this, aGivenProto);
}
void
CSSTransition::GetTransitionProperty(nsString& aRetVal) const
{
// Once we make the effect property settable (bug 1049975) we will need
// to store the transition property on the CSSTransition itself but for
// now we can just query the effect.
MOZ_ASSERT(mEffect && mEffect->AsTransition(),
"Transitions should have a transition effect");
nsCSSProperty prop = mEffect->AsTransition()->TransitionProperty();
aRetVal = NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(prop));
}
AnimationPlayState
CSSTransition::PlayStateFromJS() const
{
FlushStyle();
return Animation::PlayStateFromJS();
}
void
CSSTransition::PlayFromJS(ErrorResult& aRv)
{
FlushStyle();
Animation::PlayFromJS(aRv);
}
void
CSSTransition::UpdateTiming(SeekFlag aSeekFlag, SyncNotifyFlag aSyncNotifyFlag)
{
if (mNeedsNewAnimationIndexWhenRun &&
PlayState() != AnimationPlayState::Idle) {
mAnimationIndex = sNextAnimationIndex++;
mNeedsNewAnimationIndexWhenRun = false;
}
Animation::UpdateTiming(aSeekFlag, aSyncNotifyFlag);
}
Bug 1180125 part 7 - Queue transition events from CSSTransition::Tick; r=dbaron This patch moves the logic for queueing events out of the logic for flushing transitions making it a separate step. It still doesn't delay the dispatch of those events into a separate step, however. That is done in a subsequent patch. This patch also makes sure to clear any queued events when the nsPresShell that owns the transition manager is destroyed. We don't expect CSSTransition::Tick to be called anywhere except nsTransitionManger::FlushTransitions so there shouldn't be any orphaned events but for completeness it seems best to add this now. (Later, when we tick transitions from their timeline we will need this.) This patch introduces a separate flag to CSSTransition for tracking if a transition is newly-finished so we can correctly dispatch the transitionend event. Although, this may seem to be redundant with the "IsFinishedTransition" we also track, that state will soon be removed in bug 1181392 and hence this flag will be needed then. Note that Animation already has flags mIsPreviousStateFinished and mFinishedAtLastComposeStyle which would appear to be similar however, - mIsPreviousStateFinished will be removed in bug 1178665 and is updated more often than we queue events so it is not useful here. - mFinishedAtLastComposeStyle is used to determine if we can throttle a style update and is also updated more frequently than we queue events and hence can't be used here. Once we guarantee one call to Tick() per frame we may be able to simplify this by tracking "state on last tick" but for now we need this additional flag on CSSTransition. CSSAnimation has a similar flag for this (mPreviousPhaseOrIteration) which we may be able to unify at the same point.
2015-07-29 04:57:40 +03:00
void
CSSTransition::QueueEvents()
{
AnimationPlayState playState = PlayState();
bool newlyFinished = !mWasFinishedOnLastTick &&
playState == AnimationPlayState::Finished;
mWasFinishedOnLastTick = playState == AnimationPlayState::Finished;
if (!newlyFinished || !mEffect || !mOwningElement.IsSet()) {
return;
}
dom::Element* owningElement;
CSSPseudoElementType owningPseudoType;
Bug 1180125 part 7 - Queue transition events from CSSTransition::Tick; r=dbaron This patch moves the logic for queueing events out of the logic for flushing transitions making it a separate step. It still doesn't delay the dispatch of those events into a separate step, however. That is done in a subsequent patch. This patch also makes sure to clear any queued events when the nsPresShell that owns the transition manager is destroyed. We don't expect CSSTransition::Tick to be called anywhere except nsTransitionManger::FlushTransitions so there shouldn't be any orphaned events but for completeness it seems best to add this now. (Later, when we tick transitions from their timeline we will need this.) This patch introduces a separate flag to CSSTransition for tracking if a transition is newly-finished so we can correctly dispatch the transitionend event. Although, this may seem to be redundant with the "IsFinishedTransition" we also track, that state will soon be removed in bug 1181392 and hence this flag will be needed then. Note that Animation already has flags mIsPreviousStateFinished and mFinishedAtLastComposeStyle which would appear to be similar however, - mIsPreviousStateFinished will be removed in bug 1178665 and is updated more often than we queue events so it is not useful here. - mFinishedAtLastComposeStyle is used to determine if we can throttle a style update and is also updated more frequently than we queue events and hence can't be used here. Once we guarantee one call to Tick() per frame we may be able to simplify this by tracking "state on last tick" but for now we need this additional flag on CSSTransition. CSSAnimation has a similar flag for this (mPreviousPhaseOrIteration) which we may be able to unify at the same point.
2015-07-29 04:57:40 +03:00
mOwningElement.GetElement(owningElement, owningPseudoType);
MOZ_ASSERT(owningElement, "Owning element should be set");
// Do not queue any event for disabled properties. This could happen
// if the property has a default value which derives value from other
// property, e.g. color.
nsCSSProperty property = TransitionProperty();
if (!nsCSSProps::IsEnabled(property, nsCSSProps::eEnabledForAllContent) &&
(!nsContentUtils::IsSystemPrincipal(owningElement->NodePrincipal()) ||
!nsCSSProps::IsEnabled(property, nsCSSProps::eEnabledInChrome))) {
return;
}
Bug 1180125 part 7 - Queue transition events from CSSTransition::Tick; r=dbaron This patch moves the logic for queueing events out of the logic for flushing transitions making it a separate step. It still doesn't delay the dispatch of those events into a separate step, however. That is done in a subsequent patch. This patch also makes sure to clear any queued events when the nsPresShell that owns the transition manager is destroyed. We don't expect CSSTransition::Tick to be called anywhere except nsTransitionManger::FlushTransitions so there shouldn't be any orphaned events but for completeness it seems best to add this now. (Later, when we tick transitions from their timeline we will need this.) This patch introduces a separate flag to CSSTransition for tracking if a transition is newly-finished so we can correctly dispatch the transitionend event. Although, this may seem to be redundant with the "IsFinishedTransition" we also track, that state will soon be removed in bug 1181392 and hence this flag will be needed then. Note that Animation already has flags mIsPreviousStateFinished and mFinishedAtLastComposeStyle which would appear to be similar however, - mIsPreviousStateFinished will be removed in bug 1178665 and is updated more often than we queue events so it is not useful here. - mFinishedAtLastComposeStyle is used to determine if we can throttle a style update and is also updated more frequently than we queue events and hence can't be used here. Once we guarantee one call to Tick() per frame we may be able to simplify this by tracking "state on last tick" but for now we need this additional flag on CSSTransition. CSSAnimation has a similar flag for this (mPreviousPhaseOrIteration) which we may be able to unify at the same point.
2015-07-29 04:57:40 +03:00
nsPresContext* presContext = mOwningElement.GetRenderedPresContext();
if (!presContext) {
return;
}
nsTransitionManager* manager = presContext->TransitionManager();
manager->QueueEvent(TransitionEventInfo(owningElement, owningPseudoType,
property,
mEffect->GetComputedTiming()
.mDuration,
AnimationTimeToTimeStamp(EffectEnd()),
this));
Bug 1180125 part 7 - Queue transition events from CSSTransition::Tick; r=dbaron This patch moves the logic for queueing events out of the logic for flushing transitions making it a separate step. It still doesn't delay the dispatch of those events into a separate step, however. That is done in a subsequent patch. This patch also makes sure to clear any queued events when the nsPresShell that owns the transition manager is destroyed. We don't expect CSSTransition::Tick to be called anywhere except nsTransitionManger::FlushTransitions so there shouldn't be any orphaned events but for completeness it seems best to add this now. (Later, when we tick transitions from their timeline we will need this.) This patch introduces a separate flag to CSSTransition for tracking if a transition is newly-finished so we can correctly dispatch the transitionend event. Although, this may seem to be redundant with the "IsFinishedTransition" we also track, that state will soon be removed in bug 1181392 and hence this flag will be needed then. Note that Animation already has flags mIsPreviousStateFinished and mFinishedAtLastComposeStyle which would appear to be similar however, - mIsPreviousStateFinished will be removed in bug 1178665 and is updated more often than we queue events so it is not useful here. - mFinishedAtLastComposeStyle is used to determine if we can throttle a style update and is also updated more frequently than we queue events and hence can't be used here. Once we guarantee one call to Tick() per frame we may be able to simplify this by tracking "state on last tick" but for now we need this additional flag on CSSTransition. CSSAnimation has a similar flag for this (mPreviousPhaseOrIteration) which we may be able to unify at the same point.
2015-07-29 04:57:40 +03:00
}
void
CSSTransition::Tick()
{
Animation::Tick();
QueueEvents();
}
nsCSSProperty
CSSTransition::TransitionProperty() const
{
// FIXME: Once we support replacing/removing the effect (bug 1049975)
// we'll need to store the original transition property so we keep
// returning the same value in that case.
dom::KeyframeEffectReadOnly* effect = GetEffect();
MOZ_ASSERT(effect && effect->AsTransition(),
"Transition should have a transition effect");
return effect->AsTransition()->TransitionProperty();
}
bool
CSSTransition::HasLowerCompositeOrderThan(const CSSTransition& aOther) const
{
MOZ_ASSERT(IsTiedToMarkup() && aOther.IsTiedToMarkup(),
"Should only be called for CSS transitions that are sorted "
"as CSS transitions (i.e. tied to CSS markup)");
// 0. Object-equality case
if (&aOther == this) {
return false;
}
// 1. Sort by document order
if (!mOwningElement.Equals(aOther.mOwningElement)) {
return mOwningElement.LessThan(aOther.mOwningElement);
}
// 2. (Same element and pseudo): Sort by transition generation
if (mAnimationIndex != aOther.mAnimationIndex) {
return mAnimationIndex < aOther.mAnimationIndex;
}
// 3. (Same transition generation): Sort by transition property
return nsCSSProps::GetStringValue(TransitionProperty()) <
nsCSSProps::GetStringValue(aOther.TransitionProperty());
}
////////////////////////// nsTransitionManager ////////////////////////////
NS_IMPL_CYCLE_COLLECTION(nsTransitionManager, mEventDispatcher)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTransitionManager, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTransitionManager, Release)
void
nsTransitionManager::StyleContextChanged(dom::Element *aElement,
nsStyleContext *aOldStyleContext,
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<nsStyleContext>* aNewStyleContext /* inout */)
{
nsStyleContext* newStyleContext = *aNewStyleContext;
NS_PRECONDITION(aOldStyleContext->GetPseudo() == newStyleContext->GetPseudo(),
"pseudo type mismatch");
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;
}
if (!mPresContext->IsDynamic()) {
// For print or print preview, ignore transitions.
return;
}
if (aOldStyleContext->HasPseudoElementData() !=
newStyleContext->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;
}
// NOTE: Things in this function (and ConsiderStartingTransition)
// should never call PeekStyleData because we don't preserve gotten
// structs across reframes.
// Return sooner (before the startedAny check below) for the most
// common case: no transitions specified or running.
const nsStyleDisplay *disp = newStyleContext->StyleDisplay();
CSSPseudoElementType pseudoType = newStyleContext->GetPseudoType();
if (pseudoType != CSSPseudoElementType::NotPseudo) {
if (pseudoType != CSSPseudoElementType::before &&
pseudoType != CSSPseudoElementType::after) {
return;
}
NS_ASSERTION((pseudoType == CSSPseudoElementType::before &&
aElement->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore) ||
(pseudoType == CSSPseudoElementType::after &&
aElement->NodeInfo()->NameAtom() == 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();
}
CSSTransitionCollection* collection =
CSSTransitionCollection::GetAnimationCollection(aElement, pseudoType);
if (!collection &&
disp->mTransitionPropertyCount == 1 &&
disp->mTransitions[0].GetCombinedDuration() <= 0.0f) {
return;
}
MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
"ServoRestyleManager should not use nsTransitionManager "
"for transitions");
if (collection &&
collection->mCheckGeneration ==
mPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration()) {
// 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;
}
if (newStyleContext->GetParent() &&
newStyleContext->GetParent()->HasPseudoElementData()) {
// Ignore transitions on things that inherit properties from
// pseudo-elements.
// FIXME (Bug 522599): Add tests for this.
return;
}
NS_WARN_IF_FALSE(!nsLayoutUtils::AreAsyncAnimationsEnabled() ||
2016-01-13 01:54:55 +03:00
!mPresContext->EffectCompositor()->
HasThrottledStyleUpdates(),
"throttled animations not up to date");
// 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.
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<nsStyleContext> afterChangeStyle;
if (collection) {
MOZ_ASSERT(mPresContext->StyleSet()->IsGecko(),
"ServoStyleSets should not use nsTransitionManager "
"for transitions");
nsStyleSet* styleSet = mPresContext->StyleSet()->AsGecko();
afterChangeStyle =
styleSet->ResolveStyleWithoutAnimation(aElement, newStyleContext,
eRestyle_CSSTransitions);
} else {
afterChangeStyle = newStyleContext;
}
nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
// 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|).
bool startedAny = false;
nsCSSPropertySet whichStarted;
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
const StyleTransition& t = disp->mTransitions[i];
// Check the combined duration (combination of delay and duration)
// first, since it defaults to zero, which means we can ignore the
// transition.
if (t.GetCombinedDuration() > 0.0f) {
// We might have something to transition. See if any of the
// properties in question changed and are animatable.
// FIXME: Would be good to find a way to share code between this
// interpretation of transition-property and the one below.
nsCSSProperty property = t.GetProperty();
if (property == eCSSPropertyExtra_no_properties ||
property == eCSSPropertyExtra_variable ||
property == eCSSProperty_UNKNOWN) {
// Nothing to do, but need to exclude this from cases below.
} else if (property == eCSSPropertyExtra_all_properties) {
for (nsCSSProperty p = nsCSSProperty(0);
p < eCSSProperty_COUNT_no_shorthands;
p = nsCSSProperty(p + 1)) {
ConsiderStartingTransition(p, t, aElement, collection,
aOldStyleContext, afterChangeStyle,
&startedAny, &whichStarted);
}
} else if (nsCSSProps::IsShorthand(property)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
subprop, property, nsCSSProps::eEnabledForAllContent) {
ConsiderStartingTransition(*subprop, t, aElement, collection,
aOldStyleContext, afterChangeStyle,
&startedAny, &whichStarted);
}
} else {
ConsiderStartingTransition(property, t, aElement, collection,
aOldStyleContext, afterChangeStyle,
&startedAny, &whichStarted);
}
}
}
// Stop any transitions for properties that are no longer in
// '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.
if (collection) {
bool checkProperties =
disp->mTransitions[0].GetProperty() != eCSSPropertyExtra_all_properties;
nsCSSPropertySet allTransitionProperties;
if (checkProperties) {
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
const StyleTransition& t = disp->mTransitions[i];
// 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 ||
property == eCSSPropertyExtra_variable ||
property == eCSSProperty_UNKNOWN) {
// Nothing to do, but need to exclude this from cases below.
} else if (property == eCSSPropertyExtra_all_properties) {
for (nsCSSProperty p = nsCSSProperty(0);
p < eCSSProperty_COUNT_no_shorthands;
p = nsCSSProperty(p + 1)) {
allTransitionProperties.AddProperty(p);
}
} else if (nsCSSProps::IsShorthand(property)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
subprop, property, nsCSSProps::eEnabledForAllContent) {
allTransitionProperties.AddProperty(*subprop);
}
} else {
allTransitionProperties.AddProperty(property);
}
}
}
OwningCSSTransitionPtrArray& animations = collection->mAnimations;
size_t i = animations.Length();
MOZ_ASSERT(i != 0, "empty transitions list?");
StyleAnimationValue currentValue;
do {
--i;
CSSTransition* anim = animations[i];
dom::KeyframeEffectReadOnly* effect = anim->GetEffect();
MOZ_ASSERT(effect && effect->Properties().Length() == 1,
"Should have one animation property for a transition");
MOZ_ASSERT(effect && effect->Properties()[0].mSegments.Length() == 1,
"Animation property should have one segment for a transition");
const AnimationProperty& prop = effect->Properties()[0];
const AnimationPropertySegment& segment = prop.mSegments[0];
// properties no longer in 'transition-property'
if ((checkProperties &&
!allTransitionProperties.HasProperty(prop.mProperty)) ||
// 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
// interpolable); a new transition would have segment.mToValue
// matching currentValue
!ExtractComputedValueForTransition(prop.mProperty, afterChangeStyle,
currentValue) ||
currentValue != segment.mToValue) {
// stop the transition
if (anim->HasCurrentEffect()) {
EffectSet* effectSet = EffectSet::GetEffectSet(aElement, pseudoType);
if (effectSet) {
effectSet->UpdateAnimationGeneration(mPresContext);
}
}
anim->CancelFromStyle();
animations.RemoveElementAt(i);
}
} while (i != 0);
if (animations.IsEmpty()) {
collection->Destroy();
collection = nullptr;
}
}
MOZ_ASSERT(!startedAny || collection,
"must have element transitions if we started any transitions");
EffectCompositor::CascadeLevel cascadeLevel =
EffectCompositor::CascadeLevel::Transitions;
if (collection) {
EffectCompositor::UpdateCascadeResults(aElement, pseudoType,
newStyleContext);
collection->UpdateCheckGeneration(mPresContext);
mPresContext->EffectCompositor()->MaybeUpdateAnimationRule(aElement,
pseudoType,
cascadeLevel);
}
// 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);
}
}
void
nsTransitionManager::ConsiderStartingTransition(
nsCSSProperty aProperty,
const StyleTransition& aTransition,
dom::Element* aElement,
CSSTransitionCollection*& aElementTransitions,
nsStyleContext* aOldStyleContext,
nsStyleContext* aNewStyleContext,
bool* aStartedAny,
nsCSSPropertySet* aWhichStarted)
{
// IsShorthand itself will assert if aProperty is not a property.
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
"property out of range");
NS_ASSERTION(!aElementTransitions ||
aElementTransitions->mElement == aElement, "Element mismatch");
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;
}
dom::DocumentTimeline* timeline = aElement->OwnerDoc()->Timeline();
StyleAnimationValue startValue, endValue, dummyValue;
bool haveValues =
ExtractComputedValueForTransition(aProperty, aOldStyleContext,
startValue) &&
ExtractComputedValueForTransition(aProperty, aNewStyleContext,
endValue);
bool haveChange = startValue != endValue;
bool shouldAnimate =
haveValues &&
haveChange &&
// 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.)
StyleAnimationValue::Interpolate(aProperty, startValue, endValue,
0.5, dummyValue);
bool haveCurrentTransition = false;
size_t currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
const ElementPropertyTransition *oldPT = nullptr;
if (aElementTransitions) {
OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
for (size_t i = 0, i_end = animations.Length(); i < i_end; ++i) {
const ElementPropertyTransition *iPt =
animations[i]->GetEffect()->AsTransition();
if (iPt->TransitionProperty() == aProperty) {
haveCurrentTransition = true;
currentIndex = i;
oldPT = iPt;
break;
}
}
}
// 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!
//
// 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 .
if (haveCurrentTransition && haveValues && oldPT->ToValue() == endValue) {
// GetAnimationRule already called RestyleForAnimation.
return;
}
if (!shouldAnimate) {
if (haveCurrentTransition) {
// 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.
OwningCSSTransitionPtrArray& animations =
aElementTransitions->mAnimations;
animations[currentIndex]->CancelFromStyle();
oldPT = nullptr; // Clear pointer so it doesn't dangle
animations.RemoveElementAt(currentIndex);
EffectSet* effectSet =
EffectSet::GetEffectSet(aElement, aNewStyleContext->GetPseudoType());
if (effectSet) {
effectSet->UpdateAnimationGeneration(mPresContext);
}
if (animations.IsEmpty()) {
aElementTransitions->Destroy();
// |aElementTransitions| is now a dangling pointer!
aElementTransitions = nullptr;
}
// GetAnimationRule already called RestyleForAnimation.
}
return;
}
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;
}
StyleAnimationValue startForReversingTest = startValue;
double reversePortion = 1.0;
// If the new transition reverses an existing one, we'll need to
// handle the timing differently.
if (haveCurrentTransition &&
aElementTransitions->mAnimations[currentIndex]->HasCurrentEffect() &&
oldPT->mStartForReversingTest == endValue) {
// Compute the appropriate negative transition-delay such that right
// now we'd end up at the current position.
double valuePortion =
oldPT->CurrentValuePortion() * oldPT->mReversePortion +
(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;
}
// 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;
startForReversingTest = oldPT->ToValue();
reversePortion = valuePortion;
}
TimingParams timing;
timing.mDuration.emplace(StickyTimeDuration::FromMilliseconds(duration));
timing.mDelay = TimeDuration::FromMilliseconds(delay);
timing.mIterations = 1.0;
timing.mDirection = dom::PlaybackDirection::Normal;
timing.mFill = dom::FillMode::Backwards;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<ElementPropertyTransition> pt =
new ElementPropertyTransition(aElement->OwnerDoc(), aElement,
aNewStyleContext->GetPseudoType(), timing,
startForReversingTest, reversePortion);
AnimationProperty& prop = *pt->Properties().AppendElement();
prop.mProperty = aProperty;
AnimationPropertySegment& segment = *prop.mSegments.AppendElement();
segment.mFromValue = startValue;
segment.mToValue = endValue;
segment.mFromKey = 0;
segment.mToKey = 1;
if (tf.mType != nsTimingFunction::Type::Linear) {
ComputedTimingFunction computedTimingFunction;
computedTimingFunction.Init(tf);
segment.mTimingFunction = Some(computedTimingFunction);
}
MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
"ServoRestyleManager should not use nsTransitionManager "
"for transitions");
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CSSTransition> animation =
new CSSTransition(mPresContext->Document()->GetScopeObject());
animation->SetOwningElement(
OwningElementRef(*aElement, aNewStyleContext->GetPseudoType()));
animation->SetTimeline(timeline);
animation->SetCreationSequence(
mPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration());
// The order of the following two calls is important since PlayFromStyle
// will add the animation to the PendingAnimationTracker of its effect's
// document. When we come to make effect writeable (bug 1049975) we should
// remove this dependency.
animation->SetEffect(pt);
animation->PlayFromStyle();
if (!aElementTransitions) {
bool createdCollection = false;
aElementTransitions =
CSSTransitionCollection::GetOrCreateAnimationCollection(
aElement, aNewStyleContext->GetPseudoType(), &createdCollection);
if (!aElementTransitions) {
MOZ_ASSERT(!createdCollection, "outparam should agree with return value");
NS_WARNING("allocating collection failed");
return;
}
if (createdCollection) {
AddElementCollection(aElementTransitions);
}
}
OwningCSSTransitionPtrArray& animations = aElementTransitions->mAnimations;
#ifdef DEBUG
for (size_t i = 0, i_end = animations.Length(); i < i_end; ++i) {
MOZ_ASSERT(
i == currentIndex ||
(animations[i]->GetEffect() &&
animations[i]->GetEffect()->AsTransition()->TransitionProperty()
!= aProperty),
"duplicate transitions for property");
}
#endif
if (haveCurrentTransition) {
animations[currentIndex]->CancelFromStyle();
oldPT = nullptr; // Clear pointer so it doesn't dangle
animations[currentIndex] = animation;
} else {
if (!animations.AppendElement(animation)) {
NS_WARNING("out of memory");
return;
}
}
EffectSet* effectSet =
EffectSet::GetEffectSet(aElement, aNewStyleContext->GetPseudoType());
if (effectSet) {
effectSet->UpdateAnimationGeneration(mPresContext);
}
*aStartedAny = true;
aWhichStarted->AddProperty(aProperty);
}
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,
CSSPseudoElementType 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
nsStyleContext* aNewStyleContext)
{
CSSTransitionCollection* collection =
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.
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;
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
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;
}
dom::KeyframeEffectReadOnly* effect = anim->GetEffect();
MOZ_ASSERT(effect->Properties().Length() == 1,
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
"Should have one animation property for a transition");
MOZ_ASSERT(effect->Properties()[0].mSegments.Length() == 1,
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
"Animation property should have one segment for a transition");
const AnimationProperty& prop = effect->Properties()[0];
const AnimationPropertySegment& segment = prop.mSegments[0];
// Since effect is a finished transition, we know it didn't
// influence style.
StyleAnimationValue currentValue;
if (!ExtractComputedValueForTransition(prop.mProperty, aNewStyleContext,
currentValue) ||
currentValue != segment.mToValue) {
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;
}
}