Bug 802849 - Refactor nsPresContext::MediaFeatureValuesChanged so that it can handle rebuilding style data for all callers. r=dbaron

This commit is contained in:
Seth Fowler 2012-11-08 22:40:41 -08:00
parent f774dcd8ba
commit db5b4c84bf
2 changed files with 24 additions and 17 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}