diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 31e30063deee..3ba0aa4b5e10 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -274,7 +274,6 @@ nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType) mIsGlyph(false), mUsesRootEMUnits(false), mUsesExChUnits(false), - mUsesViewportUnits(false), mPendingViewportChange(false), mCounterStylesDirty(true), mPostedFlushCounterStyles(false), @@ -2059,7 +2058,9 @@ nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint, mUsesRootEMUnits = false; mUsesExChUnits = false; - mUsesViewportUnits = false; + if (nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko()) { + styleSet->SetUsesViewportUnits(false); + } mDocument->RebuildUserFontSet(); RebuildCounterStyles(); @@ -2122,18 +2123,6 @@ nsPresContext::MediaFeatureValuesChanged(nsRestyleHint aRestyleHint, StyleSet()->MediumFeaturesChanged(mPendingViewportChange); } - if (mPendingViewportChange && - (mUsesViewportUnits || mDocument->IsStyledByServo())) { - // Rebuild all style data without rerunning selector matching. - // - // FIXME(emilio, bug 1328652): We don't set mUsesViewportUnits in stylo yet, - // so assume the worst. - // - // Also, in this case we don't need to do a rebuild of the style data, only - // post a restyle. - aRestyleHint |= eRestyle_ForceDescendants; - } - if (aRestyleHint || aChangeHint) { RebuildAllStyleData(aChangeHint, aRestyleHint); } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 8adec1ef4316..158e211ea902 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -1153,14 +1153,6 @@ public: mUsesExChUnits = aValue; } - bool UsesViewportUnits() const { - return mUsesViewportUnits; - } - - void SetUsesViewportUnits(bool aValue) { - mUsesViewportUnits = aValue; - } - // true if there are OMTA transition updates for the current document which // have been throttled, and therefore some style information may not be up // to date @@ -1467,8 +1459,6 @@ protected: unsigned mUsesRootEMUnits : 1; // Does the associated document use ex or ch units? unsigned mUsesExChUnits : 1; - // Does the associated document use viewport units (vw/vh/vmin/vmax)? - unsigned mUsesViewportUnits : 1; // Has there been a change to the viewport's dimensions? unsigned mPendingViewportChange : 1; diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 3142d061af89..dac65daad0e3 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -119,6 +119,13 @@ ServoStyleSet::MediumFeaturesChanged(bool aViewportChanged) const if (Servo_StyleSet_MediumFeaturesChanged(mRawSet.get())) { return eRestyle_Subtree; } + if (aViewportChanged) { + // Rebuild all style data without rerunning selector matching. + // + // FIXME(emilio, bug 1328652): We don't set mUsesViewportUnits in stylo yet, + // so assume the worst. + return eRestyle_ForceDescendants; + } return nsRestyleHint(0); } diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index d7ecd0745fc7..97ebc267d1da 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -471,10 +471,14 @@ nsRuleNode::ApplyMinFontSize(nsStyleFont* aFont, static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext) { - // The caller is making use of viewport units, so notify the pres context + // The caller is making use of viewport units, so notify the style set // that it will need to rebuild the rule tree if the size of the viewport // changes. - aPresContext->SetUsesViewportUnits(true); + // It is possible for this to be called on a Servo-styled document,from + // media query evaluation outside stylesheets. + if (nsStyleSet* styleSet = aPresContext->StyleSet()->GetAsGecko()) { + styleSet->SetUsesViewportUnits(true); + } // The default (when we have 'overflow: auto' on the root element, or // trivially for 'overflow: hidden' since we never have scrollbars in that diff --git a/layout/style/nsStyleSet.cpp b/layout/style/nsStyleSet.cpp index 6892fd30213a..61431bc65cae 100644 --- a/layout/style/nsStyleSet.cpp +++ b/layout/style/nsStyleSet.cpp @@ -219,6 +219,7 @@ nsStyleSet::nsStyleSet() mInReconstruct(false), mInitFontFeatureValuesLookup(true), mNeedsRestyleAfterEnsureUniqueInner(false), + mUsesViewportUnits(false), mDirty(0), mRootStyleContextCount(0), #ifdef DEBUG @@ -2703,6 +2704,10 @@ nsStyleSet::MediumFeaturesChanged(bool aViewportChanged) if (stylesChanged) { return eRestyle_Subtree; } + if (aViewportChanged && mUsesViewportUnits) { + // Rebuild all style data without rerunning selector matching. + return eRestyle_ForceDescendants; + } return nsRestyleHint(0); } diff --git a/layout/style/nsStyleSet.h b/layout/style/nsStyleSet.h index 6dbf788a4bae..de31877754fc 100644 --- a/layout/style/nsStyleSet.h +++ b/layout/style/nsStyleSet.h @@ -491,6 +491,10 @@ class nsStyleSet final // of CSS sheet types. static bool IsCSSSheetType(mozilla::SheetType aSheetType); + void SetUsesViewportUnits(bool aValue) { + mUsesViewportUnits = aValue; + } + private: nsStyleSet(const nsStyleSet& aCopy) = delete; nsStyleSet& operator=(const nsStyleSet& aCopy) = delete; @@ -633,6 +637,8 @@ private: unsigned mInReconstruct : 1; unsigned mInitFontFeatureValuesLookup : 1; unsigned mNeedsRestyleAfterEnsureUniqueInner : 1; + // Does the associated document use viewport units (vw/vh/vmin/vmax)? + unsigned mUsesViewportUnits : 1; unsigned mDirty : int(mozilla::SheetType::Count); // one bit per sheet type uint32_t mRootStyleContextCount;