From b1ad6a1d087ab1e75c992902b573545dbfdf4a59 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 8 Oct 2014 14:27:03 -0700 Subject: [PATCH] Bug 1047928 patch 10 - Pass restyle hint to nsPresContext::MediaFeatureValuesChanged. r=bzbarsky This patch is not intended to contain any changes in behavior. The behavior changes in these callers are in the following 4 patches. --- docshell/base/nsDocShell.cpp | 2 +- layout/base/nsPresContext.cpp | 19 ++++++------------- layout/base/nsPresContext.h | 34 ++++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index fed2d6d5fd8..d2ecff40af5 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4382,7 +4382,7 @@ nsDocShell::SetDeviceSizeIsPageSize(bool aValue) nsRefPtr presContext; GetPresContext(getter_AddRefs(presContext)); if (presContext) { - presContext->MediaFeatureValuesChanged(presContext->eAlwaysRebuildStyle); + presContext->MediaFeatureValuesChanged(eRestyle_Subtree); } } return NS_OK; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 60084ab3bb6..1de6741a6fe 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -847,7 +847,7 @@ nsPresContext::AppUnitsPerDevPixelChanged() if (HasCachedStyleData()) { // All cached style data must be recomputed. - MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW); } mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel(); @@ -1711,7 +1711,7 @@ nsPresContext::ThemeChangedInternal() // 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. - MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW); } void @@ -1840,7 +1840,7 @@ nsPresContext::EmulateMedium(const nsAString& aMediaType) mMediaEmulated = do_GetAtom(mediaType); if (mMediaEmulated != previousMedium && mShell) { - MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0)); + MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0)); } } @@ -1849,7 +1849,7 @@ void nsPresContext::StopEmulatingMedium() nsIAtom* previousMedium = Medium(); mIsEmulatingMedia = false; if (Medium() != previousMedium) { - MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0)); + MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0)); } } @@ -1882,18 +1882,11 @@ nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint, } void -nsPresContext::MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, +nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint, nsChangeHint aChangeHint) { mPendingMediaFeatureValuesChanged = false; - nsRestyleHint aRestyleHint = nsRestyleHint(0); - - if (aShouldRebuild == eAlwaysRebuildStyle) { - // FIXME: Pass restyle hint from caller. - aRestyleHint |= eRestyle_Subtree; - } - // MediumFeaturesChanged updates the applied rules, so it always gets called. if (mShell && mShell->StyleSet()->MediumFeaturesChanged(this)) { aRestyleHint |= eRestyle_Subtree; @@ -1979,7 +1972,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(eRebuildStyleIfNeeded); + MediaFeatureValuesChanged(nsRestyleHint(0)); } } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index ea1c79d16b4..8be19b868e4 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -151,12 +151,6 @@ public: eContext_PageLayout // paginated & editable. }; - // Policies for rebuilding style data. - enum StyleRebuildType { - eRebuildStyleIfNeeded, - eAlwaysRebuildStyle - }; - nsPresContext(nsIDocument* aDocument, nsPresContextType aType); /** @@ -265,13 +259,33 @@ public: void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint); - void MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild, + /** + * Handle changes in the values of media features (used in media + * queries). + * + * There are three sensible values to use for aRestyleHint: + * * nsRestyleHint(0) to rebuild style data, with rerunning of + * selector matching, only if media features have changed + * * eRestyle_ForceDescendants to force rebuilding of style data (but + * still only rerun selector matching if media query results have + * changed). (RebuildAllStyleData always adds + * eRestyle_ForceDescendants internally, so here we're only using + * it to distinguish from nsRestyleHint(0) whether we need to call + * RebuildAllStyleData at all.) + * * eRestyle_Subtree to force rebuilding of style data with + * rerunning of selector matching + * + * For aChangeHint, see RestyleManager::RebuildAllStyleData. (Passing + * a nonzero aChangeHint forces rebuilding style data even if + * nsRestyleHint(0) is passed.) + */ + void MediaFeatureValuesChanged(nsRestyleHint aRestyleHint, nsChangeHint aChangeHint = nsChangeHint(0)); void PostMediaFeatureValuesChangedEvent(); void HandleMediaFeatureValuesChangedEvent(); void FlushPendingMediaFeatureValuesChanged() { if (mPendingMediaFeatureValuesChanged) - MediaFeatureValuesChanged(eRebuildStyleIfNeeded); + MediaFeatureValuesChanged(nsRestyleHint(0)); } /** @@ -535,7 +549,7 @@ public: if (HasCachedStyleData()) { // Media queries could have changed, since we changed the meaning // of 'em' units in them. - MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW); } } @@ -570,7 +584,7 @@ public: if (HasCachedStyleData()) { // Media queries could have changed, since we changed the meaning // of 'em' units in them. - MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW); + MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW); } }