Bug 1484126 - part 6: Make all CellData users refer CellData::mFirst.mRow directly r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 15 Oct 2018 04:10:32 +0000
changeset 489729 0f9a168cb7c818b7ed782228cce640699022e64e
parent 489728 181c07ae07c598314b76cb5b9b0c700d72c07488
child 489730 448d887560d4e6be3e91e831ebe161fc858bb68f
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersm_kato
bugs1484126
milestone64.0a1
Bug 1484126 - part 6: Make all CellData users refer CellData::mFirst.mRow directly r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D8343
editor/libeditor/HTMLTableEditor.cpp
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -206,17 +206,16 @@ HTMLEditor::InsertTableCellsWithTransact
   IgnoredErrorResult ignoredError;
   CellData cellDataAtSelection(*this, *table, startRowIndex, startColIndex,
                                ignoredError);
   if (NS_WARN_IF(cellDataAtSelection.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
   MOZ_ASSERT(curCell == cellDataAtSelection.mElement);
 
-  // int32_t curStartRowIndex = cellDataAtSelection.mFirst.mRow;
   // int32_t curStartColIndex = cellDataAtSelection.mFirst.mColumn;
   // int32_t rowSpan =          cellDataAtSelection.mRowSpan;
   int32_t    colSpan =          cellDataAtSelection.mColSpan;
   // int32_t actualRowSpan =    cellDataAtSelection.mEffectiveRowSpan;
   // int32_t actualColSpan =    cellDataAtSelection.mEffectiveColSpan;
   // bool    isSelected =       cellDataAtSelection.mIsSelected;
 
   int32_t newCellIndex;
@@ -445,17 +444,16 @@ HTMLEditor::InsertTableColumnsWithTransa
   IgnoredErrorResult ignoredError;
   CellData cellDataAtSelection(*this, *table, startRowIndex, startColIndex,
                                ignoredError);
   if (NS_WARN_IF(cellDataAtSelection.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
   MOZ_ASSERT(curCell == cellDataAtSelection.mElement);
 
-  // int32_t curStartRowIndex = cellDataAtSelection.mFirst.mRow;
   // int32_t curStartColIndex = cellDataAtSelection.mFirst.mColumn;
   // int32_t rowSpan =          cellDataAtSelection.mRowSpan;
   int32_t    colSpan =          cellDataAtSelection.mColSpan;
   // int32_t actualRowSpan =    cellDataAtSelection.mEffectiveRowSpan;
   int32_t    actualColSpan =    cellDataAtSelection.mEffectiveColSpan;
   // bool    isSelected =       cellDataAtSelection.mIsSelected;
 
   ErrorResult error;
@@ -515,17 +513,16 @@ HTMLEditor::InsertTableColumnsWithTransa
   for (int32_t rowIndex = 0; rowIndex < tableSize.mRowCount; rowIndex++) {
     if (startColIndex < tableSize.mColumnCount) {
       // We are inserting before an existing column.
       CellData cellData(*this, *table, rowIndex, startColIndex, ignoredError);
       if (NS_WARN_IF(cellData.FailedOrNotFound())) {
         return NS_ERROR_FAILURE;
       }
 
-      // int32_t curStartRowIndex =       cellData.mFirst.mRow;
       int32_t    curStartColIndex =       cellData.mFirst.mColumn;
       // int32_t rowSpan =                cellData.mRowSpan;
       int32_t    colSpan =                cellData.mColSpan;
       // int32_t actualRowSpan =          cellData.mEffectiveRowSpan;
       // int32_t actualColSpan =          cellData.mEffectiveColSpan;
       // bool    isSelected =             cellData.mIsSelected;
 
       // Don't fail entire process if we fail to find a cell (may fail just in
@@ -648,17 +645,16 @@ HTMLEditor::InsertTableRowsWithTransacti
   IgnoredErrorResult ignoredError;
   CellData cellDataAtSelection(*this, *table, startRowIndex, startColIndex,
                                ignoredError);
   if (NS_WARN_IF(cellDataAtSelection.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
   MOZ_ASSERT(curCell == cellDataAtSelection.mElement);
 
-  // int32_t curStartRowIndex = cellDataAtSelection.mFirst.mRow;
   // int32_t curStartColIndex = cellDataAtSelection.mFirst.mColumn;
   int32_t    rowSpan =          cellDataAtSelection.mRowSpan;
   // int32_t colSpan =          cellDataAtSelection.mColSpan;
   int32_t    actualRowSpan =    cellDataAtSelection.mEffectiveRowSpan;
   // int32_t actualColSpan =    cellDataAtSelection.mEffectiveColSpan;
   // bool isSelected =          cellDataAtSelection.mIsSelected;
 
   ErrorResult error;
@@ -707,31 +703,30 @@ HTMLEditor::InsertTableRowsWithTransacti
     // row to adjust for colspan effects while we count how many cells are
     // needed.
     for (int32_t colIndex = 0, actualColSpan = 0;; colIndex += actualColSpan) {
       CellData cellData(*this, *table, startRowIndex, colIndex, ignoredError);
       if (cellData.FailedOrNotFound()) {
         break; // Perhaps, we reach end of the row.
       }
 
-      int32_t    curStartRowIndex =           cellData.mFirst.mRow;
       // int32_t curStartColIndex =           cellData.mFirst.mColumn;
       int32_t    rowSpan =                    cellData.mRowSpan;
       // int32_t colSpan =                    cellData.mColSpan;
       // int32_t actualRowSpan =              cellData.mEffectiveRowSpan;
                  actualColSpan =              cellData.mEffectiveColSpan;
       // bool    isSelected =                 cellData.mIsSelected;
 
       // XXX So, this is impossible case. Will be removed.
       if (NS_WARN_IF(!cellData.mElement)) {
         actualColSpan = 1;
         continue;
       }
 
-      if (curStartRowIndex < cellData.mCurrent.mRow) {
+      if (cellData.mFirst.mRow < cellData.mCurrent.mRow) {
         // We have a cell spanning this location.  Increase its rowspan.
         // Note that if rowspan is 0, we do nothing since that cell should
         // automatically extend into the new row.
         if (rowSpan > 0) {
           SetRowSpan(cellData.mElement, rowSpan + aNumberOfRowsToInsert);
         }
         continue;
       }
@@ -752,31 +747,30 @@ HTMLEditor::InsertTableRowsWithTransacti
     // but we must compensate for all cells with rowspan = 0 in the last row.
     const int32_t kLastRowIndex = tableSize.mRowCount - 1;
     for (int32_t colIndex = 0, actualColSpan = 0;; colIndex += actualColSpan) {
       CellData cellData(*this, *table, kLastRowIndex, colIndex, ignoredError);
       if (cellData.FailedOrNotFound()) {
         break; // Perhaps, we reach end of the row.
       }
 
-      int32_t    curStartRowIndex =           cellData.mFirst.mRow;
       // int32_t curStartColIndex =           cellData.mFirst.mColumn;
       int32_t    rowSpan =                    cellData.mRowSpan;
       // int32_t colSpan =                    cellData.mColSpan;
       // int32_t actualRowSpan =              cellData.mEffectiveRowSpan;
                  actualColSpan =              cellData.mEffectiveColSpan;
       // bool    isSelected =                 cellData.mIsSelected;
 
       if (!rowSpan) {
         MOZ_ASSERT(cellsInRow >= actualColSpan);
         cellsInRow -= actualColSpan;
       }
 
       // Save cell from the last row that we will use below
-      if (!cellForRowParent && curStartRowIndex == cellData.mCurrent.mRow) {
+      if (!cellForRowParent && cellData.mFirst.mRow == cellData.mCurrent.mRow) {
         cellForRowParent = std::move(cellData.mElement);
       }
     }
   }
 
   if (NS_WARN_IF(!cellsInRow)) {
     // There is no cell element in the last row??
     return NS_OK;
@@ -1406,17 +1400,16 @@ HTMLEditor::DeleteTableColumnWithTransac
     // Failure means that there is no more row in the table.  In this case,
     // we shouldn't return error since we just reach the end of the table.
     // XXX Should distinguish whether CellData returns error or just not found
     //     later.
     if (cellData.FailedOrNotFound()) {
       return NS_OK;
     }
 
-    int32_t    startRowIndex =       cellData.mFirst.mRow;
     int32_t    startColIndex =       cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     int32_t    colSpan =             cellData.mColSpan;
     int32_t    actualRowSpan =       cellData.mEffectiveRowSpan;
     // int32_t actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // Find cells that don't start in column we are deleting.
@@ -1485,17 +1478,18 @@ HTMLEditor::DeleteTableColumnWithTransac
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return NS_OK;
     }
 
     // Delete the row by placing caret in cell we were to delete.  We need
     // to call DeleteTableRowWithTransaction() to handle cells with rowspan.
-    nsresult rv = DeleteTableRowWithTransaction(aTableElement, startRowIndex);
+    nsresult rv =
+      DeleteTableRowWithTransaction(aTableElement, cellData.mFirst.mRow);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // Note that we decrement rowIndex since a row was deleted.
     rowIndex--;
   }
 }
@@ -1681,54 +1675,54 @@ HTMLEditor::DeleteTableRowWithTransactio
   while (aRowIndex < tableSize.mRowCount &&
          columnIndex < tableSize.mColumnCount) {
     CellData cellData(*this, aTableElement, aRowIndex, columnIndex,
                       ignoredError);
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    int32_t    startRowIndex =       cellData.mFirst.mRow;
     int32_t    startColIndex =       cellData.mFirst.mColumn;
     int32_t    rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
     int32_t    actualRowSpan =       cellData.mEffectiveRowSpan;
     int32_t    actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // XXX So, we should distinguish if CellDate returns error or just not
     //     found later.
     if (!cellData.mElement) {
       break;
     }
 
     // Compensate for cells that don't start or extend below the row we are
     // deleting.
-    if (startRowIndex < cellData.mCurrent.mRow) {
+    if (cellData.mFirst.mRow < cellData.mCurrent.mRow) {
       // If a cell starts in row above us, decrease its rowspan to keep table
       // rectangular but we don't need to do this if rowspan=0, since it will
       // be automatically adjusted.
       if (rowSpan > 0) {
         // Build list of cells to change rowspan.  We can't do it now since
         // it upsets cell map, so we will do it after deleting the row.
         int32_t newRowSpanValue =
-          std::max(cellData.mCurrent.mRow - startRowIndex, actualRowSpan - 1);
+          std::max(cellData.mCurrent.mRow - cellData.mFirst.mRow,
+                   actualRowSpan - 1);
         spanCellArray.AppendElement(
                         SpanCell(cellData.mElement, newRowSpanValue));
       }
     } else {
       if (rowSpan > 1) {
         // Cell spans below row to delete, so we must insert new cells to
         // keep rows below.  Note that we test "rowSpan" so we don't do this
         // if rowSpan = 0 (automatic readjustment).
         int32_t aboveRowToInsertNewCellInto =
-          cellData.mCurrent.mRow - startRowIndex + 1;
+          cellData.mCurrent.mRow - cellData.mFirst.mRow + 1;
         int32_t numOfRawSpanRemainingBelow = actualRowSpan - 1;
         nsresult rv =
-          SplitCellIntoRows(&aTableElement, startRowIndex, startColIndex,
+          SplitCellIntoRows(&aTableElement, cellData.mFirst.mRow, startColIndex,
                             aboveRowToInsertNewCellInto,
                             numOfRawSpanRemainingBelow, nullptr);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       if (!cellInDeleteRow) {
         // Reference cell to find row to delete.
@@ -1904,29 +1898,28 @@ HTMLEditor::SelectBlockOfCells(Element* 
     for (int32_t col = minColumn, actualColSpan = 0;
          col <= maxColumn;
          col += std::max(actualColSpan, 1)) {
       CellData cellData(*this, *table, row, col, ignoredError);
       if (cellData.FailedOrNotFound()) {
         return NS_ERROR_FAILURE;
       }
 
-      int32_t    currentRowIndex =     cellData.mFirst.mRow;
       int32_t    currentColIndex =     cellData.mFirst.mColumn;
       // int32_t rowSpan =             cellData.mRowSpan;
       // int32_t colSpan =             cellData.mColSpan;
       // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                  actualColSpan =       cellData.mEffectiveColSpan;
       bool       isSelected =          cellData.mIsSelected;
 
       // Skip cells that already selected or are spanned from previous locations
       // XXX So, we should distinguish whether CellData returns error or just
       //     not found later.
       if (!isSelected && cellData.mElement &&
-          cellData.mCurrent.mRow == currentRowIndex &&
+          cellData.mCurrent.mRow == cellData.mFirst.mRow &&
           cellData.mCurrent.mColumn == currentColIndex) {
         rv = AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
       }
     }
   }
@@ -1979,29 +1972,28 @@ HTMLEditor::SelectAllTableCells()
          col < tableSize.mColumnCount;
          col += std::max(actualColSpan, 1)) {
       CellData cellData(*this, *table, row, col, ignoredError);
       if (NS_WARN_IF(cellData.FailedOrNotFound())) {
         rv = NS_ERROR_FAILURE;
         break;
       }
 
-      int32_t    currentRowIndex =     cellData.mFirst.mRow;
       int32_t    currentColIndex =     cellData.mFirst.mColumn;
       // int32_t rowSpan =             cellData.mRowSpan;
       // int32_t colSpan =             cellData.mColSpan;
       // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                  actualColSpan =       cellData.mEffectiveColSpan;
       // bool    isSelected =          cellData.mIsSelected;
 
       // Skip cells that are spanned from previous rows or columns
       // XXX So, we should distinguish whether CellData returns error or just
       //     not found later.
       if (cellData.mElement &&
-          cellData.mCurrent.mRow == currentRowIndex &&
+          cellData.mCurrent.mRow == cellData.mFirst.mRow &&
           cellData.mCurrent.mColumn == currentColIndex) {
         rv =  AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
         cellSelected = true;
       }
     }
@@ -2073,29 +2065,28 @@ HTMLEditor::SelectTableRow()
        col < tableSize.mColumnCount;
        col += std::max(actualColSpan, 1)) {
     CellData cellData(*this, *table, startRowIndex, col, ignoredError);
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       rv = NS_ERROR_FAILURE;
       break;
     }
 
-    int32_t    currentRowIndex =     cellData.mFirst.mRow;
     int32_t    currentColIndex =     cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
     // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // Skip cells that are spanned from previous rows or columns
     // XXX So, we should distinguish whether CellData returns error or just
     //     not found later.
     if (cellData.mElement &&
-        currentRowIndex == cellData.mCurrent.mRow &&
+        cellData.mFirst.mRow == cellData.mCurrent.mRow &&
         currentColIndex == cellData.mCurrent.mColumn) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
@@ -2162,29 +2153,28 @@ HTMLEditor::SelectTableColumn()
        row < tableSize.mRowCount;
        row += std::max(actualRowSpan, 1)) {
     CellData cellData(*this, *table, row, startColIndex, ignoredError);
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       rv = NS_ERROR_FAILURE;
       break;
     }
 
-    int32_t    currentRowIndex =     cellData.mFirst.mRow;
     int32_t    currentColIndex =     cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
                actualRowSpan =       cellData.mEffectiveRowSpan;
     // int32_t actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // Skip cells that are spanned from previous rows or columns
     // XXX So, we should distinguish whether CellData returns error or just
     //     not found later.
     if (cellData.mElement &&
-        currentRowIndex == cellData.mCurrent.mRow &&
+        cellData.mFirst.mRow == cellData.mCurrent.mRow &&
         currentColIndex == cellData.mCurrent.mColumn) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
@@ -2305,17 +2295,16 @@ HTMLEditor::SplitCellIntoColumns(Element
   }
 
   IgnoredErrorResult ignoredError;
   CellData cellData(*this, *aTable, aRowIndex, aColIndex, ignoredError);
   if (NS_WARN_IF(cellData.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
 
-  // int32_t startRowIndex =       cellData.mFirst.mRow;
   // int32_t startColIndex =       cellData.mFirst.mColumn;
   // int32_t rowSpan =             cellData.mRowSpan;
   // int32_t colSpan =             cellData.mColSpan;
   int32_t    actualRowSpan =       cellData.mEffectiveRowSpan;
   int32_t    actualColSpan =       cellData.mEffectiveColSpan;
   // bool    isSelected =          cellData.mIsSelected;
 
   // We can't split!
@@ -2367,17 +2356,16 @@ HTMLEditor::SplitCellIntoRows(Element* a
   }
 
   IgnoredErrorResult ignoredError;
   CellData cellData(*this, *aTable, aRowIndex, aColIndex, ignoredError);
   if (NS_WARN_IF(cellData.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
 
-  int32_t    startRowIndex =       cellData.mFirst.mRow;
   int32_t    startColIndex =       cellData.mFirst.mColumn;
   // int32_t rowSpan =             cellData.mRowSpan;
   // int32_t colSpan =             cellData.mColSpan;
   int32_t    actualRowSpan =       cellData.mEffectiveRowSpan;
   int32_t    actualColSpan =       cellData.mEffectiveColSpan;
   // bool    isSelected =          cellData.mIsSelected;
 
   // We can't split!
@@ -2391,47 +2379,47 @@ HTMLEditor::SplitCellIntoRows(Element* a
     return error.StealNSResult();
   }
 
   // Find a cell to insert before or after
   RefPtr<Element> cellElementAtInsertionPoint;
   RefPtr<Element> lastCellFound;
   bool insertAfter = (startColIndex > 0);
   for (int32_t colIndex = 0, actualColSpan2 = 0,
-               rowBelowIndex = startRowIndex + aRowSpanAbove;
+               rowBelowIndex = cellData.mFirst.mRow + aRowSpanAbove;
        colIndex <= tableSize.mColumnCount;
        colIndex += std::max(actualColSpan2, 1)) {
     CellData cellDataAtInsertionPoint(*this, *aTable, rowBelowIndex, colIndex,
                                       ignoredError);
     // If we fail here, it could be because row has bad rowspan values,
     // such as all cells having rowspan > 1 (Call FixRowSpan first!).
     // XXX According to the comment, this does not assume that
     //     FixRowSpan() doesn't work well and user can create non-rectangular
     //     table.  So, we should not return error when CellData cannot find
     //     a cell.
     if (NS_WARN_IF(cellDataAtInsertionPoint.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    int32_t    startRowIndex2 = cellDataAtInsertionPoint.mFirst.mRow;
     int32_t    startColIndex2 = cellDataAtInsertionPoint.mFirst.mColumn;
     // int32_t rowSpan2 =       cellDataAtInsertionPoint.mRowSpan;
     // int32_t colSpan2 =       cellDataAtInsertionPoint.mColSpan;
     // int32_t actualRowSpan2 = cellDataAtInsertionPoint.mEffectiveRowSpan;
                actualColSpan2 = cellDataAtInsertionPoint.mEffectiveColSpan;
     // bool    isSelected2 =    cellDataAtInsertionPoint.mIsSelected;
 
     // FYI: Don't use std::move() here since the following checks will use
     //      utility methods of cellDataAtInsertionPoint, but some of them
     //      check whether its mElement is not nullptr.
     cellElementAtInsertionPoint = cellDataAtInsertionPoint.mElement;
 
     // Skip over cells spanned from above (like the one we are splitting!)
     if (cellDataAtInsertionPoint.mElement &&
-        startRowIndex2 == cellDataAtInsertionPoint.mCurrent.mRow) {
+        cellDataAtInsertionPoint.mFirst.mRow ==
+          cellDataAtInsertionPoint.mCurrent.mRow) {
       if (!insertAfter) {
         // Inserting before, so stop at first cell in row we want to insert
         // into.
         break;
       }
       // New cell isn't first in row,
       // so stop after we find the cell just before new cell's column
       if (startColIndex2 + actualColSpan2 == startColIndex) {
@@ -2631,17 +2619,16 @@ HTMLEditor::JoinTableCells(bool aMergeNo
       for (int32_t actualColSpan2 = 0;
            colIndex < tableSize.mColumnCount;
            colIndex += std::max(actualColSpan2, 1)) {
         CellData cellData(*this, *table, rowIndex, colIndex, ignoredError);
         if (NS_WARN_IF(cellData.FailedOrNotFound())) {
           return NS_ERROR_FAILURE;
         }
 
-        // int32_t startRowIndex2 =          cellData.mFirst.mRow;
         // int32_t startColIndex2 =          cellData.mFirst.mColumn;
         // int32_t rowSpan2 =                cellData.mRowSpan;
         // int32_t colSpan2 =                cellData.mColSpan;
         // int32_t actualRowSpan2 =          cellData.mEffectiveRowSpan;
                    actualColSpan2 =          cellData.mEffectiveColSpan;
         bool       isSelected2 =             cellData.mIsSelected;
 
         if (isSelected2) {
@@ -2714,17 +2701,16 @@ HTMLEditor::JoinTableCells(bool aMergeNo
       for (int32_t colIndex = 0, actualColSpan2 = 0;
            colIndex < tableSize.mColumnCount;
            colIndex += std::max(actualColSpan2, 1)) {
         CellData cellData(*this, *table, rowIndex, colIndex, ignoredError);
         if (NS_WARN_IF(cellData.FailedOrNotFound())) {
           return NS_ERROR_FAILURE;
         }
 
-        int32_t    startRowIndex2 =       cellData.mFirst.mRow;
         int32_t    startColIndex2 =       cellData.mFirst.mColumn;
         // int32_t rowSpan2 =             cellData.mRowSpan;
         // int32_t colSpan2 =             cellData.mColSpan;
         // int32_t actualRowSpan2 =       cellData.mEffectiveRowSpan;
                    actualColSpan2 =       cellData.mEffectiveColSpan;
         bool       isSelected2 =          cellData.mIsSelected;
 
         // If this is 0, we are past last cell in row, so exit the loop
@@ -2737,25 +2723,26 @@ HTMLEditor::JoinTableCells(bool aMergeNo
           if (cellData.mCurrent.mRow >= firstSelectedCell.mIndexes.mRow &&
               cellData.mCurrent.mRow <= lastRowIndex &&
               cellData.mCurrent.mColumn >= firstSelectedCell.mIndexes.mColumn &&
               cellData.mCurrent.mColumn <= lastColIndex) {
             // We are within the join region
             // Problem: It is very tricky to delete cells as we merge,
             //  since that will upset the cellmap
             //  Instead, build a list of cells to delete and do it later
-            NS_ASSERTION(startRowIndex2 == cellData.mCurrent.mRow,
+            NS_ASSERTION(cellData.mFirst.mRow == cellData.mCurrent.mRow,
                          "JoinTableCells: StartRowIndex is in row above");
 
             if (actualColSpan2 > 1) {
               //Check if cell "hangs" off the boundary because of colspan > 1
               //  Use split methods to chop off excess
               int32_t extraColSpan = (startColIndex2 + actualColSpan2) - (lastColIndex+1);
               if ( extraColSpan > 0) {
-                rv = SplitCellIntoColumns(table, startRowIndex2, startColIndex2,
+                rv = SplitCellIntoColumns(table,
+                                          cellData.mFirst.mRow, startColIndex2,
                                           actualColSpan2 - extraColSpan,
                                           extraColSpan, nullptr);
                 NS_ENSURE_SUCCESS(rv, rv);
               }
             }
 
             rv =
               MergeCells(firstSelectedCell.mElement, cellData.mElement, false);
@@ -2832,71 +2819,71 @@ HTMLEditor::JoinTableCells(bool aMergeNo
     // cell.
     IgnoredErrorResult ignoredError;
     CellData leftCellData(*this, *table, startRowIndex, startColIndex,
                           ignoredError);
     if (NS_WARN_IF(leftCellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-               startRowIndex =             leftCellData.mFirst.mRow;
                startColIndex =             leftCellData.mFirst.mColumn;
     // int32_t rowSpan =                   leftCellData.mRowSpan;
     // int32_t colSpan =                   leftCellData.mColSpan;
     int32_t    actualRowSpan =             leftCellData.mEffectiveRowSpan;
     int32_t    actualColSpan =             leftCellData.mEffectiveColSpan;
     // bool    isSelected =                leftCellData.mIsSelected;
 
     // Get data for cell to the right.
     CellData rightCellData(*this, *table,
-                           startRowIndex, startColIndex + actualColSpan,
+                           leftCellData.mFirst.mRow,
+                           startColIndex + actualColSpan,
                            ignoredError);
     if (NS_WARN_IF(rightCellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    int32_t    startRowIndex2 =       rightCellData.mFirst.mRow;
     int32_t    startColIndex2 =       rightCellData.mFirst.mColumn;
     // int32_t rowSpan2 =             rightCellData.mRowSpan;
     // int32_t colSpan2 =             rightCellData.mColSpan;
     int32_t    actualRowSpan2 =       rightCellData.mEffectiveRowSpan;
     int32_t    actualColSpan2 =       rightCellData.mEffectiveColSpan;
     // bool    isSelected2 =          rightCellData.mIsSelected;
 
     // XXX So, this does not assume that CellData returns error when just not
     //     found.  We need to fix this later.
     if (!rightCellData.mElement) {
       return NS_OK; // Don't fail if there's no cell
     }
 
     // sanity check
-    NS_ASSERTION(rightCellData.mCurrent.mRow >= startRowIndex2,
-                 "JoinCells: rightCellData.mCurrent.mRow < startRowIndex2");
+    NS_ASSERTION(rightCellData.mCurrent.mRow >= rightCellData.mFirst.mRow,
+      "JoinCells: rightCellData.mCurrent.mRow < rightCellData.mFirst.mRow");
 
     // Figure out span of merged cell starting from target's starting row
     // to handle case of merged cell starting in a row above
-    int32_t spanAboveMergedCell = rightCellData.mCurrent.mRow - startRowIndex2;
+    int32_t spanAboveMergedCell =
+      rightCellData.mCurrent.mRow - rightCellData.mFirst.mRow;
     int32_t effectiveRowSpan2 = actualRowSpan2 - spanAboveMergedCell;
 
     if (effectiveRowSpan2 > actualRowSpan) {
       // Cell to the right spans into row below target
       // Split off portion below target cell's bottom-most row
-      rv = SplitCellIntoRows(table, startRowIndex2, startColIndex2,
+      rv = SplitCellIntoRows(table, rightCellData.mFirst.mRow, startColIndex2,
                              spanAboveMergedCell+actualRowSpan,
                              effectiveRowSpan2-actualRowSpan, nullptr);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     // Move contents from cell to the right
     // Delete the cell now only if it starts in the same row
     //   and has enough row "height"
     rv = MergeCells(leftCellData.mElement, rightCellData.mElement,
-                    (startRowIndex2 == rightCellData.mCurrent.mRow) &&
+                    rightCellData.mFirst.mRow == rightCellData.mCurrent.mRow &&
                     (effectiveRowSpan2 >= actualRowSpan));
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     if (effectiveRowSpan2 < actualRowSpan) {
       // Merged cell is "shorter"
       // (there are cells(s) below it that are row-spanned by target cell)
@@ -3016,32 +3003,31 @@ HTMLEditor::FixBadRowSpan(Element* aTabl
     // CellData passes if cell is missing from cellmap
     // XXX If <table> has large rowspan value or colspan value than actual
     //     cells, we may hit error.  So, this method is always failed to
     //     "fix" the rowspan...
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    int32_t    startRowIndex =       cellData.mFirst.mRow;
     // int32_t startColIndex =       cellData.mFirst.mColumn;
     int32_t    rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
     // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // XXX So, this does not assume that CellData returns error when just not
     //     found.  We need to fix this later.
     if (!cellData.mElement) {
       break;
     }
 
     if (rowSpan > 0 &&
-        startRowIndex == cellData.mCurrent.mRow &&
+        cellData.mFirst.mRow == cellData.mCurrent.mRow &&
         (rowSpan < minRowSpan || minRowSpan == -1)) {
       minRowSpan = rowSpan;
     }
     NS_ASSERTION((actualColSpan > 0),"ActualColSpan = 0 in FixBadRowSpan");
   }
   if (minRowSpan > 1) {
     // The amount to reduce everyone's rowspan
     // so at least one cell has rowspan = 1
@@ -3049,29 +3035,28 @@ HTMLEditor::FixBadRowSpan(Element* aTabl
     for (int32_t colIndex = 0, actualColSpan = 0;
          colIndex < tableSize.mColumnCount;
          colIndex += std::max(actualColSpan, 1)) {
       CellData cellData(*this, *aTable, aRowIndex, colIndex, ignoredError);
       if (NS_WARN_IF(cellData.FailedOrNotFound())) {
         return NS_ERROR_FAILURE;
       }
 
-      int32_t    startRowIndex =       cellData.mFirst.mRow;
       int32_t    startColIndex =       cellData.mFirst.mColumn;
       int32_t    rowSpan =             cellData.mRowSpan;
       // int32_t colSpan =             cellData.mColSpan;
       // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                  actualColSpan =       cellData.mEffectiveColSpan;
       // bool    isSelected =          cellData.mIsSelected;
 
       // Fixup rowspans only for cells starting in current row
       // XXX So, this does not assume that CellData returns error when just
       //     not found a cell.  Fix this later.
       if (cellData.mElement && rowSpan > 0 &&
-          startRowIndex == cellData.mCurrent.mRow &&
+          cellData.mFirst.mRow == cellData.mCurrent.mRow &&
           startColIndex == cellData.mCurrent.mColumn) {
         nsresult rv = SetRowSpan(cellData.mElement, rowSpan-rowsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       NS_ASSERTION((actualColSpan > 0),"ActualColSpan = 0 in FixBadRowSpan");
     }
@@ -3109,17 +3094,16 @@ HTMLEditor::FixBadColSpan(Element* aTabl
     // CellData passes if cell is missing from cellmap
     // XXX If <table> has large rowspan value or colspan value than actual
     //     cells, we may hit error.  So, this method is always failed to
     //     "fix" the colspan...
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    // int32_t startRowIndex =       cellData.mFirst.mRow;
     int32_t    startColIndex =       cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     int32_t    colSpan =             cellData.mColSpan;
                actualRowSpan =       cellData.mEffectiveRowSpan;
     // int32_t actualColSpan =       cellData.mEffectiveColSpan;
     // bool    isSelected =          cellData.mIsSelected;
 
     // XXX So, this does not assume that CellData returns error when just
@@ -3141,30 +3125,29 @@ HTMLEditor::FixBadColSpan(Element* aTabl
     for (int32_t rowIndex = 0, actualRowSpan = 0;
          rowIndex < tableSize.mRowCount;
          rowIndex += std::max(actualRowSpan, 1)) {
       CellData cellData(*this, *aTable, rowIndex, aColIndex, ignoredError);
       if (NS_WARN_IF(cellData.FailedOrNotFound())) {
         return NS_ERROR_FAILURE;
       }
 
-      int32_t    startRowIndex =       cellData.mFirst.mRow;
       int32_t    startColIndex =       cellData.mFirst.mColumn;
       // int32_t rowSpan =             cellData.mRowSpan;
       int32_t    colSpan =             cellData.mColSpan;
                  actualRowSpan =       cellData.mEffectiveRowSpan;
       // int32_t actualColSpan =       cellData.mEffectiveColSpan;
       // bool    isSelected =          cellData.mIsSelected;
 
       // Fixup colspans only for cells starting in current column
       // XXX So, this does not assume that CellData returns error when just
       //     not found a cell.  Fix this later.
       if (cellData.mElement && colSpan > 0 &&
           startColIndex == cellData.mCurrent.mColumn &&
-          startRowIndex == cellData.mCurrent.mRow) {
+          cellData.mFirst.mRow == cellData.mCurrent.mRow) {
         nsresult rv = SetColSpan(cellData.mElement, colSpan-colsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       NS_ASSERTION((actualRowSpan > 0),"ActualRowSpan = 0 in FixBadColSpan");
     }
   }
@@ -3256,27 +3239,26 @@ HTMLEditor::NormalizeTable(Selection& aS
       // NOTE: This is a *real* failure.
       // CellData passes if cell is missing from cellmap
       // XXX So, this method assumes that CellData won't return error when
       //     just not found.  Fix this later.
       if (NS_WARN_IF(cellData.FailedOrNotFound())) {
         return NS_ERROR_FAILURE;
       }
 
-      int32_t    startRowIndex =              cellData.mFirst.mRow;
       // int32_t startColIndex =              cellData.mFirst.mColumn;
       // int32_t rowSpan =                    cellData.mRowSpan;
       // int32_t colSpan =                    cellData.mColSpan;
       // int32_t actualRowSpan =              cellData.mEffectiveRowSpan;
       // int32_t actualColSpan =              cellData.mEffectiveColSpan;
       // bool    isSelected =                 cellData.mIsSelected;
 
       if (cellData.mElement) {
         // Save the last cell found in the same row we are scanning
-        if (startRowIndex == cellData.mCurrent.mRow) {
+        if (cellData.mFirst.mRow == cellData.mCurrent.mRow) {
           previousCellElementInRow = std::move(cellData.mElement);
         }
         continue;
       }
 
       // We are missing a cell at a cellmap location.
       // Add a cell after the previous cell element in the current row.
       if (NS_WARN_IF(!previousCellElementInRow)) {
@@ -3411,27 +3393,26 @@ HTMLEditor::GetNumberOfCellsInRow(Elemen
     // Failure means that there is no more cell in the row.  In this case,
     // we shouldn't return error since we just reach the end of the row.
     // XXX So, this method assumes that CellData won't return error when
     //     just not found.  Fix this later.
     if (cellData.FailedOrNotFound()) {
       break;
     }
 
-    int32_t    startRowIndex =              cellData.mFirst.mRow;
     // int32_t startColIndex =              cellData.mFirst.mColumn;
     // int32_t rowSpan =                    cellData.mRowSpan;
     // int32_t colSpan =                    cellData.mColSpan;
     // int32_t actualRowSpan =              cellData.mEffectiveRowSpan;
     int32_t    actualColSpan =              cellData.mEffectiveColSpan;
     // bool    isSelected =                 cellData.mIsSelected;
 
     if (cellData.mElement) {
       // Only count cells that start in row we are working with
-      if (startRowIndex == cellData.mCurrent.mRow) {
+      if (cellData.mFirst.mRow == cellData.mCurrent.mRow) {
         numberOfCells++;
       }
       // Next possible location for a cell
       columnIndex += actualColSpan;
     } else {
       columnIndex++;
     }
   }
@@ -4398,17 +4379,16 @@ HTMLEditor::AllCellsInRowSelected(Elemen
   for (int32_t col = 0, actualColSpan = 0;
        col < aNumberOfColumns;
        col += std::max(actualColSpan, 1)) {
     CellData cellData(*this, *aTable, aRowIndex, col, ignoredError);
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       return false;
     }
 
-    // int32_t curStartRowIndex =    cellData.mFirst.mRow;
     // int32_t curStartColIndex =    cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
     // int32_t actualRowSpan =       cellData.mEffectiveRowSpan;
                actualColSpan =       cellData.mEffectiveColSpan;
     bool       isSelected =          cellData.mIsSelected;
 
     // If no cell, we may have a "ragged" right edge, so return TRUE only if
@@ -4444,17 +4424,16 @@ HTMLEditor::AllCellsInColumnSelected(Ele
   for (int32_t row = 0, actualRowSpan = 0;
        row < aNumberOfRows;
        row += std::max(actualRowSpan, 1)) {
     CellData cellData(*this, *aTable, row, aColIndex, ignoredError);
     if (NS_WARN_IF(cellData.FailedOrNotFound())) {
       return false;
     }
 
-    // int32_t curStartRowIndex =    cellData.mFirst.mRow;
     // int32_t curStartColIndex =    cellData.mFirst.mColumn;
     // int32_t rowSpan =             cellData.mRowSpan;
     // int32_t colSpan =             cellData.mColSpan;
                actualRowSpan =       cellData.mEffectiveRowSpan;
     // int32_t actualColSpan =       cellData.mEffectiveColSpan;
     bool       isSelected =          cellData.mIsSelected;
 
     // If no cell, we must have a "ragged" right edge on the last column so