Bug 1484126 - part 7: Replace all comparisons of CellData::mFirst.mRow and CellData::mCurrent.mRow with CellData::IsSpannedFromOtherRow() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 15 Oct 2018 04:21:34 +0000
changeset 499832 448d887560d4e6be3e91e831ebe161fc858bb68f
parent 499831 0f9a168cb7c818b7ed782228cce640699022e64e
child 499833 b23363aa593d1dffea31f626f53f430953be556b
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 7: Replace all comparisons of CellData::mFirst.mRow and CellData::mCurrent.mRow with CellData::IsSpannedFromOtherRow() r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D8344
editor/libeditor/HTMLTableEditor.cpp
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -716,17 +716,17 @@ HTMLEditor::InsertTableRowsWithTransacti
       // bool    isSelected =                 cellData.mIsSelected;
 
       // XXX So, this is impossible case. Will be removed.
       if (NS_WARN_IF(!cellData.mElement)) {
         actualColSpan = 1;
         continue;
       }
 
-      if (cellData.mFirst.mRow < cellData.mCurrent.mRow) {
+      if (cellData.IsSpannedFromOtherRow()) {
         // 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;
       }
@@ -760,17 +760,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 && cellData.mFirst.mRow == cellData.mCurrent.mRow) {
+      if (!cellForRowParent && !cellData.IsSpannedFromOtherRow()) {
         cellForRowParent = std::move(cellData.mElement);
       }
     }
   }
 
   if (NS_WARN_IF(!cellsInRow)) {
     // There is no cell element in the last row??
     return NS_OK;
@@ -1690,17 +1690,17 @@ HTMLEditor::DeleteTableRowWithTransactio
     // 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 (cellData.mFirst.mRow < cellData.mCurrent.mRow) {
+    if (cellData.IsSpannedFromOtherRow()) {
       // 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 - cellData.mFirst.mRow,
@@ -1909,17 +1909,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 && cellData.mElement &&
-          cellData.mCurrent.mRow == cellData.mFirst.mRow &&
+          !cellData.IsSpannedFromOtherRow() &&
           cellData.mCurrent.mColumn == currentColIndex) {
         rv = AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
       }
     }
   }
@@ -1983,17 +1983,17 @@ HTMLEditor::SelectAllTableCells()
       // 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 == cellData.mFirst.mRow &&
+          !cellData.IsSpannedFromOtherRow() &&
           cellData.mCurrent.mColumn == currentColIndex) {
         rv =  AppendNodeToSelectionAsRange(cellData.mElement);
         if (NS_FAILED(rv)) {
           break;
         }
         cellSelected = true;
       }
     }
@@ -2076,17 +2076,17 @@ HTMLEditor::SelectTableRow()
     // 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.mFirst.mRow == cellData.mCurrent.mRow &&
+        !cellData.IsSpannedFromOtherRow() &&
         currentColIndex == cellData.mCurrent.mColumn) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
@@ -2164,17 +2164,17 @@ HTMLEditor::SelectTableColumn()
                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 &&
-        cellData.mFirst.mRow == cellData.mCurrent.mRow &&
+        !cellData.IsSpannedFromOtherRow() &&
         currentColIndex == cellData.mCurrent.mColumn) {
       rv = AppendNodeToSelectionAsRange(cellData.mElement);
       if (NS_FAILED(rv)) {
         break;
       }
       cellSelected = true;
     }
   }
@@ -2408,18 +2408,17 @@ HTMLEditor::SplitCellIntoRows(Element* a
 
     // 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.mFirst.mRow ==
-          cellDataAtInsertionPoint.mCurrent.mRow) {
+        !cellDataAtInsertionPoint.IsSpannedFromOtherRow()) {
       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) {
@@ -2723,17 +2722,17 @@ 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(cellData.mFirst.mRow == cellData.mCurrent.mRow,
+            NS_ASSERTION(!cellData.IsSpannedFromOtherRow(),
                          "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,
@@ -2873,17 +2872,17 @@ HTMLEditor::JoinTableCells(bool aMergeNo
         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,
-                    rightCellData.mFirst.mRow == rightCellData.mCurrent.mRow &&
+                    !rightCellData.IsSpannedFromOtherRow() &&
                     (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)
@@ -3017,17 +3016,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 (!cellData.mElement) {
       break;
     }
 
     if (rowSpan > 0 &&
-        cellData.mFirst.mRow == cellData.mCurrent.mRow &&
+        !cellData.IsSpannedFromOtherRow() &&
         (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
@@ -3046,17 +3045,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 (cellData.mElement && rowSpan > 0 &&
-          cellData.mFirst.mRow == cellData.mCurrent.mRow &&
+          !cellData.IsSpannedFromOtherRow() &&
           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");
     }
@@ -3137,17 +3136,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 (cellData.mElement && colSpan > 0 &&
           startColIndex == cellData.mCurrent.mColumn &&
-          cellData.mFirst.mRow == cellData.mCurrent.mRow) {
+          !cellData.IsSpannedFromOtherRow()) {
         nsresult rv = SetColSpan(cellData.mElement, colSpan-colsReduced);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
       NS_ASSERTION((actualRowSpan > 0),"ActualRowSpan = 0 in FixBadColSpan");
     }
   }
@@ -3248,17 +3247,17 @@ HTMLEditor::NormalizeTable(Selection& aS
       // 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 (cellData.mFirst.mRow == cellData.mCurrent.mRow) {
+        if (!cellData.IsSpannedFromOtherRow()) {
           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)) {
@@ -3402,17 +3401,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 (cellData.mElement) {
       // Only count cells that start in row we are working with
-      if (cellData.mFirst.mRow == cellData.mCurrent.mRow) {
+      if (!cellData.IsSpannedFromOtherRow()) {
         numberOfCells++;
       }
       // Next possible location for a cell
       columnIndex += actualColSpan;
     } else {
       columnIndex++;
     }
   }