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
--- 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) {