Make setting property after setting transition-duration and transition-delay to 0 stop running transitions on that property: part 3: main patch. (Bug 522643) r=bzbarsky

This commit is contained in:
L. David Baron 2009-12-21 16:46:25 -05:00
parent a031d34d0e
commit ba8d7cd017
2 changed files with 58 additions and 32 deletions

View File

@ -381,15 +381,15 @@ nsTransitionManager::StyleContextChanged(nsIContent *aElement,
// structs across reframes.
// Return sooner (before the startedAny check below) for the most
// common case: no transitions specified.
// common case: no transitions specified or running.
const nsStyleDisplay *disp = aNewStyleContext->GetStyleDisplay();
const nsStyleDisplay *oldDisp = aOldStyleContext->GetStyleDisplay();
if (disp->mTransitionPropertyCount == 1 &&
oldDisp->mTransitionPropertyCount == 1 &&
nsCSSPseudoElements::Type pseudoType = aNewStyleContext->GetPseudoType();
ElementTransitions *et =
GetElementTransitions(aElement, pseudoType, PR_FALSE);
if (!et &&
disp->mTransitionPropertyCount == 1 &&
disp->mTransitions[0].GetDelay() == 0.0f &&
disp->mTransitions[0].GetDuration() == 0.0f &&
oldDisp->mTransitions[0].GetProperty() ==
disp->mTransitions[0].GetProperty()) {
disp->mTransitions[0].GetDuration() == 0.0f) {
return nsnull;
}
@ -398,7 +398,6 @@ nsTransitionManager::StyleContextChanged(nsIContent *aElement,
return nsnull;
}
nsCSSPseudoElements::Type pseudoType = aNewStyleContext->GetPseudoType();
if (pseudoType != nsCSSPseudoElements::ePseudo_NotPseudoElement &&
pseudoType != nsCSSPseudoElements::ePseudo_before &&
pseudoType != nsCSSPseudoElements::ePseudo_after) {
@ -418,8 +417,6 @@ nsTransitionManager::StyleContextChanged(nsIContent *aElement,
// ones (tracked using |whichStarted|).
PRBool startedAny = PR_FALSE;
nsCSSPropertySet whichStarted;
ElementTransitions *et =
GetElementTransitions(aElement, pseudoType, PR_FALSE);
for (PRUint32 i = disp->mTransitionPropertyCount; i-- != 0; ) {
const nsTransition& t = disp->mTransitions[i];
// Check delay and duration first, since they default to zero, and
@ -457,39 +454,54 @@ nsTransitionManager::StyleContextChanged(nsIContent *aElement,
// Stop any transitions for properties that are no longer in
// 'transition-property'.
if (et && disp->mTransitions[0].GetProperty() !=
eCSSPropertyExtra_all_properties) {
// Also stop any transitions for properties that just changed (and are
// still in the set of properties to transition), but we didn't just
// start the transition because delay and duration are both zero.
if (et) {
PRBool checkProperties =
disp->mTransitions[0].GetProperty() != eCSSPropertyExtra_all_properties;
nsCSSPropertySet allTransitionProperties;
for (PRUint32 i = disp->mTransitionPropertyCount; i-- != 0; ) {
const nsTransition& 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 == 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);
if (checkProperties) {
for (PRUint32 i = disp->mTransitionPropertyCount; i-- != 0; ) {
const nsTransition& 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 == 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) {
allTransitionProperties.AddProperty(*subprop);
}
} else {
allTransitionProperties.AddProperty(property);
}
} else if (nsCSSProps::IsShorthand(property)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
allTransitionProperties.AddProperty(*subprop);
}
} else {
allTransitionProperties.AddProperty(property);
}
}
nsTArray<ElementPropertyTransition> &pts = et->mPropertyTransitions;
PRUint32 i = pts.Length();
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
nsStyleAnimation::Value currentValue;
do {
--i;
ElementPropertyTransition &pt = pts[i];
if (!allTransitionProperties.HasProperty(pt.mProperty)) {
// properties no longer in 'transition-property'
if ((checkProperties &&
!allTransitionProperties.HasProperty(pt.mProperty)) ||
// properties whose computed values changed but delay and
// duration are both zero
!TransExtractComputedValue(pt.mProperty, aNewStyleContext,
currentValue) ||
currentValue != pt.mEndValue) {
// stop the transition
pts.RemoveElementAt(i);
}
} while (i != 0);

View File

@ -40,6 +40,20 @@ p.style.MozTransitionProperty = "font";
is(cs.textIndent, "0px",
"relevant change to transition property does change transitioning");
/** Test for Bug 522643 */
p.style.MozTransitionDuration = "4s";
p.style.MozTransitionDelay = "-2s";
p.style.MozTransitionProperty = "text-indent";
p.style.textIndent = "100px";
is(cs.textIndent, "50px", "transition is halfway");
p.style.MozTransitionDuration = "0s";
p.style.MozTransitionDelay = "0s";
is(cs.textIndent, "50px",
"changing duration and delay doesn't change transitioning");
p.style.textIndent = "0px";
is(cs.textIndent, "0px",
"changing property after changing duration and delay stops transition");
</script>
</pre>
</body>