Bug 1174700 - patch 2 - Convert nsTableFrame::SetColumnDimensions to work with logical-order iteration over the table, so that column coordinates and collapsed borders are correct. r=dholbert
authorJonathan Kew <jkew@mozilla.com>
Sat, 20 Jun 2015 21:00:33 +0100
changeset 249898 056a7557fad64106ac402236b0384bf90e9a8357
parent 249897 e7d39a6671ea6768cb88a285f833fa07d2322c55
child 249899 dd73baf23939c062876f9c199b71249a59f2737d
push id61385
push userjkew@mozilla.com
push dateSun, 21 Jun 2015 20:21:38 +0000
treeherdermozilla-inbound@056a7557fad6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1174700
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1174700 - patch 2 - Convert nsTableFrame::SetColumnDimensions to work with logical-order iteration over the table, so that column coordinates and collapsed borders are correct. r=dholbert
layout/tables/nsTableFrame.cpp
layout/tables/nsTableFrame.h
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -1415,59 +1415,73 @@ nsTableFrame::GetLogicalSkipSides(const 
   }
   if (nullptr != GetNextInFlow()) {
     skip |= eLogicalSideBitsBEnd;
   }
   return skip;
 }
 
 void
-nsTableFrame::SetColumnDimensions(nscoord aHeight, WritingMode aWM,
-                                  const LogicalMargin& aBorderPadding)
-{
-  nscoord colHeight = aHeight -= aBorderPadding.BStartEnd(aWM) +
-                                 GetRowSpacing(-1) +
-                                 GetRowSpacing(GetRowCount());
-
+nsTableFrame::SetColumnDimensions(nscoord aBSize, WritingMode aWM,
+                                  const LogicalMargin& aBorderPadding,
+                                  nscoord aContainerWidth)
+{
+  const nscoord colBSize = aBSize - (aBorderPadding.BStartEnd(aWM) +
+                           GetRowSpacing(-1) + GetRowSpacing(GetRowCount()));
+
+  int32_t colIdx = 0;
+  LogicalPoint colGroupOrigin(aWM,
+                              aBorderPadding.IStart(aWM) + GetColSpacing(-1),
+                              aBorderPadding.BStart(aWM) + GetRowSpacing(-1));
   nsTableIterator iter(mColGroups);
-  nsIFrame* colGroupFrame = iter.First();
-  bool tableIsLTR = StyleVisibility()->mDirection == NS_STYLE_DIRECTION_LTR;
-  int32_t colX =tableIsLTR ? 0 : std::max(0, GetColCount() - 1);
-  nscoord cellSpacingX = GetColSpacing(colX);
-  int32_t tableColIncr = tableIsLTR ? 1 : -1;
-  nsPoint colGroupOrigin(aBorderPadding.IStart(aWM) + GetColSpacing(-1),
-                         aBorderPadding.BStart(aWM) + GetRowSpacing(-1));
-  while (colGroupFrame) {
+  for (nsIFrame* colGroupFrame = iter.First(); colGroupFrame;
+       colGroupFrame = iter.Next()) {
     MOZ_ASSERT(colGroupFrame->GetType() == nsGkAtoms::tableColGroupFrame);
-    nscoord colGroupWidth = 0;
+    // first we need to figure out the size of the colgroup
+    int32_t groupFirstCol = colIdx;
+    nscoord colGroupISize = 0;
+    nscoord cellSpacingI = 0;
     nsTableIterator iterCol(*colGroupFrame);
-    nsIFrame* colFrame = iterCol.First();
-    nsPoint colOrigin(0,0);
-    while (colFrame) {
+    for (nsIFrame* colFrame = iterCol.First(); colFrame;
+         colFrame = iterCol.Next()) {
       if (NS_STYLE_DISPLAY_TABLE_COLUMN ==
           colFrame->StyleDisplay()->mDisplay) {
-        NS_ASSERTION(colX < GetColCount(), "invalid number of columns");
-        nscoord colWidth = GetColumnISize(colX);
-        nsRect colRect(colOrigin.x, colOrigin.y, colWidth, colHeight);
-        colFrame->SetRect(colRect);
-        cellSpacingX = GetColSpacing(colX);
-        colOrigin.x += colWidth + cellSpacingX;
-        colGroupWidth += colWidth + cellSpacingX;
-        colX += tableColIncr;
+        NS_ASSERTION(colIdx < GetColCount(), "invalid number of columns");
+        cellSpacingI = GetColSpacing(colIdx);
+        colGroupISize += GetColumnISize(colIdx) + cellSpacingI;
+        ++colIdx;
       }
-      colFrame = iterCol.Next();
-    }
-    if (colGroupWidth) {
-      colGroupWidth -= cellSpacingX;
-    }
-
-    nsRect colGroupRect(colGroupOrigin.x, colGroupOrigin.y, colGroupWidth, colHeight);
-    colGroupFrame->SetRect(colGroupRect);
-    colGroupFrame = iter.Next();
-    colGroupOrigin.x += colGroupWidth + cellSpacingX;
+    }
+    if (colGroupISize) {
+      colGroupISize -= cellSpacingI;
+    }
+
+    LogicalRect colGroupRect(aWM, colGroupOrigin.I(aWM), colGroupOrigin.B(aWM),
+                             colGroupISize, colBSize);
+    colGroupFrame->SetRect(aWM, colGroupRect, aContainerWidth);
+    nscoord colGroupWidth = colGroupFrame->GetSize().width;
+
+    // then we can place the columns correctly within the group
+    colIdx = groupFirstCol;
+    LogicalPoint colOrigin(aWM);
+    for (nsIFrame* colFrame = iterCol.First(); colFrame;
+         colFrame = iterCol.Next()) {
+      if (NS_STYLE_DISPLAY_TABLE_COLUMN ==
+          colFrame->StyleDisplay()->mDisplay) {
+        nscoord colISize = GetColumnISize(colIdx);
+        LogicalRect colRect(aWM, colOrigin.I(aWM), colOrigin.B(aWM),
+                            colISize, colBSize);
+        colFrame->SetRect(aWM, colRect, colGroupWidth);
+        cellSpacingI = GetColSpacing(colIdx);
+        colOrigin.I(aWM) += colISize + cellSpacingI;
+        ++colIdx;
+      }
+    }
+
+    colGroupOrigin.I(aWM) += colGroupISize + cellSpacingI;
   }
 }
 
 // SEC: TODO need to worry about continuing frames prev/next in flow for splitting across pages.
 
 // XXX this could be made more general to handle row modifications that change the
 // table height, but first we need to scrutinize every Invalidate
 void
@@ -1901,17 +1915,18 @@ nsTableFrame::Reflow(nsPresContext*     
   if (!haveDesiredHeight) {
     CalcDesiredHeight(aReflowState, aDesiredSize);
   }
   if (IsRowInserted()) {
     ProcessRowInserted(aDesiredSize.Height());
   }
 
   LogicalMargin borderPadding = GetChildAreaOffset(wm, &aReflowState);
-  SetColumnDimensions(aDesiredSize.Height(), wm, borderPadding);
+  SetColumnDimensions(aDesiredSize.Height(), wm, borderPadding,
+                      aDesiredSize.Width());
   if (NeedToCollapse() &&
       (NS_UNCONSTRAINEDSIZE != aReflowState.AvailableWidth())) {
     AdjustForCollapsingRowsCols(aDesiredSize, wm, borderPadding);
   }
 
   // If there are any relatively-positioned table parts, we need to reflow their
   // absolutely-positioned descendants now that their dimensions are final.
   FixupPositionedTableParts(aPresContext, aDesiredSize, aReflowState);
--- a/layout/tables/nsTableFrame.h
+++ b/layout/tables/nsTableFrame.h
@@ -805,17 +805,18 @@ protected:
 
   BCPropertyData* GetBCProperty(bool aCreateIfNecessary = false) const;
   void SetFullBCDamageArea();
   void CalcBCBorders();
 
   void ExpandBCDamageArea(mozilla::TableArea& aRect) const;
 
   void SetColumnDimensions(nscoord aHeight, WritingMode aWM,
-                           const LogicalMargin& aBorderPadding);
+                           const LogicalMargin& aBorderPadding,
+                           nscoord aContainerWidth);
 
   int32_t CollectRows(nsIFrame*                   aFrame,
                       nsTArray<nsTableRowFrame*>& aCollection);
 
 public: /* ----- Cell Map public methods ----- */
 
   int32_t GetStartRowIndex(nsTableRowGroupFrame* aRowGroupFrame);