Bug 1395719: Make ReconstructDocElementHierarchy take an InsertionKind. draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 07 Sep 2017 13:38:41 +0200
changeset 660778 10fba0f2091399f31c1cb9b920a52dc91eaa0fa5
parent 660738 37b95547f0d27565452136d16b2df2857be840f6
child 660779 e245bd8139500f6020faedf73315170d3fef426f
push id78527
push userbmo:emilio@crisal.io
push dateThu, 07 Sep 2017 14:05:42 +0000
bugs1395719
milestone57.0a1
Bug 1395719: Make ReconstructDocElementHierarchy take an InsertionKind. Otherwise we may unexpectedly sync-construct it. MozReview-Commit-ID: LybB06img71
layout/base/PresShell.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4549,17 +4549,17 @@ PresShell::ReconstructFrames()
   mDocument->FlushPendingNotifications(FlushType::Style);
 
   if (mIsDestroying) {
     return;
   }
 
   nsAutoCauseReflowNotifier crNotifier(this);
   mFrameConstructor->BeginUpdate();
-  mFrameConstructor->ReconstructDocElementHierarchy();
+  mFrameConstructor->ReconstructDocElementHierarchy(nsCSSFrameConstructor::InsertionKind::Sync);
   VERIFY_STYLE_TREE;
   mFrameConstructor->EndUpdate();
 }
 
 void
 nsIPresShell::RestyleForCSSRuleChanges()
 {
   if (mIsDestroying) {
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -6408,24 +6408,24 @@ nsCSSFrameConstructor::ConstructFramesFr
 
 inline bool
 IsRootBoxFrame(nsIFrame *aFrame)
 {
   return (aFrame->IsRootFrame());
 }
 
 void
-nsCSSFrameConstructor::ReconstructDocElementHierarchy()
+nsCSSFrameConstructor::ReconstructDocElementHierarchy(InsertionKind aInsertionKind)
 {
   Element* rootElement = mDocument->GetRootElement();
   if (!rootElement) {
     /* nothing to do */
     return;
   }
-  RecreateFramesForContent(rootElement, InsertionKind::Sync);
+  RecreateFramesForContent(rootElement, aInsertionKind);
 }
 
 nsContainerFrame*
 nsCSSFrameConstructor::GetAbsoluteContainingBlock(nsIFrame* aFrame,
                                                   ContainingBlockType aType)
 {
   // Starting with aFrame, look for a frame that is absolutely positioned or
   // relatively positioned (and transformed, if aType is FIXED)
@@ -8966,17 +8966,17 @@ nsCSSFrameConstructor::EnsureFrameForTex
       !mAlwaysCreateFramesForIgnorableWhitespace) {
     // Text frame may have been suppressed. Disable suppression and signal
     // that a flush should be performed. We do this on a document-wide
     // basis so that pages that repeatedly query metrics for
     // collapsed-whitespace text nodes don't trigger pathological behavior.
     mAlwaysCreateFramesForIgnorableWhitespace = true;
     nsAutoScriptBlocker blocker;
     BeginUpdate();
-    ReconstructDocElementHierarchy();
+    ReconstructDocElementHierarchy(InsertionKind::Sync);
     EndUpdate();
   }
   return aContent->GetPrimaryFrame();
 }
 
 void
 nsCSSFrameConstructor::CharacterDataChanged(nsIContent* aContent,
                                             CharacterDataChangeInfo* aInfo)
@@ -9877,17 +9877,17 @@ nsCSSFrameConstructor::MaybeRecreateCont
     RecreateFramesForContent(parent->GetParent()->GetContent(), aInsertionKind);
     return true;
   }
 
 #ifdef MOZ_XUL
   if (aFrame->IsPopupSetFrame()) {
     nsIRootBox* rootBox = nsIRootBox::GetRootBox(mPresShell);
     if (rootBox && rootBox->GetPopupSetFrame() == aFrame) {
-      ReconstructDocElementHierarchy();
+      ReconstructDocElementHierarchy(aInsertionKind);
       return true;
     }
   }
 #endif
 
   // Reconstruct if inflowFrame is parent's only child, and parent is, or has,
   // a non-fluid continuation, i.e. it was split by bidi resolution
   if (!inFlowFrame->GetPrevSibling() &&
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -69,22 +69,35 @@ public:
                                   nsIAtom* aTag,  // content object's tag
                                   nsAString& aAltText);
 
 private:
   nsCSSFrameConstructor(const nsCSSFrameConstructor& aCopy) = delete;
   nsCSSFrameConstructor& operator=(const nsCSSFrameConstructor& aCopy) = delete;
 
 public:
+  /**
+   * Whether insertion should be done synchronously or asynchronously.
+   *
+   * Generally, insertion is synchronous if we're reconstructing something from
+   * frame construction/reconstruction, and async if we're removing stuff, like
+   * from ContentRemoved.
+   */
+  enum class InsertionKind
+  {
+    Sync,
+    Async,
+  };
+
   mozilla::RestyleManager* RestyleManager() const
     { return mPresShell->GetPresContext()->RestyleManager(); }
 
   nsIFrame* ConstructRootFrame();
 
-  void ReconstructDocElementHierarchy();
+  void ReconstructDocElementHierarchy(InsertionKind);
 
   // Create frames for content nodes that are marked as needing frames. This
   // should be called before ProcessPendingRestyles.
   // Note: It's the caller's responsibility to make sure to wrap a
   // CreateNeededFrames call in a view update batch and a script blocker.
   void CreateNeededFrames();
 
 private:
@@ -294,29 +307,16 @@ private:
                             nsIContent* aStartChild,
                             nsIContent* aEndChild,
                             nsILayoutHistoryState* aFrameState,
                             bool aAllowLazyConstruction,
                             bool aForReconstruction,
                             TreeMatchContext* aProvidedTreeMatchContext);
 
 public:
-  /**
-   * Whether insertion should be done synchronously or asynchronously.
-   *
-   * Generally, insertion is synchronous if we're reconstructing something from
-   * frame construction/reconstruction, and async if we're removing stuff, like
-   * from ContentRemoved.
-   */
-  enum class InsertionKind
-  {
-    Sync,
-    Async,
-  };
-
   enum RemoveFlags {
     REMOVE_CONTENT,
     REMOVE_FOR_RECONSTRUCTION,
   };
 
   /**
    * Recreate or destroy frames for aChild in aContainer.
    *