diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 1b5f36f8e0f..f2a3be1d17a 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -806,10 +806,9 @@ nsPresContext::AppUnitsPerDevPixelChanged() mDeviceContext->FlushFontCache(); - // All cached style data must be recomputed. if (HasCachedStyleData()) { - MediaFeatureValuesChanged(true); - RebuildAllStyleData(NS_STYLE_HINT_REFLOW); + // All cached style data must be recomputed. + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); } } @@ -1572,13 +1571,11 @@ nsPresContext::ThemeChangedInternal() nsCSSRuleProcessor::FreeSystemMetrics(); // Changes to system metrics can change media queries on them. - MediaFeatureValuesChanged(true); - // Changes in theme can change system colors (whose changes are // properly reflected in computed style data), system fonts (whose // changes are not), and -moz-appearance (whose changes likewise are // not), so we need to reflow. - RebuildAllStyleData(NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); } void @@ -1680,17 +1677,22 @@ nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint) } void -nsPresContext::MediaFeatureValuesChanged(bool aCallerWillRebuildStyleData) +nsPresContext::MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, + nsChangeHint aChangeHint) { + NS_ASSERTION(aShouldRebuild == eAlwaysRebuildStyle || aChangeHint == 0, + "If you don't know if we need a rebuild, how can you provide a hint?"); + mPendingMediaFeatureValuesChanged = false; // MediumFeaturesChanged updates the applied rules, so it always gets called. bool mediaFeaturesDidChange = mShell ? mShell->StyleSet()->MediumFeaturesChanged(this) : false; - if (!aCallerWillRebuildStyleData && - (mediaFeaturesDidChange || (mUsesViewportUnits && mPendingViewportChange))) { - RebuildAllStyleData(nsChangeHint(0)); + if (aShouldRebuild == eAlwaysRebuildStyle || + mediaFeaturesDidChange || + (mUsesViewportUnits && mPendingViewportChange)) { + RebuildAllStyleData(aChangeHint); } mPendingViewportChange = false; @@ -1769,7 +1771,7 @@ nsPresContext::HandleMediaFeatureValuesChangedEvent() // Null-check mShell in case the shell has been destroyed (and the // event is the only thing holding the pres context alive). if (mPendingMediaFeatureValuesChanged && mShell) { - MediaFeatureValuesChanged(false); + MediaFeatureValuesChanged(eRebuildStyleIfNeeded); } } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 0e28fe73dca..138b35d4f8c 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -157,6 +157,12 @@ public: eContext_PageLayout // paginated & editable. }; + // Policies for rebuilding style data. + enum StyleRebuildType { + eRebuildStyleIfNeeded, + eAlwaysRebuildStyle + }; + nsPresContext(nsIDocument* aDocument, nsPresContextType aType) NS_HIDDEN; /** @@ -248,12 +254,13 @@ public: */ void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint); - void MediaFeatureValuesChanged(bool aCallerWillRebuildStyleData); + void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, + nsChangeHint aChangeHint = nsChangeHint(0)); void PostMediaFeatureValuesChangedEvent(); NS_HIDDEN_(void) HandleMediaFeatureValuesChangedEvent(); void FlushPendingMediaFeatureValuesChanged() { if (mPendingMediaFeatureValuesChanged) - MediaFeatureValuesChanged(false); + MediaFeatureValuesChanged(eRebuildStyleIfNeeded); } /** @@ -493,8 +500,7 @@ public: if (HasCachedStyleData()) { // Media queries could have changed, since we changed the meaning // of 'em' units in them. - MediaFeatureValuesChanged(true); - RebuildAllStyleData(NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); } } @@ -515,8 +521,7 @@ public: if (HasCachedStyleData()) { // Media queries could have changed, since we changed the meaning // of 'em' units in them. - MediaFeatureValuesChanged(true); - RebuildAllStyleData(NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); } }