Bug 1157569 - part 13 - More conversion of physical to logical terminology in border-collapse calculations. r=dholbert
authorJonathan Kew <jkew@mozilla.com>
Sat, 27 Jun 2015 11:16:03 -0700
changeset 250503 dd2f0a7e0db39154468d56e22e651dab897812d9
parent 250502 8fe7179bfc6c991acf287d061d0cbf70323714ed
child 250504 90f43905ea1260152612e2cc5923df11226daaa4
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 13 - More conversion of physical to logical terminology in border-collapse calculations. r=dholbert
layout/tables/celldata.h
layout/tables/nsCellMap.cpp
layout/tables/nsCellMap.h
layout/tables/nsTableFrame.cpp
--- a/layout/tables/celldata.h
+++ b/layout/tables/celldata.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef CellData_h__
 #define CellData_h__
 
 #include "nsISupports.h"
 #include "nsCoord.h"
 #include "mozilla/gfx/Types.h"
+#include "mozilla/WritingModes.h"
 #include <stdint.h>
 
 class nsTableCellFrame;
 class nsCellMap;
 class BCCellData;
 
 
 #define MAX_ROWSPAN 65534 // the cellmap can not handle more.
@@ -174,67 +175,67 @@ BC_BORDER_END_HALF(BCPixelSize px) { ret
 
 static inline nscoord
 BC_BORDER_START_HALF_COORD(int32_t p2t, BCPixelSize px)
   { return BC_BORDER_START_HALF(px) * p2t; }
 static inline nscoord
 BC_BORDER_END_HALF_COORD(int32_t p2t, BCPixelSize px)
   { return BC_BORDER_END_HALF(px) * p2t; }
 
-// BCData stores the top and left border info and the corner connecting the two.
+// BCData stores the bstart and istart border info and the corner connecting the two.
 class BCData
 {
 public:
   BCData();
 
   ~BCData();
 
-  nscoord GetLeftEdge(BCBorderOwner& aOwner,
-                      bool&        aStart) const;
+  nscoord GetIStartEdge(BCBorderOwner& aOwner,
+                        bool&          aStart) const;
 
-  void SetLeftEdge(BCBorderOwner aOwner,
-                   nscoord       aSize,
-                   bool          aStart);
+  void SetIStartEdge(BCBorderOwner aOwner,
+                     nscoord       aSize,
+                     bool          aStart);
 
-  nscoord GetTopEdge(BCBorderOwner& aOwner,
-                     bool&        aStart) const;
+  nscoord GetBStartEdge(BCBorderOwner& aOwner,
+                        bool&          aStart) const;
 
-  void SetTopEdge(BCBorderOwner aOwner,
-                  nscoord       aSize,
-                  bool          aStart);
+  void SetBStartEdge(BCBorderOwner aOwner,
+                     nscoord       aSize,
+                     bool          aStart);
 
-  BCPixelSize GetCorner(mozilla::Side&       aCornerOwner,
-                        bool&  aBevel) const;
+  BCPixelSize GetCorner(mozilla::LogicalSide& aCornerOwner,
+                        bool&                 aBevel) const;
 
-  void SetCorner(BCPixelSize aSubSize,
-                 mozilla::Side aOwner,
-                 bool    aBevel);
+  void SetCorner(BCPixelSize          aSubSize,
+                 mozilla::LogicalSide aOwner,
+                 bool                 aBevel);
 
-  bool IsLeftStart() const;
+  bool IsIStartStart() const;
 
-  void SetLeftStart(bool aValue);
+  void SetIStartStart(bool aValue);
 
-  bool IsTopStart() const;
+  bool IsBStartStart() const;
 
-  void SetTopStart(bool aValue);
+  void SetBStartStart(bool aValue);
 
 
 protected:
-  BCPixelSize mLeftSize;      // size in pixels of left border
-  BCPixelSize mTopSize;       // size in pixels of top border
+  BCPixelSize mIStartSize;    // size in pixels of iStart border
+  BCPixelSize mBStartSize;    // size in pixels of bStart border
   BCPixelSize mCornerSubSize; // size of the largest border not in the
                               //   dominant plane (for example, if corner is
-                              //   owned by the segment to its top or bottom,
+                              //   owned by the segment to its bStart or bEnd,
                               //   then the size is the max of the border
-                              //   sizes of the segments to its left or right.
-  unsigned mLeftOwner:     4; // owner of left border
-  unsigned mTopOwner:      4; // owner of top border
-  unsigned mLeftStart:     1; // set if this is the start of a vertical border segment
-  unsigned mTopStart:      1; // set if this is the start of a horizontal border segment
-  unsigned mCornerSide:    2; // mozilla::Side of the owner of the upper left corner relative to the corner
+                              //   sizes of the segments to its iStart or iEnd.
+  unsigned mIStartOwner:   4; // owner of iStart border
+  unsigned mBStartOwner:   4; // owner of bStart border
+  unsigned mIStartStart:   1; // set if this is the start of a block-dir border segment
+  unsigned mBStartStart:   1; // set if this is the start of an inline-dir border segment
+  unsigned mCornerSide:    2; // LogicalSide of the owner of the bStart-iStart corner relative to the corner
   unsigned mCornerBevel:   1; // is the corner beveled (only two segments, perpendicular, not dashed or dotted).
 };
 
 // BCCellData entries replace CellData entries in the cell map if the border collapsing model is in
 // effect. BCData for a row and col entry contains the left and top borders of cell at that row and
 // col and the corner connecting the two. The right borders of the cells in the last col and the bottom
 // borders of the last row are stored in separate BCData entries in the cell map.
 class BCCellData : public CellData
@@ -397,93 +398,93 @@ inline void CellData::SetOverlap(bool aO
     else {
       mBits &= ~OVERLAP;
     }
   }
 }
 
 inline BCData::BCData()
 {
-  mLeftOwner = mTopOwner = eCellOwner;
-  mLeftStart = mTopStart = 1;
-  mLeftSize = mCornerSubSize = mTopSize = 0;
-  mCornerSide = NS_SIDE_TOP;
+  mIStartOwner = mBStartOwner = eCellOwner;
+  mIStartStart = mBStartStart = 1;
+  mIStartSize = mCornerSubSize = mBStartSize = 0;
+  mCornerSide = mozilla::eLogicalSideBStart;
   mCornerBevel = false;
 }
 
 inline BCData::~BCData()
 {
 }
 
-inline nscoord BCData::GetLeftEdge(BCBorderOwner& aOwner,
-                                   bool&        aStart) const
+inline nscoord BCData::GetIStartEdge(BCBorderOwner& aOwner,
+                                     bool&          aStart) const
 {
-  aOwner = (BCBorderOwner)mLeftOwner;
-  aStart = (bool)mLeftStart;
+  aOwner = (BCBorderOwner)mIStartOwner;
+  aStart = (bool)mIStartStart;
 
-  return (nscoord)mLeftSize;
+  return (nscoord)mIStartSize;
 }
 
-inline void BCData::SetLeftEdge(BCBorderOwner  aOwner,
-                                nscoord        aSize,
-                                bool           aStart)
+inline void BCData::SetIStartEdge(BCBorderOwner  aOwner,
+                                  nscoord        aSize,
+                                  bool           aStart)
 {
-  mLeftOwner = aOwner;
-  mLeftSize  = (aSize > MAX_BORDER_WIDTH) ? MAX_BORDER_WIDTH : aSize;
-  mLeftStart = aStart;
+  mIStartOwner = aOwner;
+  mIStartSize  = (aSize > MAX_BORDER_WIDTH) ? MAX_BORDER_WIDTH : aSize;
+  mIStartStart = aStart;
 }
 
-inline nscoord BCData::GetTopEdge(BCBorderOwner& aOwner,
-                                  bool&        aStart) const
+inline nscoord BCData::GetBStartEdge(BCBorderOwner& aOwner,
+                                     bool&          aStart) const
 {
-  aOwner = (BCBorderOwner)mTopOwner;
-  aStart = (bool)mTopStart;
+  aOwner = (BCBorderOwner)mBStartOwner;
+  aStart = (bool)mBStartStart;
 
-  return (nscoord)mTopSize;
+  return (nscoord)mBStartSize;
 }
 
-inline void BCData::SetTopEdge(BCBorderOwner  aOwner,
-                               nscoord        aSize,
-                               bool           aStart)
+inline void BCData::SetBStartEdge(BCBorderOwner  aOwner,
+                                  nscoord        aSize,
+                                  bool           aStart)
 {
-  mTopOwner = aOwner;
-  mTopSize  = (aSize > MAX_BORDER_WIDTH) ? MAX_BORDER_WIDTH : aSize;
-  mTopStart = aStart;
+  mBStartOwner = aOwner;
+  mBStartSize  = (aSize > MAX_BORDER_WIDTH) ? MAX_BORDER_WIDTH : aSize;
+  mBStartStart = aStart;
 }
 
-inline BCPixelSize BCData::GetCorner(mozilla::Side& aOwnerSide,
-                                     bool&       aBevel) const
+inline BCPixelSize BCData::GetCorner(mozilla::LogicalSide& aOwnerSide,
+                                     bool&                 aBevel) const
 {
-  aOwnerSide = mozilla::Side(mCornerSide);
+  aOwnerSide = mozilla::LogicalSide(mCornerSide);
   aBevel     = (bool)mCornerBevel;
   return mCornerSubSize;
 }
 
-inline void BCData::SetCorner(BCPixelSize aSubSize,
-                              mozilla::Side aOwnerSide,
-                              bool    aBevel)
+inline void BCData::SetCorner(BCPixelSize          aSubSize,
+                              mozilla::LogicalSide aOwnerSide,
+                              bool                 aBevel)
 {
   mCornerSubSize = aSubSize;
   mCornerSide    = aOwnerSide;
   mCornerBevel   = aBevel;
 }
 
-inline bool BCData::IsLeftStart() const
+inline bool BCData::IsIStartStart() const
 {
-  return (bool)mLeftStart;
+  return (bool)mIStartStart;
 }
 
-inline void BCData::SetLeftStart(bool aValue)
+inline void BCData::SetIStartStart(bool aValue)
 {
-  mLeftStart = aValue;
+  mIStartStart = aValue;
 }
 
-inline bool BCData::IsTopStart() const
+inline bool BCData::IsBStartStart() const
 {
-  return (bool)mTopStart;
+  return (bool)mBStartStart;
 }
 
-inline void BCData::SetTopStart(bool aValue)
+inline void BCData::SetBStartStart(bool aValue)
 {
-  mTopStart = aValue;
+  mBStartStart = aValue;
 }
 
 #endif
--- a/layout/tables/nsCellMap.cpp
+++ b/layout/tables/nsCellMap.cpp
@@ -724,46 +724,46 @@ nsTableCellMap::Dump(char* aString) cons
   while (cellMap) {
     cellMap->Dump(nullptr != mBCInfo);
     cellMap = cellMap->GetNextSibling();
   }
   if (nullptr != mBCInfo) {
     printf("***** bottom borders *****\n");
     nscoord       size;
     BCBorderOwner owner;
-    mozilla::Side side;
+    LogicalSide side;
     bool          segStart;
     bool          bevel;
     int32_t       colIndex;
     int32_t numCols = mBCInfo->mBottomBorders.Length();
     for (int32_t i = 0; i <= 2; i++) {
 
       printf("\n          ");
       for (colIndex = 0; colIndex < numCols; colIndex++) {
         BCData& cd = mBCInfo->mBottomBorders.ElementAt(colIndex);
         if (0 == i) {
-          size = cd.GetTopEdge(owner, segStart);
+          size = cd.GetBStartEdge(owner, segStart);
           printf("t=%d%X%d ", int32_t(size), owner, segStart);
         }
         else if (1 == i) {
-          size = cd.GetLeftEdge(owner, segStart);
+          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;
       if (0 == i) {
-         size = cd.GetTopEdge(owner, segStart);
+         size = cd.GetBStartEdge(owner, segStart);
          printf("t=%d%X%d ", int32_t(size), owner, segStart);
       }
       else if (1 == i) {
-        size = cd.GetLeftEdge(owner, segStart);
+        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);
       }
     }
     printf("\n");
@@ -907,76 +907,76 @@ void nsTableCellMap::ExpandZeroColSpans(
   nsCellMap* cellMap = mFirstMap;
   while (cellMap) {
     cellMap->ExpandZeroColSpans(*this);
     cellMap = cellMap->GetNextSibling();
   }
 }
 
 void
-nsTableCellMap::ResetTopStart(uint8_t    aSide,
+nsTableCellMap::ResetTopStart(LogicalSide    aSide,
                               nsCellMap& aCellMap,
                               uint32_t   aRowIndex,
                               uint32_t   aColIndex,
                               bool       aIsLowerRight)
 {
   if (!mBCInfo || aIsLowerRight) ABORT0();
 
   BCCellData* cellData;
   BCData* bcData = nullptr;
 
   switch(aSide) {
-  case NS_SIDE_BOTTOM:
+  case eLogicalSideBEnd:
     aRowIndex++;
     // FALLTHROUGH
-  case NS_SIDE_TOP:
+  case eLogicalSideBStart:
     cellData = (BCCellData*)aCellMap.GetDataAt(aRowIndex, aColIndex);
     if (cellData) {
       bcData = &cellData->mData;
     }
     else {
-      NS_ASSERTION(aSide == NS_SIDE_BOTTOM, "program error");
+      NS_ASSERTION(aSide == eLogicalSideBEnd, "program error");
       // try the next row group
       nsCellMap* cellMap = aCellMap.GetNextSibling();
       if (cellMap) {
         cellData = (BCCellData*)cellMap->GetDataAt(0, aColIndex);
         if (cellData) {
           bcData = &cellData->mData;
         }
         else {
           bcData = GetBottomMostBorder(aColIndex);
         }
       }
     }
     break;
-  case NS_SIDE_RIGHT:
+  case eLogicalSideIEnd:
     aColIndex++;
     // FALLTHROUGH
-  case NS_SIDE_LEFT:
+  case eLogicalSideIStart:
     cellData = (BCCellData*)aCellMap.GetDataAt(aRowIndex, aColIndex);
     if (cellData) {
       bcData = &cellData->mData;
     }
     else {
-      NS_ASSERTION(aSide == NS_SIDE_RIGHT, "program error");
+      NS_ASSERTION(aSide == eLogicalSideIEnd, "program error");
       bcData = GetRightMostBorder(aRowIndex);
     }
     break;
   }
   if (bcData) {
-    bcData->SetTopStart(false);
+    bcData->SetBStartStart(false);
   }
 }
 
 // store the aSide border segment at coord = (aRowIndex, aColIndex). For top/left, store
 // the info at coord. For bottom/left store it at the adjacent location so that it is
 // top/left at that location. If the new location is at the right or bottom edge of the
 // table, then store it one of the special arrays (right most borders, bottom most borders).
 void
-nsTableCellMap::SetBCBorderEdge(mozilla::Side aSide,
+nsTableCellMap::SetBCBorderEdge(LogicalSide aSide,
                                 nsCellMap&    aCellMap,
                                 uint32_t      aCellMapStart,
                                 uint32_t      aRowIndex,
                                 uint32_t      aColIndex,
                                 uint32_t      aLength,
                                 BCBorderOwner aOwner,
                                 nscoord       aSize,
                                 bool          aChanged)
@@ -986,35 +986,35 @@ nsTableCellMap::SetBCBorderEdge(mozilla:
   BCCellData* cellData;
   int32_t lastIndex, xIndex, yIndex;
   int32_t xPos = aColIndex;
   int32_t yPos = aRowIndex;
   int32_t rgYPos = aRowIndex - aCellMapStart;
   bool changed;
 
   switch(aSide) {
-  case NS_SIDE_BOTTOM:
+  case eLogicalSideBEnd:
     rgYPos++;
     yPos++;
-  case NS_SIDE_TOP:
+  case eLogicalSideBStart:
     lastIndex = xPos + aLength - 1;
     for (xIndex = xPos; xIndex <= lastIndex; xIndex++) {
       changed = aChanged && (xIndex == xPos);
       BCData* bcData = nullptr;
       cellData = (BCCellData*)aCellMap.GetDataAt(rgYPos, xIndex);
       if (!cellData) {
         int32_t numRgRows = aCellMap.GetRowCount();
         if (yPos < numRgRows) { // add a dead cell data
           TableArea damageArea;
           cellData = (BCCellData*)aCellMap.AppendCell(*this, nullptr, rgYPos,
                                                        false, 0, damageArea);
           if (!cellData) ABORT0();
         }
         else {
-          NS_ASSERTION(aSide == NS_SIDE_BOTTOM, "program error");
+          NS_ASSERTION(aSide == eLogicalSideBEnd, "program error");
           // try the next non empty row group
           nsCellMap* cellMap = aCellMap.GetNextSibling();
           while (cellMap && (0 == cellMap->GetRowCount())) {
             cellMap = cellMap->GetNextSibling();
           }
           if (cellMap) {
             cellData = (BCCellData*)cellMap->GetDataAt(0, xIndex);
             if (!cellData) { // add a dead cell
@@ -1028,37 +1028,37 @@ nsTableCellMap::SetBCBorderEdge(mozilla:
             bcData = GetBottomMostBorder(xIndex);
           }
         }
       }
       if (!bcData && cellData) {
         bcData = &cellData->mData;
       }
       if (bcData) {
-        bcData->SetTopEdge(aOwner, aSize, changed);
+        bcData->SetBStartEdge(aOwner, aSize, changed);
       }
       else NS_ERROR("Cellmap: Top edge not found");
     }
     break;
-  case NS_SIDE_RIGHT:
+  case eLogicalSideIEnd:
     xPos++;
-  case NS_SIDE_LEFT:
+  case eLogicalSideIStart:
     // since top, bottom borders were set, there should already be a cellData entry
     lastIndex = rgYPos + aLength - 1;
     for (yIndex = rgYPos; yIndex <= lastIndex; yIndex++) {
       changed = aChanged && (yIndex == rgYPos);
       cellData = (BCCellData*)aCellMap.GetDataAt(yIndex, xPos);
       if (cellData) {
-        cellData->mData.SetLeftEdge(aOwner, aSize, changed);
+        cellData->mData.SetIStartEdge(aOwner, aSize, changed);
       }
       else {
-        NS_ASSERTION(aSide == NS_SIDE_RIGHT, "program error");
+        NS_ASSERTION(aSide == eLogicalSideIEnd, "program error");
         BCData* bcData = GetRightMostBorder(yIndex + aCellMapStart);
         if (bcData) {
-          bcData->SetLeftEdge(aOwner, aSize, changed);
+          bcData->SetIStartEdge(aOwner, aSize, changed);
         }
         else NS_ERROR("Cellmap: Left edge not found");
       }
     }
     break;
   }
 }
 
@@ -1066,17 +1066,17 @@ nsTableCellMap::SetBCBorderEdge(mozilla:
 // (aRowIndex, aColIndex). For eTopRight, store it in the entry to the right where
 // it would be top left. For eBottomRight, store it in the entry to the bottom. etc.
 void
 nsTableCellMap::SetBCBorderCorner(Corner      aCorner,
                                   nsCellMap&  aCellMap,
                                   uint32_t    aCellMapStart,
                                   uint32_t    aRowIndex,
                                   uint32_t    aColIndex,
-                                  mozilla::Side aOwner,
+                                  LogicalSide aOwner,
                                   nscoord     aSubSize,
                                   bool        aBevel,
                                   bool        aIsBottomRight)
 {
   if (!mBCInfo) ABORT0();
 
   if (aIsBottomRight) {
     mBCInfo->mLowerRightCorner.SetCorner(aSubSize, aOwner, aBevel);
@@ -2580,30 +2580,30 @@ void nsCellMap::Dump(bool aIsBorderColla
         }
       } else {
         printf("----  ");
       }
     }
     if (aIsBorderCollapse) {
       nscoord       size;
       BCBorderOwner owner;
-      mozilla::Side side;
+      LogicalSide side;
       bool          segStart;
       bool          bevel;
       for (int32_t i = 0; i <= 2; i++) {
         printf("\n          ");
         for (colIndex = 0; colIndex < colCount; colIndex++) {
           BCCellData* cd = (BCCellData *)row[colIndex];
           if (cd) {
             if (0 == i) {
-              size = cd->mData.GetTopEdge(owner, segStart);
+              size = cd->mData.GetBStartEdge(owner, segStart);
               printf("t=%d%d%d ", int32_t(size), owner, segStart);
             }
             else if (1 == i) {
-              size = cd->mData.GetLeftEdge(owner, segStart);
+              size = cd->mData.GetIStartEdge(owner, segStart);
               printf("l=%d%d%d ", int32_t(size), owner, segStart);
             }
             else {
               size = cd->mData.GetCorner(side, bevel);
               printf("c=%d%d%d ", int32_t(size), side, bevel);
             }
           }
         }
--- a/layout/tables/nsCellMap.h
+++ b/layout/tables/nsCellMap.h
@@ -195,38 +195,38 @@ protected:
                               int32_t                     aStartRowIndex,
                               nsTArray<nsTableRowFrame*>* aRowsToInsert,
                               int32_t                     aNumRowsToRemove,
                               TableArea&                  aDamageArea);
 
 public:
   void ExpandZeroColSpans();
 
-  void ResetTopStart(uint8_t    aSide,
+  void ResetTopStart(mozilla::LogicalSide    aSide,
                      nsCellMap& aCellMap,
                      uint32_t   aYPos,
                      uint32_t   aXPos,
                      bool       aIsLowerRight = false);
 
-  void SetBCBorderEdge(mozilla::Side aEdge,
+  void SetBCBorderEdge(mozilla::LogicalSide aEdge,
                        nsCellMap&    aCellMap,
                        uint32_t      aCellMapStart,
                        uint32_t      aYPos,
                        uint32_t      aXPos,
                        uint32_t      aLength,
                        BCBorderOwner aOwner,
                        nscoord       aSize,
                        bool          aChanged);
 
   void SetBCBorderCorner(::Corner    aCorner,
                          nsCellMap&  aCellMap,
                          uint32_t    aCellMapStart,
                          uint32_t    aYPos,
                          uint32_t    aXPos,
-                         mozilla::Side aOwner,
+                         mozilla::LogicalSide aOwner,
                          nscoord     aSubSize,
                          bool        aBevel,
                          bool        aIsBottomRight = false);
 
   /** dump a representation of the cell map to stdout for debugging */
 #ifdef DEBUG
   void Dump(char* aString = nullptr) const;
 #endif
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -104,26 +104,26 @@ struct nsTableReflowState {
 };
 
 /********************************************************************************
  ** nsTableFrame                                                               **
  ********************************************************************************/
 
 struct BCPropertyData
 {
-  BCPropertyData() : mTopBorderWidth(0), mRightBorderWidth(0),
-                     mBottomBorderWidth(0), mLeftBorderWidth(0),
-                     mLeftCellBorderWidth(0), mRightCellBorderWidth(0) {}
+  BCPropertyData() : mBStartBorderWidth(0), mIEndBorderWidth(0),
+                     mBEndBorderWidth(0), mIStartBorderWidth(0),
+                     mIStartCellBorderWidth(0), mIEndCellBorderWidth(0) {}
   TableArea mDamageArea;
-  BCPixelSize mTopBorderWidth;
-  BCPixelSize mRightBorderWidth;
-  BCPixelSize mBottomBorderWidth;
-  BCPixelSize mLeftBorderWidth;
-  BCPixelSize mLeftCellBorderWidth;
-  BCPixelSize mRightCellBorderWidth;
+  BCPixelSize mBStartBorderWidth;
+  BCPixelSize mIEndBorderWidth;
+  BCPixelSize mBEndBorderWidth;
+  BCPixelSize mIStartBorderWidth;
+  BCPixelSize mIStartCellBorderWidth;
+  BCPixelSize mIEndCellBorderWidth;
 };
 
 nsStyleContext*
 nsTableFrame::GetParentStyleContext(nsIFrame** aProviderFrame) const
 {
   // Since our parent, the table outer frame, returned this frame, we
   // must return whatever our parent would normally have returned.
 
@@ -2649,39 +2649,39 @@ 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->mTopBorderWidth),
-               BC_BORDER_END_HALF_COORD(p2t, propData->mRightBorderWidth),
-               BC_BORDER_END_HALF_COORD(p2t, propData->mBottomBorderWidth),
-               BC_BORDER_START_HALF_COORD(p2t, propData->mLeftBorderWidth));
+    nsMargin r(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->mTopBorderWidth),
-               BC_BORDER_END_HALF_COORD(p2t, propData->mRightCellBorderWidth),
-               BC_BORDER_END_HALF_COORD(p2t, propData->mBottomBorderWidth),
-               BC_BORDER_START_HALF_COORD(p2t, propData->mLeftCellBorderWidth));
+    nsMargin r(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
 {
@@ -4306,23 +4306,23 @@ class BCMapCellIterator
 public:
   BCMapCellIterator(nsTableFrame* aTableFrame,
                     const TableArea& aDamageArea);
 
   void First(BCMapCellInfo& aMapCellInfo);
 
   void Next(BCMapCellInfo& aMapCellInfo);
 
-  void PeekRight(BCMapCellInfo& aRefInfo,
-                 uint32_t     aRowIndex,
-                 BCMapCellInfo& aAjaInfo);
-
-  void PeekBottom(BCMapCellInfo& aRefInfo,
-                  uint32_t     aColIndex,
-                  BCMapCellInfo& aAjaInfo);
+  void PeekIEnd(BCMapCellInfo& aRefInfo,
+                uint32_t       aRowIndex,
+                BCMapCellInfo& aAjaInfo);
+
+  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;}
 
   int32_t    mRowGroupStart;
@@ -4341,23 +4341,24 @@ private:
   int32_t               mRowGroupIndex;
   uint32_t              mNumTableRows;
   nsTableRowFrame*      mRow;
   nsTableRowFrame*      mPrevRow;
   bool                  mIsNewRow;
   int32_t               mRowIndex;
   uint32_t              mNumTableCols;
   int32_t               mColIndex;
-  nsPoint               mAreaStart;
-  nsPoint               mAreaEnd;
+  nsPoint               mAreaStart; // These are not really points in the usual
+  nsPoint               mAreaEnd;   // sense; they're column/row coordinates
+                                    // in the cell map.
 };
 
 BCMapCellIterator::BCMapCellIterator(nsTableFrame* aTableFrame,
                                      const TableArea& aDamageArea)
-:mTableFrame(aTableFrame)
+  : mTableFrame(aTableFrame)
 {
   mTableCellMap  = aTableFrame->GetCellMap();
 
   mAreaStart.x   = aDamageArea.StartCol();
   mAreaStart.y   = aDamageArea.StartRow();
   mAreaEnd.x     = aDamageArea.EndCol() - 1;
   mAreaEnd.y     = aDamageArea.EndRow() - 1;
 
@@ -4503,17 +4504,17 @@ BCMapCellIterator::SetNewRow(nsTableRowF
   else ABORT1(false);
 
   return !mAtEnd;
 }
 
 bool
 BCMapCellIterator::SetNewRowGroup(bool aFindFirstDamagedRow)
 {
-   mAtEnd = true;
+  mAtEnd = true;
   int32_t numRowGroups = mRowGroups.Length();
   mCellMap = nullptr;
   for (mRowGroupIndex++; mRowGroupIndex < numRowGroups; mRowGroupIndex++) {
     mRowGroup = mRowGroups[mRowGroupIndex];
     int32_t rowCount = mRowGroup->GetRowCount();
     mRowGroupStart = mRowGroup->GetStartRowIndex();
     mRowGroupEnd   = mRowGroupStart + rowCount - 1;
     if (rowCount > 0) {
@@ -4550,18 +4551,18 @@ BCMapCellIterator::First(BCMapCellInfo& 
 {
   aMapInfo.ResetCellInfo();
 
   SetNewRowGroup(true); // sets mAtEnd
   while (!mAtEnd) {
     if ((mAreaStart.y >= mRowGroupStart) && (mAreaStart.y <= mRowGroupEnd)) {
       BCCellData* cellData =
         static_cast<BCCellData*>(mCellMap->GetDataAt(mAreaStart.y -
-                                                      mRowGroupStart,
-                                                      mAreaStart.x));
+                                                     mRowGroupStart,
+                                                     mAreaStart.x));
       if (cellData && (cellData->IsOrig() || cellData->IsDead())) {
         aMapInfo.SetInfo(mRow, mAreaStart.x, cellData, this);
         return;
       }
       else {
         NS_ASSERTION(((0 == mAreaStart.x) && (mRowGroupStart == mAreaStart.y)) ,
                      "damage area expanded incorrectly");
       }
@@ -4582,18 +4583,18 @@ BCMapCellIterator::Next(BCMapCellInfo& a
     for (; mColIndex <= mAreaEnd.x; mColIndex++) {
       int32_t rgRowIndex = mRowIndex - mRowGroupStart;
       BCCellData* cellData =
          static_cast<BCCellData*>(mCellMap->GetDataAt(rgRowIndex, mColIndex));
       if (!cellData) { // add a dead cell data
         TableArea damageArea;
         cellData =
           static_cast<BCCellData*>(mCellMap->AppendCell(*mTableCellMap, nullptr,
-                                                         rgRowIndex, false, 0,
-                                                         damageArea));
+                                                        rgRowIndex, false, 0,
+                                                        damageArea));
         if (!cellData) ABORT0();
       }
       if (cellData && (cellData->IsOrig() || cellData->IsDead())) {
         aMapInfo.SetInfo(mRow, mColIndex, cellData, this);
         return;
       }
     }
     if (mRowIndex >= mRowGroupEnd) {
@@ -4602,33 +4603,33 @@ BCMapCellIterator::Next(BCMapCellInfo& a
     else {
       SetNewRow(); // could set mAtEnd
     }
   }
   mAtEnd = true;
 }
 
 void
-BCMapCellIterator::PeekRight(BCMapCellInfo&   aRefInfo,
-                             uint32_t         aRowIndex,
-                             BCMapCellInfo&   aAjaInfo)
+BCMapCellIterator::PeekIEnd(BCMapCellInfo& aRefInfo,
+                            uint32_t       aRowIndex,
+                            BCMapCellInfo& aAjaInfo)
 {
   aAjaInfo.ResetCellInfo();
   int32_t colIndex = aRefInfo.mColIndex + aRefInfo.mColSpan;
   uint32_t rgRowIndex = aRowIndex - mRowGroupStart;
 
   BCCellData* cellData =
     static_cast<BCCellData*>(mCellMap->GetDataAt(rgRowIndex, colIndex));
   if (!cellData) { // add a dead cell data
     NS_ASSERTION(colIndex < mTableCellMap->GetColCount(), "program error");
     TableArea damageArea;
     cellData =
       static_cast<BCCellData*>(mCellMap->AppendCell(*mTableCellMap, nullptr,
-                                                     rgRowIndex, false, 0,
-                                                     damageArea));
+                                                    rgRowIndex, false, 0,
+                                                    damageArea));
     if (!cellData) ABORT0();
   }
   nsTableRowFrame* row = nullptr;
   if (cellData->IsRowSpan()) {
     rgRowIndex -= cellData->GetRowSpanOffset();
     cellData =
       static_cast<BCCellData*>(mCellMap->GetDataAt(rgRowIndex, colIndex));
     if (!cellData)
@@ -4636,19 +4637,19 @@ BCMapCellIterator::PeekRight(BCMapCellIn
   }
   else {
     row = mRow;
   }
   aAjaInfo.SetInfo(row, colIndex, cellData, this);
 }
 
 void
-BCMapCellIterator::PeekBottom(BCMapCellInfo&   aRefInfo,
-                              uint32_t         aColIndex,
-                              BCMapCellInfo&   aAjaInfo)
+BCMapCellIterator::PeekBEnd(BCMapCellInfo& aRefInfo,
+                            uint32_t       aColIndex,
+                            BCMapCellInfo& aAjaInfo)
 {
   aAjaInfo.ResetCellInfo();
   int32_t rowIndex = aRefInfo.mRowIndex + aRefInfo.mRowSpan;
   int32_t rgRowIndex = rowIndex - mRowGroupStart;
   nsTableRowGroupFrame* rg = mRowGroup;
   nsCellMap* cellMap = mCellMap;
   nsTableRowFrame* nextRow = nullptr;
   if (rowIndex > mRowGroupEnd) {
@@ -4675,18 +4676,18 @@ BCMapCellIterator::PeekBottom(BCMapCellI
 
   BCCellData* cellData =
     static_cast<BCCellData*>(cellMap->GetDataAt(rgRowIndex, aColIndex));
   if (!cellData) { // add a dead cell data
     NS_ASSERTION(rgRowIndex < cellMap->GetRowCount(), "program error");
     TableArea damageArea;
     cellData =
       static_cast<BCCellData*>(cellMap->AppendCell(*mTableCellMap, nullptr,
-                                                    rgRowIndex, false, 0,
-                                                    damageArea));
+                                                   rgRowIndex, false, 0,
+                                                   damageArea));
     if (!cellData) ABORT0();
   }
   if (cellData->IsColSpan()) {
     aColIndex -= cellData->GetColSpanOffset();
     cellData =
       static_cast<BCCellData*>(cellMap->GetDataAt(rgRowIndex, aColIndex));
   }
   aAjaInfo.SetInfo(nextRow, aColIndex, cellData, this, cellMap);
@@ -4711,17 +4712,16 @@ static uint8_t styleToPriority[13] = { 0
 
 /** return the border style, border color and optionally the width in
   * pixel for a given frame and side
   * @param aFrame           - query the info for this frame
   * @param aTableWM         - the writing-mode of the frame
   * @param aSide            - the side of the frame
   * @param aStyle           - the border style
   * @param aColor           - the border color
-  * @param aWidth           - the border width in px.
   * @param aWidth           - the border width in px
   */
 static void
 GetColorAndStyle(const nsIFrame* aFrame,
                  WritingMode aTableWM,
                  LogicalSide aSide,
                  uint8_t* aStyle,
                  nscolor* aColor,
@@ -4957,62 +4957,53 @@ CompareBorders(const nsIFrame*  aTableFr
                      &tempBorder.style, &tempBorder.color, &tempBorder.width);
     tempBorder.owner = aAja ? eAjaCellOwner : eCellOwner;
     border = CompareBorders(!CELL_CORNER, border, tempBorder, false);
   }
   return border;
 }
 
 static bool
-Perpendicular(mozilla::css::Side aSide1,
-              mozilla::css::Side aSide2)
-{
-  switch (aSide1) {
-  case NS_SIDE_TOP:
-    return (NS_SIDE_BOTTOM != aSide2);
-  case NS_SIDE_RIGHT:
-    return (NS_SIDE_LEFT != aSide2);
-  case NS_SIDE_BOTTOM:
-    return (NS_SIDE_TOP != aSide2);
-  default: // NS_SIDE_LEFT
-    return (NS_SIDE_RIGHT != aSide2);
-  }
+Perpendicular(mozilla::LogicalSide aSide1,
+              mozilla::LogicalSide aSide2)
+{
+  return IsInline(aSide1) != IsInline(aSide2);
 }
 
 // XXX allocate this as number-of-cols+1 instead of number-of-cols+1 * number-of-rows+1
 struct BCCornerInfo
 {
   BCCornerInfo() { ownerColor = 0; ownerWidth = subWidth = ownerElem = subSide =
-                   subElem = hasDashDot = numSegs = bevel = 0; ownerSide = NS_SIDE_TOP;
+                   subElem = hasDashDot = numSegs = bevel = 0; ownerSide = eLogicalSideBStart;
                    ownerStyle = 0xFF; subStyle = NS_STYLE_BORDER_STYLE_SOLID;  }
-  void Set(mozilla::css::Side aSide,
+  void Set(mozilla::LogicalSide aSide,
            BCCellBorder  border);
 
-  void Update(mozilla::css::Side aSide,
+  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;    // mozilla::css::Side (e.g NS_SIDE_TOP, NS_SIDE_RIGHT, etc) of the border
+  uint32_t  ownerSide:2;    // LogicalSide (e.g NS_SIDE_TOP, NS_SIDE_RIGHT, 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
   uint32_t  bevel:1;        // is the corner beveled (uses the above two fields together with subWidth)
   uint32_t  unused:1;
 };
 
 void
-BCCornerInfo::Set(mozilla::css::Side aSide,
+BCCornerInfo::Set(mozilla::LogicalSide aSide,
                   BCCellBorder  aBorder)
 {
   ownerElem  = aBorder.owner;
   ownerStyle = aBorder.style;
   ownerWidth = aBorder.width;
   ownerColor = aBorder.color;
   ownerSide  = aSide;
   hasDashDot = 0;
@@ -5020,47 +5011,47 @@ BCCornerInfo::Set(mozilla::css::Side aSi
   if (aBorder.width > 0) {
     numSegs++;
     hasDashDot = (NS_STYLE_BORDER_STYLE_DASHED == aBorder.style) ||
                  (NS_STYLE_BORDER_STYLE_DOTTED == aBorder.style);
   }
   bevel      = 0;
   subWidth   = 0;
   // the following will get set later
-  subSide    = ((aSide == NS_SIDE_LEFT) || (aSide == NS_SIDE_RIGHT)) ? NS_SIDE_TOP : NS_SIDE_LEFT;
+  subSide    = IsInline(aSide) ? eLogicalSideBStart : eLogicalSideIStart;
   subElem    = eTableOwner;
   subStyle   = NS_STYLE_BORDER_STYLE_SOLID;
 }
 
 void
-BCCornerInfo::Update(mozilla::css::Side aSide,
+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 = (NS_SIDE_LEFT == aSide) || (NS_SIDE_RIGHT == aSide); // relative to the corner
+    bool horizontal = IsInline(aSide); // relative to the corner
     BCCellBorder oldBorder, tempBorder;
     oldBorder.owner  = (BCBorderOwner) ownerElem;
     oldBorder.style =  ownerStyle;
     oldBorder.width =  ownerWidth;
     oldBorder.color =  ownerColor;
 
-    mozilla::css::Side oldSide  = mozilla::css::Side(ownerSide);
+    LogicalSide oldSide  = LogicalSide(ownerSide);
 
     tempBorder = CompareBorders(CELL_CORNER, oldBorder, aBorder, horizontal, &existingWins);
 
     ownerElem  = tempBorder.owner;
     ownerStyle = tempBorder.style;
     ownerWidth = tempBorder.width;
     ownerColor = tempBorder.color;
     if (existingWins) { // existing corner is dominant
-      if (::Perpendicular(mozilla::css::Side(ownerSide), aSide)) {
+      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;
 
@@ -5071,17 +5062,17 @@ BCCornerInfo::Update(mozilla::css::Side 
         subWidth = tempBorder.width;
         if (!firstWins) {
           subSide = aSide;
         }
       }
     }
     else { // input args are dominant
       ownerSide = aSide;
-      if (::Perpendicular(oldSide, mozilla::css::Side(ownerSide))) {
+      if (::Perpendicular(oldSide, LogicalSide(ownerSide))) {
         subElem  = oldBorder.owner;
         subStyle = oldBorder.style;
         subWidth = oldBorder.width;
         subSide  = oldSide;
       }
     }
     if (aBorder.width > 0) {
       numSegs++;
@@ -5170,17 +5161,17 @@ SetBorder(const BCCellBorder&   aNewBord
 // should also start a new segment.
 static bool
 SetHorBorder(const BCCellBorder& aNewBorder,
              const BCCornerInfo& aCorner,
              BCCellBorder&       aBorder)
 {
   bool startSeg = ::SetBorder(aNewBorder, aBorder);
   if (!startSeg) {
-    startSeg = ((NS_SIDE_LEFT != aCorner.ownerSide) && (NS_SIDE_RIGHT != aCorner.ownerSide));
+    startSeg = !IsInline(LogicalSide(aCorner.ownerSide));
   }
   return startSeg;
 }
 
 // Make the damage area larger on the top and bottom by at least one row and on the left and right
 // at least one column. This is done so that adjacent elements are part of the border calculations.
 // The extra segments and borders outside the actual damage area will not be updated in the cell map,
 // because they in turn would need info from adjacent segments outside the damage area to be accurate.
@@ -5483,48 +5474,48 @@ BCMapCellInfo::SetRowIEndContBCBorder()
                                    eLogicalSideIEnd, ADJACENT);
     mCurrentRowFrame->SetContinuousBCBorderWidth(eLogicalSideIEnd,
                                                  currentBorder.width);
   }
 }
 void
 BCMapCellInfo::SetTableBStartBorderWidth(BCPixelSize aWidth)
 {
-  mTableBCData->mTopBorderWidth = std::max(mTableBCData->mTopBorderWidth, aWidth);
+  mTableBCData->mBStartBorderWidth = std::max(mTableBCData->mBStartBorderWidth, aWidth);
 }
 
 void
 BCMapCellInfo::SetTableIStartBorderWidth(int32_t aRowY, BCPixelSize aWidth)
 {
   // update the left/right first cell border
   if (aRowY == 0) {
     if (mTableWM.IsBidiLTR()) {
-      mTableBCData->mLeftCellBorderWidth = aWidth;
+      mTableBCData->mIStartCellBorderWidth = aWidth;
     }
     else {
-      mTableBCData->mRightCellBorderWidth = aWidth;
-    }
-  }
-  mTableBCData->mLeftBorderWidth = std::max(mTableBCData->mLeftBorderWidth,
+      mTableBCData->mIEndCellBorderWidth = aWidth;
+    }
+  }
+  mTableBCData->mIStartBorderWidth = std::max(mTableBCData->mIStartBorderWidth,
                                           aWidth);
 }
 
 void
 BCMapCellInfo::SetTableIEndBorderWidth(int32_t aRowY, BCPixelSize aWidth)
 {
   // update the left/right first cell border
   if (aRowY == 0) {
     if (mTableWM.IsBidiLTR()) {
-      mTableBCData->mRightCellBorderWidth = aWidth;
+      mTableBCData->mIEndCellBorderWidth = aWidth;
     }
     else {
-      mTableBCData->mLeftCellBorderWidth = aWidth;
-    }
-  }
-  mTableBCData->mRightBorderWidth = std::max(mTableBCData->mRightBorderWidth,
+      mTableBCData->mIStartCellBorderWidth = aWidth;
+    }
+  }
+  mTableBCData->mIEndBorderWidth = std::max(mTableBCData->mIEndBorderWidth,
                                            aWidth);
 }
 
 void
 BCMapCellInfo::SetIEndBorderWidths(BCPixelSize aWidth)
 {
    // update the borders of the cells and cols affected
   if (mCell) {
@@ -5577,17 +5568,17 @@ BCMapCellInfo::SetIStartBorderWidths(BCP
     mStartCol->SetIStartBorderWidth(
       std::max(nscoord(half), mStartCol->GetIStartBorderWidth()));
   }
 }
 
 void
 BCMapCellInfo::SetTableBEndBorderWidth(BCPixelSize aWidth)
 {
-  mTableBCData->mBottomBorderWidth = std::max(mTableBCData->mBottomBorderWidth,
+  mTableBCData->mBEndBorderWidth = std::max(mTableBCData->mBEndBorderWidth,
                                             aWidth);
 }
 
 void
 BCMapCellInfo::SetColumn(int32_t aColX)
 {
   mCurrentColFrame = mTableFrame->GetColFrame(aColX);
   if (!mCurrentColFrame) {
@@ -5730,17 +5721,17 @@ nsTableFrame::CalcBCBorders()
 
   // calculate an expanded damage area
   TableArea damageArea(propData->mDamageArea);
   ExpandBCDamageArea(damageArea);
 
   // segments that are on the table border edges need
   // to be initialized only once
   bool tableBorderReset[4];
-  for (uint32_t sideX = NS_SIDE_TOP; sideX <= NS_SIDE_LEFT; sideX++) {
+  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;
@@ -5779,272 +5770,272 @@ nsTableFrame::CalcBCBorders()
         lastBottomBorder.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
     // processed in a previous row
     if (0 == info.mRowIndex) {
-      if (!tableBorderReset[NS_SIDE_TOP]) {
-        propData->mTopBorderWidth = 0;
-        tableBorderReset[NS_SIDE_TOP] = true;
+      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
         if (0 == colIdx) {
           // we are on right hand side of the corner
-          tlCorner.Set(NS_SIDE_RIGHT, currentBorder);
+          tlCorner.Set(eLogicalSideIEnd, currentBorder);
         }
         else {
-          tlCorner.Update(NS_SIDE_RIGHT, currentBorder);
+          tlCorner.Update(eLogicalSideIEnd, currentBorder);
           tableCellMap->SetBCBorderCorner(eTopLeft, *iter.mCellMap, 0, 0, colIdx,
-                                          mozilla::css::Side(tlCorner.ownerSide),
+                                          LogicalSide(tlCorner.ownerSide),
                                           tlCorner.subWidth,
                                           tlCorner.bevel);
         }
-        topCorners[colIdx + 1].Set(NS_SIDE_LEFT, currentBorder); // top right
+        topCorners[colIdx + 1].Set(eLogicalSideIStart, currentBorder); // top right
         // update lastTopBorder and see if a new segment starts
         startSeg = SetHorBorder(currentBorder, tlCorner, lastTopBorder);
         // store the border segment in the cell map
-        tableCellMap->SetBCBorderEdge(NS_SIDE_TOP, *iter.mCellMap, 0, 0, colIdx,
+        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
       if (info.mColIndex > 0) {
         BCData& data = info.mCellData->mData;
-        if (!data.IsTopStart()) {
-          mozilla::css::Side cornerSide;
+        if (!data.IsBStartStart()) {
+          LogicalSide cornerSide;
           bool bevel;
           data.GetCorner(cornerSide, bevel);
-          if ((NS_SIDE_TOP == cornerSide) || (NS_SIDE_BOTTOM == cornerSide)) {
-            data.SetTopStart(true);
+          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,
     // otherwise it was processed in a previous col
     if (0 == info.mColIndex) {
-      if (!tableBorderReset[NS_SIDE_LEFT]) {
-        propData->mLeftBorderWidth = 0;
-        tableBorderReset[NS_SIDE_LEFT] = true;
+      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);
         currentBorder = info.GetIStartEdgeBorder();
         BCCornerInfo& tlCorner = (0 == rowY) ? topCorners[0] : bottomCorners[0];
-        tlCorner.Update(NS_SIDE_BOTTOM, currentBorder);
+        tlCorner.Update(eLogicalSideBEnd, currentBorder);
         tableCellMap->SetBCBorderCorner(eTopLeft, *iter.mCellMap,
                                         iter.mRowGroupStart, rowY, 0,
-                                        mozilla::css::Side(tlCorner.ownerSide),
+                                        LogicalSide(tlCorner.ownerSide),
                                         tlCorner.subWidth,
                                         tlCorner.bevel);
-        bottomCorners[0].Set(NS_SIDE_TOP, currentBorder); // bottom left
+        bottomCorners[0].Set(eLogicalSideBStart, currentBorder); // bottom left
 
         // update lastVerBordersBorder and see if a new segment starts
         startSeg = SetBorder(currentBorder, lastVerBorders[0]);
         // store the border segment in the cell map
-        tableCellMap->SetBCBorderEdge(NS_SIDE_LEFT, *iter.mCellMap,
+        tableCellMap->SetBCBorderEdge(eLogicalSideIStart, *iter.mCellMap,
                                       iter.mRowGroupStart, rowY, info.mColIndex,
                                       1, currentBorder.owner,
                                       currentBorder.width, startSeg);
         info.SetTableIStartBorderWidth(rowY , currentBorder.width);
         info.SetIStartBorderWidths(currentBorder.width);
         info.SetRowIStartContBCBorder();
       }
       info.SetRowGroupIStartContBCBorder();
     }
 
     // find the dominant border considering the cell's right border, adjacent
     // cells and the table, row group, row
     if (info.mNumTableCols == info.GetCellEndColIndex() + 1) {
       // touches right edge of table
-      if (!tableBorderReset[NS_SIDE_RIGHT]) {
-        propData->mRightBorderWidth = 0;
-        tableBorderReset[NS_SIDE_RIGHT] = true;
+      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);
         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(NS_SIDE_BOTTOM, currentBorder);   // top right
+        trCorner.Update(eLogicalSideBEnd, currentBorder);   // top right
         tableCellMap->SetBCBorderCorner(eTopRight, *iter.mCellMap,
                                         iter.mRowGroupStart, rowY,
                                         info.GetCellEndColIndex(),
-                                        mozilla::css::Side(trCorner.ownerSide),
+                                        LogicalSide(trCorner.ownerSide),
                                         trCorner.subWidth,
                                         trCorner.bevel);
         BCCornerInfo& brCorner = bottomCorners[info.GetCellEndColIndex() + 1];
-        brCorner.Set(NS_SIDE_TOP, currentBorder); // bottom right
+        brCorner.Set(eLogicalSideBStart, currentBorder); // bottom right
         tableCellMap->SetBCBorderCorner(eBottomRight, *iter.mCellMap,
                                         iter.mRowGroupStart, rowY,
                                         info.GetCellEndColIndex(),
-                                        mozilla::css::Side(brCorner.ownerSide),
+                                        LogicalSide(brCorner.ownerSide),
                                         brCorner.subWidth,
                                         brCorner.bevel);
         // update lastVerBorders and see if a new segment starts
         startSeg = SetBorder(currentBorder,
                              lastVerBorders[info.GetCellEndColIndex() + 1]);
         // store the border segment in the cell map and update cellBorders
-        tableCellMap->SetBCBorderEdge(NS_SIDE_RIGHT, *iter.mCellMap,
+        tableCellMap->SetBCBorderEdge(eLogicalSideIEnd, *iter.mCellMap,
                                       iter.mRowGroupStart, rowY,
                                       info.GetCellEndColIndex(), 1,
                                       currentBorder.owner, currentBorder.width,
                                       startSeg);
         info.SetTableIEndBorderWidth(rowY, 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.PeekRight(info, rowY, ajaInfo);
+        iter.PeekIEnd(info, rowY, 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
         startSeg = SetBorder(currentBorder,
                              lastVerBorders[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()) {
-          tableCellMap->SetBCBorderEdge(NS_SIDE_RIGHT, *iter.mCellMap,
+          tableCellMap->SetBCBorderEdge(eLogicalSideIEnd, *iter.mCellMap,
                                         iter.mRowGroupStart, rowY,
                                         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];
-        trCorner->Update(NS_SIDE_BOTTOM, currentBorder);
+        trCorner->Update(eLogicalSideBEnd, currentBorder);
         // if this is not the first time through,
         // consider the segment to the right
         if (rowY != info.mRowIndex) {
           currentBorder = priorAjaInfo.GetBEndInternalBorder();
           adjacentBorder = ajaInfo.GetBStartInternalBorder();
           currentBorder = CompareBorders(!CELL_CORNER, currentBorder,
                                           adjacentBorder, HORIZONTAL);
-          trCorner->Update(NS_SIDE_RIGHT, currentBorder);
+          trCorner->Update(eLogicalSideIEnd, currentBorder);
         }
         // store the top right corner in the cell map
         if (info.GetCellEndColIndex() < damageArea.EndCol() &&
             rowY >= damageArea.StartRow()) {
           if (0 != rowY) {
             tableCellMap->SetBCBorderCorner(eTopRight, *iter.mCellMap,
                                             iter.mRowGroupStart, rowY,
                                             info.GetCellEndColIndex(),
-                                            mozilla::css::Side(trCorner->ownerSide),
+                                            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,
                                             iter.mRowGroupStart, rX,
                                             info.GetCellEndColIndex(),
-                                            mozilla::css::Side(trCorner->ownerSide),
+                                            LogicalSide(trCorner->ownerSide),
                                             trCorner->subWidth, false);
           }
         }
         // update bottom right corner, topCorners, bottomCorners
         hitsSpanOnRight = (rowY + segLength <
                            ajaInfo.mRowIndex + ajaInfo.mRowSpan);
         BCCornerInfo& brCorner = (hitsSpanOnRight) ?
                                  topCorners[info.GetCellEndColIndex() + 1] :
                                  bottomCorners[info.GetCellEndColIndex() + 1];
-        brCorner.Set(NS_SIDE_TOP, currentBorder);
+        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
     // cells and the table, row group, row
     if (info.mNumTableRows == info.GetCellEndRowIndex() + 1) {
       // touches bottom edge of table
-      if (!tableBorderReset[NS_SIDE_BOTTOM]) {
-        propData->mBottomBorderWidth = 0;
-        tableBorderReset[NS_SIDE_BOTTOM] = true;
+      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
-        blCorner.Update(NS_SIDE_RIGHT, currentBorder);
+        blCorner.Update(eLogicalSideIEnd, currentBorder);
         tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
                                         iter.mRowGroupStart,
                                         info.GetCellEndRowIndex(),
                                         colIdx,
-                                        mozilla::css::Side(blCorner.ownerSide),
+                                        LogicalSide(blCorner.ownerSide),
                                         blCorner.subWidth, blCorner.bevel);
         BCCornerInfo& brCorner = bottomCorners[colIdx + 1]; // bottom right
-        brCorner.Update(NS_SIDE_LEFT, currentBorder);
+        brCorner.Update(eLogicalSideIStart, currentBorder);
         if (info.mNumTableCols == colIdx + 1) { // lower right corner of the table
           tableCellMap->SetBCBorderCorner(eBottomRight, *iter.mCellMap,
                                           iter.mRowGroupStart,
                                           info.GetCellEndRowIndex(), colIdx,
-                                          mozilla::css::Side(brCorner.ownerSide),
+                                          LogicalSide(brCorner.ownerSide),
                                           brCorner.subWidth,
                                           brCorner.bevel, true);
         }
         // update lastBottomBorder and see if a new segment starts
         startSeg = SetHorBorder(currentBorder, blCorner, lastBottomBorder);
         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
            // add 1 to the info.GetCellEndRowIndex()
            startSeg = (lastBottomBorder.rowIndex !=
                        (info.GetCellEndRowIndex() + 1));
         }
         // store the border segment in the cell map and update cellBorders
-        tableCellMap->SetBCBorderEdge(NS_SIDE_BOTTOM, *iter.mCellMap,
+        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;
@@ -6055,17 +6046,17 @@ nsTableFrame::CalcBCBorders()
       }
       info.SetRowGroupBEndContBCBorder();
       info.SetColGroupBEndContBCBorder();
     }
     else {
       int32_t segLength = 0;
       for (int32_t colIdx = info.mColIndex;
            colIdx <= info.GetCellEndColIndex(); colIdx += segLength) {
-        iter.PeekBottom(info, colIdx, ajaInfo);
+        iter.PeekBEnd(info, colIdx, ajaInfo);
         currentBorder = info.GetBEndInternalBorder();
         adjacentBorder = ajaInfo.GetBStartInternalBorder();
         currentBorder = CompareBorders(!CELL_CORNER, currentBorder,
                                         adjacentBorder, HORIZONTAL);
         segLength = std::max(1, ajaInfo.mColIndex + ajaInfo.mColSpan - colIdx);
         segLength = std::min(segLength, info.mColIndex + info.mColSpan - colIdx);
 
         // update, store the bottom left corner
@@ -6078,40 +6069,40 @@ nsTableFrame::CalcBCBorders()
           if (prevRowIndex > info.GetCellEndRowIndex() + 1) {
             // hits a rowspan on the right
             update = false;
             // the corner was taken care of during the cell on the left
           }
           else if (prevRowIndex < info.GetCellEndRowIndex() + 1) {
             // spans below the cell to the left
             topCorners[colIdx] = blCorner;
-            blCorner.Set(NS_SIDE_RIGHT, currentBorder);
+            blCorner.Set(eLogicalSideIEnd, currentBorder);
             update = false;
           }
         }
         if (update) {
-          blCorner.Update(NS_SIDE_RIGHT, currentBorder);
+          blCorner.Update(eLogicalSideIEnd, currentBorder);
         }
         if (info.GetCellEndRowIndex() < damageArea.EndRow() &&
             colIdx >= damageArea.StartCol()) {
           if (hitsSpanBelow) {
             tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
                                             iter.mRowGroupStart,
                                             info.GetCellEndRowIndex(), colIdx,
-                                            mozilla::css::Side(blCorner.ownerSide),
+                                            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];
-            corner.Set(NS_SIDE_RIGHT, currentBorder);
+            corner.Set(eLogicalSideIEnd, currentBorder);
             tableCellMap->SetBCBorderCorner(eBottomLeft, *iter.mCellMap,
                                             iter.mRowGroupStart,
                                             info.GetCellEndRowIndex(), c,
-                                            mozilla::css::Side(corner.ownerSide),
+                                            LogicalSide(corner.ownerSide),
                                             corner.subWidth,
                                             false);
           }
         }
         // update lastBottomBorders and see if a new segment starts
         startSeg = SetHorBorder(currentBorder, blCorner, lastBottomBorder);
         if (!startSeg) {
            // make sure that we did not compare apples to oranges i.e. the
@@ -6125,27 +6116,27 @@ nsTableFrame::CalcBCBorders()
         lastBottomBorder.rowSpan = info.mRowSpan;
         for (int32_t c = colIdx; c < colIdx + segLength; c++) {
           lastBottomBorders[c] = lastBottomBorder;
         }
 
         // store the border segment the cell map and update cellBorders
         if (info.GetCellEndRowIndex() < damageArea.EndRow() &&
             colIdx >= damageArea.StartCol() && colIdx < damageArea.EndCol()) {
-          tableCellMap->SetBCBorderEdge(NS_SIDE_BOTTOM, *iter.mCellMap,
+          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];
-        brCorner.Update(NS_SIDE_LEFT, currentBorder);
+        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
         //the last row in the row group, but only a cell with rowspan=1
         //will know whether *this* row is at the bottom
         const nsIFrame* nextRowGroup =
@@ -6156,28 +6147,27 @@ nsTableFrame::CalcBCBorders()
     }
 
     // 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
     if ((info.mNumTableCols != info.GetCellEndColIndex() + 1) &&
         (lastBottomBorders[info.GetCellEndColIndex() + 1].rowSpan > 1)) {
       BCCornerInfo& corner = bottomCorners[info.GetCellEndColIndex() + 1];
-      if ((NS_SIDE_TOP != corner.ownerSide) &&
-          (NS_SIDE_BOTTOM != corner.ownerSide)) {
+      if (!IsBlock(LogicalSide(corner.ownerSide))) {
         // not a vertical owner
         BCCellBorder& thisBorder = lastBottomBorder;
         BCCellBorder& nextBorder = lastBottomBorders[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(NS_SIDE_BOTTOM, *iter.mCellMap,
+            tableCellMap->ResetTopStart(eLogicalSideBEnd, *iter.mCellMap,
                                         info.GetCellEndRowIndex(),
                                         info.GetCellEndColIndex() + 1);
           }
         }
       }
     }
   } // for (iter.First(info); info.mCell; iter.Next(info)) {
   // reset the bc flag and damage area
@@ -6227,17 +6217,17 @@ struct BCVerticalSeg
   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
-  mozilla::css::Side    mTopBevelSide;  // direction to bevel at the top
+  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
                                         // amount the next segment needs to be
                                         // shifted.
   bool                  mIsBottomBevel; // should we bevel at the bottom
@@ -6258,20 +6248,20 @@ struct BCHorizontalSeg
    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
-  mozilla::css::Side mLeftBevelSide;     // direction 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
-  mozilla::css::Side mRightBevelSide;    // direction to bevel at the right
+  LogicalSide mRightBevelSide;    // direction to bevel at the right
   nscoord            mEndOffset;         // how much longer is the segment due
                                          // to the vertical 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
@@ -6295,18 +6285,18 @@ public:
    * Determine the damage area in terms of rows and columns and finalize
    * mInitialOffsetX and mInitialOffsetY.
    * @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 AccumulateOrPaintHorizontalSegment(nsRenderingContext& aRenderingContext);
-  void AccumulateOrPaintVerticalSegment(nsRenderingContext& aRenderingContext);
+  void AccumulateOrPaintInlineDirSegment(nsRenderingContext& aRenderingContext);
+  void AccumulateOrPaintBlockDirSegment(nsRenderingContext& aRenderingContext);
   void ResetVerInfo();
   void StoreColumnWidth(int32_t aIndex);
   bool VerticalSegmentOwnsCorner();
 
   nsTableFrame*         mTable;
   nsTableFrame*         mTableFirstInFlow;
   nsTableCellMap*       mTableCellMap;
   nsCellMap*            mCellMap;
@@ -6773,33 +6763,32 @@ BCPaintBorderIterator::Next()
   * @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
   */
 static nscoord
-CalcVerCornerOffset(mozilla::css::Side aCornerOwnerSide,
+CalcVerCornerOffset(LogicalSide aCornerOwnerSide,
                     BCPixelSize aCornerSubWidth,
                     BCPixelSize aHorWidth,
                     bool        aIsStartOfSeg,
                     bool        aIsBevel)
 {
   nscoord offset = 0;
   // XXX These should be replaced with appropriate side-specific macros (which?)
   BCPixelSize smallHalf, largeHalf;
-  if ((NS_SIDE_TOP == aCornerOwnerSide) ||
-      (NS_SIDE_BOTTOM == aCornerOwnerSide)) {
+  if (IsBlock(aCornerOwnerSide)) {
     DivideBCBorderSize(aCornerSubWidth, smallHalf, largeHalf);
     if (aIsBevel) {
       offset = (aIsStartOfSeg) ? -largeHalf : smallHalf;
     }
     else {
-      offset = (NS_SIDE_TOP == aCornerOwnerSide) ? smallHalf : -largeHalf;
+      offset = (eLogicalSideBStart == aCornerOwnerSide) ? smallHalf : -largeHalf;
     }
   }
   else {
     DivideBCBorderSize(aHorWidth, smallHalf, largeHalf);
     if (aIsBevel) {
       offset = (aIsStartOfSeg) ? -largeHalf : smallHalf;
     }
     else {
@@ -6814,39 +6803,38 @@ CalcVerCornerOffset(mozilla::css::Side a
   * @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(mozilla::css::Side aCornerOwnerSide,
+CalcHorCornerOffset(LogicalSide aCornerOwnerSide,
                     BCPixelSize aCornerSubWidth,
                     BCPixelSize aVerWidth,
                     bool        aIsStartOfSeg,
                     bool        aIsBevel,
                     bool        aTableIsLTR)
 {
   nscoord offset = 0;
   // XXX These should be replaced with appropriate side-specific macros (which?)
   BCPixelSize smallHalf, largeHalf;
-  if ((NS_SIDE_LEFT == aCornerOwnerSide) ||
-      (NS_SIDE_RIGHT == aCornerOwnerSide)) {
+  if (IsInline(aCornerOwnerSide)) {
     if (aTableIsLTR) {
       DivideBCBorderSize(aCornerSubWidth, smallHalf, largeHalf);
     }
     else {
       DivideBCBorderSize(aCornerSubWidth, largeHalf, smallHalf);
     }
     if (aIsBevel) {
       offset = (aIsStartOfSeg) ? -largeHalf : smallHalf;
     }
     else {
-      offset = (NS_SIDE_LEFT == aCornerOwnerSide) ? smallHalf : -largeHalf;
+      offset = (eLogicalSideIStart == aCornerOwnerSide) ? smallHalf : -largeHalf;
     }
   }
   else {
     if (aTableIsLTR) {
       DivideBCBorderSize(aVerWidth, smallHalf, largeHalf);
     }
     else {
       DivideBCBorderSize(aVerWidth, largeHalf, smallHalf);
@@ -6861,17 +6849,17 @@ CalcHorCornerOffset(mozilla::css::Side a
   return nsPresContext::CSSPixelsToAppUnits(offset);
 }
 
 BCVerticalSeg::BCVerticalSeg()
 {
   mCol = nullptr;
   mFirstCell = mLastCell = mAjaCell = nullptr;
   mOffsetX = mOffsetY = mLength = mWidth = mTopBevelOffset = 0;
-  mTopBevelSide = NS_SIDE_TOP;
+  mTopBevelSide = eLogicalSideBStart;
   mOwner = eCellOwner;
 }
 
 /**
  * Start a new vertical segment
  * @param aIter         - iterator containing the structural information
  * @param aBorderOwner  - determines the border style
  * @param aVerSegWidth  - the width of segment in pixel
@@ -6879,33 +6867,32 @@ BCVerticalSeg::BCVerticalSeg()
  *                        at the start
  */
 void
 BCVerticalSeg::Start(BCPaintBorderIterator& aIter,
                      BCBorderOwner          aBorderOwner,
                      BCPixelSize            aVerSegWidth,
                      BCPixelSize            aHorSegHeight)
 {
-  mozilla::css::Side ownerSide   = NS_SIDE_TOP;
+  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);
   nscoord offset          = CalcVerCornerOffset(ownerSide, cornerSubWidth,
                                                 maxHorSegHeight, true,
                                                 topBevel);
 
   mTopBevelOffset = topBevel ?
     nsPresContext::CSSPixelsToAppUnits(maxHorSegHeight): 0;
   // XXX this assumes that only corners where 2 segments join can be beveled
-  mTopBevelSide     = (aHorSegHeight > 0) ? NS_SIDE_RIGHT : NS_SIDE_LEFT;
+  mTopBevelSide     = (aHorSegHeight > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
   mOffsetY      += offset;
   mLength        = -offset;
   mWidth         = aVerSegWidth;
   mOwner         = aBorderOwner;
   mFirstCell     = aIter.mCell;
   mFirstRowGroup = aIter.mRg;
   mFirstRow      = aIter.mRow;
   if (aIter.GetRelativeColIndex() > 0) {
@@ -6942,17 +6929,17 @@ BCVerticalSeg::Initialize(BCPaintBorderI
  * @param aIter         - iterator containing the structural information
  * @param aHorSegHeight - the width of the horizontal segment joining the corner
  *                        at the start
  */
 void
 BCVerticalSeg::GetBottomCorner(BCPaintBorderIterator& aIter,
                                BCPixelSize            aHorSegHeight)
 {
-   mozilla::css::Side ownerSide = NS_SIDE_TOP;
+   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,
@@ -7036,28 +7023,26 @@ BCVerticalSeg::Paint(BCPaintBorderIterat
   }
   BCPixelSize smallHalf, largeHalf;
   DivideBCBorderSize(mWidth, smallHalf, largeHalf);
   nsRect segRect(mOffsetX - nsPresContext::CSSPixelsToAppUnits(largeHalf),
                  mOffsetY,
                  nsPresContext::CSSPixelsToAppUnits(mWidth), mLength);
   nscoord bottomBevelOffset = (mIsBottomBevel) ?
                   nsPresContext::CSSPixelsToAppUnits(mBottomHorSegHeight) : 0;
-  mozilla::css::Side bottomBevelSide =
-    (aHorSegHeight > 0) ^ !aIter.mTableWM.IsBidiLTR() ?
-    NS_SIDE_RIGHT : NS_SIDE_LEFT;
-  mozilla::css::Side topBevelSide =
-    (mTopBevelSide == NS_SIDE_RIGHT) ^ !aIter.mTableWM.IsBidiLTR() ?
-    NS_SIDE_RIGHT : NS_SIDE_LEFT;
+  LogicalSide bottomBevelSide =
+    (aHorSegHeight > 0) ? eLogicalSideIEnd : eLogicalSideIStart;
   nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
                                          aIter.mTableBgColor, segRect,
                                          appUnitsPerDevPixel,
                                          nsPresContext::AppUnitsPerCSSPixel(),
-                                         topBevelSide, mTopBevelOffset,
-                                         bottomBevelSide, bottomBevelOffset);
+                                         aIter.mTableWM.PhysicalSide(mTopBevelSide),
+                                          mTopBevelOffset,
+                                         aIter.mTableWM.PhysicalSide(bottomBevelSide),
+                                          bottomBevelOffset);
 }
 
 /**
  * Advance the start point of a segment
  */
 void
 BCVerticalSeg::AdvanceOffsetY()
 {
@@ -7072,50 +7057,50 @@ BCVerticalSeg::IncludeCurrentBorder(BCPa
 {
   mLastCell = aIter.mCell;
   mLength  += aIter.mRow->GetRect().height;
 }
 
 BCHorizontalSeg::BCHorizontalSeg()
 {
   mOffsetX = mOffsetY = mLength = mWidth =  mLeftBevelOffset = 0;
-  mLeftBevelSide = NS_SIDE_TOP;
+  mLeftBevelSide = eLogicalSideBStart;
   mFirstCell = mAjaCell = nullptr;
 }
 
 /** Initialize a horizontal 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
   +  */
 void
 BCHorizontalSeg::Start(BCPaintBorderIterator& aIter,
                        BCBorderOwner          aBorderOwner,
                        BCPixelSize            aBottomVerSegWidth,
                        BCPixelSize            aHorSegHeight)
 {
-  mozilla::css::Side cornerOwnerSide = NS_SIDE_TOP;
+  LogicalSide cornerOwnerSide = eLogicalSideBStart;
   bool bevel     = false;
 
   mOwner = aBorderOwner;
   nscoord cornerSubWidth  = (aIter.mBCData) ?
                              aIter.mBCData->GetCorner(cornerOwnerSide,
                                                        bevel) : 0;
 
   bool    leftBevel = (aHorSegHeight > 0) ? bevel : false;
   int32_t relColIndex = aIter.GetRelativeColIndex();
   nscoord maxVerSegWidth = std::max(aIter.mVerInfo[relColIndex].mWidth,
                                   aBottomVerSegWidth);
   nscoord offset = CalcHorCornerOffset(cornerOwnerSide, cornerSubWidth,
                                        maxVerSegWidth, true, leftBevel,
                                        aIter.mTableWM.IsBidiLTR());
   mLeftBevelOffset = (leftBevel && (aHorSegHeight > 0)) ? maxVerSegWidth : 0;
   // XXX this assumes that only corners where 2 segments join can be beveled
-  mLeftBevelSide   = (aBottomVerSegWidth > 0) ? NS_SIDE_BOTTOM : NS_SIDE_TOP;
+  mLeftBevelSide   = (aBottomVerSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
   if (aIter.mTableWM.IsBidiLTR()) {
     mOffsetX += offset;
   }
   else {
     mOffsetX -= offset;
   }
   mLength          = -offset;
   mWidth           = aHorSegHeight;
@@ -7129,32 +7114,32 @@ BCHorizontalSeg::Start(BCPaintBorderIter
  * @param aIter         - iterator containing the structural information
  * @param aLeftSegWidth - the width of the vertical segment joining the corner
  *                        at the start
  */
 void
 BCHorizontalSeg::GetRightCorner(BCPaintBorderIterator& aIter,
                                 BCPixelSize            aLeftSegWidth)
 {
-  mozilla::css::Side ownerSide = NS_SIDE_TOP;
+  LogicalSide ownerSide = eLogicalSideBStart;
   nscoord cornerSubWidth = 0;
   bool bevel = false;
   if (aIter.mBCData) {
     cornerSubWidth = aIter.mBCData->GetCorner(ownerSide, bevel);
   }
 
   mIsRightBevel = (mWidth > 0) ? bevel : 0;
   int32_t relColIndex = aIter.GetRelativeColIndex();
   nscoord verWidth = std::max(aIter.mVerInfo[relColIndex].mWidth, aLeftSegWidth);
   mEndOffset = CalcHorCornerOffset(ownerSide, cornerSubWidth, verWidth,
                                    false, mIsRightBevel, aIter.mTableWM.IsBidiLTR());
   mLength += mEndOffset;
   mRightBevelOffset = (mIsRightBevel) ?
                        nsPresContext::CSSPixelsToAppUnits(verWidth) : 0;
-  mRightBevelSide = (aLeftSegWidth > 0) ? NS_SIDE_BOTTOM : NS_SIDE_TOP;
+  mRightBevelSide = (aLeftSegWidth > 0) ? eLogicalSideBEnd : eLogicalSideBStart;
 }
 
 /**
  * Paint the horizontal segment
  * @param aIter         - iterator containing the structural information
  * @param aRenderingContext - the rendering context
  */
 void
@@ -7233,28 +7218,30 @@ BCHorizontalSeg::Paint(BCPaintBorderIter
                  mOffsetY - nsPresContext::CSSPixelsToAppUnits(largeHalf),
                  mLength,
                  nsPresContext::CSSPixelsToAppUnits(mWidth));
   if (aIter.mTableWM.IsBidiLTR()) {
     nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
                                            aIter.mTableBgColor, segRect,
                                            appUnitsPerDevPixel,
                                            nsPresContext::AppUnitsPerCSSPixel(),
-                                           mLeftBevelSide,
+                                           aIter.mTableWM.PhysicalSide(mLeftBevelSide),
                                            nsPresContext::CSSPixelsToAppUnits(mLeftBevelOffset),
-                                           mRightBevelSide, mRightBevelOffset);
+                                           aIter.mTableWM.PhysicalSide(mRightBevelSide),
+                                            mRightBevelOffset);
   }
   else {
     segRect.x -= segRect.width;
     nsCSSRendering::DrawTableBorderSegment(aRenderingContext, style, color,
                                            aIter.mTableBgColor, segRect,
                                            appUnitsPerDevPixel,
                                            nsPresContext::AppUnitsPerCSSPixel(),
-                                           mRightBevelSide, mRightBevelOffset,
-                                           mLeftBevelSide,
+                                           aIter.mTableWM.PhysicalSide(mRightBevelSide),
+                                            mRightBevelOffset,
+                                           aIter.mTableWM.PhysicalSide(mLeftBevelSide),
                                            nsPresContext::CSSPixelsToAppUnits(mLeftBevelOffset));
   }
 }
 
 /**
  * Advance the start point of a segment
  */
 void
@@ -7279,58 +7266,58 @@ void
 BCPaintBorderIterator::StoreColumnWidth(int32_t aIndex)
 {
   if (IsTableRightMost()) {
       mVerInfo[aIndex].mColWidth = mVerInfo[aIndex - 1].mColWidth;
   }
   else {
     nsTableColFrame* col = mTableFirstInFlow->GetColFrame(mColIndex);
     if (!col) ABORT0();
-    mVerInfo[aIndex].mColWidth = col->GetSize().width;
+    mVerInfo[aIndex].mColWidth = col->ISize(mTableWM);
   }
 }
 /**
  * Determine if a vertical segment owns the corder
  */
 bool
 BCPaintBorderIterator::VerticalSegmentOwnsCorner()
 {
-  mozilla::css::Side cornerOwnerSide = NS_SIDE_TOP;
+  LogicalSide cornerOwnerSide = eLogicalSideBStart;
   bool bevel = false;
   if (mBCData) {
     mBCData->GetCorner(cornerOwnerSide, bevel);
   }
   // unitialized ownerside, bevel
-  return  (NS_SIDE_TOP == cornerOwnerSide) ||
-          (NS_SIDE_BOTTOM == cornerOwnerSide);
+  return  (eLogicalSideBStart == cornerOwnerSide) ||
+          (eLogicalSideBEnd == cornerOwnerSide);
 }
 
 /**
  * Paint if necessary a horizontal segment, otherwise accumulate it
  * @param aRenderingContext - the rendering context
  */
 void
-BCPaintBorderIterator::AccumulateOrPaintHorizontalSegment(nsRenderingContext& aRenderingContext)
+BCPaintBorderIterator::AccumulateOrPaintInlineDirSegment(nsRenderingContext& aRenderingContext)
 {
 
   int32_t relColIndex = GetRelativeColIndex();
   // store the current col width if it hasn't been already
   if (mVerInfo[relColIndex].mColWidth < 0) {
     StoreColumnWidth(relColIndex);
   }
 
   BCBorderOwner borderOwner = eCellOwner;
   BCBorderOwner ignoreBorderOwner;
   bool isSegStart = true;
   bool ignoreSegStart;
 
   nscoord leftSegWidth =
-    mBCData ? mBCData->GetLeftEdge(ignoreBorderOwner, ignoreSegStart) : 0;
+    mBCData ? mBCData->GetIStartEdge(ignoreBorderOwner, ignoreSegStart) : 0;
   nscoord topSegHeight =
-    mBCData ? mBCData->GetTopEdge(borderOwner, isSegStart) : 0;
+    mBCData ? mBCData->GetBStartEdge(borderOwner, isSegStart) : 0;
 
   if (mIsNewRow || (IsDamageAreaLeftMost() && IsDamageAreaBottomMost())) {
     // 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);
   }
@@ -7351,27 +7338,27 @@ BCPaintBorderIterator::AccumulateOrPaint
   mVerInfo[relColIndex].mWidth = leftSegWidth;
   mVerInfo[relColIndex].mLastCell = mCell;
 }
 /**
  * Paint if necessary a vertical segment, otherwise  it
  * @param aRenderingContext - the rendering context
  */
 void
-BCPaintBorderIterator::AccumulateOrPaintVerticalSegment(nsRenderingContext& aRenderingContext)
+BCPaintBorderIterator::AccumulateOrPaintBlockDirSegment(nsRenderingContext& aRenderingContext)
 {
   BCBorderOwner borderOwner = eCellOwner;
   BCBorderOwner ignoreBorderOwner;
   bool isSegStart = true;
   bool ignoreSegStart;
 
   nscoord verSegWidth  =
-    mBCData ? mBCData->GetLeftEdge(borderOwner, isSegStart) : 0;
+    mBCData ? mBCData->GetIStartEdge(borderOwner, isSegStart) : 0;
   nscoord horSegHeight =
-    mBCData ? mBCData->GetTopEdge(ignoreBorderOwner, ignoreSegStart) : 0;
+    mBCData ? mBCData->GetBStartEdge(ignoreBorderOwner, ignoreSegStart) : 0;
 
   int32_t relColIndex = GetRelativeColIndex();
   BCVerticalSeg& 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);
   }
@@ -7429,25 +7416,25 @@ nsTableFrame::PaintBCBorders(nsRendering
   // 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.AccumulateOrPaintVerticalSegment(aRenderingContext);
+    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
   // corner calculations
   iter.Reset();
   for (iter.First(); !iter.mAtEnd; iter.Next()) {
-    iter.AccumulateOrPaintHorizontalSegment(aRenderingContext);
+    iter.AccumulateOrPaintInlineDirSegment(aRenderingContext);
   }
 }
 
 bool
 nsTableFrame::RowHasSpanningCells(int32_t aRowIndex, int32_t aNumEffCols)
 {
   bool result = false;
   nsTableCellMap* cellMap = GetCellMap();