Bug 1439027: Simplify PresShell::Initialize. r?bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 16 Feb 2018 20:34:46 +0100
changeset 756440 446cbd57af22697166872b2f72c8cd6ce7190142
parent 756439 f365c94a0cf2d0fdd2523ea246b6989466edeb7c
push id99490
push userbmo:emilio@crisal.io
push dateSat, 17 Feb 2018 00:02:16 +0000
reviewersbz
bugs1439027
milestone60.0a1
Bug 1439027: Simplify PresShell::Initialize. r?bz Most of the callers pass the already-existing pres-context visible area. The few that don't can set it themselves. MozReview-Commit-ID: KRi4ShrgOrE
dom/base/nsContentSink.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/html/MediaDocument.cpp
dom/xul/XULDocument.cpp
gfx/thebes/gfxSVGGlyphs.cpp
layout/base/PresShell.cpp
layout/base/PresShell.h
layout/base/nsDocumentViewer.cpp
layout/base/nsIPresShell.h
layout/printing/nsPrintJob.cpp
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -1260,19 +1260,18 @@ nsContentSink::StartLayout(bool aIgnoreP
   mDocument->SetMayStartLayout(true);
   nsCOMPtr<nsIPresShell> shell = mDocument->GetShell();
   // Make sure we don't call Initialize() for a shell that has
   // already called it. This can happen when the layout frame for
   // an iframe is constructed *between* the Embed() call for the
   // docshell in the iframe, and the content sink's call to OpenBody().
   // (Bug 153815)
   if (shell && !shell->DidInitialize()) {
-    nsRect r = shell->GetPresContext()->GetVisibleArea();
     nsCOMPtr<nsIPresShell> shellGrip = shell;
-    nsresult rv = shell->Initialize(r.Width(), r.Height());
+    nsresult rv = shell->Initialize();
     if (NS_FAILED(rv)) {
       return;
     }
   }
 
   // If the document we are loading has a reference or it is a
   // frameset document, disable the scroll bars on the views.
 
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -1368,18 +1368,17 @@ nsGlobalWindowOuter::SetInitialPrincipal
     mDoc->SetIsInitialDocument(true);
   }
 
   nsCOMPtr<nsIPresShell> shell = GetDocShell()->GetPresShell();
 
   if (shell && !shell->DidInitialize()) {
     // Ensure that if someone plays with this document they will get
     // layout happening.
-    nsRect r = shell->GetPresContext()->GetVisibleArea();
-    shell->Initialize(r.Width(), r.Height());
+    shell->Initialize();
   }
 }
 
 PopupControlState
 nsGlobalWindowOuter::PushPopupControlState(PopupControlState aState,
                                            bool aForce) const
 {
   return nsContentUtils::PushPopupControlState(aState, aForce);
--- a/dom/html/MediaDocument.cpp
+++ b/dom/html/MediaDocument.cpp
@@ -257,18 +257,17 @@ MediaDocument::CreateSyntheticDocument()
 nsresult
 MediaDocument::StartLayout()
 {
   mMayStartLayout = true;
   nsCOMPtr<nsIPresShell> shell = GetShell();
   // Don't mess with the presshell if someone has already handled
   // its initial reflow.
   if (shell && !shell->DidInitialize()) {
-    nsRect visibleArea = shell->GetPresContext()->GetVisibleArea();
-    nsresult rv = shell->Initialize(visibleArea.width, visibleArea.height);
+    nsresult rv = shell->Initialize();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 void
 MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel)
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -1571,19 +1571,17 @@ XULDocument::StartLayout(void)
         if (! cx)
             return NS_ERROR_UNEXPECTED;
 
         nsCOMPtr<nsIDocShell> docShell = cx->GetDocShell();
         NS_ASSERTION(docShell != nullptr, "container is not a docshell");
         if (! docShell)
             return NS_ERROR_UNEXPECTED;
 
-        nsresult rv = NS_OK;
-        nsRect r = cx->GetVisibleArea();
-        rv = shell->Initialize(r.width, r.height);
+        nsresult rv = shell->Initialize();
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     return NS_OK;
 }
 
 /* static */
 bool
--- a/gfx/thebes/gfxSVGGlyphs.cpp
+++ b/gfx/thebes/gfxSVGGlyphs.cpp
@@ -153,18 +153,17 @@ gfxSVGGlyphsDocument::SetupPresentation(
         rv = viewer->Open(nullptr, nullptr);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     nsCOMPtr<nsIPresShell> presShell;
     rv = viewer->GetPresShell(getter_AddRefs(presShell));
     NS_ENSURE_SUCCESS(rv, rv);
     if (!presShell->DidInitialize()) {
-        nsRect rect = presShell->GetPresContext()->GetVisibleArea();
-        rv = presShell->Initialize(rect.Width(), rect.Height());
+        rv = presShell->Initialize();
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     mDocument->FlushPendingNotifications(FlushType::Layout);
 
     if (mDocument->HasAnimationController()) {
       mDocument->GetAnimationController()
                ->Resume(nsSMILTimeContainer::PAUSE_IMAGE);
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -1725,17 +1725,17 @@ public:
     return NS_OK;
   }
 
 private:
   nsCOMPtr<nsIDocument> mDocument;
 };
 
 nsresult
-PresShell::Initialize(nscoord aWidth, nscoord aHeight)
+PresShell::Initialize()
 {
   if (mIsDestroying) {
     return NS_OK;
   }
 
   if (!mDocument) {
     // Nothing to do
     return NS_OK;
@@ -1759,21 +1759,16 @@ PresShell::Initialize(nscoord aWidth, ns
       if (uri) {
         printf("*** PresShell::Initialize (this=%p, url='%s')\n",
                (void*)this, uri->GetSpecOrDefault().get());
       }
     }
   }
 #endif
 
-  // XXX Do a full invalidate at the beginning so that invalidates along
-  // the way don't have region accumulation issues?
-
-  mPresContext->SetVisibleArea(nsRect(0, 0, aWidth, aHeight));
-
   // Get the root frame from the frame manager
   // XXXbz it would be nice to move this somewhere else... like frame manager
   // Init(), say.  But we need to make sure our views are all set up by the
   // time we do this!
   nsIFrame* rootFrame = mFrameConstructor->GetRootFrame();
   NS_ASSERTION(!rootFrame, "How did that happen, exactly?");
 
   if (!rootFrame) {
@@ -9763,18 +9758,17 @@ PresShell::VerifyIncrementalReflow()
   rv = view->CreateWidgetForParent(parentWidget, nullptr, true);
   NS_ENSURE_SUCCESS(rv, false);
 
   // Setup hierarchical relationship in view manager
   vm->SetRootView(view);
 
   // Make the new presentation context the same size as our
   // presentation context.
-  nsRect r = mPresContext->GetVisibleArea();
-  cx->SetVisibleArea(r);
+  cx->SetVisibleArea(mPresContext->GetVisibleArea());
 
   // Create a new presentation shell to view the document. Use the
   // exact same style information that this document has.
 #ifdef MOZ_OLD_STYLE
   nsAutoPtr<nsStyleSet> newGeckoSet;
 #endif
   nsAutoPtr<ServoStyleSet> newServoSet;
   StyleSetHandle newSet;
@@ -9795,17 +9789,17 @@ PresShell::VerifyIncrementalReflow()
   newGeckoSet.forget();
 #endif
   newServoSet.forget();
   // Note that after we create the shell, we must make sure to destroy it
   sh->SetVerifyReflowEnable(false); // turn off verify reflow while we're reflowing the test frame tree
   vm->SetPresShell(sh);
   {
     nsAutoCauseReflowNotifier crNotifier(this);
-    sh->Initialize(r.width, r.height);
+    sh->Initialize();
   }
   mDocument->BindingManager()->ProcessAttachedQueue();
   sh->FlushPendingNotifications(FlushType::Layout);
   sh->SetVerifyReflowEnable(true);  // turn on verify reflow again now that we're done reflowing the test frame tree
   // Force the non-primary presshell to unsuppress; it doesn't want to normally
   // because it thinks it's hidden
   ((PresShell*)sh.get())->mPaintingSuppressed = false;
   if (VERIFY_REFLOW_NOISY & gVerifyReflowFlags) {
--- a/layout/base/PresShell.h
+++ b/layout/base/PresShell.h
@@ -103,17 +103,17 @@ public:
 
   NS_IMETHOD SetDisplaySelection(int16_t aToggle) override;
   NS_IMETHOD GetDisplaySelection(int16_t *aToggle) override;
   NS_IMETHOD ScrollSelectionIntoView(RawSelectionType aRawSelectionType,
                                      SelectionRegion aRegion,
                                      int16_t aFlags) override;
   NS_IMETHOD RepaintSelection(RawSelectionType aRawSelectionType) override;
 
-  virtual nsresult Initialize(nscoord aWidth, nscoord aHeight) override;
+  virtual nsresult Initialize() override;
   virtual nsresult ResizeReflow(nscoord aWidth, nscoord aHeight,
                                 nscoord aOldWidth = 0, nscoord aOldHeight = 0,
                                 ResizeReflowOptions aOptions =
                                 ResizeReflowOptions::eBSizeExact) override;
   virtual nsresult ResizeReflowIgnoreOverride(nscoord aWidth, nscoord aHeight,
                                               nscoord aOldWidth, nscoord aOldHeight,
                                               ResizeReflowOptions aOptions =
                                               ResizeReflowOptions::eBSizeExact) override;
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -715,32 +715,29 @@ nsDocumentViewer::InitPresentationStuff(
   // Initialize our view manager
   int32_t p2a = mPresContext->AppUnitsPerDevPixel();
   MOZ_ASSERT(p2a ==
              mPresContext->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
   nscoord width = p2a * mBounds.width;
   nscoord height = p2a * mBounds.height;
 
   mViewManager->SetWindowDimensions(width, height);
+  mPresContext->SetVisibleArea(nsRect(0, 0, width, height));
   mPresContext->SetTextZoom(mTextZoom);
   mPresContext->SetFullZoom(mPageZoom);
   mPresContext->SetOverrideDPPX(mOverrideDPPX);
   mPresContext->SetBaseMinFontSize(mMinFontSize);
 
   p2a = mPresContext->AppUnitsPerDevPixel();  // zoom may have changed it
   width = p2a * mBounds.width;
   height = p2a * mBounds.height;
   if (aDoInitialReflow) {
     nsCOMPtr<nsIPresShell> shell = mPresShell;
     // Initial reflow
-    shell->Initialize(width, height);
-  } else {
-    // Store the visible area so it's available for other callers of
-    // Initialize, like nsContentSink::StartLayout.
-    mPresContext->SetVisibleArea(nsRect(0, 0, width, height));
+    shell->Initialize();
   }
 
   // now register ourselves as a selection listener, so that we get
   // called when the selection changes in the window
   if (!mSelectionListener) {
     nsDocViewerSelectionListener *selectionListener =
       new nsDocViewerSelectionListener();
 
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -358,17 +358,17 @@ public:
    * specified width and height.
    *
    * The coordinates for aWidth and aHeight must be in standard nscoords.
    *
    * Callers of this method must hold a reference to this shell that
    * is guaranteed to survive through arbitrary script execution.
    * Calling Initialize can execute arbitrary script.
    */
-  virtual nsresult Initialize(nscoord aWidth, nscoord aHeight) = 0;
+  virtual nsresult Initialize() = 0;
 
   enum class ResizeReflowOptions : uint32_t {
     // the resulting BSize should be exactly as given
     eBSizeExact,
     // the resulting BSize can be less than the given one, producing
     // shrink-to-fit sizing in the block dimension
     eBSizeLimit
   };
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2383,30 +2383,31 @@ nsPrintJob::ReflowPrintObject(const Uniq
 
   // This docshell stuff is weird; will go away when we stop having multiple
   // presentations per document
   aPO->mPresContext->SetContainer(aPO->mDocShell);
 
   aPO->mPresShell->BeginObservingDocument();
 
   aPO->mPresContext->SetPageSize(adjSize);
+  aPO->mPresContext->SetVisibleArea(nsRect(0, 0, adjSize.width, adjSize.height));
   aPO->mPresContext->SetIsRootPaginatedDocument(documentIsTopLevel);
   aPO->mPresContext->SetPageScale(aPO->mZoomRatio);
   // Calculate scale factor from printer to screen
   float printDPI = float(printData->mPrintDC->AppUnitsPerCSSInch()) /
                      float(printData->mPrintDC->AppUnitsPerDevPixel());
   aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI);
 
   if (mIsCreatingPrintPreview && documentIsTopLevel) {
     mDocViewerPrint->SetPrintPreviewPresentation(aPO->mViewManager,
                                                  aPO->mPresContext,
                                                  aPO->mPresShell);
   }
 
-  rv = aPO->mPresShell->Initialize(adjSize.width, adjSize.height);
+  rv = aPO->mPresShell->Initialize();
 
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ASSERTION(aPO->mPresShell, "Presshell should still be here");
 
   // Process the reflow event Initialize posted
   aPO->mPresShell->FlushPendingNotifications(FlushType::Layout);
 
   rv = UpdateSelectionAndShrinkPrintObject(aPO.get(), documentIsTopLevel);