Bug 1484126 - part 3: Make all CellData users use CellData::mCurrent.mRow r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 15 Oct 2018 01:43:54 +0000
changeset 499828 24e31e2070fa5386008cbf4e75589e10086d3e83
parent 499827 d3609fcd3c88b1b424ccd09cff8c8279853cba2b
child 499829 539a4c3e194663e4631be32d1ca304a9e0bd0c1e
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1484126
milestone64.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 1484126 - part 3: Make all CellData users use CellData::mCurrent.mRow r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D8340
editor/libeditor/HTMLTableEditor.cpp
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -227,17 +227,18 @@ HTMLEditor::InsertTableCellsWithTransact
     case InsertPosition::eAfterSelectedCell:
       newCellIndex = startColIndex + colSpan;
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid InsertPosition");
   }
 
   // We control selection resetting after the insert.
-  AutoSelectionSetterAfterTableEdit setCaret(*this, table, startRowIndex,
+  AutoSelectionSetterAfterTableEdit setCaret(*this, table,
+                                             cellDataAtSelection.mCurrent.mRow,
                                              newCellIndex, ePreviousColumn,
                                              false);
   // So, suppress Rules System selection munging.
   AutoTransactionsConserveSelection dontChangeSelection(*this);
 
   EditorDOMPoint pointToInsert(cellParent, cellOffset);
   if (NS_WARN_IF(!pointToInsert.IsSet())) {
     return NS_ERROR_FAILURE;
@@ -485,17 +486,18 @@ HTMLEditor::InsertTableColumnsWithTransa
         SetColSpan(curCell, actualColSpan);
       }
       break;
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid InsertPosition");
   }
 
   // We control selection resetting after the insert.
-  AutoSelectionSetterAfterTableEdit setCaret(*this, table, startRowIndex,
+  AutoSelectionSetterAfterTableEdit setCaret(*this, table,
+                                             cellDataAtSelection.mCurrent.mRow,
                                              startColIndex, ePreviousRow,
                                              false);
   // Suppress Rules System selection munging.
   AutoTransactionsConserveSelection dontChangeSelection(*this);
 
   // If we are inserting after all existing columns, make sure table is
   // "well formed" before appending new column.
   // XXX As far as I've tested, NormalizeTable() always fails to normalize
@@ -722,17 +724,17 @@ HTMLEditor::InsertTableRowsWithTransacti
       // bool    isSelected =                 cellData.mIsSelected;
 
       // XXX So, this is impossible case. Will be removed.
       if (NS_WARN_IF(!cellElement)) {
         actualColSpan = 1;
         continue;
       }
 
-      if (curStartRowIndex < startRowIndex) {
+      if (curStartRowIndex < 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(cellElement, rowSpan + aNumberOfRowsToInsert);
         }
         continue;
       }
@@ -768,17 +770,17 @@ HTMLEditor::InsertTableRowsWithTransacti
       // 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 == kLastRowIndex) {
+      if (!cellForRowParent && curStartRowIndex == cellData.mCurrent.mRow) {
         cellForRowParent = std::move(cellElement);
       }
     }
   }
 
   if (NS_WARN_IF(!cellsInRow)) {
     // There is no cell element in the last row??
     return NS_OK;
@@ -1442,17 +1444,17 @@ HTMLEditor::DeleteTableColumnWithTransac
       }
       // Skip rows which the removed cell spanned.
       rowIndex += actualRowSpan - 1;
       continue;
     }
 
     // Delete the cell
     int32_t numberOfCellsInRow =
-      GetNumberOfCellsInRow(aTableElement, rowIndex);
+      GetNumberOfCellsInRow(aTableElement, cellData.mCurrent.mRow);
     NS_WARNING_ASSERTION(numberOfCellsInRow > 0,
       "Failed to count existing cells in the row");
     if (numberOfCellsInRow != 1) {
       // If removing cell is not the last cell of the row, we can just remove
       // it.
       nsresult rv = DeleteNodeWithTransaction(*cell);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
@@ -1700,33 +1702,34 @@ HTMLEditor::DeleteTableRowWithTransactio
     // XXX So, we should distinguish if CellDate returns error or just not
     //     found later.
     if (!cell) {
       break;
     }
 
     // Compensate for cells that don't start or extend below the row we are
     // deleting.
-    if (startRowIndex < aRowIndex) {
+    if (startRowIndex < 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(aRowIndex - startRowIndex, actualRowSpan - 1);
+          std::max(cellData.mCurrent.mRow - startRowIndex, actualRowSpan - 1);
         spanCellArray.AppendElement(SpanCell(cell, 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 = aRowIndex - startRowIndex + 1;
+        int32_t aboveRowToInsertNewCellInto =
+          cellData.mCurrent.mRow - startRowIndex + 1;
         int32_t numOfRawSpanRemainingBelow = actualRowSpan - 1;
         nsresult rv =
           SplitCellIntoRows(&aTableElement, startRowIndex, startColIndex,
                             aboveRowToInsertNewCellInto,
                             numOfRawSpanRemainingBelow, nullptr);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
@@ -1917,17 +1920,17 @@ HTMLEditor::SelectBlockOfCells(Element* 
       // 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 && cell &&
-          row == currentRowIndex && col == currentColIndex) {
+          cellData.mCurrent.mRow == currentRowIndex && col == currentColIndex) {
         rv = AppendNodeToSelectionAsRange(cell);
         if (NS_FAILED(rv)) {
           break;
         }
       }
     }
   }
   // NS_OK, otherwise, the last failure of AppendNodeToSelectionAsRange().
@@ -1991,17 +1994,19 @@ HTMLEditor::SelectAllTableCells()
       // 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 (cell && row == currentRowIndex && col == currentColIndex) {
+      if (cell &&
+          cellData.mCurrent.mRow == currentRowIndex &&
+          col == currentColIndex) {
         rv =  AppendNodeToSelectionAsRange(cell);
         if (NS_FAILED(rv)) {
           break;
         }
         cellSelected = true;
       }
     }
   }
@@ -2084,17 +2089,19 @@ HTMLEditor::SelectTableRow()
     // 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 (cell && currentRowIndex == startRowIndex && currentColIndex == col) {
+    if (cell &&
+        currentRowIndex == cellData.mCurrent.mRow &&
+        currentColIndex == col) {
       rv = AppendNodeToSelectionAsRange(cell);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
   // Safety code to select starting cell if nothing else was selected
@@ -2172,17 +2179,19 @@ HTMLEditor::SelectTableColumn()
     // 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 (cell && currentRowIndex == row && currentColIndex == startColIndex) {
+    if (cell &&
+        currentRowIndex == cellData.mCurrent.mRow &&
+        currentColIndex == startColIndex) {
       rv = AppendNodeToSelectionAsRange(cell);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
   // Safety code to select starting cell if nothing else was selected
@@ -2411,17 +2420,17 @@ HTMLEditor::SplitCellIntoRows(Element* a
     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;
 
     // Skip over cells spanned from above (like the one we are splitting!)
-    if (cell2 && startRowIndex2 == rowBelowIndex) {
+    if (cell2 && startRowIndex2 == 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,38 +2640,38 @@ HTMLEditor::JoinTableCells(bool aMergeNo
                    actualColSpan2 =          cellData.mEffectiveColSpan;
         bool       isSelected2 =             cellData.mIsSelected;
 
         if (isSelected2) {
           if (!cellFoundInRow) {
             // We've just found the first selected cell in this row
             firstColInRow = colIndex;
           }
-          if (rowIndex > firstSelectedCell.mIndexes.mRow &&
+          if (cellData.mCurrent.mRow > firstSelectedCell.mIndexes.mRow &&
               firstColInRow != firstSelectedCell.mIndexes.mColumn) {
             // We're in at least the second row,
             // but left boundary is "ragged" (not the same as 1st row's start)
             //Let's just end block on previous row
             // and keep previous lastColIndex
             //TODO: We could try to find the Maximum firstColInRow
             //      so our block can still extend down more rows?
-            lastRowIndex = std::max(0, rowIndex - 1);
+            lastRowIndex = std::max(0, cellData.mCurrent.mRow - 1);
             lastRowIsSet = true;
             break;
           }
           // Save max selected column in this row, including extra colspan
           lastColInRow = colIndex + (actualColSpan2-1);
           cellFoundInRow = true;
         } else if (cellFoundInRow) {
           // No cell or not selected, but at least one cell in row was found
-          if (rowIndex > firstSelectedCell.mIndexes.mRow + 1 &&
+          if (cellData.mCurrent.mRow > firstSelectedCell.mIndexes.mRow + 1 &&
               colIndex <= lastColIndex) {
             // Cell is in a column less than current right border in
             //  the third or higher selected row, so stop block at the previous row
-            lastRowIndex = std::max(0, rowIndex - 1);
+            lastRowIndex = std::max(0, cellData.mCurrent.mRow - 1);
             lastRowIsSet = true;
           }
           // We're done with this row
           break;
         }
       } // End of column loop
 
       // Done with this row
@@ -2717,25 +2726,26 @@ HTMLEditor::JoinTableCells(bool aMergeNo
 
         // If this is 0, we are past last cell in row, so exit the loop
         if (!actualColSpan2) {
           break;
         }
 
         // Merge only selected cells (skip cell we're merging into, of course)
         if (isSelected2 && cell2 != firstSelectedCell.mElement) {
-          if (rowIndex >= firstSelectedCell.mIndexes.mRow &&
-              rowIndex <= lastRowIndex &&
+          if (cellData.mCurrent.mRow >= firstSelectedCell.mIndexes.mRow &&
+              cellData.mCurrent.mRow <= lastRowIndex &&
               colIndex >= firstSelectedCell.mIndexes.mColumn &&
               colIndex <= 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 == rowIndex, "JoinTableCells: StartRowIndex is in row above");
+            NS_ASSERTION(startRowIndex2 == 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,
                                           actualColSpan2 - extraColSpan,
@@ -2850,37 +2860,38 @@ HTMLEditor::JoinTableCells(bool aMergeNo
 
     // XXX So, this does not assume that CellData returns error when just not
     //     found.  We need to fix this later.
     if (!cell2) {
       return NS_OK; // Don't fail if there's no cell
     }
 
     // sanity check
-    NS_ASSERTION((startRowIndex >= startRowIndex2),"JoinCells: startRowIndex < startRowIndex2");
+    NS_ASSERTION(rightCellData.mCurrent.mRow >= startRowIndex2,
+                 "JoinCells: rightCellData.mCurrent.mRow < startRowIndex2");
 
     // 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 = startRowIndex - startRowIndex2;
+    int32_t spanAboveMergedCell = rightCellData.mCurrent.mRow - startRowIndex2;
     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,
                              spanAboveMergedCell+actualRowSpan,
                              effectiveRowSpan2-actualRowSpan, nullptr);
       NS_ENSURE_SUCCESS(rv, 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(targetCell, cell2,
-                    (startRowIndex2 == startRowIndex) &&
+                    (startRowIndex2 == rightCellData.mCurrent.mRow) &&
                     (effectiveRowSpan2 >= actualRowSpan));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (effectiveRowSpan2 < actualRowSpan) {
       // Merged cell is "shorter"
       // (there are cells(s) below it that are row-spanned by target cell)
       // We could try splitting those cells, but that's REAL messy,
       //  so the safest thing to do is NOT really join the cells
@@ -3010,17 +3021,17 @@ HTMLEditor::FixBadRowSpan(Element* aTabl
 
     // XXX So, this does not assume that CellData returns error when just not
     //     found.  We need to fix this later.
     if (!cell) {
       break;
     }
 
     if (rowSpan > 0 &&
-        startRowIndex == aRowIndex &&
+        startRowIndex == 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
@@ -3041,17 +3052,17 @@ HTMLEditor::FixBadRowSpan(Element* aTabl
       // 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 (cell && rowSpan > 0 &&
-          startRowIndex == aRowIndex &&
+          startRowIndex == cellData.mCurrent.mRow &&
           startColIndex ==  colIndex ) {
         nsresult rv = SetRowSpan(cell, rowSpan-rowsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       NS_ASSERTION((actualColSpan > 0),"ActualColSpan = 0 in FixBadRowSpan");
     }
@@ -3136,17 +3147,17 @@ HTMLEditor::FixBadColSpan(Element* aTabl
       // 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 (cell && colSpan > 0 &&
           startColIndex == aColIndex &&
-          startRowIndex ==  rowIndex) {
+          startRowIndex == cellData.mCurrent.mRow) {
         nsresult rv = SetColSpan(cell, colSpan-colsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       NS_ASSERTION((actualRowSpan > 0),"ActualRowSpan = 0 in FixBadColSpan");
     }
   }
@@ -3266,21 +3277,21 @@ HTMLEditor::NormalizeTable(Selection& aS
                      getter_AddRefs(cellElement));
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
 
         // Set this so we use returned new "cell" to set
         // previousCellElementInRow below.
         if (cellElement) {
-          startRowIndex = rowIndex;
+          startRowIndex = cellData.mCurrent.mRow;
         }
       }
       // Save the last cell found in the same row we are scanning
-      if (startRowIndex == rowIndex) {
+      if (startRowIndex == cellData.mCurrent.mRow) {
         previousCellElementInRow = cellElement;
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -3404,17 +3415,17 @@ HTMLEditor::GetNumberOfCellsInRow(Elemen
     // 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 (cellElement) {
       // Only count cells that start in row we are working with
-      if (startRowIndex == aRowIndex) {
+      if (startRowIndex == cellData.mCurrent.mRow) {
         numberOfCells++;
       }
       // Next possible location for a cell
       columnIndex += actualColSpan;
     } else {
       columnIndex++;
     }
   }
@@ -4442,17 +4453,17 @@ HTMLEditor::AllCellsInColumnSelected(Ele
     // int32_t actualColSpan =       cellData.mEffectiveColSpan;
     bool       isSelected =          cellData.mIsSelected;
 
     // If no cell, we must have a "ragged" right edge on the last column so
     // return TRUE only if we already found a cell in the row.
     // XXX So, this does not assume that CellData returns error when just
     //     not found a cell.  Fix this later.
     if (NS_WARN_IF(!cell)) {
-      return row > 0;
+      return cellData.mCurrent.mRow > 0;
     }
 
     // Return as soon as a non-selected cell is found.
     // XXX Odd, this is testing if each cell element is selected.  Why do
     //     we need to warn if it's false??
     if (NS_WARN_IF(!isSelected)) {
       return false;
     }