Bug 1459529: Remove UPDATE_STYLE. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 11 May 2018 18:37:47 +0200
changeset 794329 16426b39676d0a8a55210299c6c947ca2dee19ea
parent 794261 8ac5a9265ccb337266c0d886b2585a7ab4f358ed
child 794436 9e58ed8ab3dcc6c3070a13ba08227abe1f3417fa
child 794536 fc067c0fb7dbb7f46fca42a1fcd93680bb509294
push id109644
push userbmo:emilio@crisal.io
push dateFri, 11 May 2018 18:22:05 +0000
reviewersheycam
bugs1459529
milestone62.0a1
Bug 1459529: Remove UPDATE_STYLE. r?heycam Now that BeginUpdate is useless for the UPDATE_STYLE case, we don't need the update mechanism at all. Just ensure that ApplicableStylesChanged is called on the pres shell via the relevant RuleChanged, etc. notifications. There's a big hidden gotcha here. nsIDocument::BeginUpdate does put a script blocker on the stack for these updates. However it's not needed, since no script can run during these notifications (only the stylesheet events we post for devtools, but those use AsyncEventDispatcher and PostDOMEvents, so they don't try to run immediately). nsIDocument::BeginUpdate also does XBL binding attached queue stuff, but we can't change bindings during these notifications anyway, so it also doesn't matter. MozReview-Commit-ID: HJvK6zQfloh
dom/base/ShadowRoot.cpp
dom/base/nsDocument.cpp
dom/base/nsIDocumentObserver.h
dom/base/nsStyleLinkElement.cpp
dom/events/IMEContentObserver.cpp
dom/html/nsHTMLDocument.cpp
dom/svg/SVGDocument.cpp
dom/xul/XULDocument.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/StyleSheetTransactions.cpp
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/RestyleManager.cpp
layout/base/RestyleManager.h
layout/base/nsIPresShell.h
layout/style/Loader.cpp
layout/style/MediaList.cpp
layout/style/ServoCounterStyleRule.cpp
layout/style/ServoKeyframeRule.cpp
layout/style/ServoKeyframesRule.cpp
layout/style/ServoStyleRule.cpp
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/StyleSheet.cpp
--- a/dom/base/ShadowRoot.cpp
+++ b/dom/base/ShadowRoot.cpp
@@ -303,19 +303,17 @@ void
 ShadowRoot::ApplicableRulesChanged()
 {
   if (!IsComposedDocParticipant()) {
     return;
   }
 
   nsIDocument* doc = OwnerDoc();
   if (nsIPresShell* shell = doc->GetShell()) {
-    doc->BeginUpdate(UPDATE_STYLE);
     shell->RecordShadowStyleChange(*this);
-    doc->EndUpdate(UPDATE_STYLE);
   }
 }
 
 void
 ShadowRoot::InsertSheetAt(size_t aIndex, StyleSheet& aSheet)
 {
   DocumentOrShadowRoot::InsertSheetAt(aIndex, aSheet);
   if (aSheet.IsApplicable()) {
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2462,17 +2462,16 @@ nsIDocument::RemoveStyleSheetsFromStyleS
   }
 }
 
 void
 nsIDocument::ResetStylesheetsToURI(nsIURI* aURI)
 {
   MOZ_ASSERT(aURI);
 
-  mozAutoDocUpdate upd(this, UPDATE_STYLE, true);
   if (mStyleSetFilled) {
     // Skip removing style sheets from the style set if we know we haven't
     // filled the style set.  (This allows us to avoid calling
     // GetStyleBackendType() too early.)
     RemoveDocStyleSheetsFromStyleSets();
     RemoveStyleSheetsFromStyleSets(mOnDemandBuiltInUASheets, SheetType::Agent);
     RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eAgentSheet], SheetType::Agent);
     RemoveStyleSheetsFromStyleSets(mAdditionalSheets[eUserSheet], SheetType::User);
@@ -2505,19 +2504,21 @@ nsIDocument::ResetStylesheetsToURI(nsIUR
     mAttrStyleSheet = new nsHTMLStyleSheet(this);
   }
 
   if (!mStyleAttrStyleSheet) {
     mStyleAttrStyleSheet = new nsHTMLCSSStyleSheet();
   }
 
   // Now set up our style sets
-  nsCOMPtr<nsIPresShell> shell = GetShell();
-  if (shell) {
+  if (nsIPresShell* shell = GetShell()) {
     FillStyleSet(shell->StyleSet());
+    if (shell->StyleSet()->StyleSheetsHaveChanged()) {
+      shell->ApplicableStylesChanged();
+    }
   }
 }
 
 static void
 AppendSheetsToStyleSet(ServoStyleSet* aStyleSet,
                        const nsTArray<RefPtr<StyleSheet>>& aSheets,
                        SheetType aType)
 {
@@ -4246,51 +4247,49 @@ nsIDocument::RemoveChildNode(nsIContent*
 }
 
 void
 nsIDocument::EnsureOnDemandBuiltInUASheet(StyleSheet* aSheet)
 {
   if (mOnDemandBuiltInUASheets.Contains(aSheet)) {
     return;
   }
-  BeginUpdate(UPDATE_STYLE);
   AddOnDemandBuiltInUASheet(aSheet);
-  EndUpdate(UPDATE_STYLE);
 }
 
 void
 nsIDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet)
 {
   MOZ_ASSERT(!mOnDemandBuiltInUASheets.Contains(aSheet));
 
   // Prepend here so that we store the sheets in mOnDemandBuiltInUASheets in
   // the same order that they should end up in the style set.
   mOnDemandBuiltInUASheets.InsertElementAt(0, aSheet);
 
   if (aSheet->IsApplicable()) {
     // This is like |AddStyleSheetToStyleSets|, but for an agent sheet.
-    nsCOMPtr<nsIPresShell> shell = GetShell();
-    if (shell) {
+    if (nsIPresShell* shell = GetShell()) {
       // Note that prepending here is necessary to make sure that html.css etc.
       // do not override Firefox OS/Mobile's content.css sheet. Maybe we should
       // have an insertion point to match the order of
       // nsDocumentViewer::CreateStyleSet though?
       shell->StyleSet()->PrependStyleSheet(SheetType::Agent, aSheet);
+      shell->ApplicableStylesChanged();
     }
   }
 
   NotifyStyleSheetAdded(aSheet, false);
 }
 
 void
 nsIDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
 {
-  nsCOMPtr<nsIPresShell> shell = GetShell();
-  if (shell) {
+  if (nsIPresShell* shell = GetShell()) {
     shell->StyleSet()->AddDocStyleSheet(aSheet, this);
+    shell->ApplicableStylesChanged();
   }
 }
 
 #define DO_STYLESHEET_NOTIFICATION(className, type, memberName, argName)      \
   do {                                                                        \
     className##Init init;                                                     \
     init.mBubbles = true;                                                     \
     init.mCancelable = true;                                                  \
@@ -4342,16 +4341,17 @@ nsIDocument::AddStyleSheet(StyleSheet* a
   NotifyStyleSheetAdded(aSheet, true);
 }
 
 void
 nsIDocument::RemoveStyleSheetFromStyleSets(StyleSheet* aSheet)
 {
   if (nsIPresShell* shell = GetShell()) {
     shell->StyleSet()->RemoveDocStyleSheet(aSheet);
+    shell->ApplicableStylesChanged();
   }
 }
 
 void
 nsIDocument::RemoveStyleSheet(StyleSheet* aSheet)
 {
   MOZ_ASSERT(aSheet);
   RefPtr<StyleSheet> sheet = DocumentOrShadowRoot::RemoveSheet(*aSheet);
@@ -4371,18 +4371,16 @@ nsIDocument::RemoveStyleSheet(StyleSheet
 
   sheet->ClearAssociatedDocumentOrShadowRoot();
 }
 
 void
 nsIDocument::UpdateStyleSheets(nsTArray<RefPtr<StyleSheet>>& aOldSheets,
                                nsTArray<RefPtr<StyleSheet>>& aNewSheets)
 {
-  BeginUpdate(UPDATE_STYLE);
-
   // XXX Need to set the sheet on the ownernode, if any
   MOZ_ASSERT(aOldSheets.Length() == aNewSheets.Length(),
              "The lists must be the same length!");
   int32_t count = aOldSheets.Length();
 
   RefPtr<StyleSheet> oldSheet;
   int32_t i;
   for (i = 0; i < count; ++i) {
@@ -4399,18 +4397,16 @@ nsIDocument::UpdateStyleSheets(nsTArray<
       DocumentOrShadowRoot::InsertSheetAt(oldIndex, *newSheet);
       if (newSheet->IsApplicable()) {
         AddStyleSheetToStyleSets(newSheet);
       }
 
       NotifyStyleSheetAdded(newSheet, true);
     }
   }
-
-  EndUpdate(UPDATE_STYLE);
 }
 
 void
 nsIDocument::InsertStyleSheetAt(StyleSheet* aSheet, size_t aIndex)
 {
   MOZ_ASSERT(aSheet);
 
   DocumentOrShadowRoot::InsertSheetAt(aIndex, *aSheet);
@@ -4548,57 +4544,52 @@ nsIDocument::AddAdditionalStyleSheet(add
   if (mAdditionalSheets[aType].Contains(aSheet))
     return NS_ERROR_INVALID_ARG;
 
   if (!aSheet->IsApplicable())
     return NS_ERROR_INVALID_ARG;
 
   mAdditionalSheets[aType].AppendElement(aSheet);
 
-  BeginUpdate(UPDATE_STYLE);
-  nsCOMPtr<nsIPresShell> shell = GetShell();
-  if (shell) {
+  if (nsIPresShell* shell = GetShell()) {
     SheetType type = ConvertAdditionalSheetType(aType);
     shell->StyleSet()->AppendStyleSheet(type, aSheet);
+    shell->ApplicableStylesChanged();
   }
 
   // Passing false, so documet.styleSheets.length will not be affected by
   // these additional sheets.
   NotifyStyleSheetAdded(aSheet, false);
-  EndUpdate(UPDATE_STYLE);
   return NS_OK;
 }
 
 void
 nsIDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aSheetURI)
 {
   MOZ_ASSERT(aSheetURI);
 
   nsTArray<RefPtr<StyleSheet>>& sheets = mAdditionalSheets[aType];
 
   int32_t i = FindSheet(mAdditionalSheets[aType], aSheetURI);
   if (i >= 0) {
     RefPtr<StyleSheet> sheetRef = sheets[i];
     sheets.RemoveElementAt(i);
 
-    BeginUpdate(UPDATE_STYLE);
     if (!mIsGoingAway) {
       MOZ_ASSERT(sheetRef->IsApplicable());
-      nsCOMPtr<nsIPresShell> shell = GetShell();
-      if (shell) {
+      if (nsIPresShell* shell = GetShell()) {
         SheetType type = ConvertAdditionalSheetType(aType);
         shell->StyleSet()->RemoveStyleSheet(type, sheetRef);
+        shell->ApplicableStylesChanged();
       }
     }
 
     // Passing false, so documet.styleSheets.length will not be affected by
     // these additional sheets.
     NotifyStyleSheetRemoved(sheetRef, false);
-    EndUpdate(UPDATE_STYLE);
-
     sheetRef->ClearAssociatedDocumentOrShadowRoot();
   }
 }
 
 nsIGlobalObject*
 nsIDocument::GetScopeObject() const
 {
   nsCOMPtr<nsIGlobalObject> scope(do_QueryReferent(mScopeObject));
@@ -5031,16 +5022,18 @@ nsIDocument::MaybeEndOutermostXBLUpdate(
 
 void
 nsIDocument::BeginUpdate(nsUpdateType aUpdateType)
 {
   // If the document is going away, then it's probably okay to do things to it
   // in the wrong DocGroup. We're unlikely to run JS or do anything else
   // observable at this point. We reach this point when cycle collecting a
   // <link> element and the unlink code removes a style sheet.
+  //
+  // TODO(emilio): Style updates are gone, can this happen now?
   if (mDocGroup && !mIsGoingAway && !mInUnlinkOrDeletion && !mIgnoreDocGroupMismatches) {
     mDocGroup->ValidateAccess();
   }
 
   if (mUpdateNestLevel == 0 && !mInXBLUpdate) {
     mInXBLUpdate = true;
     BindingManager()->BeginOutermostUpdate();
   }
@@ -5451,42 +5444,54 @@ nsIDocument::DocumentStatesChanged(Event
 {
   UpdateDocumentStates(aStateMask);
   NS_DOCUMENT_NOTIFY_OBSERVERS(DocumentStatesChanged, (this, aStateMask));
 }
 
 void
 nsIDocument::StyleRuleChanged(StyleSheet* aSheet, css::Rule* aStyleRule)
 {
+  if (nsIPresShell* shell = GetShell()) {
+    shell->ApplicableStylesChanged();
+  }
+
   if (!StyleSheetChangeEventsEnabled()) {
     return;
   }
 
   DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent,
                              "StyleRuleChanged",
                              mRule,
                              aStyleRule);
 }
 
 void
 nsIDocument::StyleRuleAdded(StyleSheet* aSheet, css::Rule* aStyleRule)
 {
+  if (nsIPresShell* shell = GetShell()) {
+    shell->ApplicableStylesChanged();
+  }
+
   if (!StyleSheetChangeEventsEnabled()) {
     return;
   }
 
   DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent,
                              "StyleRuleAdded",
                              mRule,
                              aStyleRule);
 }
 
 void
 nsIDocument::StyleRuleRemoved(StyleSheet* aSheet, css::Rule* aStyleRule)
 {
+  if (nsIPresShell* shell = GetShell()) {
+    shell->ApplicableStylesChanged();
+  }
+
   if (!StyleSheetChangeEventsEnabled()) {
     return;
   }
 
   DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent,
                              "StyleRuleRemoved",
                              mRule,
                              aStyleRule);
@@ -6040,32 +6045,35 @@ nsIDocument::EnableStyleSheetsForSet(con
     EnableStyleSheetsForSetInternal(aSheetSet, false);
   }
 }
 
 void
 nsIDocument::EnableStyleSheetsForSetInternal(const nsAString& aSheetSet,
                                              bool aUpdateCSSLoader)
 {
-  BeginUpdate(UPDATE_STYLE);
   size_t count = SheetCount();
   nsAutoString title;
   for (size_t index = 0; index < count; index++) {
     StyleSheet* sheet = SheetAt(index);
     NS_ASSERTION(sheet, "Null sheet in sheet list!");
 
     sheet->GetTitle(title);
     if (!title.IsEmpty()) {
       sheet->SetEnabled(title.Equals(aSheetSet));
     }
   }
   if (aUpdateCSSLoader) {
     CSSLoader()->DocumentStyleSheetSetChanged();
   }
-  EndUpdate(UPDATE_STYLE);
+  if (nsIPresShell* shell = GetShell()) {
+    if (shell->StyleSet()->StyleSheetsHaveChanged()) {
+      shell->ApplicableStylesChanged();
+    }
+  }
 }
 
 void
 nsIDocument::GetCharacterSet(nsAString& aCharacterSet) const
 {
   nsAutoCString charset;
   GetDocumentCharacterSet()->Name(charset);
   CopyASCIItoUTF16(charset, aCharacterSet);
--- a/dom/base/nsIDocumentObserver.h
+++ b/dom/base/nsIDocumentObserver.h
@@ -16,18 +16,16 @@ class nsIDocument;
 
 #define NS_IDOCUMENT_OBSERVER_IID \
 { 0x71041fa3, 0x6dd7, 0x4cde, \
   { 0xbb, 0x76, 0xae, 0xcc, 0x69, 0xe1, 0x75, 0x78 } }
 
 typedef uint32_t nsUpdateType;
 
 #define UPDATE_CONTENT_MODEL 0x00000001
-#define UPDATE_STYLE         0x00000002
-#define UPDATE_ALL (UPDATE_CONTENT_MODEL | UPDATE_STYLE)
 
 // Document observer interface
 class nsIDocumentObserver : public nsIMutationObserver
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_OBSERVER_IID)
 
   /**
--- a/dom/base/nsStyleLinkElement.cpp
+++ b/dom/base/nsStyleLinkElement.cpp
@@ -309,19 +309,17 @@ nsStyleLinkElement::DoUpdateStyleSheet(n
 
     // We're removing the link element from the document or shadow tree,
     // unload the stylesheet.  We want to do this even if updates are
     // disabled, since otherwise a sheet with a stale linking element pointer
     // will be hanging around -- not good!
     if (aOldShadowRoot) {
       aOldShadowRoot->RemoveSheet(mStyleSheet);
     } else {
-      aOldDocument->BeginUpdate(UPDATE_STYLE);
       aOldDocument->RemoveStyleSheet(mStyleSheet);
-      aOldDocument->EndUpdate(UPDATE_STYLE);
     }
 
     nsStyleLinkElement::SetStyleSheet(nullptr);
   }
 
   // When static documents are created, stylesheets are cloned manually.
   if (mDontLoadStyle || !mUpdatesEnabled ||
       thisContent->OwnerDoc()->IsStaticDocument()) {
@@ -350,19 +348,17 @@ nsStyleLinkElement::DoUpdateStyleSheet(n
     }
   }
 
   if (mStyleSheet) {
     if (thisContent->IsInShadowTree()) {
       ShadowRoot* containingShadow = thisContent->GetContainingShadow();
       containingShadow->RemoveSheet(mStyleSheet);
     } else {
-      doc->BeginUpdate(UPDATE_STYLE);
       doc->RemoveStyleSheet(mStyleSheet);
-      doc->EndUpdate(UPDATE_STYLE);
     }
 
     nsStyleLinkElement::SetStyleSheet(nullptr);
   }
 
   if (!info) {
     return Update { };
   }
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -2294,31 +2294,25 @@ IMEContentObserver::DocumentObserver::De
 
 void
 IMEContentObserver::DocumentObserver::BeginUpdate(nsIDocument* aDocument,
                                                   nsUpdateType aUpdateType)
 {
   if (NS_WARN_IF(Destroyed()) || NS_WARN_IF(!IsObserving())) {
     return;
   }
-  if (!(aUpdateType & UPDATE_CONTENT_MODEL)) {
-    return;
-  }
   mDocumentUpdating++;
   mIMEContentObserver->BeginDocumentUpdate();
 }
 
 void
 IMEContentObserver::DocumentObserver::EndUpdate(nsIDocument* aDocument,
                                                 nsUpdateType aUpdateType)
 {
   if (NS_WARN_IF(Destroyed()) || NS_WARN_IF(!IsObserving()) ||
       NS_WARN_IF(!IsUpdating())) {
     return;
   }
-  if (!(aUpdateType & UPDATE_CONTENT_MODEL)) {
-    return;
-  }
   mDocumentUpdating--;
   mIMEContentObserver->EndDocumentUpdate();
 }
 
 } // namespace mozilla
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -2260,17 +2260,17 @@ nsHTMLDocument::TearingDownEditor()
     auto cache = nsLayoutStylesheetCache::Singleton();
 
     agentSheets.RemoveElement(cache->ContentEditableSheet());
     if (oldState == eDesignMode)
       agentSheets.RemoveElement(cache->DesignModeSheet());
 
     presShell->SetAgentStyleSheets(agentSheets);
 
-    presShell->RestyleForCSSRuleChanges();
+    presShell->ApplicableStylesChanged();
   }
 }
 
 nsresult
 nsHTMLDocument::TurnEditingOff()
 {
   NS_ASSERTION(mEditingState != eOff, "Editing is already off.");
 
@@ -2428,17 +2428,17 @@ nsHTMLDocument::EditingStateChanged()
       // designMode is being turned off (contentEditable is still on).
       agentSheets.RemoveElement(cache->DesignModeSheet());
       updateState = true;
     }
 
     rv = presShell->SetAgentStyleSheets(agentSheets);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    presShell->RestyleForCSSRuleChanges();
+    presShell->ApplicableStylesChanged();
 
     // Adjust focused element with new style but blur event shouldn't be fired
     // until mEditingState is modified with newState.
     nsAutoScriptBlocker scriptBlocker;
     if (designMode) {
       nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
       nsIContent* focusedContent =
         nsFocusManager::GetFocusedDescendant(window,
--- a/dom/svg/SVGDocument.cpp
+++ b/dom/svg/SVGDocument.cpp
@@ -93,18 +93,16 @@ SVGDocument::EnsureNonSVGUserAgentStyleS
     // nsIDocument::CreateStaticClone will handle cloning the original
     // document's sheets, including the on-demand non-SVG UA sheets,
     // for us.
     return;
   }
 
   mHasLoadedNonSVGUserAgentStyleSheets = true;
 
-  BeginUpdate(UPDATE_STYLE);
-
   if (IsBeingUsedAsImage()) {
     // nsDocumentViewer::CreateStyleSet skipped loading all user-agent/user
     // style sheets in this case, but we'll need B2G/Fennec's
     // content.css. We could load all the sheets registered with the
     // nsIStyleSheetService (and maybe we should) but most likely it isn't
     // desirable or necessary for foreignObject in SVG-as-an-image. Instead we
     // only load the "agent-style-sheets" that nsStyleSheetService::Init()
     // pulls in from the category manager. That keeps memory use of
@@ -162,18 +160,16 @@ SVGDocument::EnsureNonSVGUserAgentStyleS
   EnsureOnDemandBuiltInUASheet(cache->HTMLSheet());
   if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
     EnsureOnDemandBuiltInUASheet(cache->NoFramesSheet());
   }
   if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
     EnsureOnDemandBuiltInUASheet(cache->NoScriptSheet());
   }
   EnsureOnDemandBuiltInUASheet(cache->UASheet());
-
-  EndUpdate(UPDATE_STYLE);
 }
 
 } // namespace dom
 } // namespace mozilla
 
 ////////////////////////////////////////////////////////////////////////
 // Exported creation functions
 
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -2687,17 +2687,16 @@ XULDocument::DoneWalking()
 {
     MOZ_ASSERT(mPendingSheets == 0, "there are sheets to be loaded");
     MOZ_ASSERT(!mStillWalking, "walk not done");
 
     // XXXldb This is where we should really be setting the chromehidden
     // attribute.
 
     {
-        mozAutoDocUpdate updateBatch(this, UPDATE_STYLE, true);
         uint32_t count = mOverlaySheets.Length();
         for (uint32_t i = 0; i < count; ++i) {
             AddStyleSheet(mOverlaySheets[i]);
         }
     }
 
     mOverlaySheets.Clear();
 
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2981,18 +2981,17 @@ HTMLEditor::AddOverrideStyleSheet(const 
                   &sheet);
 
   // Synchronous loads should ALWAYS return completed
   NS_ENSURE_TRUE(sheet, NS_ERROR_NULL_POINTER);
 
   // Add the override style sheet
   // (This checks if already exists)
   ps->AddOverrideStyleSheet(sheet);
-
-  ps->RestyleForCSSRuleChanges();
+  ps->ApplicableStylesChanged();
 
   // Save as the last-loaded sheet
   mLastOverrideStyleSheetURL = aURL;
 
   //Add URL and style sheet to our lists
   return AddNewStyleSheetToList(aURL, sheet);
 }
 
@@ -3029,17 +3028,17 @@ HTMLEditor::RemoveOverrideStyleSheet(con
 
   if (NS_WARN_IF(!IsInitialized())) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   nsCOMPtr<nsIPresShell> ps = GetPresShell();
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
   ps->RemoveOverrideStyleSheet(sheet);
-  ps->RestyleForCSSRuleChanges();
+  ps->ApplicableStylesChanged();
 
   // Remove it from our internal list
   return rv;
 }
 
 NS_IMETHODIMP
 HTMLEditor::EnableStyleSheet(const nsAString& aURL,
                              bool aEnable)
--- a/editor/libeditor/StyleSheetTransactions.cpp
+++ b/editor/libeditor/StyleSheetTransactions.cpp
@@ -9,39 +9,32 @@
 
 #include "nsAString.h"
 #include "nsCOMPtr.h"                   // for nsCOMPtr, do_QueryInterface, etc.
 #include "mozilla/StyleSheet.h"   // for mozilla::StyleSheet
 #include "mozilla/StyleSheetInlines.h"
 #include "nsDebug.h"                    // for NS_ENSURE_TRUE
 #include "nsError.h"                    // for NS_OK, etc.
 #include "nsIDocument.h"                // for nsIDocument
-#include "nsIDocumentObserver.h"        // for UPDATE_STYLE
 
 namespace mozilla {
 
 static void
 AddStyleSheet(EditorBase& aEditor, StyleSheet* aSheet)
 {
-  nsCOMPtr<nsIDocument> doc = aEditor.GetDocument();
-  if (doc) {
-    doc->BeginUpdate(UPDATE_STYLE);
+  if (nsCOMPtr<nsIDocument> doc = aEditor.GetDocument()) {
     doc->AddStyleSheet(aSheet);
-    doc->EndUpdate(UPDATE_STYLE);
   }
 }
 
 static void
 RemoveStyleSheet(EditorBase& aEditor, StyleSheet* aSheet)
 {
-  nsCOMPtr<nsIDocument> doc = aEditor.GetDocument();
-  if (doc) {
-    doc->BeginUpdate(UPDATE_STYLE);
+  if (nsCOMPtr<nsIDocument> doc = aEditor.GetDocument()) {
     doc->RemoveStyleSheet(aSheet);
-    doc->EndUpdate(UPDATE_STYLE);
   }
 }
 
 /******************************************************************************
  * AddStyleSheetTransaction
  ******************************************************************************/
 
 AddStyleSheetTransaction::AddStyleSheetTransaction(EditorBase& aEditorBase,
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -1437,17 +1437,17 @@ nsIPresShell::GetRefreshDriver() const
   return mPresContext ? mPresContext->RefreshDriver() : nullptr;
 }
 
 void
 nsIPresShell::SetAuthorStyleDisabled(bool aStyleDisabled)
 {
   if (aStyleDisabled != mStyleSet->GetAuthorStyleDisabled()) {
     mStyleSet->SetAuthorStyleDisabled(aStyleDisabled);
-    RestyleForCSSRuleChanges();
+    ApplicableStylesChanged();
 
     nsCOMPtr<nsIObserverService> observerService =
       mozilla::services::GetObserverService();
     if (observerService) {
       observerService->NotifyObservers(mDocument,
                                        "author-style-disabled-changed",
                                        nullptr);
     }
@@ -1537,50 +1537,50 @@ PresShell::AddUserSheet(StyleSheet* aShe
   }
 
   // Now iterate backwards, so that the order of userSheets will be the same as
   // the order of sheets from it in the style set.
   for (StyleSheet* sheet : Reversed(userSheets)) {
     mStyleSet->PrependStyleSheet(SheetType::User, sheet);
   }
 
-  RestyleForCSSRuleChanges();
+  ApplicableStylesChanged();
 }
 
 void
 PresShell::AddAgentSheet(StyleSheet* aSheet)
 {
   // Make sure this does what nsDocumentViewer::CreateStyleSet does
   // wrt ordering.
   mStyleSet->AppendStyleSheet(SheetType::Agent, aSheet);
-  RestyleForCSSRuleChanges();
+  ApplicableStylesChanged();
 }
 
 void
 PresShell::AddAuthorSheet(StyleSheet* aSheet)
 {
   // Document specific "additional" Author sheets should be stronger than the
   // ones added with the StyleSheetService.
   StyleSheet* firstAuthorSheet =
     mDocument->GetFirstAdditionalAuthorSheet();
   if (firstAuthorSheet) {
     mStyleSet->InsertStyleSheetBefore(SheetType::Doc, aSheet,
                                       firstAuthorSheet);
   } else {
     mStyleSet->AppendStyleSheet(SheetType::Doc, aSheet);
   }
 
-  RestyleForCSSRuleChanges();
+  ApplicableStylesChanged();
 }
 
 void
 PresShell::RemoveSheet(SheetType aType, StyleSheet* aSheet)
 {
   mStyleSet->RemoveStyleSheet(aType, aSheet);
-  RestyleForCSSRuleChanges();
+  ApplicableStylesChanged();
 }
 
 NS_IMETHODIMP
 PresShell::SetDisplaySelection(int16_t aToggle)
 {
   RefPtr<nsFrameSelection> frameSelection = mSelection;
   frameSelection->SetDisplaySelection(aToggle);
   return NS_OK;
@@ -2517,26 +2517,16 @@ PresShell::GetPageSequenceFrame() const
 nsCanvasFrame*
 PresShell::GetCanvasFrame() const
 {
   nsIFrame* frame = mFrameConstructor->GetDocElementContainingBlock();
   return do_QueryFrame(frame);
 }
 
 void
-PresShell::EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType)
-{
-  if (aUpdateType & UPDATE_STYLE) {
-    if (mStyleSet->StyleSheetsHaveChanged()) {
-      RestyleForCSSRuleChanges();
-    }
-  }
-}
-
-void
 PresShell::RestoreRootScrollPosition()
 {
   nsIScrollableFrame* scrollableFrame = GetRootScrollFrameAsScrollable();
   if (scrollableFrame) {
     scrollableFrame->ScrollToRestoredPosition();
   }
 }
 
@@ -4586,37 +4576,31 @@ PresShell::ReconstructFrames()
     return;
   }
 
   nsAutoCauseReflowNotifier crNotifier(this);
   mFrameConstructor->ReconstructDocElementHierarchy(nsCSSFrameConstructor::InsertionKind::Sync);
 }
 
 void
-nsIPresShell::RestyleForCSSRuleChanges()
+nsIPresShell::ApplicableStylesChanged()
 {
   if (mIsDestroying) {
     // We don't want to mess with restyles at this point
     return;
   }
 
   EnsureStyleFlush();
   mDocument->MarkUserFontSetDirty();
 
   if (mPresContext) {
     mPresContext->MarkCounterStylesDirty();
     mPresContext->MarkFontFeatureValuesDirty();
-  }
-
-  if (!mDidInitialize) {
-    // Nothing to do here, since we have no frames yet
-    return;
-  }
-
-  mStyleSet->InvalidateStyleForCSSRuleChanges();
+    mPresContext->RestyleManager()->NextRestyleIsForCSSRuleChanges();
+  }
 }
 
 nsresult
 PresShell::RenderDocument(const nsRect& aRect, uint32_t aFlags,
                           nscolor aBackgroundColor,
                           gfxContext* aThebesContext)
 {
   NS_ENSURE_TRUE(!(aFlags & RENDER_IS_UNTRUSTED), NS_ERROR_NOT_IMPLEMENTED);
@@ -6157,16 +6141,17 @@ private:
   PresShell* mShell;
   uint32_t mFlags;
 };
 
 void
 nsIPresShell::RecordShadowStyleChange(ShadowRoot& aShadowRoot)
 {
   mStyleSet->RecordShadowStyleChange(aShadowRoot);
+  ApplicableStylesChanged();
 }
 
 void
 PresShell::Paint(nsView*         aViewToPaint,
                  const nsRegion& aDirtyRegion,
                  uint32_t        aFlags)
 {
 #ifdef MOZ_GECKO_PROFILER
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -278,17 +278,16 @@ public:
   NS_IMETHOD CompleteScroll(bool aForward) override;
   NS_IMETHOD CompleteMove(bool aForward, bool aExtend) override;
   NS_IMETHOD SelectAll() override;
   NS_IMETHOD CheckVisibility(nsIDOMNode *node, int16_t startOffset, int16_t EndOffset, bool *_retval) override;
   nsresult CheckVisibilityContent(nsIContent* aNode, int16_t aStartOffset,
                                   int16_t aEndOffset, bool* aRetval) override;
 
   // nsIDocumentObserver
-  NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE
   NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD
   NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD
   NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED
   NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -2187,23 +2187,16 @@ RestyleManager::PostRestyleEvent(Element
   }
 
   if (aRestyleHint || aMinChangeHint) {
     Servo_NoteExplicitHints(aElement, aRestyleHint, aMinChangeHint);
   }
 }
 
 void
-RestyleManager::PostRestyleEventForCSSRuleChanges()
-{
-  mRestyleForCSSRuleChanges = true;
-  mPresContext->PresShell()->EnsureStyleFlush();
-}
-
-void
 RestyleManager::PostRestyleEventForAnimations(
   Element* aElement,
   CSSPseudoElementType aPseudoType,
   nsRestyleHint aRestyleHint)
 {
   Element* elementToRestyle =
     EffectCompositor::GetElementToRestyle(aElement, aPseudoType);
 
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -331,17 +331,20 @@ public:
    * style flush is needed since this function is supposed to be called during
    * restyling process and this restyle event will be processed in the second
    * traversal of the same restyling process.
    */
   void PostRestyleEventForAnimations(dom::Element*,
                                      CSSPseudoElementType,
                                      nsRestyleHint);
 
-  void PostRestyleEventForCSSRuleChanges();
+  void NextRestyleIsForCSSRuleChanges()
+  {
+    mRestyleForCSSRuleChanges = true;
+  }
 
   void RebuildAllStyleData(nsChangeHint aExtraHint, nsRestyleHint aRestyleHint);
   void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
                                     nsRestyleHint aRestyleHint);
 
   void ProcessPendingRestyles();
   void ProcessAllPendingAttributeAndStateInvalidations();
 
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -286,36 +286,21 @@ public:
   /* Enable/disable author style level. Disabling author style disables the entire
    * author level of the cascade, including the HTML preshint level.
    */
   // XXX these could easily be inlined, but there is a circular #include
   // problem with nsStyleSet.
   void SetAuthorStyleDisabled(bool aDisabled);
   bool GetAuthorStyleDisabled() const;
 
-  /*
-   * Called when stylesheets are added/removed/enabled/disabled to
-   * recompute style and clear other cached data as needed.  This will
-   * not reconstruct style synchronously; if you need to do that, call
-   * FlushPendingNotifications to flush out style reresolves.
-   *
-   * This handles the the addition and removal of the various types of
-   * style rules that can be in CSS style sheets, such as @font-face
-   * rules and @counter-style rules.
-   *
-   * It requires that StyleSheetAdded, StyleSheetRemoved,
-   * StyleSheetApplicableStateChanged, StyleRuleAdded, StyleRuleRemoved,
-   * or StyleRuleChanged has been called on the style sheets that have
-   * changed.
-   *
-   * // XXXbz why do we have this on the interface anyway?  The only consumer
-   * is calling AddOverrideStyleSheet/RemoveOverrideStyleSheet, and I think
-   * those should just handle reconstructing style data...
+  /**
+   * Needs to be called any time the applicable style can has changed, in order
+   * to schedule a style flush and setup all the relevant state.
    */
-  void RestyleForCSSRuleChanges();
+  void ApplicableStylesChanged();
 
   /**
    * Update the style set somehow to take into account changed prefs which
    * affect document styling.
    */
   virtual void UpdatePreferenceStyles() = 0;
 
   /**
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1217,19 +1217,17 @@ Loader::InsertSheetInDoc(StyleSheet* aSh
   // XXX <meta> elements do not implement nsIStyleSheetLinkingElement;
   // need to fix this for them to be ordered correctly.
   nsCOMPtr<nsIStyleSheetLinkingElement>
     linkingElement = do_QueryInterface(aLinkingContent);
   if (linkingElement) {
     linkingElement->SetStyleSheet(aSheet); // This sets the ownerNode on the sheet
   }
 
-  aDocument->BeginUpdate(UPDATE_STYLE);
   aDocument->InsertStyleSheetAt(aSheet, insertionPoint);
-  aDocument->EndUpdate(UPDATE_STYLE);
   LOG(("  Inserting into document at position %d", insertionPoint));
 
   return NS_OK;
 }
 
 /**
  * InsertChildSheet handles ordering of @import-ed sheet in their
  * parent sheets.  Here we want to just insert based on order of the
--- a/layout/style/MediaList.cpp
+++ b/layout/style/MediaList.cpp
@@ -40,19 +40,16 @@ MediaList::SetStyleSheet(StyleSheet* aSh
              "Multiple style sheets competing for one media list");
   mStyleSheet = aSheet;
 }
 
 template<typename Func>
 nsresult
 MediaList::DoMediaChange(Func aCallback)
 {
-  nsIDocument* doc =
-    mStyleSheet ? mStyleSheet->GetComposedDoc() : nullptr;
-  mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true);
   if (mStyleSheet) {
     mStyleSheet->WillDirty();
   }
 
   nsresult rv = aCallback();
   if (NS_FAILED(rv)) {
     return rv;
   }
--- a/layout/style/ServoCounterStyleRule.cpp
+++ b/layout/style/ServoCounterStyleRule.cpp
@@ -53,17 +53,16 @@ ServoCounterStyleRule::GetName(nsAString
   nsStyleUtil::AppendEscapedCSSIdent(nameStr, aName);
 }
 
 void
 ServoCounterStyleRule::SetName(const nsAString& aName)
 {
   NS_ConvertUTF16toUTF8 name(aName);
   if (Servo_CounterStyleRule_SetName(mRawRule, &name)) {
-    MOZ_AUTO_DOC_UPDATE(GetComposedDoc(), UPDATE_STYLE, true);
     if (StyleSheet* sheet = GetStyleSheet()) {
       sheet->RuleChanged(this);
     }
   }
 }
 
 #define CSS_COUNTER_DESC(name_, method_)                        \
   void                                                          \
@@ -74,17 +73,16 @@ ServoCounterStyleRule::SetName(const nsA
       mRawRule, eCSSCounterDesc_##method_, &aValue);            \
   }                                                             \
   void                                                          \
   ServoCounterStyleRule::Set##method_(const nsAString& aValue)  \
   {                                                             \
     NS_ConvertUTF16toUTF8 value(aValue);                        \
     if (Servo_CounterStyleRule_SetDescriptor(                   \
           mRawRule, eCSSCounterDesc_##method_, &value)) {       \
-      MOZ_AUTO_DOC_UPDATE(GetComposedDoc(), UPDATE_STYLE, true);\
       if (StyleSheet* sheet = GetStyleSheet()) {                \
         sheet->RuleChanged(this);                               \
       }                                                         \
     }                                                           \
   }
 #include "nsCSSCounterDescList.h"
 #undef CSS_COUNTER_DESC
 
--- a/layout/style/ServoKeyframeRule.cpp
+++ b/layout/style/ServoKeyframeRule.cpp
@@ -144,18 +144,16 @@ ServoKeyframeRule::List(FILE* out, int32
   fprintf_stderr(out, "%s\n", str.get());
 }
 #endif
 
 template<typename Func>
 void
 ServoKeyframeRule::UpdateRule(Func aCallback)
 {
-  MOZ_AUTO_DOC_UPDATE(GetComposedDoc(), UPDATE_STYLE, true);
-
   aCallback();
 
   if (StyleSheet* sheet = GetStyleSheet()) {
     sheet->RuleChanged(this);
   }
 }
 
 void
--- a/layout/style/ServoKeyframesRule.cpp
+++ b/layout/style/ServoKeyframesRule.cpp
@@ -227,20 +227,17 @@ ServoKeyframesRule::FindRuleIndexForKey(
   NS_ConvertUTF16toUTF8 key(aKey);
   return Servo_KeyframesRule_FindRule(mRawRule, &key);
 }
 
 template<typename Func>
 void
 ServoKeyframesRule::UpdateRule(Func aCallback)
 {
-  MOZ_AUTO_DOC_UPDATE(GetComposedDoc(), UPDATE_STYLE, true);
-
   aCallback();
-
   if (StyleSheet* sheet = GetStyleSheet()) {
     sheet->RuleChanged(this);
   }
 }
 
 void
 ServoKeyframesRule::GetName(nsAString& aName) const
 {
--- a/layout/style/ServoStyleRule.cpp
+++ b/layout/style/ServoStyleRule.cpp
@@ -67,17 +67,16 @@ ServoStyleRuleDeclaration::GetCSSDeclara
   return mDecls;
 }
 
 nsresult
 ServoStyleRuleDeclaration::SetCSSDeclaration(DeclarationBlock* aDecl)
 {
   ServoStyleRule* rule = Rule();
   if (RefPtr<StyleSheet> sheet = rule->GetStyleSheet()) {
-    mozAutoDocUpdate updateBatch(sheet->GetComposedDoc(), UPDATE_STYLE, true);
     if (aDecl != mDecls) {
       mDecls->SetOwningRule(nullptr);
       RefPtr<ServoDeclarationBlock> decls = aDecl->AsServo();
       Servo_StyleRule_SetStyle(rule->Raw(), decls->Raw());
       mDecls = decls.forget();
       mDecls->SetOwningRule(rule);
     }
     sheet->RuleChanged(rule);
@@ -191,18 +190,16 @@ ServoStyleRule::GetSelectorText(nsAStrin
 {
   Servo_StyleRule_GetSelectorText(mRawRule, &aSelectorText);
 }
 
 void
 ServoStyleRule::SetSelectorText(const nsAString& aSelectorText)
 {
   if (RefPtr<StyleSheet> sheet = GetStyleSheet()) {
-    mozAutoDocUpdate updateBatch(sheet->GetComposedDoc(), UPDATE_STYLE, true);
-
     // StyleRule lives inside of the Inner, it is unsafe to call WillDirty
     // if sheet does not already have a unique Inner.
     sheet->AssertHasUniqueInner();
     sheet->WillDirty();
 
     const RawServoStyleSheetContents* contents = sheet->RawContents();
     if (Servo_StyleRule_SetSelectorText(contents, mRawRule, &aSelectorText)) {
       sheet->RuleChanged(this);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -190,25 +190,16 @@ ServoStyleSet::Shutdown()
   // Make sure we drop our cached styles before the presshell arena starts going
   // away.
   ClearNonInheritingComputedStyles();
   mRawSet = nullptr;
   mStyleRuleMap = nullptr;
 }
 
 void
-ServoStyleSet::InvalidateStyleForCSSRuleChanges()
-{
-  MOZ_ASSERT(StylistNeedsUpdate());
-  if (nsPresContext* pc = GetPresContext()) {
-    pc->RestyleManager()->PostRestyleEventForCSSRuleChanges();
-  }
-}
-
-void
 ServoStyleSet::RecordShadowStyleChange(ShadowRoot& aShadowRoot)
 {
   // TODO(emilio): We could keep track of the actual shadow roots that need
   // their styles recomputed.
   SetStylistXBLStyleSheetsDirty();
 
   // FIXME(emilio): This should be done using stylesheet invalidation instead.
   if (nsPresContext* pc = GetPresContext()) {
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -128,18 +128,16 @@ public:
   // Evaluates a given SourceSizeList, returning the optimal viewport width in
   // app units.
   //
   // The SourceSizeList parameter can be null, in which case it will return
   // 100vw.
   inline nscoord EvaluateSourceSizeList(
       const RawServoSourceSizeList* aSourceSizeList) const;
 
-  void InvalidateStyleForCSSRuleChanges();
-
   void AddSizeOfIncludingThis(nsWindowSizes& aSizes) const;
   const RawServoStyleSet* RawSet() const {
     return mRawSet.get();
   }
 
   bool GetAuthorStyleDisabled() const
   {
     return mAuthorStyleDisabled;
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -255,20 +255,17 @@ StyleSheet::ApplicableStateChanged(bool 
   if (!mDocumentOrShadowRoot) {
     return;
   }
 
   nsINode& node = mDocumentOrShadowRoot->AsNode();
   if (auto* shadow = ShadowRoot::FromNode(node)) {
     shadow->StyleSheetApplicableStateChanged(*this, aApplicable);
   } else {
-    nsIDocument* doc = node.AsDocument();
-    doc->BeginUpdate(UPDATE_STYLE);
-    doc->SetStyleSheetApplicableState(this, aApplicable);
-    doc->EndUpdate(UPDATE_STYLE);
+    node.AsDocument()->SetStyleSheetApplicableState(this, aApplicable);
   }
 }
 
 void
 StyleSheet::SetEnabled(bool aEnabled)
 {
   // Internal method, so callers must handle BeginUpdate/EndUpdate
   bool oldDisabled = mDisabled;
@@ -396,18 +393,16 @@ void
 StyleSheet::GetType(nsAString& aType)
 {
   aType.AssignLiteral("text/css");
 }
 
 void
 StyleSheet::SetDisabled(bool aDisabled)
 {
-  // DOM method, so handle BeginUpdate/EndUpdate
-  MOZ_AUTO_DOC_UPDATE(GetComposedDoc(), UPDATE_STYLE, true);
   SetEnabled(!aDisabled);
 }
 
 void
 StyleSheet::GetHref(nsAString& aHref, ErrorResult& aRv)
 {
   if (nsIURI* sheetURI = Inner().mOriginalSheetURI) {
     nsAutoCString str;
@@ -580,18 +575,16 @@ StyleSheet::DeleteRuleFromGroup(css::Gro
   RefPtr<css::Rule> rule = aGroup->GetStyleRuleAt(aIndex);
   NS_ENSURE_TRUE(rule, NS_ERROR_ILLEGAL_VALUE);
 
   // check that the rule actually belongs to this sheet!
   if (this != rule->GetStyleSheet()) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
-
   WillDirty();
 
   nsresult result = aGroup->DeleteStyleRuleAt(aIndex);
   NS_ENSURE_SUCCESS(result, result);
 
   rule->SetStyleSheet(nullptr);
   RuleRemoved(*rule);
   return NS_OK;
@@ -661,25 +654,21 @@ StyleSheet::InsertRuleIntoGroup(const ns
                                 uint32_t aIndex)
 {
   NS_ASSERTION(IsComplete(), "No inserting into an incomplete sheet!");
   // check that the group actually belongs to this sheet!
   if (this != aGroup->GetStyleSheet()) {
     return NS_ERROR_INVALID_ARG;
   }
 
-  // parse and grab the rule
-  mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
-
   WillDirty();
 
   nsresult result = InsertRuleIntoGroupInternal(aRule, aGroup, aIndex);
   NS_ENSURE_SUCCESS(result, result);
   RuleAdded(*aGroup->GetStyleRuleAt(aIndex));
-
   return NS_OK;
 }
 
 uint64_t
 StyleSheet::FindOwningWindowInnerID() const
 {
   uint64_t windowID = 0;
   if (nsIDocument* doc = GetOwnerDoc()) {
@@ -1120,18 +1109,16 @@ StyleSheet::ReparseSheet(const nsAString
   RefPtr<css::Loader> loader;
   if (nsIDocument* doc = GetOwnerDoc()) {
     loader = doc->CSSLoader();
     NS_ASSERTION(loader, "Document with no CSS loader!");
   } else {
     loader = new css::Loader;
   }
 
-  mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
-
   WillDirty();
 
   // cache child sheets to reuse
   css::LoaderReusableStyleSheets reusableSheets;
   for (StyleSheet* child = GetFirstChild(); child; child = child->mNext) {
     if (child->GetOriginalURI()) {
       reusableSheets.AddReusableSheet(child);
     }
@@ -1213,17 +1200,16 @@ StyleSheet::StyleSheetLoaded(StyleSheet*
 {
   if (!aSheet->GetParentSheet()) {
     return NS_OK; // ignore if sheet has been detached already
   }
   NS_ASSERTION(this == aSheet->GetParentSheet(),
                "We are being notified of a sheet load for a sheet that is not our child!");
 
   if (NS_SUCCEEDED(aStatus)) {
-    mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
     RuleAdded(*aSheet->GetOwnerRule());
   }
 
   return NS_OK;
 }
 
 void
 StyleSheet::DropRuleList()
@@ -1266,17 +1252,16 @@ StyleSheet::GetCssRulesInternal()
 uint32_t
 StyleSheet::InsertRuleInternal(const nsAString& aRule,
                                uint32_t aIndex,
                                ErrorResult& aRv)
 {
   // Ensure mRuleList is constructed.
   GetCssRulesInternal();
 
-  mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
   aRv = mRuleList->InsertRule(aRule, aIndex);
   if (aRv.Failed()) {
     return 0;
   }
 
   // XXX We may not want to get the rule when stylesheet change event
   // is not enabled.
   css::Rule* rule = mRuleList->GetRule(aIndex);
@@ -1293,17 +1278,16 @@ StyleSheet::DeleteRuleInternal(uint32_t 
 {
   // Ensure mRuleList is constructed.
   GetCssRulesInternal();
   if (aIndex >= mRuleList->Length()) {
     aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
-  mozAutoDocUpdate updateBatch(GetComposedDoc(), UPDATE_STYLE, true);
   // Hold a strong ref to the rule so it doesn't die when we remove it
   // from the list. XXX We may not want to hold it if stylesheet change
   // event is not enabled.
   RefPtr<css::Rule> rule = mRuleList->GetRule(aIndex);
   aRv = mRuleList->DeleteRule(aIndex);
   MOZ_ASSERT(!aRv.ErrorCodeIs(NS_ERROR_DOM_INDEX_SIZE_ERR),
              "IndexSizeError should have been handled earlier");
   if (!aRv.Failed()) {