Bug 1418433 - Increment RestyleGeneration for undisplayed elements when invalidating servo stylist. r=heycam, a=gchang
authorJeremy Chen <jeremychen@mozilla.com>
Sun, 26 Nov 2017 15:24:12 +0000
changeset 445124 d23f5b4bf54978803f0c4b5312b00b209d12b55d
parent 445123 25f3d0651a78a6d30dfe4237d5d41d3d653b463e
child 445125 43f74013ae081e9b5a84cdc6c087d4e206af068b
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, gchang
bugs1418433
milestone58.0
Bug 1418433 - Increment RestyleGeneration for undisplayed elements when invalidating servo stylist. r=heycam, a=gchang 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
@@ -1147,22 +1147,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) {