Bug 1047928 patch 2 - Pass restyle hint to RestyleManager::RebuildAllStyleData. r=bzbarsky
This patch is not intended to contain any changes in behavior.
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -64,16 +64,17 @@ RestyleManager::RestyleManager(nsPresCon
, mRebuildAllStyleData(false)
, mObservingRefreshDriver(false)
, mInStyleRefresh(false)
, mSkipAnimationRules(false)
, mPostAnimationRestyles(false)
, mIsProcessingAnimationStyleChange(false)
, mHoverGeneration(0)
, mRebuildAllExtraHint(nsChangeHint(0))
+ , mRebuildAllRestyleHint(nsRestyleHint(0))
, mLastUpdateForThrottledAnimations(aPresContext->RefreshDriver()->
MostRecentRefresh())
, mAnimationGeneration(0)
, mReframingStyleContexts(nullptr)
, mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE |
ELEMENT_IS_POTENTIAL_RESTYLE_ROOT)
, mPendingAnimationRestyles(ELEMENT_HAS_PENDING_ANIMATION_RESTYLE |
ELEMENT_IS_POTENTIAL_ANIMATION_RESTYLE_ROOT)
@@ -1404,25 +1405,28 @@ RestyleManager::RestyleForRemove(Element
if (content == aFollowingSibling) {
reachedFollowingSibling = true;
}
}
}
}
void
-RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint)
+RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
+ nsRestyleHint aRestyleHint)
{
NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
"Should not reconstruct the root of the frame tree. "
"Use ReconstructDocElementHierarchy instead.");
mRebuildAllStyleData = false;
NS_UpdateHint(aExtraHint, mRebuildAllExtraHint);
+ aRestyleHint |= mRebuildAllRestyleHint;
mRebuildAllExtraHint = nsChangeHint(0);
+ mRebuildAllRestyleHint = nsRestyleHint(0);
nsIPresShell* presShell = mPresContext->GetPresShell();
if (!presShell || !presShell->GetRootFrame())
return;
// Make sure that the viewmanager will outlive the presshell
nsRefPtr<nsViewManager> vm = presShell->GetViewManager();
@@ -1443,23 +1447,17 @@ RestyleManager::RebuildAllStyleData(nsCh
// 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, eRestyle_Subtree);
+ DoRebuildAllStyleData(mPendingRestyles, aExtraHint, aRestyleHint);
mPostAnimationRestyles = false;
mSkipAnimationRules = false;
#ifdef DEBUG
mIsProcessingRestyles = false;
#endif
// Make sure that we process any pending animation restyles from the
@@ -1584,17 +1582,17 @@ RestyleManager::ProcessPendingRestyles()
NS_POSTCONDITION(mPendingRestyles.Count() == oldPendingRestyleCount,
"We should not have posted new non-animation restyles while "
"processing animation restyles");
if (mRebuildAllStyleData) {
// We probably wasted a lot of work up above, but this seems safest
// and it should be rarely used.
// This might add us as a refresh observer again; that's ok.
- RebuildAllStyleData(nsChangeHint(0));
+ RebuildAllStyleData(nsChangeHint(0), nsRestyleHint(0));
}
}
void
RestyleManager::BeginProcessingRestyles()
{
// Make sure to not rebuild quote or counter lists while we're
// processing restyles
@@ -1694,16 +1692,18 @@ void
RestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
{
NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
"Should not reconstruct the root of the frame tree. "
"Use ReconstructDocElementHierarchy instead.");
mRebuildAllStyleData = true;
NS_UpdateHint(mRebuildAllExtraHint, aExtraHint);
+ // FIXME: pass through from callers
+ mRebuildAllRestyleHint = eRestyle_Subtree;
// Get a restyle event posted if necessary
PostRestyleEventInternal(false);
}
#ifdef DEBUG
static void
DumpContext(nsIFrame* aFrame, nsStyleContext* aContext)
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -300,17 +300,27 @@ public:
bool ThrottledAnimationStyleIsUpToDate() const {
return mLastUpdateForThrottledAnimations ==
mPresContext->RefreshDriver()->MostRecentRefresh();
}
// Rebuilds all style data by throwing out the old rule tree and
// building a new one, and additionally applying aExtraHint (which
// must not contain nsChangeHint_ReconstructFrame) to the root frame.
- void RebuildAllStyleData(nsChangeHint aExtraHint);
+ //
+ // aRestyleHint says which restyle hint to use for the computation;
+ // the only sensible values to use are eRestyle_Subtree (which says
+ // that the rebuild must run selector matching) and nsRestyleHint(0)
+ // (which says that rerunning selector matching is not required. (The
+ // method adds eRestyle_ForceDescendants internally, and including it
+ // in the restyle hint is harmless; some callers (e.g.,
+ // nsPresContext::MediaFeatureValuesChanged) might do this for their
+ // own reasons.)
+ void RebuildAllStyleData(nsChangeHint aExtraHint,
+ nsRestyleHint aRestyleHint);
// Helper that does part of the work of RebuildAllStyleData, shared by
// RestyleElement for 'rem' handling.
void DoRebuildAllStyleData(RestyleTracker& aRestyleTracker,
nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint);
// See PostRestyleEventCommon below.
@@ -457,16 +467,17 @@ private:
// mSkipAnimationRules is also true.
bool mPostAnimationRestyles : 1;
// Whether we're currently in the animation phase of restyle
// processing (to be eliminated in bug 960465)
bool mIsProcessingAnimationStyleChange : 1;
uint32_t mHoverGeneration;
nsChangeHint mRebuildAllExtraHint;
+ nsRestyleHint mRebuildAllRestyleHint;
mozilla::TimeStamp mLastUpdateForThrottledAnimations;
OverflowChangedTracker mOverflowChangedTracker;
// The total number of animation flushes by this frame constructor.
// Used to keep the layer and animation manager in sync.
uint64_t mAnimationGeneration;
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1859,17 +1859,18 @@ nsPresContext::RebuildAllStyleData(nsCha
return;
}
mUsesRootEMUnits = false;
mUsesViewportUnits = false;
RebuildUserFontSet();
RebuildCounterStyles();
- RestyleManager()->RebuildAllStyleData(aExtraHint);
+ // FIXME: Pass through from callers
+ RestyleManager()->RebuildAllStyleData(aExtraHint, eRestyle_Subtree);
}
void
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint)
{
if (!mShell) {
// We must have been torn down. Nothing to do here.
return;