Bug 1382077 part 2 - Move mUsesViewportUnits into nsStyleSet. r?heycam
MozReview-Commit-ID: DQ4ZoLLNPeN
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -269,17 +269,16 @@ nsPresContext::nsPresContext(nsIDocument
mPendingThemeChanged(false),
mPendingUIResolutionChanged(false),
mPendingMediaFeatureValuesChanged(false),
mPrefChangePendingNeedsReflow(false),
mIsEmulatingMedia(false),
mIsGlyph(false),
mUsesRootEMUnits(false),
mUsesExChUnits(false),
- mUsesViewportUnits(false),
mPendingViewportChange(false),
mCounterStylesDirty(true),
mPostedFlushCounterStyles(false),
mSuppressResizeReflow(false),
mIsVisual(false),
mFireAfterPaintEvents(false),
mIsChrome(false),
mIsChromeOriginImage(false),
@@ -2054,17 +2053,19 @@ nsPresContext::RebuildAllStyleData(nsCha
{
if (!mShell) {
// We must have been torn down. Nothing to do here.
return;
}
mUsesRootEMUnits = false;
mUsesExChUnits = false;
- mUsesViewportUnits = false;
+ if (nsStyleSet* styleSet = mShell->StyleSet()->GetAsGecko()) {
+ styleSet->SetUsesViewportUnits(false);
+ }
mDocument->RebuildUserFontSet();
RebuildCounterStyles();
RestyleManager()->RebuildAllStyleData(aExtraHint, aRestyleHint);
}
void
nsPresContext::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
@@ -2117,28 +2118,16 @@ nsPresContext::MediaFeatureValuesChanged
mPendingMediaFeatureValuesChanged = false;
// MediumFeaturesChanged updates the applied rules, so it always gets called.
if (mShell) {
aRestyleHint |= mShell->
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);
}
mPendingViewportChange = false;
if (mDocument->IsBeingUsedAsImage()) {
MOZ_ASSERT(mDocument->MediaQueryLists().isEmpty());
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -1148,24 +1148,16 @@ public:
bool UsesExChUnits() const {
return mUsesExChUnits;
}
void SetUsesExChUnits(bool aValue) {
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
bool ExistThrottledUpdates() const {
return mExistThrottledUpdates;
}
void SetExistThrottledUpdates(bool aExistThrottledUpdates) {
@@ -1462,18 +1454,16 @@ protected:
// Are we currently drawing an SVG glyph?
unsigned mIsGlyph : 1;
// Does the associated document use root-em (rem) units?
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;
// Is the current mCounterStyleManager valid?
unsigned mCounterStylesDirty : 1;
// Do we currently have an event posted to call FlushCounterStyles?
unsigned mPostedFlushCounterStyles: 1;
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -114,16 +114,23 @@ ServoStyleSet::InvalidateStyleForCSSRule
}
nsRestyleHint
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);
}
size_t
ServoStyleSet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -466,20 +466,24 @@ nsRuleNode::ApplyMinFontSize(nsStyleFont
fontSize = aMinFontSize;
}
}
aFont->mFont.size = fontSize;
}
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
// case) is to define the scale of the viewport units without considering
// scrollbars.
nsSize viewportSize(aPresContext->GetVisibleArea().Size());
// Check for 'overflow: scroll' styles on the root scroll frame. If we find
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -214,16 +214,17 @@ nsStyleSet::nsStyleSet()
mBatching(0),
mStylesHaveChanged(0),
mInShutdown(false),
mInGC(false),
mAuthorStyleDisabled(false),
mInReconstruct(false),
mInitFontFeatureValuesLookup(true),
mNeedsRestyleAfterEnsureUniqueInner(false),
+ mUsesViewportUnits(false),
mDirty(0),
mRootStyleContextCount(0),
#ifdef DEBUG
mOldRootNode(nullptr),
#endif
mUnusedRuleNodeCount(0)
{
}
@@ -2698,16 +2699,20 @@ nsStyleSet::MediumFeaturesChanged(bool a
bool thisChanged = false;
mBindingManager->MediumFeaturesChanged(presContext, &thisChanged);
stylesChanged = stylesChanged || thisChanged;
}
if (stylesChanged) {
return eRestyle_Subtree;
}
+ if (aViewportChanged && mUsesViewportUnits) {
+ // Rebuild all style data without rerunning selector matching.
+ return eRestyle_ForceDescendants;
+ }
return nsRestyleHint(0);
}
bool
nsStyleSet::EnsureUniqueInnerOnCSSSheets()
{
AutoTArray<StyleSheet*, 32> queue;
for (SheetType type : gCSSSheetTypes) {
--- a/layout/style/nsStyleSet.h
+++ b/layout/style/nsStyleSet.h
@@ -486,16 +486,20 @@ class nsStyleSet final
// to drop any nsCSSSelector pointers it has.
void ClearSelectors();
// Returns whether aSheetType represents a level of the cascade that uses
// CSSStyleSheets. See gCSSSheetTypes in nsStyleSet.cpp for the list
// 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;
// Free all the rules with reference-count zero. This continues iterating
// over the free list until it is empty, which allows immediate collection
// of nodes whose reference-count drops to zero during the destruction of
// a child node. This allows the collection of entire trees at once, since
@@ -628,16 +632,18 @@ private:
// in mStylesHaveChanged.
unsigned mStylesHaveChanged : 1;
unsigned mInShutdown : 1;
unsigned mInGC : 1;
unsigned mAuthorStyleDisabled: 1;
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;
#ifdef DEBUG
// In debug builds, we stash a weak pointer here to the old root during
// reconstruction. During GC, we check for this pointer, and null it out
// when we encounter it. This allows us to assert that the old root (and