Bug 1316051 - Part 5: [css-grid] Subtract the caption size from the CB size that is used for stretching table items. r=dholbert, a=jcristau
authorMats Palmgren <mats@mozilla.com>
Fri, 18 Nov 2016 19:08:31 +0100
changeset 352597 3d566e0afb53759c6a36f82bbba8c75a64e5aa52
parent 352596 5d48cde123834ab9e302dff96eac35540e026bd5
child 352598 d4c4c6c42b1fe2ec2be48235496552e1c63bbf7f
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, jcristau
bugs1316051
milestone52.0a2
Bug 1316051 - Part 5: [css-grid] Subtract the caption size from the CB size that is used for stretching table items. r=dholbert, a=jcristau
layout/tables/nsTableWrapperFrame.cpp
--- a/layout/tables/nsTableWrapperFrame.cpp
+++ b/layout/tables/nsTableWrapperFrame.cpp
@@ -946,29 +946,50 @@ nsTableWrapperFrame::Reflow(nsPresContex
     OuterDoReflowChild(aPresContext, mCaptionFrames.FirstChild(),
                        *captionRI, *captionMet, capStatus);
     captionSize.ISize(wm) = captionMet->ISize(wm);
     captionSize.BSize(wm) = captionMet->BSize(wm);
     captionMargin =
       captionRI->ComputedLogicalMargin().ConvertTo(wm, captionWM);
     // Now that we know the bsize of the caption, reduce the available bsize
     // for the table frame if we are bsize constrained and the caption is above
-    // or below the inner table.
-    if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize()) {
+    // or below the inner table.  Also reduce the CB size that we store for
+    // our children in case we're a grid item, by the same amount.
+    LogicalSize* cbSize = Properties().Get(GridItemCBSizeProperty());
+    if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize() || cbSize) {
       nscoord captionBSize = 0;
+      nscoord captionISize = 0;
       switch (captionSide) {
         case NS_STYLE_CAPTION_SIDE_TOP:
         case NS_STYLE_CAPTION_SIDE_BOTTOM:
         case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE:
         case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE:
           captionBSize = captionSize.BSize(wm) + captionMargin.BStartEnd(wm);
           break;
+        case NS_STYLE_CAPTION_SIDE_LEFT:
+        case NS_STYLE_CAPTION_SIDE_RIGHT:
+          captionISize = captionSize.ISize(wm) + captionMargin.IStartEnd(wm);
+          break;
       }
-      innerRI->AvailableBSize() =
-        std::max(0, innerRI->AvailableBSize() - captionBSize);
+      if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize()) {
+        innerRI->AvailableBSize() =
+          std::max(0, innerRI->AvailableBSize() - captionBSize);
+      }
+      if (cbSize) {
+        // Shrink the CB size by the size reserved for the caption.
+        LogicalSize oldCBSize = *cbSize;
+        cbSize->ISize(wm) = std::max(0, cbSize->ISize(wm) - captionISize);
+        cbSize->BSize(wm) = std::max(0, cbSize->BSize(wm) - captionBSize);
+        if (oldCBSize != *cbSize) {
+          // Reset the inner table's ReflowInput to stretch it to the new size.
+          innerRI.reset();
+          OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI,
+                                innerRI, aOuterRI.ComputedSize(wm).ISize(wm));
+        }
+      }
     }
   }
 
   // Then, now that we know how much to reduce the isize of the inner
   // table to account for side captions, reflow the inner table.
   ReflowOutput innerMet(innerRI->GetWritingMode());
   OuterDoReflowChild(aPresContext, InnerTableFrame(), *innerRI,
                      innerMet, aStatus);