Bug 1166147 - Part2: Convert physical co-ordinates to logical co-ordinates for nsSimplePageSequenceFrame. r?dholbert draft
authorNeerja Pancholi <npancholi@mozilla.com>
Sun, 29 Jan 2017 23:30:05 -0800
changeset 468253 ab4d166996b632f148101de309bf5be1ae079a20
parent 468169 eed3bd2c649e574e241dc4689b722dabf4e7cbc5
child 468254 dcc6a72a96af4e2d0609d981f7e985ffea536d34
child 468256 9fd0800f2e39e5eb513fcbe875bdcb6d543a6577
push id43400
push userbmo:npancholi@mozilla.com
push dateMon, 30 Jan 2017 23:20:59 +0000
reviewersdholbert
bugs1166147
milestone54.0a1
Bug 1166147 - Part2: Convert physical co-ordinates to logical co-ordinates for nsSimplePageSequenceFrame. r?dholbert MozReview-Commit-ID: FAETDfZOyfh
layout/generic/nsSimplePageSequenceFrame.cpp
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -81,24 +81,29 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContaine
 //----------------------------------------------------------------------
 
 void
 nsSimplePageSequenceFrame::SetDesiredSize(ReflowOutput& aDesiredSize,
                                           const ReflowInput& aReflowInput,
                                           nscoord aWidth,
                                           nscoord aHeight)
 {
-    // Aim to fill the whole size of the document, not only so we
-    // can act as a background in print preview but also handle overflow
-    // in child page frames correctly.
-    // Use availableWidth so we don't cause a needless horizontal scrollbar.
-    aDesiredSize.Width() = std::max(aReflowInput.AvailableWidth(),
-                                nscoord(aWidth * PresContext()->GetPrintPreviewScale()));
-    aDesiredSize.Height() = std::max(aReflowInput.ComputedHeight(),
-                                 nscoord(aHeight * PresContext()->GetPrintPreviewScale()));
+  // Aim to fill the whole size of the document, not only so we
+  // can act as a background in print preview but also handle overflow
+  // in child page frames correctly.
+  // Use availableISize so we don't cause a needless horizontal scrollbar.
+  WritingMode wm = aReflowInput.GetWritingMode();
+  nscoord scaledWidth = aWidth * PresContext()->GetPrintPreviewScale();
+  nscoord scaledHeight = aHeight * PresContext()->GetPrintPreviewScale();
+
+  nscoord scaledISize = (wm.IsVertical() ? scaledHeight : scaledWidth);
+  nscoord scaledBSize = (wm.IsVertical() ? scaledWidth : scaledHeight);
+
+  aDesiredSize.ISize(wm) = std::max(scaledISize, aReflowInput.AvailableISize());
+  aDesiredSize.BSize(wm) = std::max(scaledBSize, aReflowInput.ComputedBSize());
 }
 
 // Helper function to compute the offset needed to center a child
 // page-frame's margin-box inside our content-box.
 nscoord
 nsSimplePageSequenceFrame::ComputeCenteringMargin(
   nscoord aContainerContentBoxWidth,
   nscoord aChildPaddingBoxWidth,
@@ -128,21 +133,26 @@ nsSimplePageSequenceFrame::ComputeCenter
 
   // To center the child, we want to give it an additional left-margin of half
   // of the extra space.  And then, we have to scale that space back down, so
   // that it'll produce the correct scaled-up amount when we render (because
   // rendering will scale it back up):
   return NSToCoordRound(scaledExtraSpace * 0.5 / ppScale);
 }
 
+/*
+ * Note: we largely position/size out our children (page frames) using
+ * \*physical\* x/y/width/height values, because the print preview UI is always
+ * arranged in the same orientation, regardless of writing mode.
+ */
 void
-nsSimplePageSequenceFrame::Reflow(nsPresContext*          aPresContext,
-                                  ReflowOutput&     aDesiredSize,
+nsSimplePageSequenceFrame::Reflow(nsPresContext*     aPresContext,
+                                  ReflowOutput&      aDesiredSize,
                                   const ReflowInput& aReflowInput,
-                                  nsReflowStatus&          aStatus)
+                                  nsReflowStatus&    aStatus)
 {
   MarkInReflow();
   NS_PRECONDITION(aPresContext->IsRootPaginatedDocument(),
                   "A Page Sequence is only for real pages");
   DO_GLOBAL_REFLOW_COUNT("nsSimplePageSequenceFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
   NS_FRAME_TRACE_REFLOW_IN("nsSimplePageSequenceFrame::Reflow");
 
@@ -158,17 +168,17 @@ nsSimplePageSequenceFrame::Reflow(nsPres
 
     if (GetRect().Width() != aDesiredSize.Width()) {
       // Our width is changing; we need to re-center our children (our pages).
       for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
         nsIFrame* child = e.get();
         nsMargin pageCSSMargin = child->GetUsedMargin();
         nscoord centeringMargin =
           ComputeCenteringMargin(aReflowInput.ComputedWidth(),
-                                 child->GetRect().width,
+                                 child->GetRect().Width(),
                                  pageCSSMargin);
         nscoord newX = pageCSSMargin.left + centeringMargin;
 
         // Adjust the child's x-position:
         child->MovePositionBy(nsPoint(newX - child->GetNormalPosition().x, 0));
       }
     }
     return;
@@ -237,23 +247,25 @@ nsSimplePageSequenceFrame::Reflow(nsPres
   for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) {
     nsIFrame* kidFrame = e.get();
     // Set the shared data into the page frame before reflow
     nsPageFrame * pf = static_cast<nsPageFrame*>(kidFrame);
     pf->SetSharedPageData(mPageData);
 
     // Reflow the page
     ReflowInput kidReflowInput(aPresContext, aReflowInput, kidFrame,
-                                     LogicalSize(kidFrame->GetWritingMode(),
+                               LogicalSize(kidFrame->GetWritingMode(),
                                                  pageSize));
     nsReflowStatus  status;
 
-    kidReflowInput.SetComputedWidth(kidReflowInput.AvailableWidth());
+    kidReflowInput.SetComputedISize(kidReflowInput.AvailableISize());
     //kidReflowInput.SetComputedHeight(kidReflowInput.AvailableHeight());
-    PR_PL(("AV W: %d   H: %d\n", kidReflowInput.AvailableWidth(), kidReflowInput.AvailableHeight()));
+    PR_PL(("AV ISize: %d   BSize: %d\n",
+           kidReflowInput.AvailableISize(),
+           kidReflowInput.AvailableBSize()));
 
     nsMargin pageCSSMargin = kidReflowInput.ComputedPhysicalMargin();
     y += pageCSSMargin.top;
 
     nscoord x = pageCSSMargin.left;
 
     // Place and size the page.
     ReflowChild(kidFrame, aPresContext, kidSize, kidReflowInput, x, y, 0, status);