Bug 1615581: part 7) Move `UnselectCells` to `TableSelection`. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D63063

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2020-02-20 14:06:30 +00:00
Родитель 86af384543
Коммит 8308badf1c
2 изменённых файлов: 45 добавлений и 26 удалений

Просмотреть файл

@ -2371,8 +2371,15 @@ nsresult nsFrameSelection::SelectBlockOfCells(nsIContent* aStartCell,
if (mDragSelectingCells) {
// Drag selecting: remove selected cells outside of new block limits
UnselectCells(table, startRowIndex, startColIndex, endRowIndex, endColIndex,
true);
const int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
const RefPtr<mozilla::dom::Selection> selection = mDomSelections[index];
if (!selection) {
return NS_ERROR_NULL_POINTER;
}
// TODO: `UnselectCells`'s return value shouldn't be ignored.
mTableSelection.UnselectCells(table, startRowIndex, startColIndex,
endRowIndex, endColIndex, true, *selection);
}
// Note that we select block in the direction of user's mouse dragging,
@ -2381,14 +2388,11 @@ nsresult nsFrameSelection::SelectBlockOfCells(nsIContent* aStartCell,
endColIndex);
}
nsresult nsFrameSelection::UnselectCells(nsIContent* aTableContent,
int32_t aStartRowIndex,
int32_t aStartColumnIndex,
int32_t aEndRowIndex,
int32_t aEndColumnIndex,
bool aRemoveOutsideOfCellRange) {
int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
nsresult nsFrameSelection::TableSelection::UnselectCells(
nsIContent* aTableContent, int32_t aStartRowIndex,
int32_t aStartColumnIndex, int32_t aEndRowIndex, int32_t aEndColumnIndex,
bool aRemoveOutsideOfCellRange, mozilla::dom::Selection& aNormalSelection) {
MOZ_ASSERT(aNormalSelection.Type() == SelectionType::eNormal);
nsTableWrapperFrame* tableFrame =
do_QueryFrame(aTableContent->GetPrimaryFrame());
@ -2400,8 +2404,7 @@ nsresult nsFrameSelection::UnselectCells(nsIContent* aTableContent,
int32_t maxColIndex = std::max(aStartColumnIndex, aEndColumnIndex);
// Strong reference because we sometimes remove the range
RefPtr<nsRange> range =
mTableSelection.GetFirstCellRange(*mDomSelections[index]);
RefPtr<nsRange> range = GetFirstCellRange(aNormalSelection);
nsIContent* cellNode = GetFirstSelectedContent(range);
MOZ_ASSERT(!range || cellNode, "Must have cellNode if had a range");
@ -2418,10 +2421,10 @@ nsresult nsFrameSelection::UnselectCells(nsIContent* aTableContent,
if (aRemoveOutsideOfCellRange) {
if (curRowIndex < minRowIndex || curRowIndex > maxRowIndex ||
curColIndex < minColIndex || curColIndex > maxColIndex) {
mDomSelections[index]->RemoveRangeAndUnselectFramesAndNotifyListeners(
aNormalSelection.RemoveRangeAndUnselectFramesAndNotifyListeners(
*range, IgnoreErrors());
// Since we've removed the range, decrement pointer to next range
mTableSelection.mSelectedCellIndex--;
mSelectedCellIndex--;
}
} else {
@ -2444,16 +2447,15 @@ nsresult nsFrameSelection::UnselectCells(nsIContent* aTableContent,
maxColIndex >= 0 &&
origColIndex + actualColSpan - 1 >=
static_cast<uint32_t>(minColIndex)) {
mDomSelections[index]->RemoveRangeAndUnselectFramesAndNotifyListeners(
aNormalSelection.RemoveRangeAndUnselectFramesAndNotifyListeners(
*range, IgnoreErrors());
// Since we've removed the range, decrement pointer to next range
mTableSelection.mSelectedCellIndex--;
mSelectedCellIndex--;
}
}
}
const Selection* selection = mDomSelections[index];
range = selection ? mTableSelection.GetNextCellRange(*selection) : nullptr;
range = GetNextCellRange(aNormalSelection);
cellNode = GetFirstSelectedContent(range);
MOZ_ASSERT(!range || cellNode, "Must have cellNode if had a range");
}
@ -2514,8 +2516,15 @@ nsresult nsFrameSelection::RemoveCellsFromSelection(nsIContent* aTable,
int32_t aStartColumnIndex,
int32_t aEndRowIndex,
int32_t aEndColumnIndex) {
return UnselectCells(aTable, aStartRowIndex, aStartColumnIndex, aEndRowIndex,
aEndColumnIndex, false);
const int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
const RefPtr<mozilla::dom::Selection> selection = mDomSelections[index];
if (!selection) {
return NS_ERROR_NULL_POINTER;
}
return mTableSelection.UnselectCells(aTable, aStartRowIndex,
aStartColumnIndex, aEndRowIndex,
aEndColumnIndex, false, *selection);
}
nsresult nsFrameSelection::RestrictCellsToSelection(nsIContent* aTable,
@ -2523,8 +2532,15 @@ nsresult nsFrameSelection::RestrictCellsToSelection(nsIContent* aTable,
int32_t aStartColumnIndex,
int32_t aEndRowIndex,
int32_t aEndColumnIndex) {
return UnselectCells(aTable, aStartRowIndex, aStartColumnIndex, aEndRowIndex,
aEndColumnIndex, true);
const int8_t index = GetIndexFromSelectionType(SelectionType::eNormal);
const RefPtr<mozilla::dom::Selection> selection = mDomSelections[index];
if (!selection) {
return NS_ERROR_NULL_POINTER;
}
return mTableSelection.UnselectCells(aTable, aStartRowIndex,
aStartColumnIndex, aEndRowIndex,
aEndColumnIndex, true, *selection);
}
nsresult nsFrameSelection::SelectRowOrColumn(nsIContent* aCellContent,

Просмотреть файл

@ -790,10 +790,6 @@ class nsFrameSelection final {
nsresult SelectBlockOfCells(nsIContent* aStartNode, nsIContent* aEndNode);
nsresult SelectRowOrColumn(nsIContent* aCellContent,
mozilla::TableSelectionMode aTarget);
nsresult UnselectCells(nsIContent* aTable, int32_t aStartRowIndex,
int32_t aStartColumnIndex, int32_t aEndRowIndex,
int32_t aEndColumnIndex,
bool aRemoveOutsideOfCellRange);
static nsresult GetCellIndexes(nsIContent* aCell, int32_t& aRowIndex,
int32_t& aColIndex);
@ -823,6 +819,13 @@ class nsFrameSelection final {
// (according to GetFirstCellNodeInRange).
nsRange* GetNextCellRange(const mozilla::dom::Selection& aNormalSelection);
// TODO: mark as `MOZ_CAN_RUN_SCRIPT`.
nsresult UnselectCells(nsIContent* aTable, int32_t aStartRowIndex,
int32_t aStartColumnIndex, int32_t aEndRowIndex,
int32_t aEndColumnIndex,
bool aRemoveOutsideOfCellRange,
mozilla::dom::Selection& aNormalSelection);
nsCOMPtr<nsINode> mCellParent; // used to snap to table selection
nsCOMPtr<nsIContent> mStartSelectedCell;
nsCOMPtr<nsIContent> mEndSelectedCell;