Bug 1484126 - part 17: Make all CellData users refer CellData::mIsSelected directly r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 15 Oct 2018 11:34:40 +0000
changeset 489740 cbb895793f89b70afd138fb2df2ed2fbaf491e4e
parent 489739 4c70964d90fda77a9c06094accf3815fdfac1f2c
child 489741 8a2722c90ac91c4d4969100f4e6d4481bf2ab4d2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersm_kato
bugs1484126
milestone64.0a1
Bug 1484126 - part 17: Make all CellData users refer CellData::mIsSelected directly r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D8354
editor/libeditor/HTMLTableEditor.cpp
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -206,18 +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);
 
-  // bool    isSelected =       cellDataAtSelection.mIsSelected;
-
   int32_t newCellIndex;
   switch (aInsertPosition) {
     case InsertPosition::eBeforeSelectedCell:
       newCellIndex = cellDataAtSelection.mCurrent.mColumn;
       break;
     case InsertPosition::eAfterSelectedCell:
       newCellIndex =
         cellDataAtSelection.mCurrent.mColumn + cellDataAtSelection.mColSpan;
@@ -440,18 +438,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);
 
-  // bool    isSelected =       cellDataAtSelection.mIsSelected;
-
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
   // Should not be empty since we've already found a cell.
   MOZ_ASSERT(!tableSize.IsEmpty());
 
@@ -505,18 +501,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;
       }
 
-      // bool    isSelected =             cellData.mIsSelected;
-
       // Don't fail entire process if we fail to find a cell (may fail just in
       // particular rows with < adequate cells per row).
       // XXX So, here wants to know whether the CellData actually failed above.
       //     Fix this later.
       if (!cellData.mElement) {
         continue;
       }
 
@@ -633,18 +627,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);
 
-  // bool isSelected =          cellDataAtSelection.mIsSelected;
-
   ErrorResult error;
   TableSize tableSize(*this, *table, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
   // Should not be empty since we've already found a cell.
   MOZ_ASSERT(!tableSize.IsEmpty());
 
@@ -687,18 +679,16 @@ 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.
       }
 
-      // bool    isSelected =                 cellData.mIsSelected;
-
       // XXX So, this is impossible case. Will be removed.
       if (NS_WARN_IF(!cellData.mElement)) {
         actualColSpan = 1;
         continue;
       }
 
       actualColSpan = cellData.mEffectiveColSpan;
 
@@ -729,18 +719,16 @@ 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.
       }
 
-      // bool    isSelected =                 cellData.mIsSelected;
-
      actualColSpan = cellData.mEffectiveColSpan;
 
       if (!cellData.mRowSpan) {
         MOZ_ASSERT(cellsInRow >= actualColSpan);
         cellsInRow -= actualColSpan;
       }
 
       // Save cell from the last row that we will use below
@@ -1379,18 +1367,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;
     }
 
-    // bool    isSelected =          cellData.mIsSelected;
-
     // Find cells that don't start in column we are deleting.
     MOZ_ASSERT(cellData.mColSpan >= 0);
     if (cellData.IsSpannedFromOtherColumn() || cellData.mColSpan != 1) {
       // If we have a cell spanning this location, decrease its colspan to
       // keep table rectangular, but if colspan is 0, it'll be adjusted
       // automatically.
       if (cellData.mColSpan > 0) {
         NS_WARNING_ASSERTION(cellData.mColSpan > 1,
@@ -1650,18 +1636,16 @@ 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;
     }
 
-    // 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.
@@ -1868,22 +1852,20 @@ 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;
       }
 
-      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 &&
+      if (!cellData.mIsSelected && cellData.mElement &&
           !cellData.IsSpannedFromOtherRowOrColumn()) {
         rv = AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
       }
 
       actualColSpan = cellData.mEffectiveColSpan;
@@ -1938,18 +1920,16 @@ 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;
       }
 
-      // 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.IsSpannedFromOtherRowOrColumn()) {
         rv =  AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
@@ -2027,18 +2007,16 @@ 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;
     }
 
-    // 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.IsSpannedFromOtherRowOrColumn()) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
@@ -2111,18 +2089,16 @@ 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;
     }
 
-    // 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.IsSpannedFromOtherRowOrColumn()) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
@@ -2248,18 +2224,16 @@ HTMLEditor::SplitCellIntoColumns(Element
   }
 
   IgnoredErrorResult ignoredError;
   CellData cellData(*this, *aTable, aRowIndex, aColIndex, ignoredError);
   if (NS_WARN_IF(cellData.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
 
-  // bool    isSelected =          cellData.mIsSelected;
-
   // We can't split!
   if (cellData.mEffectiveColSpan <= 1 ||
       aColSpanLeft + aColSpanRight > cellData.mEffectiveColSpan) {
     return NS_OK;
   }
 
   // Reduce colspan of cell to split
   nsresult rv = SetColSpan(cellData.mElement, aColSpanLeft);
@@ -2306,18 +2280,16 @@ HTMLEditor::SplitCellIntoRows(Element* a
   }
 
   IgnoredErrorResult ignoredError;
   CellData cellData(*this, *aTable, aRowIndex, aColIndex, ignoredError);
   if (NS_WARN_IF(cellData.FailedOrNotFound())) {
     return NS_ERROR_FAILURE;
   }
 
-  // bool    isSelected =          cellData.mIsSelected;
-
   // We can't split!
   if (cellData.mEffectiveRowSpan <= 1 ||
       aRowSpanAbove + aRowSpanBelow > cellData.mEffectiveRowSpan) {
     return NS_OK;
   }
 
   ErrorResult error;
   TableSize tableSize(*this, *aTable, error);
@@ -2340,18 +2312,16 @@ HTMLEditor::SplitCellIntoRows(Element* a
     // 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;
     }
 
-    // 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 &&
         !cellDataAtInsertionPoint.IsSpannedFromOtherRow()) {
@@ -2564,19 +2534,17 @@ 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;
         }
 
-        bool       isSelected2 =             cellData.mIsSelected;
-
-        if (isSelected2) {
+        if (cellData.mIsSelected) {
           if (!cellFoundInRow) {
             // We've just found the first selected cell in this row
             firstColInRow = cellData.mCurrent.mColumn;
           }
           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)
@@ -2643,25 +2611,24 @@ 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;
         }
 
-        bool       isSelected2 =          cellData.mIsSelected;
-
         // If this is 0, we are past last cell in row, so exit the loop
         if (!cellData.mEffectiveColSpan) {
           break;
         }
 
         // Merge only selected cells (skip cell we're merging into, of course)
-        if (isSelected2 && cellData.mElement != firstSelectedCell.mElement) {
+        if (cellData.mIsSelected &&
+            cellData.mElement != firstSelectedCell.mElement) {
           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
@@ -2762,30 +2729,26 @@ HTMLEditor::JoinTableCells(bool aMergeNo
     // cell.
     IgnoredErrorResult ignoredError;
     CellData leftCellData(*this, *table, startRowIndex, startColIndex,
                           ignoredError);
     if (NS_WARN_IF(leftCellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    // bool    isSelected =                leftCellData.mIsSelected;
-
     // Get data for cell to the right.
     CellData rightCellData(
                *this, *table,
                leftCellData.mFirst.mRow,
                leftCellData.mFirst.mColumn + leftCellData.mEffectiveColSpan,
                ignoredError);
     if (NS_WARN_IF(rightCellData.FailedOrNotFound())) {
       return NS_ERROR_FAILURE;
     }
 
-    // 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 >= rightCellData.mFirst.mRow,
@@ -2942,18 +2905,16 @@ 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;
     }
 
-    // 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 (cellData.mRowSpan > 0 &&
         !cellData.IsSpannedFromOtherRow() &&
@@ -2970,18 +2931,16 @@ 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;
       }
 
-      // 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 && cellData.mRowSpan > 0 &&
           !cellData.IsSpannedFromOtherRowOrColumn()) {
         nsresult rv =
           SetRowSpan(cellData.mElement, cellData.mRowSpan - rowsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -3025,18 +2984,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;
     }
 
-    // bool    isSelected =          cellData.mIsSelected;
-
     // XXX So, this does not assume that CellData returns error when just
     //     not found a cell.  Fix this later.
     if (!cellData.mElement) {
       break;
     }
     if (cellData.mColSpan > 0 &&
         !cellData.IsSpannedFromOtherColumn() &&
         (cellData.mColSpan < minColSpan || minColSpan == -1)) {
@@ -3052,18 +3009,16 @@ 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;
       }
 
-      // 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 && cellData.mColSpan > 0 &&
           !cellData.IsSpannedFromOtherRowOrColumn()) {
         nsresult rv =
           SetColSpan(cellData.mElement, cellData.mColSpan - colsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -3162,18 +3117,16 @@ 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;
       }
 
-      // bool    isSelected =                 cellData.mIsSelected;
-
       if (cellData.mElement) {
         // Save the last cell found in the same row we are scanning
         if (!cellData.IsSpannedFromOtherRow()) {
           previousCellElementInRow = std::move(cellData.mElement);
         }
         continue;
       }
 
@@ -3311,18 +3264,16 @@ 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;
     }
 
-    // bool    isSelected =                 cellData.mIsSelected;
-
     if (cellData.mElement) {
       // Only count cells that start in row we are working with
       if (!cellData.IsSpannedFromOtherRow()) {
         numberOfCells++;
       }
       // Next possible location for a cell
       columnIndex += cellData.mEffectiveColSpan;
     } else {
@@ -4292,30 +4243,28 @@ 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;
     }
 
-    bool       isSelected =          cellData.mIsSelected;
-
     // If no cell, we may have a "ragged" right edge, 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(!cellData.mElement)) {
       return cellData.mCurrent.mColumn > 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)) {
+    if (NS_WARN_IF(!cellData.mIsSelected)) {
       return false;
     }
 
     MOZ_ASSERT(cellData.mEffectiveColSpan > 0);
     actualColSpan = cellData.mEffectiveColSpan;
   }
   return true;
 }
@@ -4333,30 +4282,28 @@ 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;
     }
 
-    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(!cellData.mElement)) {
       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)) {
+    if (NS_WARN_IF(!cellData.mIsSelected)) {
       return false;
     }
 
     actualRowSpan = cellData.mEffectiveRowSpan;
   }
   return true;
 }