Bug 1418433 - increment RestyleGeneration for undisplayed elements when invalidating servo stylist. draft
authorJeremy Chen <jeremychen@mozilla.com>
Sun, 26 Nov 2017 15:24:12 +0000
changeset 705195 5ab7dac85cb97c686af337e0de76d40900fae4ee
parent 705194 fbac96bd4f376e62452565a33183c120e824a1ae
child 742288 dd3ae3ff0540d554dcc2c92a1e63594d1702ffe5
push id91391
push userbmo:jeremychen@mozilla.com
push dateWed, 29 Nov 2017 16:17:22 +0000
bugs1418433
milestone59.0a1
Bug 1418433 - increment RestyleGeneration for undisplayed elements when invalidating servo stylist. In the current implementation, we call SetStylistStyleSheetsDirty() every time a style sheet is changed. However, the dirty bit setting may or may not always update the style data. For example, the style data for undisplayed elements are deliberately not updated in Stylo. However, the getComputedStyle API is supposed to provide a way to get the up-to-date computed style data, even for undisplayed elements. In this patch, we increment RestyleGeneration for undisplayed elements when we call SetStylistStyleSheetsDirty(). This could flush the cached data that getComputedStyle API holds, and ensures the getComputedStyle API computes a new one. MozReview-Commit-ID: JDDhACOG3z4
layout/style/ServoStyleSet.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1024,22 +1024,37 @@ ServoStyleSet::MarkOriginsDirty(OriginFl
                                         mAuthorStyleDisabled,
                                         aChangedOrigins);
 }
 
 void
 ServoStyleSet::SetStylistStyleSheetsDirty()
 {
   mStylistState |= StylistState::StyleSheetsDirty;
+
+  // We need to invalidate cached style in getComputedStyle for undisplayed
+  // elements, since we don't know if any of the style sheet change that we
+  // do would affect undisplayed elements.
+  if (mPresContext) {
+    // XBL sheets don't have a pres context, but invalidating the restyle generation
+    // in that case is handled by SetXBLStyleSheetsDirty in the "master" stylist.
+    mPresContext->RestyleManager()->AsServo()->IncrementUndisplayedRestyleGeneration();
+  }
 }
 
 void
 ServoStyleSet::SetStylistXBLStyleSheetsDirty()
 {
   mStylistState |= StylistState::XBLStyleSheetsDirty;
+
+  // We need to invalidate cached style in getComputedStyle for undisplayed
+  // elements, since we don't know if any of the style sheet change that we
+  // do would affect undisplayed elements.
+  MOZ_ASSERT(mPresContext);
+  mPresContext->RestyleManager()->AsServo()->IncrementUndisplayedRestyleGeneration();
 }
 
 void
 ServoStyleSet::RecordStyleSheetChange(
     ServoStyleSheet* aSheet,
     StyleSheet::ChangeType aChangeType)
 {
   switch (aChangeType) {