Bug 1157569 - part 14 - Finish conversion of border-collapse code in nsTableFrame to logical coordinates. r=dholbert
authorJonathan Kew <jkew@mozilla.com>
Sat, 27 Jun 2015 11:16:10 -0700
changeset 250504 90f43905ea1260152612e2cc5923df11226daaa4
parent 250503 dd2f0a7e0db39154468d56e22e651dab897812d9
child 250505 8d7c0d471925a7449db469d949f58c9c0d852564
push id28956
push usercbook@mozilla.com
push dateMon, 29 Jun 2015 12:17:35 +0000
treeherdermozilla-central@e137fc38c431 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1157569
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 1157569 - part 14 - Finish conversion of border-collapse code in nsTableFrame to logical coordinates. r=dholbert
layout/tables/nsCellMap.cpp
layout/tables/nsCellMap.h
layout/tables/nsTableFrame.cpp
layout/tables/nsTableFrame.h
layout/tables/nsTablePainter.cpp
--- a/layout/tables/nsCellMap.cpp
+++ b/layout/tables/nsCellMap.cpp
@@ -99,47 +99,47 @@ nsTableCellMap::~nsTableCellMap()
 }
 
 // Get the bcData holding the border segments of the right edge of the table
 BCData*
 nsTableCellMap::GetRightMostBorder(int32_t aRowIndex)
 {
   if (!mBCInfo) ABORT1(nullptr);
 
-  int32_t numRows = mBCInfo->mRightBorders.Length();
+  int32_t numRows = mBCInfo->mIEndBorders.Length();
   if (aRowIndex < numRows) {
-    return &mBCInfo->mRightBorders.ElementAt(aRowIndex);
+    return &mBCInfo->mIEndBorders.ElementAt(aRowIndex);
   }
 
-  mBCInfo->mRightBorders.SetLength(aRowIndex+1);
-  return &mBCInfo->mRightBorders.ElementAt(aRowIndex);
+  mBCInfo->mIEndBorders.SetLength(aRowIndex+1);
+  return &mBCInfo->mIEndBorders.ElementAt(aRowIndex);
 }
 
 // Get the bcData holding the border segments of the bottom edge of the table
 BCData*
 nsTableCellMap::GetBottomMostBorder(int32_t aColIndex)
 {
   if (!mBCInfo) ABORT1(nullptr);
 
-  int32_t numCols = mBCInfo->mBottomBorders.Length();
+  int32_t numCols = mBCInfo->mBEndBorders.Length();
   if (aColIndex < numCols) {
-    return &mBCInfo->mBottomBorders.ElementAt(aColIndex);
+    return &mBCInfo->mBEndBorders.ElementAt(aColIndex);
   }
 
-  mBCInfo->mBottomBorders.SetLength(aColIndex+1);
-  return &mBCInfo->mBottomBorders.ElementAt(aColIndex);
+  mBCInfo->mBEndBorders.SetLength(aColIndex+1);
+  return &mBCInfo->mBEndBorders.ElementAt(aColIndex);
 }
 
 // delete the borders corresponding to the right and bottom edges of the table
 void
 nsTableCellMap::DeleteRightBottomBorders()
 {
   if (mBCInfo) {
-    mBCInfo->mBottomBorders.Clear();
-    mBCInfo->mRightBorders.Clear();
+    mBCInfo->mBEndBorders.Clear();
+    mBCInfo->mIEndBorders.Clear();
   }
 }
 
 void
 nsTableCellMap::InsertGroupCellMap(nsCellMap* aPrevMap,
                                    nsCellMap& aNewMap)
 {
   nsCellMap* next;
@@ -421,17 +421,17 @@ nsTableCellMap::GetDataAt(int32_t aRowIn
 
 void
 nsTableCellMap::AddColsAtEnd(uint32_t aNumCols)
 {
   if (!mCols.AppendElements(aNumCols)) {
     NS_WARNING("Could not AppendElement");
   }
   if (mBCInfo) {
-    if (!mBCInfo->mBottomBorders.AppendElements(aNumCols)) {
+    if (!mBCInfo->mBEndBorders.AppendElements(aNumCols)) {
       NS_WARNING("Could not AppendElement");
     }
   }
 }
 
 void
 nsTableCellMap::RemoveColsAtEnd()
 {
@@ -440,32 +440,32 @@ nsTableCellMap::RemoveColsAtEnd()
   int32_t numCols = GetColCount();
   int32_t lastGoodColIndex = mTableFrame.GetIndexOfLastRealCol();
   for (int32_t colX = numCols - 1; (colX >= 0) && (colX > lastGoodColIndex); colX--) {
     nsColInfo& colInfo = mCols.ElementAt(colX);
     if ((colInfo.mNumCellsOrig <= 0) && (colInfo.mNumCellsSpan <= 0))  {
       mCols.RemoveElementAt(colX);
 
       if (mBCInfo) {
-        int32_t count = mBCInfo->mBottomBorders.Length();
+        int32_t count = mBCInfo->mBEndBorders.Length();
         if (colX < count) {
-          mBCInfo->mBottomBorders.RemoveElementAt(colX);
+          mBCInfo->mBEndBorders.RemoveElementAt(colX);
         }
       }
     }
     else break; // only remove until we encounter the 1st valid one
   }
 }
 
 void
 nsTableCellMap::ClearCols()
 {
   mCols.Clear();
   if (mBCInfo)
-    mBCInfo->mBottomBorders.Clear();
+    mBCInfo->mBEndBorders.Clear();
 }
 void
 nsTableCellMap::InsertRows(nsTableRowGroupFrame*       aParent,
                            nsTArray<nsTableRowFrame*>& aRows,
                            int32_t                     aFirstRowIndex,
                            bool                        aConsiderSpans,
                            TableArea&                  aDamageArea)
 {
@@ -479,26 +479,26 @@ nsTableCellMap::InsertRows(nsTableRowGro
     nsTableRowGroupFrame* rg = cellMap->GetRowGroup();
     if (rg == aParent) {
       cellMap->InsertRows(*this, aRows, rowIndex, aConsiderSpans,
                           rgStartRowIndex, aDamageArea);
 #ifdef DEBUG_TABLE_CELLMAP
       Dump("after InsertRows");
 #endif
       if (mBCInfo) {
-        int32_t count = mBCInfo->mRightBorders.Length();
+        int32_t count = mBCInfo->mIEndBorders.Length();
         if (aFirstRowIndex < count) {
           for (int32_t rowX = aFirstRowIndex; rowX < aFirstRowIndex + numNewRows; rowX++) {
-            mBCInfo->mRightBorders.InsertElementAt(rowX);
+            mBCInfo->mIEndBorders.InsertElementAt(rowX);
           }
         }
         else {
           GetRightMostBorder(aFirstRowIndex); // this will create missing entries
           for (int32_t rowX = aFirstRowIndex + 1; rowX < aFirstRowIndex + numNewRows; rowX++) {
-            mBCInfo->mRightBorders.AppendElement();
+            mBCInfo->mIEndBorders.AppendElement();
           }
         }
       }
       return;
     }
     int32_t rowCount = cellMap->GetRowCount();
     rgStartRowIndex += rowCount;
     rowIndex -= rowCount;
@@ -519,18 +519,18 @@ nsTableCellMap::RemoveRows(int32_t      
   nsCellMap* cellMap = mFirstMap;
   while (cellMap) {
     int32_t rowCount = cellMap->GetRowCount();
     if (rowCount > rowIndex) {
       cellMap->RemoveRows(*this, rowIndex, aNumRowsToRemove, aConsiderSpans,
                           rgStartRowIndex, aDamageArea);
       if (mBCInfo) {
         for (int32_t rowX = aFirstRowIndex + aNumRowsToRemove - 1; rowX >= aFirstRowIndex; rowX--) {
-          if (uint32_t(rowX) < mBCInfo->mRightBorders.Length()) {
-            mBCInfo->mRightBorders.RemoveElementAt(rowX);
+          if (uint32_t(rowX) < mBCInfo->mIEndBorders.Length()) {
+            mBCInfo->mIEndBorders.RemoveElementAt(rowX);
           }
         }
       }
       break;
     }
     rgStartRowIndex += rowCount;
     rowIndex -= rowCount;
     cellMap = cellMap->GetNextSibling();
@@ -728,36 +728,36 @@ nsTableCellMap::Dump(char* aString) cons
   if (nullptr != mBCInfo) {
     printf("***** bottom borders *****\n");
     nscoord       size;
     BCBorderOwner owner;
     LogicalSide side;
     bool          segStart;
     bool          bevel;
     int32_t       colIndex;
-    int32_t numCols = mBCInfo->mBottomBorders.Length();
+    int32_t numCols = mBCInfo->mBEndBorders.Length();
     for (int32_t i = 0; i <= 2; i++) {
 
       printf("\n          ");
       for (colIndex = 0; colIndex < numCols; colIndex++) {
-        BCData& cd = mBCInfo->mBottomBorders.ElementAt(colIndex);
+        BCData& cd = mBCInfo->mBEndBorders.ElementAt(colIndex);
         if (0 == i) {
           size = cd.GetBStartEdge(owner, segStart);
           printf("t=%d%X%d ", int32_t(size), owner, segStart);
         }
         else if (1 == i) {
           size = cd.GetIStartEdge(owner, segStart);
           printf("l=%d%X%d ", int32_t(size), owner, segStart);
         }
         else {
           size = cd.GetCorner(side, bevel);
           printf("c=%d%X%d ", int32_t(size), side, bevel);
         }
       }
-      BCData& cd = mBCInfo->mLowerRightCorner;
+      BCData& cd = mBCInfo->mBEndIEndCorner;
       if (0 == i) {
          size = cd.GetBStartEdge(owner, segStart);
          printf("t=%d%X%d ", int32_t(size), owner, segStart);
       }
       else if (1 == i) {
         size = cd.GetIStartEdge(owner, segStart);
         printf("l=%d%X%d ", int32_t(size), owner, segStart);
       }
@@ -1069,48 +1069,48 @@ void
 nsTableCellMap::SetBCBorderCorner(Corner      aCorner,
                                   nsCellMap&  aCellMap,
                                   uint32_t    aCellMapStart,
                                   uint32_t    aRowIndex,
                                   uint32_t    aColIndex,
                                   LogicalSide aOwner,
                                   nscoord     aSubSize,
                                   bool        aBevel,
-                                  bool        aIsBottomRight)
+                                  bool        aIsBEndIEnd)
 {
   if (!mBCInfo) ABORT0();
 
-  if (aIsBottomRight) {
-    mBCInfo->mLowerRightCorner.SetCorner(aSubSize, aOwner, aBevel);
+  if (aIsBEndIEnd) {
+    mBCInfo->mBEndIEndCorner.SetCorner(aSubSize, aOwner, aBevel);
     return;
   }
 
   int32_t xPos = aColIndex;
   int32_t yPos = aRowIndex;
   int32_t rgYPos = aRowIndex - aCellMapStart;
 
-  if (eTopRight == aCorner) {
+  if (eBStartIEnd == aCorner) {
     xPos++;
   }
-  else if (eBottomRight == aCorner) {
+  else if (eBEndIEnd == aCorner) {
     xPos++;
     rgYPos++;
     yPos++;
   }
-  else if (eBottomLeft == aCorner) {
+  else if (eBEndIStart == aCorner) {
     rgYPos++;
     yPos++;
   }
 
   BCCellData* cellData = nullptr;
   BCData*     bcData   = nullptr;
   if (GetColCount() <= xPos) {
     NS_ASSERTION(xPos == GetColCount(), "program error");
     // at the right edge of the table as we checked the corner before
-    NS_ASSERTION(!aIsBottomRight, "should be handled before");
+    NS_ASSERTION(!aIsBEndIEnd, "should be handled before");
     bcData = GetRightMostBorder(yPos);
   }
   else {
     cellData = (BCCellData*)aCellMap.GetDataAt(rgYPos, xPos);
     if (!cellData) {
       int32_t numRgRows = aCellMap.GetRowCount();
       if (yPos < numRgRows) { // add a dead cell data
         TableArea damageArea;
--- a/layout/tables/nsCellMap.h
+++ b/layout/tables/nsCellMap.h
@@ -33,27 +33,27 @@ struct nsColInfo
 
   nsColInfo();
   nsColInfo(int32_t aNumCellsOrig,
             int32_t aNumCellsSpan);
 };
 
 enum Corner
 {
-  eTopLeft     = 0,
-  eTopRight    = 1,
-  eBottomRight = 2,
-  eBottomLeft  = 3
+  eBStartIStart = 0,
+  eBStartIEnd   = 1,
+  eBEndIEnd     = 2,
+  eBEndIStart   = 3
 };
 
 struct BCInfo
 {
-  nsTArray<BCData> mRightBorders;
-  nsTArray<BCData> mBottomBorders;
-  BCData           mLowerRightCorner;
+  nsTArray<BCData> mIEndBorders;
+  nsTArray<BCData> mBEndBorders;
+  BCData           mBEndIEndCorner;
 };
 
 class nsTableCellMap
 {
   typedef mozilla::TableArea TableArea;
 
 public:
   nsTableCellMap(nsTableFrame&   aTableFrame,
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -492,18 +492,18 @@ void
 nsTableFrame::AdjustRowIndices(int32_t         aRowIndex,
                                int32_t         aAdjustment)
 {
   // Iterate over the row groups and adjust the row indices of all rows
   // whose index is >= aRowIndex.
   RowGroupArray rowGroups;
   OrderRowGroups(rowGroups);
 
-  for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    rowGroups[rgX]->AdjustRowIndices(aRowIndex, aAdjustment);
+  for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    rowGroups[rgIdx]->AdjustRowIndices(aRowIndex, aAdjustment);
   }
 }
 
 
 void
 nsTableFrame::ResetRowIndices(const nsFrameList::Slice& aRowGroupsToExclude)
 {
   // Iterate over the row groups and adjust the row indices of all rows
@@ -514,18 +514,18 @@ nsTableFrame::ResetRowIndices(const nsFr
   int32_t rowIndex = 0;
   nsTHashtable<nsPtrHashKey<nsTableRowGroupFrame> > excludeRowGroups;
   nsFrameList::Enumerator excludeRowGroupsEnumerator(aRowGroupsToExclude);
   while (!excludeRowGroupsEnumerator.AtEnd()) {
     excludeRowGroups.PutEntry(static_cast<nsTableRowGroupFrame*>(excludeRowGroupsEnumerator.get()));
     excludeRowGroupsEnumerator.Next();
   }
 
-  for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
     if (!excludeRowGroups.GetEntry(rgFrame)) {
       const nsFrameList& rowFrames = rgFrame->PrincipalChildList();
       for (nsFrameList::Enumerator rows(rowFrames); !rows.AtEnd(); rows.Next()) {
         if (NS_STYLE_DISPLAY_TABLE_ROW==rows.get()->StyleDisplay()->mDisplay) {
           ((nsTableRowFrame *)rows.get())->SetRowIndex(rowIndex);
           rowIndex++;
         }
       }
@@ -912,19 +912,19 @@ nsTableFrame::InsertRows(nsTableRowGroup
     int32_t numNewRows = aRowFrames.Length();
     cellMap->InsertRows(aRowGroupFrame, aRowFrames, aRowIndex, aConsiderSpans, damageArea);
     MatchCellMapToColCache(cellMap);
     if (aRowIndex < origNumRows) {
       AdjustRowIndices(aRowIndex, numNewRows);
     }
     // assign the correct row indices to the new rows. If they were adjusted above
     // it may not have been done correctly because each row is constructed with index 0
-    for (int32_t rowY = 0; rowY < numNewRows; rowY++) {
-      nsTableRowFrame* rowFrame = aRowFrames.ElementAt(rowY);
-      rowFrame->SetRowIndex(aRowIndex + rowY);
+    for (int32_t rowB = 0; rowB < numNewRows; rowB++) {
+      nsTableRowFrame* rowFrame = aRowFrames.ElementAt(rowB);
+      rowFrame->SetRowIndex(aRowIndex + rowB);
     }
     if (IsBorderCollapse()) {
       AddBCDamageArea(damageArea);
     }
   }
 #ifdef DEBUG_TABLE_CELLMAP
   printf("=== insertRowsAfter \n");
   Dump(true, false, true);
@@ -1483,18 +1483,18 @@ nsTableFrame::SetColumnDimensions(nscoor
 // table bsize, but first we need to scrutinize every Invalidate
 void
 nsTableFrame::ProcessRowInserted(nscoord aNewBSize)
 {
   SetRowInserted(false); // reset the bit that got us here
   nsTableFrame::RowGroupArray rowGroups;
   OrderRowGroups(rowGroups);
   // find the row group containing the inserted row
-  for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
     NS_ASSERTION(rgFrame, "Must have rgFrame here");
     nsIFrame* childFrame = rgFrame->GetFirstPrincipalChild();
     // find the row that was inserted first
     while (childFrame) {
       nsTableRowFrame *rowFrame = do_QueryFrame(childFrame);
       if (rowFrame) {
         if (rowFrame->IsFirstInserted()) {
           rowFrame->SetFirstInserted(false);
@@ -2649,40 +2649,40 @@ nsTableFrame::GetOuterBCBorder(const Wri
 {
   if (NeedToCalcBCBorders()) {
     const_cast<nsTableFrame*>(this)->CalcBCBorders();
   }
 
   int32_t p2t = nsPresContext::AppUnitsPerCSSPixel();
   BCPropertyData* propData = GetBCProperty();
   if (propData) {
-    nsMargin r(BC_BORDER_START_HALF_COORD(p2t, propData->mBStartBorderWidth),
+    return LogicalMargin(aWM,
+               BC_BORDER_START_HALF_COORD(p2t, propData->mBStartBorderWidth),
                BC_BORDER_END_HALF_COORD(p2t, propData->mIEndBorderWidth),
                BC_BORDER_END_HALF_COORD(p2t, propData->mBEndBorderWidth),
                BC_BORDER_START_HALF_COORD(p2t, propData->mIStartBorderWidth));
-    return LogicalMargin(aWM, r);
   }
   return LogicalMargin(aWM);
 }
 
 LogicalMargin
 nsTableFrame::GetIncludedOuterBCBorder(const WritingMode aWM) const
 {
   if (NeedToCalcBCBorders()) {
     const_cast<nsTableFrame*>(this)->CalcBCBorders();
   }
 
   int32_t p2t = nsPresContext::AppUnitsPerCSSPixel();
   BCPropertyData* propData = GetBCProperty();
   if (propData) {
-    nsMargin r(BC_BORDER_START_HALF_COORD(p2t, propData->mBStartBorderWidth),
+    return LogicalMargin(aWM,
+               BC_BORDER_START_HALF_COORD(p2t, propData->mBStartBorderWidth),
                BC_BORDER_END_HALF_COORD(p2t, propData->mIEndCellBorderWidth),
                BC_BORDER_END_HALF_COORD(p2t, propData->mBEndBorderWidth),
                BC_BORDER_START_HALF_COORD(p2t, propData->mIStartCellBorderWidth));
-    return LogicalMargin(aWM, r);
   }
   return LogicalMargin(aWM);
 }
 
 LogicalMargin
 nsTableFrame::GetExcludedOuterBCBorder(const WritingMode aWM) const
 {
   return GetOuterBCBorder(aWM) - GetIncludedOuterBCBorder(aWM);
@@ -2728,17 +2728,17 @@ nsTableFrame::InitChildReflowState(nsHTM
     pCollapseBorder = &collapseBorder;
   }
   aReflowState.Init(presContext, nullptr, pCollapseBorder, &padding);
 
   NS_ASSERTION(!mBits.mResizedColumns ||
                !aReflowState.parentReflowState->mFlags.mSpecialBSizeReflow,
                "should not resize columns on special bsize reflow");
   if (mBits.mResizedColumns) {
-    aReflowState.SetHResize(true);
+    aReflowState.SetIResize(true);
   }
 }
 
 // Position and size aKidFrame and update our reflow state. The origin of
 // aKidRect is relative to the upper-left origin of our frame
 void
 nsTableFrame::PlaceChild(nsTableReflowState&  aReflowState,
                          nsIFrame*            aKidFrame,
@@ -3319,20 +3319,20 @@ nsTableFrame::CalcDesiredBSize(const nsH
     }
     return;
   }
   int32_t rowCount = cellMap->GetRowCount();
   int32_t colCount = cellMap->GetColCount();
   nscoord desiredBSize = borderPadding.BStartEnd(wm);
   if (rowCount > 0 && colCount > 0) {
     desiredBSize += GetRowSpacing(-1);
-    for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-      desiredBSize += rowGroups[rgX]->BSize(wm) +
-                       GetRowSpacing(rowGroups[rgX]->GetRowCount() +
-                                     rowGroups[rgX]->GetStartRowIndex());
+    for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+      desiredBSize += rowGroups[rgIdx]->BSize(wm) +
+                       GetRowSpacing(rowGroups[rgIdx]->GetRowCount() +
+                                     rowGroups[rgIdx]->GetStartRowIndex());
     }
   }
 
   // see if a specified table bsize requires dividing additional space to rows
   if (!GetPrevInFlow()) {
     nscoord tableSpecifiedBSize = CalcBorderBoxBSize(aReflowState);
     if ((tableSpecifiedBSize > 0) &&
         (tableSpecifiedBSize != NS_UNCONSTRAINEDSIZE) &&
@@ -3355,18 +3355,18 @@ void ResizeCells(nsTableFrame& aTableFra
 {
   nsTableFrame::RowGroupArray rowGroups;
   aTableFrame.OrderRowGroups(rowGroups);
   WritingMode wm = aTableFrame.GetWritingMode();
   nsHTMLReflowMetrics tableDesiredSize(wm);
   tableDesiredSize.SetSize(wm, aTableFrame.GetLogicalSize(wm));
   tableDesiredSize.SetOverflowAreasToDesiredBounds();
 
-  for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
 
     nsHTMLReflowMetrics groupDesiredSize(wm);
     groupDesiredSize.SetSize(wm, rgFrame->GetLogicalSize(wm));
     groupDesiredSize.SetOverflowAreasToDesiredBounds();
 
     nsTableRowFrame* rowFrame = rgFrame->GetFirstRow();
     while (rowFrame) {
       rowFrame->DidResize();
@@ -3399,19 +3399,19 @@ nsTableFrame::DistributeBSizeToRows(cons
 
   nscoord amountUsed = 0;
   // distribute space to each pct bsize row whose row group doesn't have a computed
   // bsize, and base the pct on the table bsize. If the row group had a computed
   // bsize, then this was already done in nsTableRowGroupFrame::CalculateRowBSizes
   nscoord pctBasis = aReflowState.ComputedBSize() - GetRowSpacing(-1, GetRowCount());
   nscoord bOriginRG = borderPadding.BStart(wm) + GetRowSpacing(0);
   nscoord bEndRG = bOriginRG;
-  uint32_t rgX;
-  for (rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  uint32_t rgIdx;
+  for (rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
     nscoord amountUsedByRG = 0;
     nscoord bOriginRow = 0;
     LogicalRect rgNormalRect(wm, rgFrame->GetNormalRect(), containerWidth);
     if (!rgFrame->HasStyleBSize()) {
       nsTableRowFrame* rowFrame = rgFrame->GetFirstRow();
       while (rowFrame) {
         // We don't know the final width of the rowGroupFrame yet, so use zero
         // as a "fake" containerWidth here; we'll adjust the row positions at
@@ -3485,18 +3485,18 @@ nsTableFrame::DistributeBSizeToRows(cons
     ResizeCells(*this);
     return;
   }
 
   // get the first row without a style bsize where its row group has an
   // unconstrained bsize
   nsTableRowGroupFrame* firstUnStyledRG  = nullptr;
   nsTableRowFrame*      firstUnStyledRow = nullptr;
-  for (rgX = 0; rgX < rowGroups.Length() && !firstUnStyledRG; rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  for (rgIdx = 0; rgIdx < rowGroups.Length() && !firstUnStyledRG; rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
     if (!rgFrame->HasStyleBSize()) {
       nsTableRowFrame* rowFrame = rgFrame->GetFirstRow();
       while (rowFrame) {
         if (!rowFrame->HasStyleBSize()) {
           firstUnStyledRG = rgFrame;
           firstUnStyledRow = rowFrame;
           break;
         }
@@ -3514,18 +3514,18 @@ nsTableFrame::DistributeBSizeToRows(cons
   int32_t eligibleRows = 0;
   bool expandEmptyRows = false;
 
   if (!firstUnStyledRow) {
     // there is no unstyled row
     divisor = GetRowCount();
   }
   else {
-    for (rgX = 0; rgX < rowGroups.Length(); rgX++) {
-      nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+    for (rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+      nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
       if (!firstUnStyledRG || !rgFrame->HasStyleBSize()) {
         nsTableRowFrame* rowFrame = rgFrame->GetFirstRow();
         while (rowFrame) {
           if (!firstUnStyledRG || !rowFrame->HasStyleBSize()) {
             NS_ASSERTION(rowFrame->BSize(wm) >= 0,
                          "negative row frame block-size");
             divisor += rowFrame->BSize(wm);
             eligibleRows++;
@@ -3544,18 +3544,18 @@ nsTableFrame::DistributeBSizeToRows(cons
         return;
       }
     }
   }
   // allocate the extra bsize to the unstyled row groups and rows
   nscoord bSizeToDistribute = aAmount - amountUsed;
   bOriginRG = borderPadding.BStart(wm) + GetRowSpacing(-1);
   bEndRG = bOriginRG;
-  for (rgX = 0; rgX < rowGroups.Length(); rgX++) {
-    nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+  for (rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
     nscoord amountUsedByRG = 0;
     nscoord bOriginRow = 0;
     LogicalRect rgNormalRect(wm, rgFrame->GetNormalRect(), containerWidth);
     nsRect rgVisualOverflow = rgFrame->GetVisualOverflowRect();
     // see if there is an eligible row group or we distribute to all rows
     if (!firstUnStyledRG || !rgFrame->HasStyleBSize() || !eligibleRows) {
       for (nsTableRowFrame* rowFrame = rgFrame->GetFirstRow();
            rowFrame; rowFrame = rowFrame->GetNextRow()) {
@@ -4126,19 +4126,19 @@ struct BCCellBorder
   BCPixelSize   width;    // border segment width in pixel coordinates !!
   uint8_t       style;    // border segment style, possible values are defined
                           // in nsStyleConsts.h as NS_STYLE_BORDER_STYLE_*
   BCBorderOwner owner;    // border segment owner, possible values are defined
                           // in celldata.h. In the cellmap for each border
                           // segment we store the owner and later when
                           // painting we know the owner and can retrieve the
                           // style info from the corresponding frame
-  int32_t       rowIndex; // rowIndex of temporary stored horizontal border
+  int32_t       rowIndex; // rowIndex of temporary stored inline-dir border
                           // segments relative to the table
-  int32_t       rowSpan;  // row span of temporary stored horizontal border
+  int32_t       rowSpan;  // row span of temporary stored inline-dir border
                           // segments
 };
 
 void
 BCCellBorder::Reset(uint32_t aRowIndex,
                     uint32_t aRowSpan)
 {
   style = NS_STYLE_BORDER_STYLE_NONE;
@@ -4183,18 +4183,18 @@ struct BCMapCellInfo
   void SetColumnBEndContBCBorder();
   void SetColGroupBEndContBCBorder();
   void SetInnerRowGroupBEndContBCBorder(const nsIFrame* aNextRowGroup,
                                         nsTableRowFrame* aNextRow);
 
   // functions to set the border widths on the table related frames, where the
   // knowledge about the current position in the table is used.
   void SetTableBStartBorderWidth(BCPixelSize aWidth);
-  void SetTableIStartBorderWidth(int32_t aRowY, BCPixelSize aWidth);
-  void SetTableIEndBorderWidth(int32_t aRowY, BCPixelSize aWidth);
+  void SetTableIStartBorderWidth(int32_t aRowB, BCPixelSize aWidth);
+  void SetTableIEndBorderWidth(int32_t aRowB, BCPixelSize aWidth);
   void SetTableBEndBorderWidth(BCPixelSize aWidth);
   void SetIStartBorderWidths(BCPixelSize aWidth);
   void SetIEndBorderWidths(BCPixelSize aWidth);
   void SetBStartBorderWidths(BCPixelSize aWidth);
   void SetBEndBorderWidths(BCPixelSize aWidth);
 
   // functions to compute the borders; they depend on the
   // knowledge about the current position in the table. The edge functions
@@ -4204,41 +4204,41 @@ struct BCMapCellInfo
   BCCellBorder GetBEndEdgeBorder();
   BCCellBorder GetIStartEdgeBorder();
   BCCellBorder GetIEndEdgeBorder();
   BCCellBorder GetIEndInternalBorder();
   BCCellBorder GetIStartInternalBorder();
   BCCellBorder GetBStartInternalBorder();
   BCCellBorder GetBEndInternalBorder();
 
-  // functions to set the interal position information
+  // functions to set the internal position information
   void SetColumn(int32_t aColX);
   // Increment the row as we loop over the rows of a rowspan
-  void IncrementRow(bool aResetToTopRowOfCell = false);
+  void IncrementRow(bool aResetToBStartRowOfCell = false);
 
   // Helper functions to get extent of the cell
   int32_t GetCellEndRowIndex() const;
   int32_t GetCellEndColIndex() const;
 
   // storage of table information
   nsTableFrame*         mTableFrame;
   int32_t               mNumTableRows;
   int32_t               mNumTableCols;
   BCPropertyData*       mTableBCData;
   WritingMode           mTableWM;
 
   // a cell can only belong to one rowgroup
   nsTableRowGroupFrame* mRowGroup;
 
-  // a cell with a rowspan has a top and a bottom row, and rows in between
+  // a cell with a rowspan has a bstart and a bend row, and rows in between
   nsTableRowFrame*      mStartRow;
   nsTableRowFrame*      mEndRow;
   nsTableRowFrame*      mCurrentRowFrame;
 
-  // a cell with a colspan has a left and right column and columns in between
+  // a cell with a colspan has an istart and iend column and columns in between
   // they can belong to different colgroups
   nsTableColGroupFrame* mColGroup;
   nsTableColGroupFrame* mCurrentColGroupFrame;
 
   nsTableColFrame*      mStartCol;
   nsTableColFrame*      mEndCol;
   nsTableColFrame*      mCurrentColFrame;
 
@@ -4247,17 +4247,17 @@ struct BCMapCellInfo
   nsBCTableCellFrame*   mCell;
 
   int32_t               mRowIndex;
   int32_t               mRowSpan;
   int32_t               mColIndex;
   int32_t               mColSpan;
 
   // flags to describe the position of the cell with respect to the row- and
-  // colgroups, for instance mRgAtStart documents that the top cell border hits
+  // colgroups, for instance mRgAtStart documents that the bStart cell border hits
   // a rowgroup border
   bool                  mRgAtStart;
   bool                  mRgAtEnd;
   bool                  mCgAtStart;
   bool                  mCgAtEnd;
 
 };
 
@@ -4318,17 +4318,17 @@ public:
   void PeekBEnd(BCMapCellInfo& aRefInfo,
                 uint32_t       aColIndex,
                 BCMapCellInfo& aAjaInfo);
 
   bool IsNewRow() { return mIsNewRow; }
 
   nsTableRowFrame* GetPrevRow() const { return mPrevRow; }
   nsTableRowFrame* GetCurrentRow() const { return mRow; }
-  nsTableRowGroupFrame* GetCurrentRowGroup() const { return mRowGroup;}
+  nsTableRowGroupFrame* GetCurrentRowGroup() const { return mRowGroup; }
 
   int32_t    mRowGroupStart;
   int32_t    mRowGroupEnd;
   bool       mAtEnd;
   nsCellMap* mCellMap;
 
 private:
   bool SetNewRow(nsTableRowFrame* row = nullptr);
@@ -4827,17 +4827,17 @@ nsTableFrame::BCRecalcNeeded(nsStyleCont
 
 // Compare two border segments, this comparison depends whether the two
 // segments meet at a corner and whether the second segment is horizontal.
 // The return value is whichever of aBorder1 or aBorder2 dominates.
 static const BCCellBorder&
 CompareBorders(bool                aIsCorner, // Pass true for corner calculations
                const BCCellBorder& aBorder1,
                const BCCellBorder& aBorder2,
-               bool                aSecondIsHorizontal,
+               bool                aSecondIsInlineDir,
                bool*               aFirstDominates = nullptr)
 {
   bool firstDominates = true;
 
   if (NS_STYLE_BORDER_STYLE_HIDDEN == aBorder1.style) {
     firstDominates = (aIsCorner) ? false : true;
   }
   else if (NS_STYLE_BORDER_STYLE_HIDDEN == aBorder2.style) {
@@ -4847,17 +4847,17 @@ CompareBorders(bool                aIsCo
     firstDominates = false;
   }
   else if (aBorder1.width == aBorder2.width) {
     if (styleToPriority[aBorder1.style] < styleToPriority[aBorder2.style]) {
       firstDominates = false;
     }
     else if (styleToPriority[aBorder1.style] == styleToPriority[aBorder2.style]) {
       if (aBorder1.owner == aBorder2.owner) {
-        firstDominates = !aSecondIsHorizontal;
+        firstDominates = !aSecondIsInlineDir;
       }
       else if (aBorder1.owner < aBorder2.owner) {
         firstDominates = false;
       }
     }
   }
 
   if (aFirstDominates)
@@ -4865,32 +4865,32 @@ CompareBorders(bool                aIsCo
 
   if (firstDominates)
     return aBorder1;
   return aBorder2;
 }
 
 /** calc the dominant border by considering the table, row/col group, row/col,
   * cell.
-  * Depending on whether the side is vertical or horizontal and whether
+  * Depending on whether the side is block-dir or inline-dir and whether
   * adjacent frames are taken into account the ownership of a single border
   * segment is defined. The return value is the dominating border
-  * The cellmap stores only top and left borders for each cellmap position.
-  * If the cell border is owned by the cell that is left of the border
+  * The cellmap stores only bstart and istart borders for each cellmap position.
+  * If the cell border is owned by the cell that is istart-wards of the border
   * it will be an adjacent owner aka eAjaCellOwner. See celldata.h for the other
   * scenarios with a adjacent owner.
   * @param xxxFrame         - the frame for style information, might be zero if
   *                           it should not be considered
   * @param aTableWM         - the writing mode of the frame
   * @param aSide            - side of the frames that should be considered
   * @param aAja             - the border comparison takes place from the point of
   *                           a frame that is adjacent to the cellmap entry, for
   *                           when a cell owns its lower border it will be the
-  *                           adjacent owner as in the cellmap only top and left
-  *                           borders are stored.
+  *                           adjacent owner as in the cellmap only bstart and
+  *                           istart borders are stored.
   */
 static BCCellBorder
 CompareBorders(const nsIFrame*  aTableFrame,
                const nsIFrame*  aColGroupFrame,
                const nsIFrame*  aColFrame,
                const nsIFrame*  aRowGroupFrame,
                const nsIFrame*  aRowFrame,
                const nsIFrame*  aCellFrame,
@@ -4910,17 +4910,17 @@ CompareBorders(const nsIFrame*  aTableFr
       return border;
     }
   }
   // see if the colgroup is dominant
   if (aColGroupFrame) {
     GetColorAndStyle(aColGroupFrame, aTableWM, aSide,
                      &tempBorder.style, &tempBorder.color, &tempBorder.width);
     tempBorder.owner = aAja && !inlineAxis ? eAjaColGroupOwner : eColGroupOwner;
-    // pass here and below false for aSecondIsHorizontal as it is only used for corner calculations.
+    // pass here and below false for aSecondIsInlineDir as it is only used for corner calculations.
     border = CompareBorders(!CELL_CORNER, border, tempBorder, false);
     if (NS_STYLE_BORDER_STYLE_HIDDEN == border.style) {
       return border;
     }
   }
   // see if the col is dominant
   if (aColFrame) {
     GetColorAndStyle(aColFrame, aTableWM, aSide,
@@ -4979,17 +4979,17 @@ struct BCCornerInfo
 
   void Update(mozilla::LogicalSide aSide,
               BCCellBorder  border);
 
   nscolor   ownerColor;     // color of borderOwner
   uint16_t  ownerWidth;     // pixel width of borderOwner
   uint16_t  subWidth;       // pixel width of the largest border intersecting the border perpendicular
                             // to ownerSide
-  uint32_t  ownerSide:2;    // LogicalSide (e.g NS_SIDE_TOP, NS_SIDE_RIGHT, etc) of the border
+  uint32_t  ownerSide:2;    // LogicalSide (e.g eLogicalSideBStart, etc) of the border
                             // owning the corner relative to the corner
   uint32_t  ownerElem:3;    // elem type (e.g. eTable, eGroup, etc) owning the corner
   uint32_t  ownerStyle:8;   // border style of ownerElem
   uint32_t  subSide:2;      // side of border with subWidth relative to the corner
   uint32_t  subElem:3;      // elem type (e.g. eTable, eGroup, etc) of sub owner
   uint32_t  subStyle:8;     // border style of subElem
   uint32_t  hasDashDot:1;   // does a dashed, dotted segment enter the corner, they cannot be beveled
   uint32_t  numSegs:3;      // number of segments entering corner
@@ -5025,42 +5025,42 @@ void
 BCCornerInfo::Update(mozilla::LogicalSide aSide,
                      BCCellBorder  aBorder)
 {
   bool existingWins = false;
   if (0xFF == ownerStyle) { // initial value indiating that it hasn't been set yet
     Set(aSide, aBorder);
   }
   else {
-    bool horizontal = IsInline(aSide); // relative to the corner
+    bool isInline = IsInline(aSide); // relative to the corner
     BCCellBorder oldBorder, tempBorder;
     oldBorder.owner  = (BCBorderOwner) ownerElem;
     oldBorder.style =  ownerStyle;
     oldBorder.width =  ownerWidth;
     oldBorder.color =  ownerColor;
 
     LogicalSide oldSide  = LogicalSide(ownerSide);
 
-    tempBorder = CompareBorders(CELL_CORNER, oldBorder, aBorder, horizontal, &existingWins);
+    tempBorder = CompareBorders(CELL_CORNER, oldBorder, aBorder, isInline, &existingWins);
 
     ownerElem  = tempBorder.owner;
     ownerStyle = tempBorder.style;
     ownerWidth = tempBorder.width;
     ownerColor = tempBorder.color;
     if (existingWins) { // existing corner is dominant
       if (::Perpendicular(LogicalSide(ownerSide), aSide)) {
         // see if the new sub info replaces the old
         BCCellBorder subBorder;
         subBorder.owner = (BCBorderOwner) subElem;
         subBorder.style =  subStyle;
         subBorder.width =  subWidth;
         subBorder.color = 0; // we are not interested in subBorder color
         bool firstWins;
 
-        tempBorder = CompareBorders(CELL_CORNER, subBorder, aBorder, horizontal, &firstWins);
+        tempBorder = CompareBorders(CELL_CORNER, subBorder, aBorder, isInline, &firstWins);
 
         subElem  = tempBorder.owner;
         subStyle = tempBorder.style;
         subWidth = tempBorder.width;
         if (!firstWins) {
           subSide = aSide;
         }
       }
@@ -5155,19 +5155,19 @@ SetBorder(const BCCellBorder&   aNewBord
 
   return changed;
 }
 
 // this function will set the horizontal border. It will return true if the
 // existing segment will not be continued. Having a vertical owner of a corner
 // should also start a new segment.
 static bool
-SetHorBorder(const BCCellBorder& aNewBorder,
-             const BCCornerInfo& aCorner,
-             BCCellBorder&       aBorder)
+SetInlineDirBorder(const BCCellBorder& aNewBorder,
+                   const BCCornerInfo& aCorner,
+                   BCCellBorder&       aBorder)
 {
   bool startSeg = ::SetBorder(aNewBorder, aBorder);
   if (!startSeg) {
     startSeg = !IsInline(LogicalSide(aCorner.ownerSide));
   }
   return startSeg;
 }
 
@@ -5208,18 +5208,18 @@ nsTableFrame::ExpandBCDamageArea(TableAr
   if ((dStartX > 0) || (dEndX < (numCols - 1)) || (dStartY > 0) || (dEndY < (numRows - 1))) {
     nsTableCellMap* tableCellMap = GetCellMap(); if (!tableCellMap) ABORT0();
     // Get the ordered row groups
     RowGroupArray rowGroups;
     OrderRowGroups(rowGroups);
 
     // Scope outside loop to be used as hint.
     nsCellMap* cellMap = nullptr;
-    for (uint32_t rgX = 0; rgX < rowGroups.Length(); rgX++) {
-      nsTableRowGroupFrame* rgFrame = rowGroups[rgX];
+    for (uint32_t rgIdx = 0; rgIdx < rowGroups.Length(); rgIdx++) {
+      nsTableRowGroupFrame* rgFrame = rowGroups[rgIdx];
       int32_t rgStartY = rgFrame->GetStartRowIndex();
       int32_t rgEndY   = rgStartY + rgFrame->GetRowCount() - 1;
       if (dEndY < rgStartY)
         break;
       cellMap = tableCellMap->GetMapFor(rgFrame, cellMap);
       if (!cellMap) ABORT0();
       // check for spanners from above and below
       if ((dStartY > 0) && (dStartY >= rgStartY) && (dStartY <= rgEndY)) {
@@ -5300,17 +5300,17 @@ nsTableFrame::ExpandBCDamageArea(TableAr
     aArea.StartRow() = dStartY;
     aArea.ColCount() = 1 + dEndX - dStartX;
     aArea.RowCount() = 1 + dEndY - dStartY;
   }
 }
 
 
 #define ADJACENT    true
-#define HORIZONTAL  true
+#define INLINE_DIR  true
 
 void
 BCMapCellInfo::SetTableBStartIStartContBCBorder()
 {
   BCCellBorder currentBorder;
   //calculate continuous top first row & rowgroup border: special case
   //because it must include the table in the collapse
   if (mStartRow) {
@@ -5327,17 +5327,17 @@ BCMapCellInfo::SetTableBStartIStartContB
                                    eLogicalSideBStart, !ADJACENT);
     mColGroup->SetContinuousBCBorderWidth(eLogicalSideBStart,
                                           currentBorder.width);
   }
   if (0 == mColIndex) {
     currentBorder = CompareBorders(mTableFrame, mColGroup, mStartCol, nullptr,
                                    nullptr, nullptr, mTableWM,
                                    eLogicalSideIStart, !ADJACENT);
-    mTableFrame->SetContinuousLeftBCBorderWidth(currentBorder.width);
+    mTableFrame->SetContinuousIStartBCBorderWidth(currentBorder.width);
   }
 }
 
 void
 BCMapCellInfo::SetRowGroupIStartContBCBorder()
 {
   BCCellBorder currentBorder;
   //get row group continuous borders
@@ -5369,18 +5369,18 @@ BCMapCellInfo::SetColumnBStartIEndContBC
 {
   BCCellBorder currentBorder;
   //calculate column continuous borders
   //we only need to do this once, so we'll do it only on the first row
   currentBorder = CompareBorders(mTableFrame, mCurrentColGroupFrame,
                                  mCurrentColFrame, mRowGroup, mStartRow,
                                  nullptr, mTableWM, eLogicalSideBStart,
                                  !ADJACENT);
-  ((nsTableColFrame*) mCurrentColFrame)->
-    SetContinuousBCBorderWidth(eLogicalSideBStart, currentBorder.width);
+  mCurrentColFrame->SetContinuousBCBorderWidth(eLogicalSideBStart,
+                                               currentBorder.width);
   if (mNumTableCols == GetCellEndColIndex() + 1) {
     currentBorder = CompareBorders(mTableFrame, mCurrentColGroupFrame,
                                    mCurrentColFrame, nullptr, nullptr, nullptr,
                                    mTableWM, eLogicalSideIEnd, !ADJACENT);
   }
   else {
     currentBorder = CompareBorders(nullptr, mCurrentColGroupFrame,
                                    mCurrentColFrame, nullptr,nullptr, nullptr,
@@ -5435,17 +5435,17 @@ BCMapCellInfo::SetInnerRowGroupBEndContB
   const nsIFrame* rowgroup = mRgAtEnd ? mRowGroup : nullptr;
   currentBorder = CompareBorders(nullptr, nullptr, nullptr, rowgroup, mEndRow,
                                  nullptr, mTableWM, eLogicalSideBEnd, ADJACENT);
 
   adjacentBorder = CompareBorders(nullptr, nullptr, nullptr, aNextRowGroup,
                                   aNextRow, nullptr, mTableWM, eLogicalSideBStart,
                                   !ADJACENT);
   currentBorder = CompareBorders(false, currentBorder, adjacentBorder,
-                                 HORIZONTAL);
+                                 INLINE_DIR);
   if (aNextRow) {
     aNextRow->SetContinuousBCBorderWidth(eLogicalSideBStart,
                                          currentBorder.width);
   }
   if (mRgAtEnd && mRowGroup) {
     mRowGroup->SetContinuousBCBorderWidth(eLogicalSideBEnd, currentBorder.width);
   }
 }
@@ -5474,49 +5474,40 @@ BCMapCellInfo::SetRowIEndContBCBorder()
                                    eLogicalSideIEnd, ADJACENT);
     mCurrentRowFrame->SetContinuousBCBorderWidth(eLogicalSideIEnd,
                                                  currentBorder.width);
   }
 }
 void
 BCMapCellInfo::SetTableBStartBorderWidth(BCPixelSize aWidth)
 {
-  mTableBCData->mBStartBorderWidth = std::max(mTableBCData->mBStartBorderWidth, aWidth);
+  mTableBCData->mBStartBorderWidth = std::max(mTableBCData->mBStartBorderWidth,
+                                              aWidth);
 }
 
 void
-BCMapCellInfo::SetTableIStartBorderWidth(int32_t aRowY, BCPixelSize aWidth)
+BCMapCellInfo::SetTableIStartBorderWidth(int32_t aRowB, BCPixelSize aWidth)
 {
   // update the left/right first cell border
-  if (aRowY == 0) {
-    if (mTableWM.IsBidiLTR()) {
-      mTableBCData->mIStartCellBorderWidth = aWidth;
-    }
-    else {
-      mTableBCData->mIEndCellBorderWidth = aWidth;
-    }
+  if (aRowB == 0) {
+    mTableBCData->mIStartCellBorderWidth = aWidth;
   }
   mTableBCData->mIStartBorderWidth = std::max(mTableBCData->mIStartBorderWidth,
-                                          aWidth);
+                                              aWidth);
 }
 
 void
-BCMapCellInfo::SetTableIEndBorderWidth(int32_t aRowY, BCPixelSize aWidth)
+BCMapCellInfo::SetTableIEndBorderWidth(int32_t aRowB, BCPixelSize aWidth)
 {
   // update the left/right first cell border
-  if (aRowY == 0) {
-    if (mTableWM.IsBidiLTR()) {
-      mTableBCData->mIEndCellBorderWidth = aWidth;
-    }
-    else {
-      mTableBCData->mIStartCellBorderWidth = aWidth;
-    }
+  if (aRowB == 0) {
+    mTableBCData->mIEndCellBorderWidth = aWidth;
   }
   mTableBCData->mIEndBorderWidth = std::max(mTableBCData->mIEndBorderWidth,
-                                           aWidth);
+                                            aWidth);
 }
 
 void
 BCMapCellInfo::SetIEndBorderWidths(BCPixelSize aWidth)
 {
    // update the borders of the cells and cols affected
   if (mCell) {
     mCell->SetBorderWidth(eLogicalSideIEnd, std::max(aWidth,
@@ -5587,20 +5578,20 @@ BCMapCellInfo::SetColumn(int32_t aColX)
   mCurrentColGroupFrame = static_cast<nsTableColGroupFrame*>
                             (mCurrentColFrame->GetParent());
   if (!mCurrentColGroupFrame) {
     NS_ERROR("null mCurrentColGroupFrame");
   }
 }
 
 void
-BCMapCellInfo::IncrementRow(bool aResetToTopRowOfCell)
+BCMapCellInfo::IncrementRow(bool aResetToBStartRowOfCell)
 {
   mCurrentRowFrame =
-    aResetToTopRowOfCell ? mStartRow : mCurrentRowFrame->GetNextRow();
+    aResetToBStartRowOfCell ? mStartRow : mCurrentRowFrame->GetNextRow();
 }
 
 BCCellBorder
 BCMapCellInfo::GetBStartEdgeBorder()
 {
   return CompareBorders(mTableFrame, mCurrentColGroupFrame, mCurrentColFrame,
                         mRowGroup, mStartRow, mCell, mTableWM,
                         eLogicalSideBStart, !ADJACENT);
@@ -5654,17 +5645,19 @@ BCMapCellInfo::GetBEndInternalBorder()
 BCCellBorder
 BCMapCellInfo::GetBStartInternalBorder()
 {
   const nsIFrame* rg = mRgAtStart ? mRowGroup : nullptr;
   return CompareBorders(nullptr, nullptr, nullptr, rg, mStartRow, mCell,
                         mTableWM, eLogicalSideBStart, !ADJACENT);
 }
 
-/* Here is the order for storing border edges in the cell map as a cell is processed. There are
+/* XXX This comment is still written in physical (horizontal-tb) terms.
+
+   Here is the order for storing border edges in the cell map as a cell is processed. There are
    n=colspan top and bottom border edges per cell and n=rowspan left and right border edges per cell.
 
    1) On the top edge of the table, store the top edge. Never store the top edge otherwise, since
       a bottom edge from a cell above will take care of it.
    2) On the left edge of the table, store the left edge. Never store the left edge othewise, since
       a right edge from a cell to the left will take care of it.
    3) Store the right edge (or edges if a row span)
    4) Store the bottom edge (or edges if a col span)
@@ -5725,442 +5718,442 @@ nsTableFrame::CalcBCBorders()
 
   // segments that are on the table border edges need
   // to be initialized only once
   bool tableBorderReset[4];
   for (uint32_t sideX = eLogicalSideBStart; sideX <= eLogicalSideIStart; sideX++) {
     tableBorderReset[sideX] = false;
   }
 
-  // vertical borders indexed in x-direction (cols)
-  BCCellBorders lastVerBorders(damageArea.ColCount() + 1,
-                               damageArea.StartCol());
-  if (!lastVerBorders.borders) ABORT0();
-  BCCellBorder  lastTopBorder, lastBottomBorder;
-  // horizontal borders indexed in x-direction (cols)
-  BCCellBorders lastBottomBorders(damageArea.ColCount() + 1,
-                                  damageArea.StartCol());
-  if (!lastBottomBorders.borders) ABORT0();
+  // block-dir borders indexed in inline-direction (cols)
+  BCCellBorders lastBlockDirBorders(damageArea.ColCount() + 1,
+                                    damageArea.StartCol());
+  if (!lastBlockDirBorders.borders) ABORT0();
+  BCCellBorder  lastBStartBorder, lastBEndBorder;
+  // inline-dir borders indexed in inline-direction (cols)
+  BCCellBorders lastBEndBorders(damageArea.ColCount() + 1,
+                                damageArea.StartCol());
+  if (!lastBEndBorders.borders) ABORT0();
   bool startSeg;
   bool gotRowBorder = false;
 
   BCMapCellInfo  info(this), ajaInfo(this);
 
   BCCellBorder currentBorder, adjacentBorder;
-  BCCorners topCorners(damageArea.ColCount() + 1, damageArea.StartCol());
-  if (!topCorners.corners) ABORT0();
-  BCCorners bottomCorners(damageArea.ColCount() + 1, damageArea.StartCol());
-  if (!bottomCorners.corners) ABORT0();
+  BCCorners bStartCorners(damageArea.ColCount() + 1, damageArea.StartCol());
+  if (!bStartCorners.corners) ABORT0();
+  BCCorners bEndCorners(damageArea.ColCount() + 1, damageArea.StartCol());
+  if (!bEndCorners.corners) ABORT0();
 
   BCMapCellIterator iter(this, damageArea);
   for (iter.First(info); !iter.mAtEnd; iter.Next(info)) {
-    // see if lastTopBorder, lastBottomBorder need to be reset
+    // see if lastBStartBorder, lastBEndBorder need to be reset
     if (iter.IsNewRow()) {
       gotRowBorder = false;
-      lastTopBorder.Reset(info.mRowIndex, info.mRowSpan);
-      lastBottomBorder.Reset(info.GetCellEndRowIndex() + 1, info.mRowSpan);
+      lastBStartBorder.Reset(info.mRowIndex, info.mRowSpan);
+      lastBEndBorder.Reset(info.GetCellEndRowIndex() + 1, info.mRowSpan);
     }
     else if (info.mColIndex > damageArea.StartCol()) {
-      lastBottomBorder = lastBottomBorders[info.mColIndex - 1];
+      lastBEndBorder = lastBEndBorders[info.mColIndex - 1];
       if (info.mRowIndex >
-          (lastBottomBorder.rowIndex - lastBottomBorder.rowSpan)) {
-        // the top border's left edge butts against the middle of a rowspan
-        lastTopBorder.Reset(info.mRowIndex, info.mRowSpan);
+          (lastBEndBorder.rowIndex - lastBEndBorder.rowSpan)) {
+        // the bStart border's iStart edge butts against the middle of a rowspan
+        lastBStartBorder.Reset(info.mRowIndex, info.mRowSpan);
       }
-      if (lastBottomBorder.rowIndex > (info.GetCellEndRowIndex() + 1)) {
-        // the bottom border's left edge butts against the middle of a rowspan
-        lastBottomBorder.Reset(info.GetCellEndRowIndex() + 1, info.mRowSpan);
+      if (lastBEndBorder.rowIndex > (info.GetCellEndRowIndex() + 1)) {
+        // the bEnd border's iStart edge butts against the middle of a rowspan
+        lastBEndBorder.Reset(info.GetCellEndRowIndex() + 1, info.mRowSpan);
       }
     }
 
-    // find the dominant border considering the cell's top border and the table,
-    // row group, row if the border is at the top of the table, otherwise it was
+    // find the dominant border considering the cell's bStart border and the table,
+    // row group, row if the border is at the bStart of the table, otherwise it was
     // processed in a previous row
     if (0 == info.mRowIndex) {
       if (!tableBorderReset[eLogicalSideBStart]) {
         propData->mBStartBorderWidth = 0;
         tableBorderReset[eLogicalSideBStart] = true;
       }
       for (int32_t colIdx = info.mColIndex;
            colIdx <= info.GetCellEndColIndex(); colIdx++) {
         info.SetColumn(colIdx);
         currentBorder = info.GetBStartEdgeBorder();
-        // update/store the top left & top right corners of the seg
-        BCCornerInfo& tlCorner = topCorners[colIdx]; // top left
+        // update/store the bStart-iStart & bStart-iEnd corners of the seg
+        BCCornerInfo& tlCorner = bStartCorners[colIdx]; // bStart-iStart
         if (0 == colIdx) {
-          // we are on right hand side of the corner
+          // we are on the iEnd side of the corner
           tlCorner.Set(eLogicalSideIEnd, currentBorder);
         }
         else {
           tlCorner.Update(eLogicalSideIEnd, currentBorder);
-          tableCellMap->SetBCBorderCorner(eTopLeft, *iter.mCellMap, 0, 0, colIdx,
+          tableCellMap->SetBCBorderCorner(eBStartIStart, *iter.mCellMap, 0, 0, colIdx,
                                           LogicalSide(tlCorner.ownerSide),
                                           tlCorner.subWidth,
                                           tlCorner.bevel);
         }
-        topCorners[colIdx + 1].Set(eLogicalSideIStart, currentBorder); // top right
-        // update lastTopBorder and see if a new segment starts
-        startSeg = SetHorBorder(currentBorder, tlCorner, lastTopBorder);
+        bStartCorners[colIdx + 1].Set(eLogicalSideIStart, currentBorder); // bStart-iEnd
+        // update lastBStartBorder and see if a new segment starts
+        startSeg = SetInlineDirBorder(currentBorder, tlCorner, lastBStartBorder);
         // store the border segment in the cell map
         tableCellMap->SetBCBorderEdge(eLogicalSideBStart, *iter.mCellMap, 0, 0, colIdx,
                                       1, currentBorder.owner,
                                       currentBorder.width, startSeg);
 
         info.SetTableBStartBorderWidth(currentBorder.width);
         info.SetBStartBorderWidths(currentBorder.width);
         info.SetColumnBStartIEndContBCBorder();
       }
       info.SetTableBStartIStartContBCBorder();
     }
     else {
-      // see if the top border needs to be the start of a segment due to a
-      // vertical border owning the corner
+      // see if the bStart border needs to be the start of a segment due to a
+      // block-dir border owning the corner
       if (info.mColIndex > 0) {
         BCData& data = info.mCellData->mData;
         if (!data.IsBStartStart()) {
           LogicalSide cornerSide;
           bool bevel;
           data.GetCorner(cornerSide, bevel);
           if (IsBlock(cornerSide)) {
             data.SetBStartStart(true);
           }
         }
       }
     }
 
-    // find the dominant border considering the cell's left border and the
-    // table, col group, col if the border is at the left of the table,
+    // find the dominant border considering the cell's iStart border and the
+    // table, col group, col if the border is at the iStart of the table,
     // otherwise it was processed in a previous col
     if (0 == info.mColIndex) {
       if (!tableBorderReset[eLogicalSideIStart]) {
         propData->mIStartBorderWidth = 0;
         tableBorderReset[eLogicalSideIStart] = true;
       }
       info.mCurrentRowFrame = nullptr;
-      for (int32_t rowY = info.mRowIndex; rowY <= info.GetCellEndRowIndex();
-           rowY++) {
-        info.IncrementRow(rowY == info.mRowIndex);
+      for (int32_t rowB = info.mRowIndex; rowB <= info.GetCellEndRowIndex();
+           rowB++) {
+        info.IncrementRow(rowB == info.mRowIndex);
         currentBorder = info.GetIStartEdgeBorder();
-        BCCornerInfo& tlCorner = (0 == rowY) ? topCorners[0] : bottomCorners[0];
+        BCCornerInfo& tlCorner = (0 == rowB) ? bStartCorners[0] : bEndCorners[0];
         tlCorner.Update(eLogicalSideBEnd, currentBorder);
-        tableCellMap->SetBCBorderCorner(eTopLeft, *iter.mCellMap,
-                                        iter.mRowGroupStart, rowY, 0,
+        tableCellMap->SetBCBorderCorner(eBStartIStart, *iter.mCellMap,
+                                        iter.mRowGroupStart, rowB, 0,
                                         LogicalSide(tlCorner.ownerSide),
                                         tlCorner.subWidth,
                                         tlCorner.bevel);
-        bottomCorners[0].Set(eLogicalSideBStart, currentBorder); // bottom left
-
-        // update lastVerBordersBorder and see if a new segment starts
-        startSeg = SetBorder(currentBorder, lastVerBorders[0]);
+        bEndCorners[0].Set(eLogicalSideBStart, currentBorder); // bEnd-iStart
+
+        // update lastBlockDirBorders and see if a new segment starts
+        startSeg = SetBorder(currentBorder, lastBlockDirBorders[0]);
         // store the border segment in the cell map
         tableCellMap->SetBCBorderEdge(eLogicalSideIStart, *iter.mCellMap,
-                                      iter.mRowGroupStart, rowY, info.mColIndex,
+                                      iter.mRowGroupStart, rowB, info.mColIndex,
                                       1, currentBorder.owner,
                                       currentBorder.width, startSeg);
-        info.SetTableIStartBorderWidth(rowY , currentBorder.width);
+        info.SetTableIStartBorderWidth(rowB , currentBorder.width);
         info.SetIStartBorderWidths(currentBorder.width);
         info.SetRowIStartContBCBorder();
       }
       info.SetRowGroupIStartContBCBorder();
     }
 
-    // find the dominant border considering the cell's right border, adjacent
+    // find the dominant border considering the cell's iEnd border, adjacent
     // cells and the table, row group, row
     if (info.mNumTableCols == info.GetCellEndColIndex() + 1) {
-      // touches right edge of table
+      // touches iEnd edge of table
       if (!tableBorderReset[eLogicalSideIEnd]) {
         propData->mIEndBorderWidth = 0;
         tableBorderReset[eLogicalSideIEnd] = true;
       }
       info.mCurrentRowFrame = nullptr;
-      for (int32_t rowY = info.mRowIndex; rowY <= info.GetCellEndRowIndex();
-           rowY++) {
-        info.IncrementRow(rowY == info.mRowIndex);
+      for (int32_t rowB = info.mRowIndex; rowB <= info.GetCellEndRowIndex();
+           rowB++) {
+        info.IncrementRow(rowB == info.mRowIndex);
         currentBorder = info.GetIEndEdgeBorder();
-        // update/store the top right & bottom right corners
-        BCCornerInfo& trCorner = (0 == rowY) ?
-                                 topCorners[info.GetCellEndColIndex() + 1] :
-                                 bottomCorners[info.GetCellEndColIndex() + 1];
-        trCorner.Update(eLogicalSideBEnd, currentBorder);   // top right
-        tableCellMap->SetBCBorderCorner(eTopRight, *iter.mCellMap,
-                                        iter.mRowGroupStart, rowY,
+        // update/store the bStart-iEnd & bEnd-iEnd corners
+        BCCornerInfo& trCorner = (0 == rowB) ?
+                                 bStartCorners[info.GetCellEndColIndex() + 1] :
+                                 bEndCorners[info.GetCellEndColIndex() + 1];
+        trCorner.Update(eLogicalSideBEnd, currentBorder);   // bStart-iEnd
+        tableCellMap->SetBCBorderCorner(eBStartIEnd, *iter.mCellMap,
+                                        iter.mRowGroupStart, rowB,
                                         info.GetCellEndColIndex(),
                                         LogicalSide(trCorner.ownerSide),
                                         trCorner.subWidth,
                                         trCorner.bevel);
-        BCCornerInfo& brCorner = bottomCorners[info.GetCellEndColIndex() + 1];
-        brCorner.Set(eLogicalSideBStart, currentBorder); // bottom right
-        tableCellMap->SetBCBorderCorner(eBottomRight, *iter.mCellMap,
-                                        iter.mRowGroupStart, rowY,
+        BCCornerInfo& brCorner = bEndCorners[info.GetCellEndColIndex() + 1];
+        brCorner.Set(eLogicalSideBStart, currentBorder); // bEnd-iEnd
+        tableCellMap->SetBCBorderCorner(eBEndIEnd, *iter.mCellMap,
+                                        iter.mRowGroupStart, rowB,
                                         info.GetCellEndColIndex(),
                                         LogicalSide(brCorner.ownerSide),
                                         brCorner.subWidth,
                                         brCorner.bevel);
-        // update lastVerBorders and see if a new segment starts
+        // update lastBlockDirBorders and see if a new segment starts
         startSeg = SetBorder(currentBorder,
-                             lastVerBorders[info.GetCellEndColIndex() + 1]);
+                             lastBlockDirBorders[info.GetCellEndColIndex() + 1]);
         // store the border segment in the cell map and update cellBorders
         tableCellMap->SetBCBorderEdge(eLogicalSideIEnd, *iter.mCellMap,
-                                      iter.mRowGroupStart, rowY,
+                                      iter.mRowGroupStart, rowB,
                                       info.GetCellEndColIndex(), 1,
                                       currentBorder.owner, currentBorder.width,
                                       startSeg);
-        info.SetTableIEndBorderWidth(rowY, currentBorder.width);
+        info.SetTableIEndBorderWidth(rowB, currentBorder.width);
         info.SetIEndBorderWidths(currentBorder.width);
         info.SetRowIEndContBCBorder();
       }
       info.SetRowGroupIEndContBCBorder();
     }
     else {
       int32_t segLength = 0;
       BCMapCellInfo priorAjaInfo(this);
-      for (int32_t rowY = info.mRowIndex; rowY <= info.GetCellEndRowIndex();
-           rowY += segLength) {
-        iter.PeekIEnd(info, rowY, ajaInfo);
+      for (int32_t rowB = info.mRowIndex; rowB <= info.GetCellEndRowIndex();
+           rowB += segLength) {
+        iter.PeekIEnd(info, rowB, ajaInfo);
         currentBorder = info.GetIEndInternalBorder();
         adjacentBorder = ajaInfo.GetIStartInternalBorder();
         currentBorder = CompareBorders(!CELL_CORNER, currentBorder,
-                                        adjacentBorder, !HORIZONTAL);
-
-        segLength = std::max(1, ajaInfo.mRowIndex + ajaInfo.mRowSpan - rowY);
-        segLength = std::min(segLength, info.mRowIndex + info.mRowSpan - rowY);
-
-        // update lastVerBorders and see if a new segment starts
+                                        adjacentBorder, !INLINE_DIR);
+
+        segLength = std::max(1, ajaInfo.mRowIndex + ajaInfo.mRowSpan - rowB);
+        segLength = std::min(segLength, info.mRowIndex + info.mRowSpan - rowB);
+
+        // update lastBlockDirBorders and see if a new segment starts
         startSeg = SetBorder(currentBorder,
-                             lastVerBorders[info.GetCellEndColIndex() + 1]);
+                             lastBlockDirBorders[info.GetCellEndColIndex() + 1]);
         // store the border segment in the cell map and update cellBorders
         if (info.GetCellEndColIndex() < damageArea.EndCol() &&
-            rowY >= damageArea.StartRow() && rowY < damageArea.EndRow()) {
+            rowB >= damageArea.StartRow() && rowB < damageArea.EndRow()) {
           tableCellMap->SetBCBorderEdge(eLogicalSideIEnd, *iter.mCellMap,
-                                        iter.mRowGroupStart, rowY,
+                                        iter.mRowGroupStart, rowB,
                                         info.GetCellEndColIndex(), segLength,
                                         currentBorder.owner,
                                         currentBorder.width, startSeg);
           info.SetIEndBorderWidths(currentBorder.width);
           ajaInfo.SetIStartBorderWidths(currentBorder.width);
         }
-        // update the top right corner
-        bool hitsSpanOnRight = (rowY > ajaInfo.mRowIndex) &&
-                                  (rowY < ajaInfo.mRowIndex + ajaInfo.mRowSpan);
-        BCCornerInfo* trCorner = ((0 == rowY) || hitsSpanOnRight) ?
-                                 &topCorners[info.GetCellEndColIndex() + 1] :
-                                 &bottomCorners[info.GetCellEndColIndex() + 1];
+        // update the bStart-iEnd corner
+        bool hitsSpanOnIEnd = (rowB > ajaInfo.mRowIndex) &&
+                                  (rowB < ajaInfo.mRowIndex + ajaInfo.mRowSpan);
+        BCCornerInfo* trCorner = ((0 == rowB) || hitsSpanOnIEnd) ?
+                                 &bStartCorners[info.GetCellEndColIndex() + 1] :
+                                 &bEndCorners[info.GetCellEndColIndex() + 1];
         trCorner->Update(eLogicalSideBEnd, currentBorder);
         // if this is not the first time through,
-        // consider the segment to the right
-        if (rowY != info.mRowIndex) {
+        // consider the segment to the iEnd side
+        if (rowB != info.mRowIndex) {
           currentBorder = priorAjaInfo.GetBEndInternalBorder();
           adjacentBorder = ajaInfo.GetBStartInternalBorder();
           currentBorder = CompareBorders(!CELL_CORNER, currentBorder,
-                                          adjacentBorder, HORIZONTAL);
+                                          adjacentBorder, INLINE_DIR);
           trCorner->Update(eLogicalSideIEnd, currentBorder);
         }
-        // store the top right corner in the cell map
+        // store the bStart-iEnd corner in the cell map
         if (info.GetCellEndColIndex() < damageArea.EndCol() &&
-            rowY >= damageArea.StartRow()) {
-          if (0 != rowY) {
-            tableCellMap->SetBCBorderCorner(eTopRight, *iter.mCellMap,
-                                            iter.mRowGroupStart, rowY,
+            rowB >= damageArea.StartRow()) {
+          if (0 != rowB) {
+            tableCellMap->SetBCBorderCorner(eBStartIEnd, *iter.mCellMap,
+                                            iter.mRowGroupStart, rowB,
                                             info.GetCellEndColIndex(),
                                             LogicalSide(trCorner->ownerSide),
                                             trCorner->subWidth,
                                             trCorner->bevel);
           }
           // store any corners this cell spans together with the aja cell
-          for (int32_t rX = rowY + 1; rX < rowY + segLength; rX++) {
-            tableCellMap->SetBCBorderCorner(eBottomRight, *iter.mCellMap,
+          for (int32_t rX = rowB + 1; rX < rowB + segLength; rX++) {
+            tableCellMap->SetBCBorderCorner(eBEndIEnd, *iter.mCellMap,
                                             iter.mRowGroupStart, rX,
                                             info.GetCellEndColIndex(),
                                             LogicalSide(trCorner->ownerSide),
                                             trCorner->subWidth, false);
           }
         }
-        // update bottom right corner, topCorners, bottomCorners
-        hitsSpanOnRight = (rowY + segLength <
+        // update bEnd-iEnd corner, bStartCorners, bEndCorners
+        hitsSpanOnIEnd = (rowB + segLength <
                            ajaInfo.mRowIndex + ajaInfo.mRowSpan);
-        BCCornerInfo& brCorner = (hitsSpanOnRight) ?
-                                 topCorners[info.GetCellEndColIndex() + 1] :
-                                 bottomCorners[info.GetCellEndColIndex() + 1];
+        BCCornerInfo& brCorner = (hitsSpanOnIEnd) ?
+                                 bStartCorners[info.GetCellEndColIndex() + 1] :
+                                 bEndCorners[info.GetCellEndColIndex() + 1];
         brCorner.Set(eLogicalSideBStart, currentBorder);
         priorAjaInfo = ajaInfo;
       }
     }
     for (int32_t colIdx = info.mColIndex + 1;
          colIdx <= info.GetCellEndColIndex(); colIdx++) {
-      lastVerBorders[colIdx].Reset(0,1);
-    }
-
-    // find the dominant border considering the cell's bottom border, adjacent
+      lastBlockDirBorders[colIdx].Reset(0,1);
+    }
+
+    // find the dominant border considering the cell's bEnd border, adjacent
     // cells and the table, row group, row
     if (info.mNumTableRows == info.GetCellEndRowIndex() + 1) {
       // touches bottom edge of table
       if (!tableBorderReset[eLogicalSideBEnd]) {
         propData->mBEndBorderWidth = 0;
         tableBorderReset[eLogicalSideBEnd] = true;
       }
       for (int32_t colIdx = info.mColIndex;
            colIdx <= info.GetCellEndColIndex(); colIdx++) {
         info.SetColumn(colIdx);
         currentBorder = info.GetBEndEdgeBorder();
-        // update/store the bottom left & bottom right corners
-        BCCornerInfo& blCorner = bottomCorners[colIdx]; // bottom left
+        // update/store the bEnd-iStart & bEnd-IEnd corners
+        BCCornerInfo& blCorner = bEndCorners[colIdx]; // bEnd-iStart
         blCorner.Update(eLogicalSideIEnd, currentBorder);
-        tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
+        tableCellMap->SetBCBorderCorner(eBEndIStart, *iter.mCellMap,
                                         iter.mRowGroupStart,
                                         info.GetCellEndRowIndex(),
                                         colIdx,
                                         LogicalSide(blCorner.ownerSide),
                                         blCorner.subWidth, blCorner.bevel);
-        BCCornerInfo& brCorner = bottomCorners[colIdx + 1]; // bottom right
+        BCCornerInfo& brCorner = bEndCorners[colIdx + 1]; // bEnd-iEnd
         brCorner.Update(eLogicalSideIStart, currentBorder);
-        if (info.mNumTableCols == colIdx + 1) { // lower right corner of the table
-          tableCellMap->SetBCBorderCorner(eBottomRight, *iter.mCellMap,
+        if (info.mNumTableCols == colIdx + 1) { // bEnd-IEnd corner of the table
+          tableCellMap->SetBCBorderCorner(eBEndIEnd, *iter.mCellMap,
                                           iter.mRowGroupStart,
                                           info.GetCellEndRowIndex(), colIdx,
                                           LogicalSide(brCorner.ownerSide),
                                           brCorner.subWidth,
                                           brCorner.bevel, true);
         }
-        // update lastBottomBorder and see if a new segment starts
-        startSeg = SetHorBorder(currentBorder, blCorner, lastBottomBorder);
+        // update lastBEndBorder and see if a new segment starts
+        startSeg = SetInlineDirBorder(currentBorder, blCorner, lastBEndBorder);
         if (!startSeg) {
            // make sure that we did not compare apples to oranges i.e. the
-           // current border should be a continuation of the lastBottomBorder,
-           // as it is a bottom border
+           // current border should be a continuation of the lastBEndBorder,
+           // as it is a bEnd border
            // add 1 to the info.GetCellEndRowIndex()
-           startSeg = (lastBottomBorder.rowIndex !=
+           startSeg = (lastBEndBorder.rowIndex !=
                        (info.GetCellEndRowIndex() + 1));
         }
         // store the border segment in the cell map and update cellBorders
         tableCellMap->SetBCBorderEdge(eLogicalSideBEnd, *iter.mCellMap,
                                       iter.mRowGroupStart,
                                       info.GetCellEndRowIndex(),
                                       colIdx, 1, currentBorder.owner,
                                       currentBorder.width, startSeg);
-        // update lastBottomBorders
-        lastBottomBorder.rowIndex = info.GetCellEndRowIndex() + 1;
-        lastBottomBorder.rowSpan = info.mRowSpan;
-        lastBottomBorders[colIdx] = lastBottomBorder;
+        // update lastBEndBorders
+        lastBEndBorder.rowIndex = info.GetCellEndRowIndex() + 1;
+        lastBEndBorder.rowSpan = info.mRowSpan;
+        lastBEndBorders[colIdx] = lastBEndBorder;
 
         info.SetBEndBorderWidths(currentBorder.width);
         info.SetTableBEndBorderWidth(currentBorder.width);
         info.SetColumnBEndContBCBorder();
       }
       info.SetRowGroupBEndContBCBorder();
       info.SetColGroupBEndContBCBorder();
     }
     else {
       int32_t segLength = 0;
       for (int32_t colIdx = info.mColIndex;
            colIdx <= info.GetCellEndColIndex(); colIdx += segLength) {
         iter.PeekBEnd(info, colIdx, ajaInfo);
         currentBorder = info.GetBEndInternalBorder();
         adjacentBorder = ajaInfo.GetBStartInternalBorder();
         currentBorder = CompareBorders(!CELL_CORNER, currentBorder,
-                                        adjacentBorder, HORIZONTAL);
+                                        adjacentBorder, INLINE_DIR);
         segLength = std::max(1, ajaInfo.mColIndex + ajaInfo.mColSpan - colIdx);
         segLength = std::min(segLength, info.mColIndex + info.mColSpan - colIdx);
 
-        // update, store the bottom left corner
-        BCCornerInfo& blCorner = bottomCorners[colIdx]; // bottom left
+        // update, store the bEnd-iStart corner
+        BCCornerInfo& blCorner = bEndCorners[colIdx]; // bEnd-iStart
         bool hitsSpanBelow = (colIdx > ajaInfo.mColIndex) &&
                                (colIdx < ajaInfo.mColIndex + ajaInfo.mColSpan);
         bool update = true;
         if (colIdx == info.mColIndex && colIdx > damageArea.StartCol()) {
-          int32_t prevRowIndex = lastBottomBorders[colIdx - 1].rowIndex;
+          int32_t prevRowIndex = lastBEndBorders[colIdx - 1].rowIndex;
           if (prevRowIndex > info.GetCellEndRowIndex() + 1) {
-            // hits a rowspan on the right
+            // hits a rowspan on the iEnd side
             update = false;
-            // the corner was taken care of during the cell on the left
+            // the corner was taken care of during the cell on the iStart side
           }
           else if (prevRowIndex < info.GetCellEndRowIndex() + 1) {
-            // spans below the cell to the left
-            topCorners[colIdx] = blCorner;
+            // spans below the cell to the iStart side
+            bStartCorners[colIdx] = blCorner;
             blCorner.Set(eLogicalSideIEnd, currentBorder);
             update = false;
           }
         }
         if (update) {
           blCorner.Update(eLogicalSideIEnd, currentBorder);
         }
         if (info.GetCellEndRowIndex() < damageArea.EndRow() &&
             colIdx >= damageArea.StartCol()) {
           if (hitsSpanBelow) {
-            tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
+            tableCellMap->SetBCBorderCorner(eBEndIStart, *iter.mCellMap,
                                             iter.mRowGroupStart,
                                             info.GetCellEndRowIndex(), colIdx,
                                             LogicalSide(blCorner.ownerSide),
                                             blCorner.subWidth, blCorner.bevel);
           }
           // store any corners this cell spans together with the aja cell
           for (int32_t c = colIdx + 1; c < colIdx + segLength; c++) {
-            BCCornerInfo& corner = bottomCorners[c];
+            BCCornerInfo& corner = bEndCorners[c];
             corner.Set(eLogicalSideIEnd, currentBorder);
-            tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
+            tableCellMap->SetBCBorderCorner(eBEndIStart, *iter.mCellMap,
                                             iter.mRowGroupStart,
                                             info.GetCellEndRowIndex(), c,
                                             LogicalSide(corner.ownerSide),
                                             corner.subWidth,
                                             false);
           }
         }
-        // update lastBottomBorders and see if a new segment starts
-        startSeg = SetHorBorder(currentBorder, blCorner, lastBottomBorder);
+        // update lastBEndBorders and see if a new segment starts
+        startSeg = SetInlineDirBorder(currentBorder, blCorner, lastBEndBorder);
         if (!startSeg) {
            // make sure that we did not compare apples to oranges i.e. the
-           // current border should be a continuation of the lastBottomBorder,
-           // as it is a bottom border
+           // current border should be a continuation of the lastBEndBorder,
+           // as it is a bEnd border
            // add 1 to the info.GetCellEndRowIndex()
-           startSeg = (lastBottomBorder.rowIndex !=
+           startSeg = (lastBEndBorder.rowIndex !=
                        info.GetCellEndRowIndex() + 1);
         }
-        lastBottomBorder.rowIndex = info.GetCellEndRowIndex() + 1;
-        lastBottomBorder.rowSpan = info.mRowSpan;
+        lastBEndBorder.rowIndex = info.GetCellEndRowIndex() + 1;
+        lastBEndBorder.rowSpan = info.mRowSpan;
         for (int32_t c = colIdx; c < colIdx + segLength; c++) {
-          lastBottomBorders[c] = lastBottomBorder;
+          lastBEndBorders[c] = lastBEndBorder;
         }
 
         // store the border segment the cell map and update cellBorders
         if (info.GetCellEndRowIndex() < damageArea.EndRow() &&
             colIdx >= damageArea.StartCol() && colIdx < damageArea.EndCol()) {
           tableCellMap->SetBCBorderEdge(eLogicalSideBEnd, *iter.mCellMap,
                                         iter.mRowGroupStart,
                                         info.GetCellEndRowIndex(),
                                         colIdx, segLength, currentBorder.owner,
                                         currentBorder.width, startSeg);
           info.SetBEndBorderWidths(currentBorder.width);
           ajaInfo.SetBStartBorderWidths(currentBorder.width);
         }
-        // update bottom right corner
-        BCCornerInfo& brCorner = bottomCorners[colIdx + segLength];
+        // update bEnd-iEnd corner
+        BCCornerInfo& brCorner = bEndCorners[colIdx + segLength];
         brCorner.Update(eLogicalSideIStart, currentBorder);
       }
       if (!gotRowBorder && 1 == info.mRowSpan &&
           (ajaInfo.mStartRow || info.mRgAtEnd)) {
         //get continuous row/row group border
-        //we need to check the row group's bottom border if this is
+        //we need to check the row group's bEnd border if this is
         //the last row in the row group, but only a cell with rowspan=1
-        //will know whether *this* row is at the bottom
+        //will know whether *this* row is at the bEnd
         const nsIFrame* nextRowGroup =
           ajaInfo.mRgAtStart ? ajaInfo.mRowGroup : nullptr;
         info.SetInnerRowGroupBEndContBCBorder(nextRowGroup, ajaInfo.mStartRow);
         gotRowBorder = true;
       }
     }
 
-    // see if the cell to the right had a rowspan and its lower left border
-    // needs be joined with this one's bottom
-    // if  there is a cell to the right and the cell to right was a rowspan
+    // see if the cell to the iEnd side had a rowspan and its bEnd-iStart border
+    // needs be joined with this one's bEnd
+    // if  there is a cell to the iEnd and the cell to iEnd side was a rowspan
     if ((info.mNumTableCols != info.GetCellEndColIndex() + 1) &&
-        (lastBottomBorders[info.GetCellEndColIndex() + 1].rowSpan > 1)) {
-      BCCornerInfo& corner = bottomCorners[info.GetCellEndColIndex() + 1];
+        (lastBEndBorders[info.GetCellEndColIndex() + 1].rowSpan > 1)) {
+      BCCornerInfo& corner = bEndCorners[info.GetCellEndColIndex() + 1];
       if (!IsBlock(LogicalSide(corner.ownerSide))) {
-        // not a vertical owner
-        BCCellBorder& thisBorder = lastBottomBorder;
-        BCCellBorder& nextBorder = lastBottomBorders[info.mColIndex + 1];
+        // not a block-dir owner
+        BCCellBorder& thisBorder = lastBEndBorder;
+        BCCellBorder& nextBorder = lastBEndBorders[info.mColIndex + 1];
         if ((thisBorder.color == nextBorder.color) &&
             (thisBorder.width == nextBorder.width) &&
             (thisBorder.style == nextBorder.style)) {
           // set the flag on the next border indicating it is not the start of a
           // new segment
           if (iter.mCellMap) {
             tableCellMap->ResetTopStart(eLogicalSideBEnd, *iter.mCellMap,
                                         info.GetCellEndRowIndex(),
@@ -6175,150 +6168,149 @@ nsTableFrame::CalcBCBorders()
   propData->mDamageArea = TableArea(0, 0, 0, 0);
 #ifdef DEBUG_TABLE_CELLMAP
   mCellMap->Dump();
 #endif
 }
 
 class BCPaintBorderIterator;
 
-struct BCVerticalSeg
-{
-  BCVerticalSeg();
+struct BCBlockDirSeg
+{
+  BCBlockDirSeg();
 
   void Start(BCPaintBorderIterator& aIter,
              BCBorderOwner          aBorderOwner,
-             BCPixelSize            aVerSegWidth,
-             BCPixelSize            aHorSegHeight);
+             BCPixelSize            aBlockSegISize,
+             BCPixelSize            aInlineSegBSize);
 
   void Initialize(BCPaintBorderIterator& aIter);
-  void GetBottomCorner(BCPaintBorderIterator& aIter,
-                       BCPixelSize            aHorSegHeight);
+  void GetBEndCorner(BCPaintBorderIterator& aIter,
+                       BCPixelSize            aInlineSegBSize);
 
 
    void Paint(BCPaintBorderIterator& aIter,
               nsRenderingContext&   aRenderingContext,
-              BCPixelSize            aHorSegHeight);
-  void AdvanceOffsetY();
+              BCPixelSize            aInlineSegBSize);
+  void AdvanceOffsetB();
   void IncludeCurrentBorder(BCPaintBorderIterator& aIter);
 
 
   union {
     nsTableColFrame*  mCol;
     int32_t           mColWidth;
   };
-  nscoord               mOffsetX;    // x-offset with respect to the table edge
-  nscoord               mOffsetY;    // y-offset with respect to the table edge
-  nscoord               mLength;     // vertical length including corners
-  BCPixelSize           mWidth;      // width in pixels
+  nscoord               mOffsetI;    // i-offset with respect to the table edge
+  nscoord               mOffsetB;    // b-offset with respect to the table edge
+  nscoord               mLength;     // block-dir length including corners
+  BCPixelSize           mWidth;      // thickness in pixels
 
   nsTableCellFrame*     mAjaCell;       // previous sibling to the first cell
                                         // where the segment starts, it can be
                                         // the owner of a segment
   nsTableCellFrame*     mFirstCell;     // cell at the start of the segment
   nsTableRowGroupFrame* mFirstRowGroup; // row group at the start of the segment
   nsTableRowFrame*      mFirstRow;      // row at the start of the segment
   nsTableCellFrame*     mLastCell;      // cell at the current end of the
                                         // segment
 
 
   uint8_t               mOwner;         // owner of the border, defines the
                                         // style
-  LogicalSide    mTopBevelSide;  // direction to bevel at the top
-  nscoord               mTopBevelOffset; // how much to bevel at the top
-  BCPixelSize           mBottomHorSegHeight; // height of the crossing
-                                        //horizontal border
-  nscoord               mBottomOffset;  // how much longer is the segment due
-                                        // to the horizontal border, by this
+  LogicalSide           mBStartBevelSide;    // direction to bevel at the bStart
+  nscoord               mBStartBevelOffset;  // how much to bevel at the bStart
+  BCPixelSize           mBEndInlineSegBSize; // bSize of the crossing
+                                             // inline-dir border
+  nscoord               mBEndOffset;    // how much longer is the segment due
+                                        // to the inline-dir border, by this
                                         // amount the next segment needs to be
                                         // shifted.
-  bool                  mIsBottomBevel; // should we bevel at the bottom
+  bool                  mIsBEndBevel;   // should we bevel at the bEnd
 };
 
-struct BCHorizontalSeg
-{
-  BCHorizontalSeg();
+struct BCInlineDirSeg
+{
+  BCInlineDirSeg();
 
   void Start(BCPaintBorderIterator& aIter,
              BCBorderOwner          aBorderOwner,
-             BCPixelSize            aBottomVerSegWidth,
-             BCPixelSize            aHorSegHeight);
-   void GetRightCorner(BCPaintBorderIterator& aIter,
-                       BCPixelSize            aLeftSegWidth);
-   void AdvanceOffsetX(int32_t aIncrement);
+             BCPixelSize            aBEndBlockSegWidth,
+             BCPixelSize            aInlineSegBSize);
+   void GetIEndCorner(BCPaintBorderIterator& aIter,
+                      BCPixelSize            aIStartSegWidth);
+   void AdvanceOffsetI(int32_t aIncrement);
    void IncludeCurrentBorder(BCPaintBorderIterator& aIter);
    void Paint(BCPaintBorderIterator& aIter,
-              nsRenderingContext&   aRenderingContext);
-
-  nscoord            mOffsetX;       // x-offset with respect to the table edge
-  nscoord            mOffsetY;       // y-offset with respect to the table edge
-  nscoord            mLength;        // horizontal length including corners
-  BCPixelSize        mWidth;         // border width in pixels
-  nscoord            mLeftBevelOffset;   // how much to bevel at the left
-  LogicalSide mLeftBevelSide;     // direction to bevel at the left
-  bool               mIsRightBevel;      // should we bevel at the right end
-  nscoord            mRightBevelOffset;  // how much to bevel at the right
-  LogicalSide mRightBevelSide;    // direction to bevel at the right
+              nsRenderingContext&    aRenderingContext);
+
+  nscoord            mOffsetI;       // i-offset with respect to the table edge
+  nscoord            mOffsetB;       // b-offset with respect to the table edge
+  nscoord            mLength;        // inline-dir length including corners
+  BCPixelSize        mWidth;         // border thickness in pixels
+  nscoord            mIStartBevelOffset; // how much to bevel at the iStart
+  LogicalSide        mIStartBevelSide;   // direction to bevel at the iStart
+  bool               mIsIEndBevel;       // should we bevel at the iEnd end
+  nscoord            mIEndBevelOffset;   // how much to bevel at the iEnd
+  LogicalSide        mIEndBevelSide;     // direction to bevel at the iEnd
   nscoord            mEndOffset;         // how much longer is the segment due
-                                         // to the vertical border, by this
+                                         // to the block-dir border, by this
                                          // amount the next segment needs to be
                                          // shifted.
   uint8_t            mOwner;             // owner of the border, defines the
                                          // style
   nsTableCellFrame*  mFirstCell;         // cell at the start of the segment
   nsTableCellFrame*  mAjaCell;           // neighboring cell to the first cell
                                          // where the segment starts, it can be
                                          // the owner of a segment
 };
 
-// Iterates over borders (left border, corner, top border) in the cell map within a damage area
-// from left to right, top to bottom. All members are in terms of the 1st in flow frames, except
+// Iterates over borders (iStart border, corner, bStart border) in the cell map within a damage area
+// from iStart to iEnd, bStart to bEnd. All members are in terms of the 1st in flow frames, except
 // where suffixed by InFlow.
 class BCPaintBorderIterator
 {
 public:
   explicit BCPaintBorderIterator(nsTableFrame* aTable);
   ~BCPaintBorderIterator() { if (mVerInfo) {
                               delete [] mVerInfo;
                            }}
   void Reset();
 
   /**
    * Determine the damage area in terms of rows and columns and finalize
-   * mInitialOffsetX and mInitialOffsetY.
+   * mInitialOffsetI and mInitialOffsetB.
    * @param aDirtyRect - dirty rect in table coordinates
    * @return - true if we need to paint something given dirty rect
    */
   bool SetDamageArea(const nsRect& aDamageRect);
   void First();
   void Next();
   void AccumulateOrPaintInlineDirSegment(nsRenderingContext& aRenderingContext);
   void AccumulateOrPaintBlockDirSegment(nsRenderingContext& aRenderingContext);
   void ResetVerInfo();
   void StoreColumnWidth(int32_t aIndex);
-  bool VerticalSegmentOwnsCorner();
+  bool BlockDirSegmentOwnsCorner();
 
   nsTableFrame*         mTable;
   nsTableFrame*         mTableFirstInFlow;
   nsTableCellMap*       mTableCellMap;
   nsCellMap*            mCellMap;
   WritingMode           mTableWM;
-  int32_t               mColInc;            // +1 for ltr -1 for rtl
   const nsStyleBackground* mTableBgColor;
   nsTableFrame::RowGroupArray mRowGroups;
 
   nsTableRowGroupFrame* mPrevRg;
   nsTableRowGroupFrame* mRg;
   bool                  mIsRepeatedHeader;
   bool                  mIsRepeatedFooter;
   nsTableRowGroupFrame* mStartRg; // first row group in the damagearea
   int32_t               mRgIndex; // current row group index in the
-                                        // mRowgroups array
+                                  // mRowgroups array
   int32_t               mFifRgFirstRowIndex; // start row index of the first in
-                                           // flow of the row group
+                                             // flow of the row group
   int32_t               mRgFirstRowIndex; // row index of the first row in the
                                           // row group
   int32_t               mRgLastRowIndex; // row index of the last row in the row
                                          // group
   int32_t               mNumTableRows;   // number of rows in the table and all
                                          // continuations
   int32_t               mNumTableCols;   // number of columns in the table
   int32_t               mColIndex;       // with respect to the table
@@ -6326,72 +6318,72 @@ public:
   int32_t               mRepeatedHeaderRowIndex; // row index in a repeated
                                             //header, it's equivalent to
                                             // mRowIndex when we're in a repeated
                                             // header, and set to the last row
                                             // index of a repeated header when
                                             // we're not
   bool                  mIsNewRow;
   bool                  mAtEnd;             // the iterator cycled over all
-                                             // borders
+                                            // borders
   nsTableRowFrame*      mPrevRow;
   nsTableRowFrame*      mRow;
   nsTableRowFrame*      mStartRow;    //first row in a inside the damagearea
 
 
   // cell properties
   nsTableCellFrame*     mPrevCell;
   nsTableCellFrame*     mCell;
   BCCellData*           mPrevCellData;
   BCCellData*           mCellData;
   BCData*               mBCData;
 
   bool                  IsTableTopMost()    {return (mRowIndex == 0) && !mTable->GetPrevInFlow();}
   bool                  IsTableRightMost()  {return (mColIndex >= mNumTableCols);}
   bool                  IsTableBottomMost() {return (mRowIndex >= mNumTableRows) && !mTable->GetNextInFlow();}
   bool                  IsTableLeftMost()   {return (mColIndex == 0);}
-  bool IsDamageAreaTopMost() const
+  bool IsDamageAreaBStartMost() const
     { return mRowIndex == mDamageArea.StartRow(); }
-  bool IsDamageAreaRightMost() const
+  bool IsDamageAreaIEndMost() const
     { return mColIndex >= mDamageArea.EndCol(); }
-  bool IsDamageAreaBottomMost() const
+  bool IsDamageAreaBEndMost() const
     { return mRowIndex >= mDamageArea.EndRow(); }
-  bool IsDamageAreaLeftMost() const
+  bool IsDamageAreaIStartMost() const
     { return mColIndex == mDamageArea.StartCol(); }
   int32_t GetRelativeColIndex() const
     { return mColIndex - mDamageArea.StartCol(); }
 
   TableArea             mDamageArea;        // damageArea in cellmap coordinates
   bool                  IsAfterRepeatedHeader() { return !mIsRepeatedHeader && (mRowIndex == (mRepeatedHeaderRowIndex + 1));}
   bool StartRepeatedFooter() const
   {
     return mIsRepeatedFooter && mRowIndex == mRgFirstRowIndex &&
       mRowIndex != mDamageArea.StartRow();
   }
 
-  nscoord               mInitialOffsetX;  // offsetX of the first border with
+  nscoord               mInitialOffsetI;    // offsetI of the first border with
                                             // respect to the table
-  nscoord               mInitialOffsetY;    // offsetY of the first border with
+  nscoord               mInitialOffsetB;    // offsetB of the first border with
                                             // respect to the table
-  nscoord               mNextOffsetY;       // offsetY of the next segment
-  BCVerticalSeg*        mVerInfo; // this array is used differently when
-                                  // horizontal and vertical borders are drawn
-                                  // When horizontal border are drawn we cache
+  nscoord               mNextOffsetB;       // offsetB of the next segment
+  BCBlockDirSeg*        mVerInfo; // this array is used differently when
+                                  // inline-dir and block-dir borders are drawn
+                                  // When inline-dir border are drawn we cache
                                   // the column widths and the width of the
-                                  // vertical borders that arrive from top
-                                  // When we draw vertical borders we store
-                                  // lengths and width for vertical borders
+                                  // block-dir borders that arrive from bStart
+                                  // When we draw block-dir borders we store
+                                  // lengths and width for block-dir borders
                                   // before they are drawn while we  move over
                                   // the columns in the damage area
                                   // It has one more elements than columns are
-                                  //in the table.
-  BCHorizontalSeg       mHorSeg;            // the horizontal segment while we
+                                  // in the table.
+  BCInlineDirSeg        mInlineSeg;         // the inline-dir segment while we
                                             // move over the colums
-  BCPixelSize           mPrevHorSegHeight;  // the height of the previous
-                                            // horizontal border
+  BCPixelSize           mPrevInlineSegBSize; // the bSize of the previous
+                                             // inline-dir border
 
 private:
 
   bool SetNewRow(nsTableRowFrame* aRow = nullptr);
   bool SetNewRowGroup();
   void   SetNewData(int32_t aRowIndex, int32_t aColIndex);
 
 };
@@ -6402,157 +6394,138 @@ BCPaintBorderIterator::BCPaintBorderIter
   : mTable(aTable)
   , mTableFirstInFlow(static_cast<nsTableFrame*>(aTable->FirstInFlow()))
   , mTableCellMap(aTable->GetCellMap())
   , mTableWM(aTable->StyleContext())
 {
   mVerInfo    = nullptr;
   LogicalMargin childAreaOffset = mTable->GetChildAreaOffset(mTableWM, nullptr);
   // y position of first row in damage area
-  mInitialOffsetY =
+  mInitialOffsetB =
     mTable->GetPrevInFlow() ? 0 : childAreaOffset.BStart(mTableWM);
   mNumTableRows  = mTable->GetRowCount();
   mNumTableCols  = mTable->GetColCount();
 
   // Get the ordered row groups
   mTable->OrderRowGroups(mRowGroups);
   // initialize to a non existing index
   mRepeatedHeaderRowIndex = -99;
 
-  mColInc = mTableWM.IsBidiLTR() ? 1 : -1;
-
   nsIFrame* bgFrame =
     nsCSSRendering::FindNonTransparentBackgroundFrame(aTable);
   mTableBgColor = bgFrame->StyleBackground();
 }
 
 bool
 BCPaintBorderIterator::SetDamageArea(const nsRect& aDirtyRect)
 {
-
+  nscoord containerWidth = mTable->GetRect().width;
+  LogicalRect dirtyRect(mTableWM, aDirtyRect, containerWidth);
   uint32_t startRowIndex, endRowIndex, startColIndex, endColIndex;
   startRowIndex = endRowIndex = startColIndex = endColIndex = 0;
   bool done = false;
   bool haveIntersect = false;
   // find startRowIndex, endRowIndex
-  nscoord rowY = mInitialOffsetY;
-  for (uint32_t rgX = 0; rgX < mRowGroups.Length() && !done; rgX++) {
-    nsTableRowGroupFrame* rgFrame = mRowGroups[rgX];
+  nscoord rowB = mInitialOffsetB;
+  for (uint32_t rgIdx = 0; rgIdx < mRowGroups.Length() && !done; rgIdx++) {
+    nsTableRowGroupFrame* rgFrame = mRowGroups[rgIdx];
     for (nsTableRowFrame* rowFrame = rgFrame->GetFirstRow(); rowFrame;
          rowFrame = rowFrame->GetNextRow()) {
       // get the row rect relative to the table rather than the row group
-      nsSize rowSize = rowFrame->GetSize();
+      nscoord rowBSize = rowFrame->BSize(mTableWM);
       if (haveIntersect) {
         // conservatively estimate the half border widths outside the row
         nscoord borderHalf = mTable->GetPrevInFlow() ? 0 : nsPresContext::
           CSSPixelsToAppUnits(rowFrame->GetBStartBCBorderWidth() + 1);
-        if (aDirtyRect.YMost() >= rowY - borderHalf) {
+        if (dirtyRect.BEnd(mTableWM) >= rowB - borderHalf) {
           nsTableRowFrame* fifRow =
             static_cast<nsTableRowFrame*>(rowFrame->FirstInFlow());
           endRowIndex = fifRow->GetRowIndex();
         }
         else done = true;
       }
       else {
         // conservatively estimate the half border widths outside the row
         nscoord borderHalf = mTable->GetNextInFlow() ? 0 : nsPresContext::
           CSSPixelsToAppUnits(rowFrame->GetBEndBCBorderWidth() + 1);
-        if (rowY + rowSize.height + borderHalf >= aDirtyRect.y) {
+        if (rowB + rowBSize + borderHalf >= dirtyRect.BStart(mTableWM)) {
           mStartRg  = rgFrame;
           mStartRow = rowFrame;
           nsTableRowFrame* fifRow =
             static_cast<nsTableRowFrame*>(rowFrame->FirstInFlow());
           startRowIndex = endRowIndex = fifRow->GetRowIndex();
           haveIntersect = true;
         }
         else {
-          mInitialOffsetY += rowSize.height;
+          mInitialOffsetB += rowBSize;
         }
       }
-      rowY += rowSize.height;
-    }
-  }
-  mNextOffsetY = mInitialOffsetY;
+      rowB += rowBSize;
+    }
+  }
+  mNextOffsetB = mInitialOffsetB;
 
   // XXX comment refers to the obsolete NS_FRAME_OUTSIDE_CHILDREN flag
   // XXX but I don't understand it, so not changing it for now
   // outer table borders overflow the table, so the table might be
   // target to other areas as the NS_FRAME_OUTSIDE_CHILDREN is set
   // on the table
   if (!haveIntersect)
     return false;
   // find startColIndex, endColIndex, startColX
   haveIntersect = false;
   if (0 == mNumTableCols)
     return false;
   int32_t leftCol, rightCol; // columns are in the range [leftCol, rightCol)
 
   LogicalMargin childAreaOffset = mTable->GetChildAreaOffset(mTableWM, nullptr);
-  if (mTableWM.IsBidiLTR()) {
-    // x position of first col in damage area
-    mInitialOffsetX = childAreaOffset.IStart(mTableWM);
-    leftCol = 0;
-    rightCol = mNumTableCols;
-  } else {
-    // x position of first col in damage area
-    mInitialOffsetX =
-      mTable->GetRect().width - childAreaOffset.IStart(mTableWM);
-    leftCol = mNumTableCols-1;
-    rightCol = -1;
-  }
+
+  // x position of first col in damage area
+  mInitialOffsetI = childAreaOffset.IStart(mTableWM);
+  leftCol = 0;
+  rightCol = mNumTableCols;
+
   nscoord x = 0;
   int32_t colX;
-  for (colX = leftCol; colX != rightCol; colX += mColInc) {
+  for (colX = leftCol; colX != rightCol; colX++) {
     nsTableColFrame* colFrame = mTableFirstInFlow->GetColFrame(colX);
     if (!colFrame) ABORT1(false);
     // get the col rect relative to the table rather than the col group
-    nsSize size = colFrame->GetSize();
+    nscoord colISize = colFrame->ISize(mTableWM);
     if (haveIntersect) {
-      // conservatively estimate the left half border width outside the col
-      nscoord istartBorderHalf = nsPresContext::
+      // conservatively estimate the iStart half border width outside the col
+      nscoord iStartBorderHalf = nsPresContext::
         CSSPixelsToAppUnits(colFrame->GetIStartBorderWidth() + 1);
-      if (aDirtyRect.XMost() >= x - istartBorderHalf) {
+      if (dirtyRect.IEnd(mTableWM) >= x - iStartBorderHalf) {
         endColIndex = colX;
       }
       else break;
     }
     else {
-      // conservatively estimate the right half border width outside the col
-      nscoord iendBorderHalf = nsPresContext::
+      // conservatively estimate the iEnd half border width outside the col
+      nscoord iEndBorderHalf = nsPresContext::
         CSSPixelsToAppUnits(colFrame->GetIEndBorderWidth() + 1);
-      if (x + size.width + iendBorderHalf >= aDirtyRect.x) {
+      if (x + colISize + iEndBorderHalf >= dirtyRect.IStart(mTableWM)) {
         startColIndex = endColIndex = colX;
         haveIntersect = true;
       }
       else {
-        mInitialOffsetX += mColInc * size.width;
+        mInitialOffsetI += colISize;
       }
     }
-    x += size.width;
-  }
-  if (!mTableWM.IsBidiLTR()) {
-    uint32_t temp;
-    mInitialOffsetX =
-      mTable->GetRect().width - childAreaOffset.IStart(mTableWM);
-    temp = startColIndex; startColIndex = endColIndex; endColIndex = temp;
-    for (uint32_t column = 0; column < startColIndex; column++) {
-      nsTableColFrame* colFrame = mTableFirstInFlow->GetColFrame(column);
-      if (!colFrame) ABORT1(false);
-      nsSize size = colFrame->GetSize();
-      mInitialOffsetX += mColInc * size.width;
-    }
+    x += colISize;
   }
   if (!haveIntersect)
     return false;
   mDamageArea = TableArea(startColIndex, startRowIndex,
                           1 + DeprecatedAbs<int32_t>(endColIndex - startColIndex),
                           1 + endRowIndex - startRowIndex);
 
   Reset();
-  mVerInfo = new BCVerticalSeg[mDamageArea.ColCount() + 1];
+  mVerInfo = new BCBlockDirSeg[mDamageArea.ColCount() + 1];
   if (!mVerInfo)
     return false;
   return true;
 }
 
 void
 BCPaintBorderIterator::Reset()
 {
@@ -6582,25 +6555,25 @@ BCPaintBorderIterator::SetNewData(int32_
 {
   if (!mTableCellMap || !mTableCellMap->mBCInfo) ABORT0();
 
   mColIndex    = aX;
   mRowIndex    = aY;
   mPrevCellData = mCellData;
   if (IsTableRightMost() && IsTableBottomMost()) {
    mCell = nullptr;
-   mBCData = &mTableCellMap->mBCInfo->mLowerRightCorner;
+   mBCData = &mTableCellMap->mBCInfo->mBEndIEndCorner;
   }
   else if (IsTableRightMost()) {
     mCellData = nullptr;
-    mBCData = &mTableCellMap->mBCInfo->mRightBorders.ElementAt(aY);
+    mBCData = &mTableCellMap->mBCInfo->mIEndBorders.ElementAt(aY);
   }
   else if (IsTableBottomMost()) {
     mCellData = nullptr;
-    mBCData = &mTableCellMap->mBCInfo->mBottomBorders.ElementAt(aX);
+    mBCData = &mTableCellMap->mBCInfo->mBEndBorders.ElementAt(aX);
   }
   else {
     if (uint32_t(mRowIndex - mFifRgFirstRowIndex) < mCellMap->mRows.Length()) {
       mBCData = nullptr;
       mCellData =
         (BCCellData*)mCellMap->mRows[mRowIndex - mFifRgFirstRowIndex].SafeElementAt(mColIndex);
       if (mCellData) {
         mBCData = &mCellData->mData;
@@ -6633,17 +6606,17 @@ bool
 BCPaintBorderIterator::SetNewRow(nsTableRowFrame* aRow)
 {
   mPrevRow = mRow;
   mRow     = (aRow) ? aRow : mRow->GetNextRow();
   if (mRow) {
     mIsNewRow = true;
     mRowIndex = mRow->GetRowIndex();
     mColIndex = mDamageArea.StartCol();
-    mPrevHorSegHeight = 0;
+    mPrevInlineSegBSize = 0;
     if (mIsRepeatedHeader) {
       mRepeatedHeaderRowIndex = mRowIndex;
     }
   }
   else {
     mAtEnd = true;
   }
   return !mAtEnd;
@@ -6754,16 +6727,17 @@ BCPaintBorderIterator::Next()
   }
   if (!mAtEnd) {
     SetNewData(mRowIndex, mColIndex);
   }
 }
 
 // XXX if CalcVerCornerOffset and CalcHorCornerOffset remain similar, combine
 // them
+// XXX Update terminology from physical to logical
 /** Compute the vertical offset of a vertical border segment
   * @param aCornerOwnerSide - which side owns the corner
   * @param aCornerSubWidth  - how wide is the nonwinning side of the corner
   * @param aHorWidth        - how wide is the horizontal edge of the corner
   * @param aIsStartOfSeg    - does this corner start a new segment
   * @param aIsBevel         - is this corner beveled
   * @return                 - offset in twips
   */
@@ -6799,175 +6773,163 @@ CalcVerCornerOffset(LogicalSide aCornerO
 }
 
 /** Compute the horizontal offset of a horizontal border segment
   * @param aCornerOwnerSide - which side owns the corner
   * @param aCornerSubWidth  - how wide is the nonwinning side of the corner
   * @param aVerWidth        - how wide is the vertical edge of the corner
   * @param aIsStartOfSeg    - does this corner start a new segment
   * @param aIsBevel         - is this corner beveled
-  * @param aTableIsLTR      - direction, the computation depends on ltr or rtl
   * @return                 - offset in twips
   */
 static nscoord
 CalcHorCornerOffset(LogicalSide aCornerOwnerSide,
                     BCPixelSize aCornerSubWidth,
                     BCPixelSize aVerWidth,
                     bool        aIsStartOfSeg,
-                    bool        aIsBevel,
-                    bool        aTableIsLTR)
+                    bool        aIsBevel)
 {
   nscoord offset = 0;
   // XXX These should be replaced with appropriate side-specific macros (which?)
   BCPixelSize smallHalf, largeHalf;
   if (IsInline(aCornerOwnerSide)) {
-    if (aTableIsLTR) {
-      DivideBCBorderSize(aCornerSubWidth, smallHalf, largeHalf);
-    }
-    else {
-      DivideBCBorderSize(aCornerSubWidth, largeHalf, smallHalf);
-    }
+    DivideBCBorderSize(aCornerSubWidth, smallHalf, largeHalf);
     if (aIsBevel) {
       offset = (aIsStartOfSeg) ? -largeHalf : smallHalf;
     }
     else {
       offset = (eLogicalSideIStart == aCornerOwnerSide) ? smallHalf : -largeHalf;
     }
   }
   else {
-    if (aTableIsLTR) {
-      DivideBCBorderSize(aVerWidth, smallHalf, largeHalf);
-    }
-    else {
-      DivideBCBorderSize(aVerWidth, largeHalf, smallHalf);
-    }
+    DivideBCBorderSize(aVerWidth, smallHalf, largeHalf);
     if (aIsBevel) {
       offset = (aIsStartOfSeg) ? -largeHalf : smallHalf;
     }
     else {
       offset = (aIsStartOfSeg) ? smallHalf : -largeHalf;
     }
   }
   return nsPresContext::CSSPixelsToAppUnits(offset);
 }
 
-BCVerticalSeg::BCVerticalSeg()
+BCBlockDirSeg::BCBlockDirSeg()
 {
   mCol = nullptr;
   mFirstCell = mLastCell = mAjaCell = nullptr;
-  mOffsetX = mOffsetY = mLength = mWidth = mTopBevelOffset = 0;
-  mTopBevelSide = eLogicalSideBStart;
+  mOffsetI = mOffsetB = mLength = mWidth = mBStartBevelOffset = 0;
+  mBStartBevelSide = eLogicalSideBStart;
   mOwner = eCellOwner;
 }
 
 /**
- * Start a new vertical segment
+ * Start a new block-direction segment
  * @param aIter         - iterator containing the structural information
  * @param aBorderOwner  - determines the border style
- * @param aVerSegWidth  - the width of segment in pixel
- * @param aHorSegHeight - the width of the horizontal segment joining the corner
+ * @param aBlockSegISize  - the width of segment in pixel
+ * @param aInlineSegBSize - the width of the inline-dir segment joining the corner
  *                        at the start
  */
 void
-BCVerticalSeg::Start(BCPaintBorderIterator& aIter,
+BCBlockDirSeg::Start(BCPaintBorderIterator& aIter,
                      BCBorderOwner          aBorderOwner,
-                     BCPixelSize            aVerSegWidth,
-                     BCPixelSize            aHorSegHeight)
+                     BCPixelSize            aBlockSegISize,
+                     BCPixelSize            aInlineSegBSize)
 {
   LogicalSide ownerSide   = eLogicalSideBStart;
   bool bevel       = false;
 
   nscoord cornerSubWidth  = (aIter.mBCData) ?
                                aIter.mBCData->GetCorner(ownerSide, bevel) : 0;
 
-  bool    topBevel        = (aVerSegWidth > 0) ? bevel : false;
-  BCPixelSize maxHorSegHeight = std::max(aIter.mPrevHorSegHeight, aHorSegHeight);
+  bool    topBevel        = (aBlockSegISize > 0) ? bevel : false;
+  BCPixelSize maxInlineSegBSize = std::max(aIter.mPrevInlineSegBSize, aInlineSegBSize);
   nscoord offset          = CalcVerCornerOffset(ownerSide, cornerSubWidth,
-                                                maxHorSegHeight, true,
+                                                maxInlineSegBSize, true,
                                                 topBevel);
 
-  mTopBevelOffset = topBevel ?
-    nsPresContext::CSSPixelsToAppUnits(maxHorSegHeight): 0;
+  mBStartBevelOffset = topBevel ?
+    nsPresContext::CSSPixelsToAppUnits(maxInlineSegBSize): 0;
   // XXX this assumes that only corners where 2 segments join can be beveled
-  mTopBevelSide     = (aHorSegHeight > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
-  mOffsetY      += offset;
+  mBStartBevelSide     = (aInlineSegBSize > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
+  mOffsetB      += offset;
   mLength        = -offset;
-  mWidth         = aVerSegWidth;
+  mWidth         = aBlockSegISize;
   mOwner         = aBorderOwner;
   mFirstCell     = aIter.mCell;
   mFirstRowGroup = aIter.mRg;
   mFirstRow      = aIter.mRow;
   if (aIter.GetRelativeColIndex() > 0) {
     mAjaCell = aIter.mVerInfo[aIter.GetRelativeColIndex() - 1].mLastCell;
   }
 }
 
 /**
  * Initialize the vertical segments with information that will persist for any
  * vertical segment in this column
  * @param aIter - iterator containing the structural information
  */
 void
-BCVerticalSeg::Initialize(BCPaintBorderIterator& aIter)
+BCBlockDirSeg::Initialize(BCPaintBorderIterator& aIter)
 {
   int32_t relColIndex = aIter.GetRelativeColIndex();
   mCol = aIter.IsTableRightMost() ? aIter.mVerInfo[relColIndex - 1].mCol :
            aIter.mTableFirstInFlow->GetColFrame(aIter.mColIndex);
   if (!mCol) ABORT0();
   if (0 == relColIndex) {
-    mOffsetX = aIter.mInitialOffsetX;
+    mOffsetI = aIter.mInitialOffsetI;
   }
   // set colX for the next column
-  if (!aIter.IsDamageAreaRightMost()) {
-    aIter.mVerInfo[relColIndex + 1].mOffsetX = mOffsetX +
-                                         aIter.mColInc * mCol->GetSize().width;
-  }
-  mOffsetY = aIter.mInitialOffsetY;
+  if (!aIter.IsDamageAreaIEndMost()) {
+    aIter.mVerInfo[relColIndex + 1].mOffsetI =
+      mOffsetI + mCol->ISize(aIter.mTableWM);
+  }
+  mOffsetB = aIter.mInitialOffsetB;
   mLastCell = aIter.mCell;
 }
 
 /**
  * Compute the offsets for the bottom corner of a vertical segment
  * @param aIter         - iterator containing the structural information
- * @param aHorSegHeight - the width of the horizontal segment joining the corner
+ * @param aInlineSegBSize - the width of the horizontal segment joining the corner
  *                        at the start
  */
 void
-BCVerticalSeg::GetBottomCorner(BCPaintBorderIterator& aIter,
-                               BCPixelSize            aHorSegHeight)
+BCBlockDirSeg::GetBEndCorner(BCPaintBorderIterator& aIter,
+                               BCPixelSize            aInlineSegBSize)
 {
    LogicalSide ownerSide = eLogicalSideBStart;
    nscoord cornerSubWidth = 0;
    bool bevel = false;
    if (aIter.mBCData) {
      cornerSubWidth = aIter.mBCData->GetCorner(ownerSide, bevel);
    }
-   mIsBottomBevel = (mWidth > 0) ? bevel : false;
-   mBottomHorSegHeight = std::max(aIter.mPrevHorSegHeight, aHorSegHeight);
-   mBottomOffset = CalcVerCornerOffset(ownerSide, cornerSubWidth,
-                                    mBottomHorSegHeight,
-                                    false, mIsBottomBevel);
-   mLength += mBottomOffset;
+   mIsBEndBevel = (mWidth > 0) ? bevel : false;
+   mBEndInlineSegBSize = std::max(aIter.mPrevInlineSegBSize, aInlineSegBSize);
+   mBEndOffset = CalcVerCornerOffset(ownerSide, cornerSubWidth,
+                                    mBEndInlineSegBSize,
+                                    false, mIsBEndBevel);
+   mLength += mBEndOffset;
 }
 
 /**
  * Paint the vertical segment
  * @param aIter         - iterator containing the structural information
  * @param aRenderingContext - the rendering context
- * @param aHorSegHeight - the width of the horizontal segment joining the corner
+ * @param aInlineSegBSize - the width of the horizontal segment joining the corner
  *                        at the start
  */
 void
-BCVerticalSeg::Paint(BCPaintBorderIterator& aIter,
+BCBlockDirSeg::Paint(BCPaintBorderIterator& aIter,
                      nsRenderingContext&   aRenderingContext,
-                     BCPixelSize            aHorSegHeight)
+                     BCPixelSize            aInlineSegBSize)
 {
   // get the border style, color and paint the segment
   LogicalSide side =
-    aIter.IsDamageAreaRightMost() ? eLogicalSideIEnd : eLogicalSideIStart;
+    aIter.IsDamageAreaIEndMost() ? eLogicalSideIEnd : eLogicalSideIStart;
   int32_t relColIndex = aIter.GetRelativeColIndex();
   nsTableColFrame* col           = mCol; if (!col) ABORT0();
   nsTableCellFrame* cell         = mFirstCell; // ???
   nsIFrame* owner = nullptr;
   uint8_t style = NS_STYLE_BORDER_STYLE_SOLID;
   nscolor color = 0xFFFFFFFF;
 
   // All the tables frames have the same presContext, so we just use any one
@@ -7018,142 +6980,139 @@ BCVerticalSeg::Paint(BCPaintBorderIterat
       owner = cell;
       break;
   }
   if (owner) {
     ::GetPaintStyleInfo(owner, aIter.mTableWM, side, &style, &color);
   }
   BCPixelSize smallHalf, largeHalf;
   DivideBCBorderSize(mWidth, smallHalf, largeHalf);
-  nsRect segRect(mOffsetX - nsPresContext::CSSPixelsToAppUnits(largeHalf),
-                 mOffsetY,
+  LogicalRect segRect(aIter.mTableWM,
+                 mOffsetI - nsPresContext::CSSPixelsToAppUnits(largeHalf),
+                 mOffsetB,
                  nsPresContext::CSSPixelsToAppUnits(mWidth), mLength);
-  nscoord bottomBevelOffset = (mIsBottomBevel) ?
-                  nsPresContext::CSSPixelsToAppUnits(mBottomHorSegHeight) : 0;
-  LogicalSide bottomBevelSide =
-    (aHorSegHeight > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
+  nscoord bEndBevelOffset = (mIsBEndBevel) ?
+                  nsPresContext::CSSPixelsToAppUnits(mBEndInlineSegBSize) : 0;
+  LogicalSide bEndBevelSide =
+    (aInlineSegBSize > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
   nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
-                                         aIter.mTableBgColor, segRect,
+                                         aIter.mTableBgColor,
+                                         segRect.GetPhysicalRect(aIter.mTableWM,
+                                           aIter.mTable->GetSize().width),
                                          appUnitsPerDevPixel,
                                          nsPresContext::AppUnitsPerCSSPixel(),
-                                         aIter.mTableWM.PhysicalSide(mTopBevelSide),
-                                          mTopBevelOffset,
-                                         aIter.mTableWM.PhysicalSide(bottomBevelSide),
-                                          bottomBevelOffset);
+                                         aIter.mTableWM.PhysicalSide(mBStartBevelSide),
+                                         mBStartBevelOffset,
+                                         aIter.mTableWM.PhysicalSide(bEndBevelSide),
+                                         bEndBevelOffset);
 }
 
 /**
  * Advance the start point of a segment
  */
 void
-BCVerticalSeg::AdvanceOffsetY()
-{
-  mOffsetY +=  mLength - mBottomOffset;
+BCBlockDirSeg::AdvanceOffsetB()
+{
+  mOffsetB +=  mLength - mBEndOffset;
 }
 
 /**
  * Accumulate the current segment
  */
 void
-BCVerticalSeg::IncludeCurrentBorder(BCPaintBorderIterator& aIter)
+BCBlockDirSeg::IncludeCurrentBorder(BCPaintBorderIterator& aIter)
 {
   mLastCell = aIter.mCell;
-  mLength  += aIter.mRow->GetRect().height;
-}
-
-BCHorizontalSeg::BCHorizontalSeg()
-{
-  mOffsetX = mOffsetY = mLength = mWidth =  mLeftBevelOffset = 0;
-  mLeftBevelSide = eLogicalSideBStart;
+  mLength  += aIter.mRow->BSize(aIter.mTableWM);
+}
+
+BCInlineDirSeg::BCInlineDirSeg()
+{
+  mOffsetI = mOffsetB = mLength = mWidth =  mIStartBevelOffset = 0;
+  mIStartBevelSide = eLogicalSideBStart;
   mFirstCell = mAjaCell = nullptr;
 }
 
-/** Initialize a horizontal border segment for painting
+/** Initialize an inline-dir border segment for painting
   * @param aIter              - iterator storing the current and adjacent frames
   * @param aBorderOwner       - which frame owns the border
-  * @param aBottomVerSegWidth - vertical segment width coming from up
-  * @param aHorSegHeight      - the height of the segment
+  * @param aBEndBlockSegWidth - block-dir segment width coming from up
+  * @param aInlineSegBSize    - the thickness of the segment
   +  */
 void
-BCHorizontalSeg::Start(BCPaintBorderIterator& aIter,
-                       BCBorderOwner          aBorderOwner,
-                       BCPixelSize            aBottomVerSegWidth,
-                       BCPixelSize            aHorSegHeight)
+BCInlineDirSeg::Start(BCPaintBorderIterator& aIter,
+                      BCBorderOwner          aBorderOwner,
+                      BCPixelSize            aBEndBlockSegWidth,
+                      BCPixelSize            aInlineSegBSize)
 {
   LogicalSide cornerOwnerSide = eLogicalSideBStart;
   bool bevel     = false;
 
   mOwner = aBorderOwner;
   nscoord cornerSubWidth  = (aIter.mBCData) ?
                              aIter.mBCData->GetCorner(cornerOwnerSide,
                                                        bevel) : 0;
 
-  bool    leftBevel = (aHorSegHeight > 0) ? bevel : false;
+  bool    leftBevel = (aInlineSegBSize > 0) ? bevel : false;
   int32_t relColIndex = aIter.GetRelativeColIndex();
-  nscoord maxVerSegWidth = std::max(aIter.mVerInfo[relColIndex].mWidth,
-                                  aBottomVerSegWidth);
+  nscoord maxBlockSegISize = std::max(aIter.mVerInfo[relColIndex].mWidth,
+                                  aBEndBlockSegWidth);
   nscoord offset = CalcHorCornerOffset(cornerOwnerSide, cornerSubWidth,
-                                       maxVerSegWidth, true, leftBevel,
-                                       aIter.mTableWM.IsBidiLTR());
-  mLeftBevelOffset = (leftBevel && (aHorSegHeight > 0)) ? maxVerSegWidth : 0;
+                                       maxBlockSegISize, true, leftBevel);
+  mIStartBevelOffset = (leftBevel && (aInlineSegBSize > 0)) ? maxBlockSegISize : 0;
   // XXX this assumes that only corners where 2 segments join can be beveled
-  mLeftBevelSide   = (aBottomVerSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
-  if (aIter.mTableWM.IsBidiLTR()) {
-    mOffsetX += offset;
-  }
-  else {
-    mOffsetX -= offset;
-  }
+  mIStartBevelSide   = (aBEndBlockSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
+  mOffsetI += offset;
   mLength          = -offset;
-  mWidth           = aHorSegHeight;
+  mWidth           = aInlineSegBSize;
   mFirstCell       = aIter.mCell;
-  mAjaCell         = (aIter.IsDamageAreaTopMost()) ? nullptr :
+  mAjaCell         = (aIter.IsDamageAreaBStartMost()) ? nullptr :
                      aIter.mVerInfo[relColIndex].mLastCell;
 }
 
 /**
  * Compute the offsets for the right corner of a horizontal segment
  * @param aIter         - iterator containing the structural information
- * @param aLeftSegWidth - the width of the vertical segment joining the corner
+ * @param aIStartSegWidth - the width of the vertical segment joining the corner
  *                        at the start
  */
 void
-BCHorizontalSeg::GetRightCorner(BCPaintBorderIterator& aIter,
-                                BCPixelSize            aLeftSegWidth)
+BCInlineDirSeg::GetIEndCorner(BCPaintBorderIterator& aIter,
+                              BCPixelSize            aIStartSegWidth)
 {
   LogicalSide ownerSide = eLogicalSideBStart;
   nscoord cornerSubWidth = 0;
   bool bevel = false;
   if (aIter.mBCData) {
     cornerSubWidth = aIter.mBCData->GetCorner(ownerSide, bevel);
   }
 
-  mIsRightBevel = (mWidth > 0) ? bevel : 0;
+  mIsIEndBevel = (mWidth > 0) ? bevel : 0;
   int32_t relColIndex = aIter.GetRelativeColIndex();
-  nscoord verWidth = std::max(aIter.mVerInfo[relColIndex].mWidth, aLeftSegWidth);
+  nscoord verWidth = std::max(aIter.mVerInfo[relColIndex].mWidth, aIStartSegWidth);
   mEndOffset = CalcHorCornerOffset(ownerSide, cornerSubWidth, verWidth,
-                                   false, mIsRightBevel, aIter.mTableWM.IsBidiLTR());
+                                   false, mIsIEndBevel);
   mLength += mEndOffset;
-  mRightBevelOffset = (mIsRightBevel) ?
+  mIEndBevelOffset = (mIsIEndBevel) ?
                        nsPresContext::CSSPixelsToAppUnits(verWidth) : 0;
-  mRightBevelSide = (aLeftSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
+  mIEndBevelSide = (aIStartSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
 }
 
 /**
- * Paint the horizontal segment
+ * Paint the inline-dir segment
  * @param aIter         - iterator containing the structural information
  * @param aRenderingContext - the rendering context
  */
 void
-BCHorizontalSeg::Paint(BCPaintBorderIterator& aIter,
+BCInlineDirSeg::Paint(BCPaintBorderIterator& aIter,
                        nsRenderingContext&   aRenderingContext)
 {
   // get the border style, color and paint the segment
   LogicalSide side =
-    aIter.IsDamageAreaBottomMost() ? eLogicalSideBEnd : eLogicalSideBStart;
+    aIter.IsDamageAreaBEndMost() ? eLogicalSideBEnd : eLogicalSideBStart;
   nsIFrame* rg   = aIter.mRg;  if (!rg) ABORT0();
   nsIFrame* row  = aIter.mRow; if (!row) ABORT0();
   nsIFrame* cell = mFirstCell;
   nsIFrame* col;
   nsIFrame* owner = nullptr;
 
   // All the tables frames have the same presContext, so we just use any one
   // that exists here:
@@ -7191,17 +7150,17 @@ BCHorizontalSeg::Paint(BCPaintBorderIter
       // and fall through
     case eRowGroupOwner:
       owner = rg;
       break;
     case eAjaRowOwner:
       side = eLogicalSideBEnd;
       row = (aIter.IsTableBottomMost()) ? aIter.mRow : aIter.mPrevRow;
       // and fall through
-      case eRowOwner:
+    case eRowOwner:
       owner = row;
       break;
     case eAjaCellOwner:
       side = eLogicalSideBEnd;
       // if this is null due to the damage area origin-y > 0, then the border
       // won't show up anyway
       cell = mAjaCell;
       // and fall through
@@ -7209,57 +7168,59 @@ BCHorizontalSeg::Paint(BCPaintBorderIter
       owner = cell;
       break;
   }
   if (owner) {
     ::GetPaintStyleInfo(owner, aIter.mTableWM, side, &style, &color);
   }
   BCPixelSize smallHalf, largeHalf;
   DivideBCBorderSize(mWidth, smallHalf, largeHalf);
-  nsRect segRect(mOffsetX,
-                 mOffsetY - nsPresContext::CSSPixelsToAppUnits(largeHalf),
-                 mLength,
-                 nsPresContext::CSSPixelsToAppUnits(mWidth));
+  LogicalRect segRect(aIter.mTableWM, mOffsetI,
+                      mOffsetB - nsPresContext::CSSPixelsToAppUnits(largeHalf),
+                      mLength,
+                      nsPresContext::CSSPixelsToAppUnits(mWidth));
   if (aIter.mTableWM.IsBidiLTR()) {
     nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
-                                           aIter.mTableBgColor, segRect,
+                                           aIter.mTableBgColor,
+                                           segRect.GetPhysicalRect(aIter.mTableWM,
+                                             aIter.mTable->GetSize().width),
                                            appUnitsPerDevPixel,
                                            nsPresContext::AppUnitsPerCSSPixel(),
-                                           aIter.mTableWM.PhysicalSide(mLeftBevelSide),
-                                           nsPresContext::CSSPixelsToAppUnits(mLeftBevelOffset),
-                                           aIter.mTableWM.PhysicalSide(mRightBevelSide),
-                                            mRightBevelOffset);
-  }
-  else {
-    segRect.x -= segRect.width;
+                                           aIter.mTableWM.PhysicalSide(mIStartBevelSide),
+                                           nsPresContext::CSSPixelsToAppUnits(mIStartBevelOffset),
+                                           aIter.mTableWM.PhysicalSide(mIEndBevelSide),
+                                           mIEndBevelOffset);
+  } else {
     nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
-                                           aIter.mTableBgColor, segRect,
+                                           aIter.mTableBgColor,
+                                           segRect.GetPhysicalRect(aIter.mTableWM,
+                                             aIter.mTable->GetSize().width),
                                            appUnitsPerDevPixel,
                                            nsPresContext::AppUnitsPerCSSPixel(),
-                                           aIter.mTableWM.PhysicalSide(mRightBevelSide),
-                                            mRightBevelOffset,
-                                           aIter.mTableWM.PhysicalSide(mLeftBevelSide),
-                                           nsPresContext::CSSPixelsToAppUnits(mLeftBevelOffset));
+                                           aIter.mTableWM.PhysicalSide(mIEndBevelSide),
+                                           mIEndBevelOffset,
+                                           aIter.mTableWM.PhysicalSide(mIStartBevelSide),
+                                           nsPresContext::CSSPixelsToAppUnits(mIStartBevelOffset));
   }
 }
 
 /**
  * Advance the start point of a segment
  */
 void
-BCHorizontalSeg::AdvanceOffsetX(int32_t aIncrement)
-{
-  mOffsetX += aIncrement * (mLength - mEndOffset);
+BCInlineDirSeg::AdvanceOffsetI(int32_t aIncrement)
+{
+  mOffsetI += aIncrement * (mLength - mEndOffset);
 }
 
 /**
  * Accumulate the current segment
  */
 void
-BCHorizontalSeg::IncludeCurrentBorder(BCPaintBorderIterator& aIter)
+BCInlineDirSeg::IncludeCurrentBorder(BCPaintBorderIterator& aIter)
 {
   mLength += aIter.mVerInfo[aIter.GetRelativeColIndex()].mColWidth;
 }
 
 /**
  * store the column width information while painting horizontal segment
  */
 void
@@ -7273,30 +7234,30 @@ BCPaintBorderIterator::StoreColumnWidth(
     if (!col) ABORT0();
     mVerInfo[aIndex].mColWidth = col->ISize(mTableWM);
   }
 }
 /**
  * Determine if a vertical segment owns the corder
  */
 bool
-BCPaintBorderIterator::VerticalSegmentOwnsCorner()
+BCPaintBorderIterator::BlockDirSegmentOwnsCorner()
 {
   LogicalSide cornerOwnerSide = eLogicalSideBStart;
   bool bevel = false;
   if (mBCData) {
     mBCData->GetCorner(cornerOwnerSide, bevel);
   }
   // unitialized ownerside, bevel
   return  (eLogicalSideBStart == cornerOwnerSide) ||
           (eLogicalSideBEnd == cornerOwnerSide);
 }
 
 /**
- * Paint if necessary a horizontal segment, otherwise accumulate it
+ * Paint if necessary an inline-dir segment, otherwise accumulate it
  * @param aRenderingContext - the rendering context
  */
 void
 BCPaintBorderIterator::AccumulateOrPaintInlineDirSegment(nsRenderingContext& aRenderingContext)
 {
 
   int32_t relColIndex = GetRelativeColIndex();
   // store the current col width if it hasn't been already
@@ -7304,95 +7265,95 @@ BCPaintBorderIterator::AccumulateOrPaint
     StoreColumnWidth(relColIndex);
   }
 
   BCBorderOwner borderOwner = eCellOwner;
   BCBorderOwner ignoreBorderOwner;
   bool isSegStart = true;
   bool ignoreSegStart;
 
-  nscoord leftSegWidth =
+  nscoord iStartSegISize =
     mBCData ? mBCData->GetIStartEdge(ignoreBorderOwner, ignoreSegStart) : 0;
-  nscoord topSegHeight =
+  nscoord bStartSegBSize =
     mBCData ? mBCData->GetBStartEdge(borderOwner, isSegStart) : 0;
 
-  if (mIsNewRow || (IsDamageAreaLeftMost() && IsDamageAreaBottomMost())) {
+  if (mIsNewRow || (IsDamageAreaIStartMost() && IsDamageAreaBEndMost())) {
     // reset for every new row and on the bottom of the last row
-    mHorSeg.mOffsetY = mNextOffsetY;
-    mNextOffsetY     = mNextOffsetY + mRow->GetSize().height;
-    mHorSeg.mOffsetX = mInitialOffsetX;
-    mHorSeg.Start(*this, borderOwner, leftSegWidth, topSegHeight);
-  }
-
-  if (!IsDamageAreaLeftMost() && (isSegStart || IsDamageAreaRightMost() ||
-                                  VerticalSegmentOwnsCorner())) {
-    // paint the previous seg or the current one if IsDamageAreaRightMost()
-    if (mHorSeg.mLength > 0) {
-      mHorSeg.GetRightCorner(*this, leftSegWidth);
-      if (mHorSeg.mWidth > 0) {
-        mHorSeg.Paint(*this, aRenderingContext);
+    mInlineSeg.mOffsetB = mNextOffsetB;
+    mNextOffsetB     = mNextOffsetB + mRow->BSize(mTableWM);
+    mInlineSeg.mOffsetI = mInitialOffsetI;
+    mInlineSeg.Start(*this, borderOwner, iStartSegISize, bStartSegBSize);
+  }
+
+  if (!IsDamageAreaIStartMost() && (isSegStart || IsDamageAreaIEndMost() ||
+                                  BlockDirSegmentOwnsCorner())) {
+    // paint the previous seg or the current one if IsDamageAreaIEndMost()
+    if (mInlineSeg.mLength > 0) {
+      mInlineSeg.GetIEndCorner(*this, iStartSegISize);
+      if (mInlineSeg.mWidth > 0) {
+        mInlineSeg.Paint(*this, aRenderingContext);
       }
-      mHorSeg.AdvanceOffsetX(mColInc);
-    }
-    mHorSeg.Start(*this, borderOwner, leftSegWidth, topSegHeight);
-  }
-  mHorSeg.IncludeCurrentBorder(*this);
-  mVerInfo[relColIndex].mWidth = leftSegWidth;
+      mInlineSeg.AdvanceOffsetI(1);
+    }
+    mInlineSeg.Start(*this, borderOwner, iStartSegISize, bStartSegBSize);
+  }
+  mInlineSeg.IncludeCurrentBorder(*this);
+  mVerInfo[relColIndex].mWidth = iStartSegISize;
   mVerInfo[relColIndex].mLastCell = mCell;
 }
 /**
- * Paint if necessary a vertical segment, otherwise  it
+ * Paint if necessary a block-dir segment, otherwise  it
  * @param aRenderingContext - the rendering context
  */
 void
 BCPaintBorderIterator::AccumulateOrPaintBlockDirSegment(nsRenderingContext& aRenderingContext)
 {
   BCBorderOwner borderOwner = eCellOwner;
   BCBorderOwner ignoreBorderOwner;
   bool isSegStart = true;
   bool ignoreSegStart;
 
-  nscoord verSegWidth  =
+  nscoord blockSegISize  =
     mBCData ? mBCData->GetIStartEdge(borderOwner, isSegStart) : 0;
-  nscoord horSegHeight =
+  nscoord inlineSegBSize =
     mBCData ? mBCData->GetBStartEdge(ignoreBorderOwner, ignoreSegStart) : 0;
 
   int32_t relColIndex = GetRelativeColIndex();
-  BCVerticalSeg& verSeg = mVerInfo[relColIndex];
+  BCBlockDirSeg& verSeg = mVerInfo[relColIndex];
   if (!verSeg.mCol) { // on the first damaged row and the first segment in the
                       // col
     verSeg.Initialize(*this);
-    verSeg.Start(*this, borderOwner, verSegWidth, horSegHeight);
-  }
-
-  if (!IsDamageAreaTopMost() && (isSegStart || IsDamageAreaBottomMost() ||
+    verSeg.Start(*this, borderOwner, blockSegISize, inlineSegBSize);
+  }
+
+  if (!IsDamageAreaBStartMost() && (isSegStart || IsDamageAreaBEndMost() ||
                                  IsAfterRepeatedHeader() ||
                                  StartRepeatedFooter())) {
-    // paint the previous seg or the current one if IsDamageAreaBottomMost()
+    // paint the previous seg or the current one if IsDamageAreaBEndMost()
     if (verSeg.mLength > 0) {
-      verSeg.GetBottomCorner(*this, horSegHeight);
+      verSeg.GetBEndCorner(*this, inlineSegBSize);
       if (verSeg.mWidth > 0) {
-        verSeg.Paint(*this, aRenderingContext, horSegHeight);
+        verSeg.Paint(*this, aRenderingContext, inlineSegBSize);
       }
-      verSeg.AdvanceOffsetY();
-    }
-    verSeg.Start(*this, borderOwner, verSegWidth, horSegHeight);
+      verSeg.AdvanceOffsetB();
+    }
+    verSeg.Start(*this, borderOwner, blockSegISize, inlineSegBSize);
   }
   verSeg.IncludeCurrentBorder(*this);
-  mPrevHorSegHeight = horSegHeight;
+  mPrevInlineSegBSize = inlineSegBSize;
 }
 
 /**
- * Reset the vertical information cache
+ * Reset the block-dir information cache
  */
 void
 BCPaintBorderIterator::ResetVerInfo()
 {
   if (mVerInfo) {
-    memset(mVerInfo, 0, mDamageArea.ColCount() * sizeof(BCVerticalSeg));
+    memset(mVerInfo, 0, mDamageArea.ColCount() * sizeof(BCBlockDirSeg));
     // XXX reinitialize properly
     for (auto xIndex : MakeRange(mDamageArea.ColCount())) {
       mVerInfo[xIndex].mColWidth = -1;
     }
   }
 }
 
 /**
@@ -7406,31 +7367,32 @@ nsTableFrame::PaintBCBorders(nsRendering
                              const nsRect&       aDirtyRect)
 {
   // We first transfer the aDirtyRect into cellmap coordinates to compute which
   // cell borders need to be painted
   BCPaintBorderIterator iter(this);
   if (!iter.SetDamageArea(aDirtyRect))
     return;
 
+  // XXX comment still has physical terminology
   // First, paint all of the vertical borders from top to bottom and left to
   // right as they become complete. They are painted first, since they are less
   // efficient to paint than horizontal segments. They were stored with as few
   // segments as possible (since horizontal borders are painted last and
   // possibly over them). For every cell in a row that fails in the damage are
   // we look up if the current border would start a new segment, if so we paint
   // the previously stored vertical segment and start a new segment. After
   // this we  the now active segment with the current border. These
   // segments are stored in mVerInfo to be used on the next row
   for (iter.First(); !iter.mAtEnd; iter.Next()) {
     iter.AccumulateOrPaintBlockDirSegment(aRenderingContext);
   }
 
-  // Next, paint all of the horizontal border segments from top to bottom reuse
-  // the mVerInfo array to keep track of col widths and vertical segments for
+  // Next, paint all of the inline-dir border segments from bStart to bEnd reuse
+  // the mVerInfo array to keep track of col widths and block-dir segments for
   // corner calculations
   iter.Reset();
   for (iter.First(); !iter.mAtEnd; iter.Next()) {
     iter.AccumulateOrPaintInlineDirSegment(aRenderingContext);
   }
 }
 
 bool
--- a/layout/tables/nsTableFrame.h
+++ b/layout/tables/nsTableFrame.h
@@ -298,18 +298,18 @@ public:
    * by the outer BC border. Compute the reduction needed.
    */
   nsMargin GetDeflationForBackground(nsPresContext* aPresContext) const;
 
   /** Get width of table + colgroup + col collapse: elements that
    *  continue along the length of the whole left side.
    *  see nsTablePainter about continuous borders
    */
-  nscoord GetContinuousLeftBCBorderWidth() const;
-  void SetContinuousLeftBCBorderWidth(nscoord aValue);
+  nscoord GetContinuousIStartBCBorderWidth() const;
+  void SetContinuousIStartBCBorderWidth(nscoord aValue);
 
   friend class nsDelayedCalcBCBorders;
 
   void AddBCDamageArea(const mozilla::TableArea& aValue);
   bool BCRecalcNeeded(nsStyleContext* aOldStyleContext,
                         nsStyleContext* aNewStyleContext);
   void PaintBCBorders(nsRenderingContext& aRenderingContext,
                       const nsRect&        aDirtyRect);
@@ -868,17 +868,17 @@ protected:
   struct TableBits {
     uint32_t mHaveReflowedColGroups:1; // have the col groups gotten their initial reflow
     uint32_t mHasPctCol:1;             // does any cell or col have a pct width
     uint32_t mCellSpansPctCol:1;       // does any cell span a col with a pct width (or containing a cell with a pct width)
     uint32_t mIsBorderCollapse:1;      // border collapsing model vs. separate model
     uint32_t mRowInserted:1;
     uint32_t mNeedToCalcBCBorders:1;
     uint32_t mGeometryDirty:1;
-    uint32_t mLeftContBCBorder:8;
+    uint32_t mIStartContBCBorder:8;
     uint32_t mNeedToCollapse:1;    // rows, cols that have visibility:collapse need to be collapsed
     uint32_t mHasZeroColSpans:1;
     uint32_t mNeedColSpanExpansion:1;
     uint32_t mResizedColumns:1;        // have we resized columns since last reflow?
   } mBits;
 
   nsTableCellMap*         mCellMap;            // maintains the relationships between rows, cols, and cells
   nsITableLayoutStrategy* mTableLayoutStrategy;// the layout strategy for this frame
@@ -990,25 +990,25 @@ inline bool nsTableFrame::NeedToCalcBCBo
 }
 
 inline void nsTableFrame::SetNeedToCalcBCBorders(bool aValue)
 {
   mBits.mNeedToCalcBCBorders = (unsigned)aValue;
 }
 
 inline nscoord
-nsTableFrame::GetContinuousLeftBCBorderWidth() const
+nsTableFrame::GetContinuousIStartBCBorderWidth() const
 {
   int32_t aPixelsToTwips = nsPresContext::AppUnitsPerCSSPixel();
-  return BC_BORDER_END_HALF_COORD(aPixelsToTwips, mBits.mLeftContBCBorder);
+  return BC_BORDER_END_HALF_COORD(aPixelsToTwips, mBits.mIStartContBCBorder);
 }
 
-inline void nsTableFrame::SetContinuousLeftBCBorderWidth(nscoord aValue)
+inline void nsTableFrame::SetContinuousIStartBCBorderWidth(nscoord aValue)
 {
-  mBits.mLeftContBCBorder = (unsigned) aValue;
+  mBits.mIStartContBCBorder = (unsigned) aValue;
 }
 
 #define ABORT0() \
 {NS_ASSERTION(false, "CellIterator program error"); \
 return;}
 
 #define ABORT1(aReturn) \
 {NS_ASSERTION(false, "CellIterator program error"); \
--- a/layout/tables/nsTablePainter.cpp
+++ b/layout/tables/nsTablePainter.cpp
@@ -225,17 +225,17 @@ TableBackgroundPainter::PaintTableFrame(
       border.BEnd(wm) = tempBorder.BEnd(wm);
 
       nsTableRowFrame* rowFrame = aFirstRowGroup->GetFirstRow();
       if (rowFrame) {
         rowFrame->GetContinuousBCBorderWidth(wm, tempBorder);
         border.BStart(wm) = tempBorder.BStart(wm);
       }
 
-      border.IStart(wm) = aTableFrame->GetContinuousLeftBCBorderWidth();
+      border.IStart(wm) = aTableFrame->GetContinuousIStartBCBorderWidth();
 
       tableData.SetBCBorder(border.GetPhysicalMargin(wm));
     }
   }
 
   DrawResult result = DrawResult::SUCCESS;
 
   if (tableData.IsVisible()) {
@@ -317,17 +317,17 @@ TableBackgroundPainter::PaintTable(nsTab
     // we grab references to its contents and need those to stay valid until
     // mColGroups is destroyed as part of TablePainter destruction.
     mColGroups.SetCapacity(colGroupFrames.Length());
 
     LogicalMargin border(wm);
     /* BC left borders aren't stored on cols, but the previous column's
        right border is the next one's left border.*/
     //Start with table's left border.
-    nscoord lastLeftBorder = aTableFrame->GetContinuousLeftBCBorderWidth();
+    nscoord lastLeftBorder = aTableFrame->GetContinuousIStartBCBorderWidth();
 
     for (nsTableColGroupFrame* cgFrame : colGroupFrames) {
       /*Create data struct for column group*/
       TableBackgroundData& cgData = *mColGroups.AppendElement(TableBackgroundData(cgFrame));
       if (mIsBorderCollapse && cgData.ShouldSetBCBorder()) {
         border.IStart(wm) = lastLeftBorder;
         cgFrame->GetContinuousBCBorderWidth(wm, border);
         cgData.SetBCBorder(border.GetPhysicalMargin(wm));
@@ -490,24 +490,24 @@ TableBackgroundPainter::PaintRow(nsTable
   /* Load row data */
   WritingMode wm = aFrame->GetWritingMode();
   if (aPassThrough) {
     aRowBGData.MakeInvisible();
   } else {
     if (mIsBorderCollapse && aRowBGData.ShouldSetBCBorder()) {
       LogicalMargin border(wm);
       nsTableRowFrame* nextRow = aFrame->GetNextRow();
-      if (nextRow) { //outer top below us is inner bottom for us
+      if (nextRow) { //outer bStart after us is inner bEnd for us
         border.BEnd(wm) = nextRow->GetOuterBStartContBCBorderWidth();
       }
-      else { //acquire rg's bottom border
+      else { //acquire rg's bEnd border
         nsTableRowGroupFrame* rowGroup = static_cast<nsTableRowGroupFrame*>(aFrame->GetParent());
         rowGroup->GetContinuousBCBorderWidth(wm, border);
       }
-      //get the rest of the borders; will overwrite all but bottom
+      //get the rest of the borders; will overwrite all but bEnd
       aFrame->GetContinuousBCBorderWidth(wm, border);
 
       aRowBGData.SetBCBorder(border.GetPhysicalMargin(wm));
     }
     aPassThrough = !aRowBGData.IsVisible();
   }
 
   /* Translate */