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.
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4377,17 +4377,17 @@ nsDocShell::GetWindow()
NS_IMETHODIMP
nsDocShell::SetDeviceSizeIsPageSize(bool aValue)
{
if (mDeviceSizeIsPageSize != aValue) {
mDeviceSizeIsPageSize = aValue;
nsRefPtr<nsPresContext> presContext;
GetPresContext(getter_AddRefs(presContext));
if (presContext) {
- presContext->MediaFeatureValuesChanged(presContext->eAlwaysRebuildStyle);
+ presContext->MediaFeatureValuesChanged(eRestyle_Subtree);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetDeviceSizeIsPageSize(bool* aValue)
{
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -842,17 +842,17 @@ nsPresContext::AppUnitsPerDevPixelChange
InvalidatePaintedLayers();
if (mDeviceContext) {
mDeviceContext->FlushFontCache();
}
if (HasCachedStyleData()) {
// All cached style data must be recomputed.
- MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
+ MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW);
}
mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
}
void
nsPresContext::PreferenceChanged(const char* aPrefName)
{
@@ -1706,17 +1706,17 @@ nsPresContext::ThemeChangedInternal()
// This will force the system metrics to be generated the next time they're used
nsCSSRuleProcessor::FreeSystemMetrics();
// Changes to system metrics can change media queries on them.
// 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.
- MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
+ MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW);
}
void
nsPresContext::SysColorChanged()
{
if (!mPendingSysColorChanged) {
sLookAndFeelChanged = true;
nsCOMPtr<nsIRunnable> ev =
@@ -1835,26 +1835,26 @@ nsPresContext::EmulateMedium(const nsASt
nsIAtom* previousMedium = Medium();
mIsEmulatingMedia = true;
nsAutoString mediaType;
nsContentUtils::ASCIIToLower(aMediaType, mediaType);
mMediaEmulated = do_GetAtom(mediaType);
if (mMediaEmulated != previousMedium && mShell) {
- MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0));
+ MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
}
}
void nsPresContext::StopEmulatingMedium()
{
nsIAtom* previousMedium = Medium();
mIsEmulatingMedia = false;
if (Medium() != previousMedium) {
- MediaFeatureValuesChanged(eRebuildStyleIfNeeded, nsChangeHint(0));
+ MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0));
}
}
void
nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint)
{
if (!mShell) {
@@ -1877,28 +1877,21 @@ nsPresContext::PostRebuildAllStyleDataEv
if (!mShell) {
// We must have been torn down. Nothing to do here.
return;
}
RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
}
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;
}
if (mUsesViewportUnits && mPendingViewportChange) {
// Rebuild all style data without rerunning selector matching.
aRestyleHint |= eRestyle_ForceDescendants;
@@ -1974,17 +1967,17 @@ nsPresContext::PostMediaFeatureValuesCha
}
void
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));
}
}
already_AddRefed<MediaQueryList>
nsPresContext::MatchMedia(const nsAString& aMediaQueryList)
{
nsRefPtr<MediaQueryList> result = new MediaQueryList(this, aMediaQueryList);
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -146,22 +146,16 @@ public:
enum nsPresContextType {
eContext_Galley, // unpaginated screen presentation
eContext_PrintPreview, // paginated screen presentation
eContext_Print, // paginated printer presentation
eContext_PageLayout // paginated & editable.
};
- // Policies for rebuilding style data.
- enum StyleRebuildType {
- eRebuildStyleIfNeeded,
- eAlwaysRebuildStyle
- };
-
nsPresContext(nsIDocument* aDocument, nsPresContextType aType);
/**
* Initialize the presentation context from a particular device.
*/
nsresult Init(nsDeviceContext* aDeviceContext);
/**
@@ -260,23 +254,43 @@ public:
void RebuildAllStyleData(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint);
/**
* Just like RebuildAllStyleData, except (1) asynchronous and (2) it
* doesn't rebuild the user font set.
*/
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));
}
/**
* Support for window.matchMedia()
*/
already_AddRefed<mozilla::dom::MediaQueryList>
MatchMedia(const nsAString& aMediaQueryList);
@@ -530,17 +544,17 @@ public:
void SetTextZoom(float aZoom) {
if (aZoom == mTextZoom)
return;
mTextZoom = aZoom;
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);
}
}
/**
* Get the minimum font size for the specified language. If aLanguage
* is nullptr, then the document's language is used. This combines
* the language-specific global preference with the per-presentation
* base minimum font size.
@@ -565,17 +579,17 @@ public:
void SetBaseMinFontSize(int32_t aMinFontSize) {
if (aMinFontSize == mBaseMinFontSize)
return;
mBaseMinFontSize = aMinFontSize;
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);
}
}
float GetFullZoom() { return mFullZoom; }
void SetFullZoom(float aZoom);
nscoord GetAutoQualityMinFontSize() {
return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref);