2009-10-07 20:22:42 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07: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-07 20:22:42 -07:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#ifndef nsTransitionManager_h_
|
|
|
|
#define nsTransitionManager_h_
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-04-20 18:22:09 -07:00
|
|
|
#include "mozilla/dom/Animation.h"
|
2015-04-14 16:48:21 -07:00
|
|
|
#include "mozilla/dom/KeyframeEffect.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "AnimationCommon.h"
|
2009-12-10 23:37:40 -08:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2015-04-27 23:48:35 -07:00
|
|
|
class nsIGlobalObject;
|
2009-10-07 20:22:42 -07:00
|
|
|
class nsStyleContext;
|
|
|
|
class nsPresContext;
|
|
|
|
class nsCSSPropertySet;
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2014-06-26 16:57:12 -07:00
|
|
|
namespace mozilla {
|
|
|
|
struct StyleTransition;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace mozilla
|
2014-06-26 16:57:12 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
/*****************************************************************************
|
|
|
|
* Per-Element data *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-06-26 16:57:12 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-04-30 06:06:43 -07:00
|
|
|
struct ElementPropertyTransition : public dom::KeyframeEffectReadOnly
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2014-08-10 00:06:52 -07:00
|
|
|
ElementPropertyTransition(nsIDocument* aDocument,
|
2014-10-01 23:14:15 -07:00
|
|
|
dom::Element* aTarget,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2014-08-10 00:06:52 -07:00
|
|
|
const AnimationTiming &aTiming)
|
2015-06-30 23:19:04 -07:00
|
|
|
: dom::KeyframeEffectReadOnly(aDocument, aTarget, aPseudoType, aTiming)
|
2014-10-01 23:14:15 -07:00
|
|
|
{ }
|
2014-07-15 17:02:30 -07:00
|
|
|
|
2015-06-08 19:13:53 -07:00
|
|
|
ElementPropertyTransition* AsTransition() override { return this; }
|
|
|
|
const ElementPropertyTransition* AsTransition() const override
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-05-14 16:38:37 -07:00
|
|
|
|
2015-04-13 17:11:44 -07:00
|
|
|
nsCSSProperty TransitionProperty() const {
|
|
|
|
MOZ_ASSERT(Properties().Length() == 1,
|
|
|
|
"Transitions should have exactly one animation property. "
|
|
|
|
"Perhaps we are using an un-initialized transition?");
|
|
|
|
return Properties()[0].mProperty;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
// This is the start value to be used for a check for whether a
|
2014-04-02 22:57:27 -07:00
|
|
|
// transition is being reversed. Normally the same as
|
|
|
|
// mProperties[0].mSegments[0].mFromValue, except when this transition
|
|
|
|
// started as the reversal of another in-progress transition.
|
|
|
|
// Needed so we can handle two reverses in a row.
|
2014-06-23 23:29:54 -07:00
|
|
|
mozilla::StyleAnimationValue mStartForReversingTest;
|
2012-07-31 10:28:21 -07:00
|
|
|
// Likewise, the portion (in value space) of the "full" reversed
|
|
|
|
// transition that we're actually covering. For example, if a :hover
|
|
|
|
// effect has a transition that moves the element 10px to the right
|
|
|
|
// (by changing 'left' from 0px to 10px), and the mouse moves in to
|
|
|
|
// the element (starting the transition) but then moves out after the
|
|
|
|
// transition has advanced 4px, the second transition (from 10px/4px
|
|
|
|
// to 0px) will have mReversePortion of 0.4. (If the mouse then moves
|
|
|
|
// in again when the transition is back to 2px, the mReversePortion
|
|
|
|
// for the third transition (from 0px/2px to 10px) will be 0.8.
|
|
|
|
double mReversePortion;
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
// Compute the portion of the *value* space that we should be through
|
2014-07-15 17:02:32 -07:00
|
|
|
// at the current time. (The input to the transition timing function
|
2012-07-31 10:28:21 -07:00
|
|
|
// has time units, the output has value units.)
|
2014-07-15 17:02:32 -07:00
|
|
|
double CurrentValuePortion() const;
|
2012-07-31 10:28:21 -07:00
|
|
|
};
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2015-06-29 18:00:39 -07:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class CSSTransition final : public Animation
|
2014-11-16 20:45:57 -08:00
|
|
|
{
|
|
|
|
public:
|
2015-04-28 01:21:58 -07:00
|
|
|
explicit CSSTransition(nsIGlobalObject* aGlobal)
|
|
|
|
: dom::Animation(aGlobal)
|
2014-11-16 20:45:57 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-29 18:00:39 -07:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2015-06-08 19:13:53 -07:00
|
|
|
CSSTransition* AsCSSTransition() override { return this; }
|
|
|
|
const CSSTransition* AsCSSTransition() const override { return this; }
|
2014-11-16 20:45:57 -08:00
|
|
|
|
2015-06-30 20:27:48 -07:00
|
|
|
// CSSTransition interface
|
2015-06-30 23:19:04 -07:00
|
|
|
void GetTransitionProperty(nsString& aRetVal) const;
|
2015-06-30 20:27:48 -07:00
|
|
|
|
|
|
|
// Animation interface overrides
|
2015-06-29 18:00:39 -07:00
|
|
|
virtual AnimationPlayState PlayStateFromJS() const override;
|
2015-05-18 22:00:48 -07:00
|
|
|
virtual void PlayFromJS(ErrorResult& aRv) override;
|
2014-11-16 20:45:58 -08:00
|
|
|
|
2014-12-04 08:28:38 -08:00
|
|
|
// A variant of Play() that avoids posting style updates since this method
|
|
|
|
// is expected to be called whilst already updating style.
|
2015-05-18 22:00:48 -07:00
|
|
|
void PlayFromStyle()
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
DoPlay(rv, Animation::LimitBehavior::Continue);
|
|
|
|
// play() should not throw when LimitBehavior is Continue
|
|
|
|
MOZ_ASSERT(!rv.Failed(), "Unexpected exception playing transition");
|
|
|
|
}
|
2014-12-04 08:28:38 -08:00
|
|
|
|
2015-06-08 19:13:53 -07:00
|
|
|
void CancelFromStyle() override
|
|
|
|
{
|
2015-06-08 19:13:54 -07:00
|
|
|
mOwningElement = OwningElementRef();
|
2015-06-08 19:13:53 -07:00
|
|
|
Animation::CancelFromStyle();
|
2015-06-08 19:13:54 -07:00
|
|
|
MOZ_ASSERT(mSequenceNum == kUnsequenced);
|
|
|
|
}
|
|
|
|
|
2015-06-08 19:13:54 -07:00
|
|
|
nsCSSProperty TransitionProperty() const;
|
|
|
|
|
2015-06-08 19:13:54 -07:00
|
|
|
bool HasLowerCompositeOrderThan(const Animation& aOther) const override;
|
2015-06-08 19:13:54 -07:00
|
|
|
bool IsUsingCustomCompositeOrder() const override
|
|
|
|
{
|
|
|
|
return mOwningElement.IsSet();
|
|
|
|
}
|
2015-06-08 19:13:54 -07:00
|
|
|
|
|
|
|
void SetCreationSequence(uint64_t aIndex)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsUsingCustomCompositeOrder());
|
|
|
|
mSequenceNum = aIndex;
|
2015-06-08 19:13:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the element or pseudo-element whose transition-property property
|
|
|
|
// this CSSTransition corresponds to (if any). This is used for determining
|
2015-06-08 19:13:54 -07:00
|
|
|
// the relative composite order of transitions generated from CSS markup.
|
2015-06-08 19:13:53 -07:00
|
|
|
//
|
|
|
|
// Typically this will be the same as the target element of the keyframe
|
|
|
|
// effect associated with this transition. However, it can differ in the
|
|
|
|
// following circumstances:
|
|
|
|
//
|
|
|
|
// a) If script removes or replaces the effect of this transition,
|
|
|
|
// b) If this transition is cancelled (e.g. by updating the
|
|
|
|
// transition-property or removing the owning element from the document),
|
|
|
|
// c) If this object is generated from script using the CSSTransition
|
|
|
|
// constructor.
|
|
|
|
//
|
2015-06-08 19:13:54 -07:00
|
|
|
// For (b) and (c) the returned owning element will return !IsSet().
|
|
|
|
const OwningElementRef& OwningElement() const { return mOwningElement; }
|
2015-06-08 19:13:53 -07:00
|
|
|
|
2015-06-08 19:13:54 -07:00
|
|
|
// Sets the owning element which is used for determining the composite
|
|
|
|
// oder of CSSTransition objects generated from CSS markup.
|
2015-06-08 19:13:53 -07:00
|
|
|
//
|
2015-06-08 19:13:54 -07:00
|
|
|
// @see OwningElement()
|
|
|
|
void SetOwningElement(const OwningElementRef& aElement)
|
2015-06-08 19:13:53 -07:00
|
|
|
{
|
2015-06-08 19:13:54 -07:00
|
|
|
mOwningElement = aElement;
|
2015-06-08 19:13:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-16 20:45:57 -08:00
|
|
|
protected:
|
2015-06-08 19:13:53 -07:00
|
|
|
virtual ~CSSTransition()
|
|
|
|
{
|
2015-06-08 19:13:54 -07:00
|
|
|
MOZ_ASSERT(!mOwningElement.IsSet(), "Owning element should be cleared "
|
|
|
|
"before a CSS transition is destroyed");
|
2015-06-08 19:13:53 -07:00
|
|
|
}
|
2014-11-16 20:45:58 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual css::CommonAnimationManager* GetAnimationManager() const override;
|
2015-06-08 19:13:53 -07:00
|
|
|
|
|
|
|
// The (pseudo-)element whose computed transition-property refers to this
|
|
|
|
// transition (if any).
|
2015-06-08 19:13:54 -07:00
|
|
|
OwningElementRef mOwningElement;
|
2014-11-16 20:45:57 -08:00
|
|
|
};
|
|
|
|
|
2015-06-29 18:00:39 -07:00
|
|
|
} // namespace dom
|
2014-06-26 16:57:12 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class nsTransitionManager final
|
2013-06-25 01:58:46 -07:00
|
|
|
: public mozilla::css::CommonAnimationManager
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2009-10-07 20:22:42 -07:00
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit nsTransitionManager(nsPresContext *aPresContext)
|
2011-04-11 23:18:43 -07:00
|
|
|
: mozilla::css::CommonAnimationManager(aPresContext)
|
2014-08-06 22:58:44 -07:00
|
|
|
, mInAnimationOnlyStyleUpdate(false)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
|
2015-04-20 18:22:10 -07:00
|
|
|
typedef mozilla::AnimationCollection AnimationCollection;
|
2014-06-26 16:57:12 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
/**
|
2012-07-31 10:28:22 -07:00
|
|
|
* StyleContextChanged
|
2009-10-07 20:22:42 -07:00
|
|
|
*
|
|
|
|
* To be called from nsFrameManager::ReResolveStyleContext when the
|
2010-06-30 18:54:29 -07:00
|
|
|
* style of an element has changed, to initiate transitions from
|
|
|
|
* that style change. For style contexts with :before and :after
|
|
|
|
* pseudos, aElement is expected to be the generated before/after
|
|
|
|
* element.
|
2009-10-07 20:22:42 -07:00
|
|
|
*
|
2015-02-16 14:15:02 -08:00
|
|
|
* It may modify the new style context (by replacing
|
|
|
|
* *aNewStyleContext) to cover up some of the changes for the duration
|
|
|
|
* of the restyling of descendants. If it does, this function will
|
|
|
|
* take care of causing the necessary restyle afterwards.
|
2009-10-07 20:22:42 -07:00
|
|
|
*/
|
2015-02-16 14:15:02 -08:00
|
|
|
void StyleContextChanged(mozilla::dom::Element *aElement,
|
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsRefPtr<nsStyleContext>* aNewStyleContext /* inout */);
|
2009-10-07 20:22:42 -07:00
|
|
|
|
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.
2015-04-26 19:20:19 -07:00
|
|
|
/**
|
|
|
|
* When we're resolving style for an element that previously didn't have
|
|
|
|
* style, we might have some old finished transitions for it, if,
|
|
|
|
* say, it was display:none for a while, but previously displayed.
|
|
|
|
*
|
|
|
|
* This method removes any finished transitions that don't match the
|
|
|
|
* new style.
|
|
|
|
*/
|
|
|
|
void PruneCompletedTransitions(mozilla::dom::Element* aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
nsStyleContext* aNewStyleContext);
|
|
|
|
|
2015-04-20 18:22:10 -07:00
|
|
|
void UpdateCascadeResultsWithTransitions(AnimationCollection* aTransitions);
|
|
|
|
void UpdateCascadeResultsWithAnimations(AnimationCollection* aAnimations);
|
2015-03-19 21:10:00 -07:00
|
|
|
void UpdateCascadeResultsWithAnimationsToBeDestroyed(
|
2015-04-20 18:22:10 -07:00
|
|
|
const AnimationCollection* aAnimations);
|
|
|
|
void UpdateCascadeResults(AnimationCollection* aTransitions,
|
|
|
|
AnimationCollection* aAnimations);
|
2015-03-19 21:10:00 -07:00
|
|
|
|
2014-08-06 22:58:44 -07:00
|
|
|
void SetInAnimationOnlyStyleUpdate(bool aInAnimationOnlyUpdate) {
|
|
|
|
mInAnimationOnlyStyleUpdate = aInAnimationOnlyUpdate;
|
|
|
|
}
|
|
|
|
|
2015-02-16 14:15:04 -08:00
|
|
|
bool InAnimationOnlyStyleUpdate() const {
|
|
|
|
return mInAnimationOnlyStyleUpdate;
|
|
|
|
}
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2015-03-21 09:28:04 -07:00
|
|
|
MOZ_MUST_OVERRIDE override;
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2015-03-21 09:28:04 -07:00
|
|
|
MOZ_MUST_OVERRIDE override;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
void FlushTransitions(FlushFlags aFlags);
|
|
|
|
|
2014-11-19 18:48:41 -08:00
|
|
|
protected:
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::transitionsProperty;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsBeforeAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::transitionsOfBeforeProperty;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsAfterAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::transitionsOfAfterProperty;
|
|
|
|
}
|
2013-10-22 05:14:41 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
private:
|
2014-06-26 16:57:12 -07:00
|
|
|
void
|
|
|
|
ConsiderStartingTransition(nsCSSProperty aProperty,
|
|
|
|
const mozilla::StyleTransition& aTransition,
|
|
|
|
mozilla::dom::Element* aElement,
|
2015-04-20 18:22:10 -07:00
|
|
|
AnimationCollection*& aElementTransitions,
|
2014-06-26 16:57:12 -07:00
|
|
|
nsStyleContext* aOldStyleContext,
|
|
|
|
nsStyleContext* aNewStyleContext,
|
|
|
|
bool* aStartedAny,
|
|
|
|
nsCSSPropertySet* aWhichStarted);
|
2014-08-06 22:58:44 -07:00
|
|
|
|
|
|
|
bool mInAnimationOnlyStyleUpdate;
|
2009-10-07 20:22:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsTransitionManager_h_) */
|