Bug 1336863: Flush stylesheets in RestyleForCSSRuleChanges if not under an update. r=heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 25 Apr 2017 21:03:18 +0200
changeset 569378 4b09facd4bfd5f4925d46c2a66450c9d2a25f932
parent 569377 df784708d0681f1efb547eb79dc10edcc1105083
child 569379 5fa048a13cac1b053983bc7a7921e46519a9268c
push id56156
push userbmo:emilio+bugs@crisal.io
push dateThu, 27 Apr 2017 11:08:01 +0000
reviewersheycam
bugs1336863
milestone55.0a1
Bug 1336863: Flush stylesheets in RestyleForCSSRuleChanges if not under an update. r=heycam This also moves the NoteStyleSheetsChanged to RecordStylesheetChange, which makes more sense, and stopped special-casing author styles, since it's not needed now. MozReview-Commit-ID: 9WKFa0JxqlU
layout/base/PresShell.cpp
layout/style/ServoStyleSet.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4554,29 +4554,16 @@ nsIPresShell::RestyleForCSSRuleChanges()
   }
 
   mDocument->RebuildUserFontSet();
 
   if (mPresContext) {
     mPresContext->RebuildCounterStyles();
   }
 
-  // Tell Servo that the contents of style sheets have changed.
-  //
-  // NB: It's important to do so before bailing out.
-  //
-  // Even if we have no frames, we can end up styling those when creating
-  // them, and it's important for Servo to know that it needs to use the
-  // correct styles.
-  // We don't do this notification if author styles are disabled, because
-  // the ServoStyleSet has already taken care of it.
-  if (mStyleSet->IsServo() && !mStyleSet->AsServo()->GetAuthorStyleDisabled()) {
-    mStyleSet->AsServo()->NoteStyleSheetsChanged();
-  }
-
   Element* root = mDocument->GetRootElement();
   if (!mDidInitialize) {
     // Nothing to do here, since we have no frames yet
     return;
   }
 
   if (!root) {
     // No content to restyle
@@ -4603,16 +4590,21 @@ void
 PresShell::RecordStyleSheetChange(StyleSheet* aStyleSheet)
 {
   // too bad we can't check that the update is UPDATE_STYLE
   NS_ASSERTION(mUpdateCount != 0, "must be in an update");
 
   if (mStylesHaveChanged)
     return;
 
+  // Tell Servo that the contents of style sheets have changed.
+  if (ServoStyleSet* set = mStyleSet->GetAsServo()) {
+    set->NoteStyleSheetsChanged();
+  }
+
   if (aStyleSheet->IsGecko()) {
     // XXXheycam ServoStyleSheets don't support <style scoped> yet.
     Element* scopeElement = aStyleSheet->AsGecko()->GetScopeElement();
     if (scopeElement) {
       mChangedScopeStyleRoots.AppendElement(scopeElement);
       return;
     }
   } else {
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -138,20 +138,22 @@ ServoStyleSet::SetAuthorStyleDisabled(bo
   }
 
   mAuthorStyleDisabled = aStyleDisabled;
 
   // If we've just disabled, we have to note the stylesheets have changed and
   // call flush directly, since the PresShell won't.
   if (mAuthorStyleDisabled) {
     NoteStyleSheetsChanged();
-    Servo_StyleSet_FlushStyleSheets(mRawSet.get());
   }
   // If we've just enabled, then PresShell will trigger the notification and
   // later flush when the stylesheet objects are enabled in JS.
+  //
+  // TODO(emilio): Users can have JS disabled, can't they? Will that affect that
+  // notification on content documents?
 
   return NS_OK;
 }
 
 void
 ServoStyleSet::BeginUpdate()
 {
   ++mBatching;
@@ -833,16 +835,19 @@ ServoStyleSet::StyleSubtreeForReconstruc
                               TraversalRestyleBehavior::ForReconstruct);
   MOZ_ASSERT(!postTraversalRequired);
 }
 
 void
 ServoStyleSet::NoteStyleSheetsChanged()
 {
   Servo_StyleSet_NoteStyleSheetsChanged(mRawSet.get(), mAuthorStyleDisabled);
+  if (!mBatching) {
+    Servo_StyleSet_FlushStyleSheets(mRawSet.get());
+  }
 }
 
 #ifdef DEBUG
 void
 ServoStyleSet::AssertTreeIsClean()
 {
   DocumentStyleRootIterator iter(mPresContext->Document());
   while (Element* root = iter.GetNextStyleRoot()) {