Bug 1341721 Part 1: ServoStyleSet implementation of SetAuthorStyleDisabled. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 11 Apr 2017 15:43:14 +0800
changeset 561912 4569416733acd3c400ea13e76e7cbdac3d0b8284
parent 561911 819a666afddc804b6099ee1b3cff3a0fdf35ec15
child 561913 4a447e5c18bc000b79add5f805c3f9c265814ee1
push id53894
push userbwerth@mozilla.com
push dateThu, 13 Apr 2017 08:30:03 +0000
bugs1341721
milestone55.0a1
Bug 1341721 Part 1: ServoStyleSet implementation of SetAuthorStyleDisabled. MozReview-Commit-ID: Bd0TJDfcj94
layout/base/PresShell.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4603,17 +4603,19 @@ nsIPresShell::RestyleForCSSRuleChanges()
 
   // 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.
-  if (mStyleSet->IsServo()) {
+  // 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;
   }
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -25,16 +25,17 @@
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 ServoStyleSet::ServoStyleSet()
   : mPresContext(nullptr)
   , mBatching(0)
   , mAllowResolveStaleStyles(false)
+  , mAuthorStyleDisabled(false)
 {
 }
 
 ServoStyleSet::~ServoStyleSet()
 {
 }
 
 void
@@ -119,23 +120,38 @@ ServoStyleSet::SizeOfIncludingThis(Mallo
   // - mPresContext, because it a non-owning pointer
 
   return n;
 }
 
 bool
 ServoStyleSet::GetAuthorStyleDisabled() const
 {
-  return false;
+  return mAuthorStyleDisabled;
 }
 
 nsresult
 ServoStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled)
 {
-  MOZ_CRASH("stylo: not implemented");
+  if (mAuthorStyleDisabled == aStyleDisabled) {
+    return NS_OK;
+  }
+
+  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.
+
+  return NS_OK;
 }
 
 void
 ServoStyleSet::BeginUpdate()
 {
   ++mBatching;
 }
 
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -339,16 +339,17 @@ private:
                                                            nsIAtom* aPseudoTag);
 
   nsPresContext* mPresContext;
   UniquePtr<RawServoStyleSet> mRawSet;
   EnumeratedArray<SheetType, SheetType::Count,
                   nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
   int32_t mBatching;
   bool mAllowResolveStaleStyles;
+  bool mAuthorStyleDisabled;
 
   // Stores pointers to our cached style contexts for non-inheriting anonymous
   // boxes.
   EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
                   nsCSSAnonBoxes::NonInheriting::_Count,
                   RefPtr<nsStyleContext>> mNonInheritingStyleContexts;
 
   static bool sInServoTraversal;