Bug 1075137 patch 2 - Add new booleans for whether to skip animation styles and whether to post animation restyles. r=birtles
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -59,16 +59,18 @@ FrameTagToString(const nsIFrame* aFrame)
}
#endif
RestyleManager::RestyleManager(nsPresContext* aPresContext)
: mPresContext(aPresContext)
, mRebuildAllStyleData(false)
, mObservingRefreshDriver(false)
, mInStyleRefresh(false)
+ , mSkipAnimationRules(false)
+ , mPostAnimationRestyles(false)
, mHoverGeneration(0)
, mRebuildAllExtraHint(nsChangeHint(0))
, mLastUpdateForThrottledAnimations(aPresContext->RefreshDriver()->
MostRecentRefresh())
, mAnimationGeneration(0)
, mReframingStyleContexts(nullptr)
, mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE |
ELEMENT_IS_POTENTIAL_RESTYLE_ROOT)
@@ -1434,26 +1436,35 @@ RestyleManager::RebuildAllStyleData(nsCh
nsAutoScriptBlocker scriptBlocker;
MOZ_ASSERT(!mIsProcessingRestyles, "Nesting calls to processing restyles");
#ifdef DEBUG
mIsProcessingRestyles = true;
#endif
mPresContext->SetProcessingRestyles(true);
+ // Until we get rid of these phases in bug 960465, we need to skip
+ // animation restyles during the non-animation phase, and post
+ // animation restyles so that we restyle those elements again in the
+ // animation phase.
+ mSkipAnimationRules = true;
+ mPostAnimationRestyles = true;
+
// FIXME (bug 1047928): Many of the callers probably don't need
// eRestyle_Subtree because they're changing things that affect data
// computation rather than selector matching; we could have a restyle
// hint passed in, and substantially improve the performance of things
// like pref changes and the restyling that we do for downloadable
// font loads.
DoRebuildAllStyleData(mPendingRestyles, aExtraHint,
nsRestyleHint(eRestyle_Subtree |
eRestyle_ForceDescendants));
+ mPostAnimationRestyles = false;
+ mSkipAnimationRules = false;
#ifdef DEBUG
mIsProcessingRestyles = false;
#endif
mPresContext->SetProcessingRestyles(false);
// Make sure that we process any pending animation restyles from the
// above style change. Note that we can *almost* implement the above
// by just posting a style change -- except we really need to restyle
@@ -1534,18 +1545,28 @@ RestyleManager::ProcessPendingRestyles()
// if any style changes we cause trigger transitions, we have the
// correct old style for starting the transition.
if (nsLayoutUtils::AreAsyncAnimationsEnabled() &&
mPendingRestyles.Count() > 0) {
++mAnimationGeneration;
UpdateOnlyAnimationStyles();
}
+ // Until we get rid of these phases in bug 960465, we need to skip
+ // animation restyles during the non-animation phase, and post
+ // animation restyles so that we restyle those elements again in the
+ // animation phase.
+ mSkipAnimationRules = true;
+ mPostAnimationRestyles = true;
+
mPendingRestyles.ProcessRestyles();
+ mPostAnimationRestyles = false;
+ mSkipAnimationRules = false;
+
#ifdef DEBUG
uint32_t oldPendingRestyleCount = mPendingRestyles.Count();
#endif
// ...and then process animation restyles. This needs to happen
// second because we need to start animations that resulted from the
// first set of restyles (e.g., CSS transitions with negative
// transition-delay), and because we need to immediately
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -87,16 +87,32 @@ public:
// Get an integer that increments every time there is a style change
// as a result of a change to the :hover content state.
uint32_t GetHoverGeneration() const { return mHoverGeneration; }
// Get a counter that increments on every style change, that we use to
// track whether off-main-thread animations are up-to-date.
uint64_t GetAnimationGeneration() const { return mAnimationGeneration; }
+ // Whether rule matching should skip styles associated with animation
+ bool SkipAnimationRules() const {
+ MOZ_ASSERT(mSkipAnimationRules || !mPostAnimationRestyles,
+ "inconsistent state");
+ return mSkipAnimationRules;
+ }
+
+ // Whether rule matching should post animation restyles when it skips
+ // styles associated with animation. Only true when
+ // SkipAnimationRules() is also true.
+ bool PostAnimationRestyles() const {
+ MOZ_ASSERT(mSkipAnimationRules || !mPostAnimationRestyles,
+ "inconsistent state");
+ return mPostAnimationRestyles;
+ }
+
/**
* Reparent the style contexts of this frame subtree. The parent frame of
* aFrame must be changed to the new parent before this function is called;
* the new parent style context will be automatically computed based on the
* new position in the frame tree.
*
* @param aFrame the root of the subtree to reparent. Must not be null.
*/
@@ -422,16 +438,23 @@ private:
private:
nsPresContext* mPresContext; // weak, disconnected in Disconnect
bool mRebuildAllStyleData : 1;
// True if we're already waiting for a refresh notification
bool mObservingRefreshDriver : 1;
// True if we're in the middle of a nsRefreshDriver refresh
bool mInStyleRefresh : 1;
+ // Whether rule matching should skip styles associated with animation
+ bool mSkipAnimationRules : 1;
+ // Whether rule matching should post animation restyles when it skips
+ // styles associated with animation. Only true when
+ // mSkipAnimationRules is also true.
+ bool mPostAnimationRestyles : 1;
+
uint32_t mHoverGeneration;
nsChangeHint mRebuildAllExtraHint;
mozilla::TimeStamp mLastUpdateForThrottledAnimations;
OverflowChangedTracker mOverflowChangedTracker;
// The total number of animation flushes by this frame constructor.