Bug 1671556 - part 13: Make `HTMLEditor::GetFirstSelectedCellInTable()` stop using `CellAndIndexes` which uses `HTMLEditor::GetFirstSelectedTableCellElement()` r=m_kato

The method is tested by `test_nsITableEditor_getFirstSelectedCellInTable.html`.

And now, nobody uses `CellAndIndexes` so that this patch removes it.

Depends on D94239

Differential Revision: https://phabricator.services.mozilla.com/D94240
This commit is contained in:
Masayuki Nakano 2020-10-26 05:53:26 +00:00
Родитель bd4dbbf6bf
Коммит 632bea14d4
2 изменённых файлов: 17 добавлений и 56 удалений

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

@ -3206,7 +3206,6 @@ class HTMLEditor final : public TextEditor,
Element* GetNextTableRowElement(Element& aTableRowElement,
ErrorResult& aRv) const;
struct CellAndIndexes;
struct CellData;
/**
@ -3274,35 +3273,9 @@ class HTMLEditor final : public TextEditor,
private:
CellIndexes() : mRow(-1), mColumn(-1) {}
friend struct CellAndIndexes;
friend struct CellData;
};
struct MOZ_STACK_CLASS CellAndIndexes final {
RefPtr<Element> mElement;
CellIndexes mIndexes;
/**
* This constructor initializes the members with cell element which is
* selected by first range of the Selection. Note that even if the
* first range is in the cell element, this does not treat it as the
* cell element is selected.
*/
MOZ_CAN_RUN_SCRIPT CellAndIndexes(HTMLEditor& aHTMLEditor,
Selection& aSelection, ErrorResult& aRv) {
Update(aHTMLEditor, aSelection, aRv);
}
/**
* Update mElement and mIndexes with cell element which is selected by
* first range of the Selection. Note that even if the first range is
* in the cell element, this does not treat it as the cell element is
* selected.
*/
MOZ_CAN_RUN_SCRIPT void Update(HTMLEditor& aHTMLEditor,
Selection& aSelection, ErrorResult& aRv);
};
struct MOZ_STACK_CLASS CellData final {
RefPtr<Element> mElement;
// Current indexes which this is initialized with.

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

@ -3993,45 +3993,33 @@ NS_IMETHODIMP HTMLEditor::GetFirstSelectedCellInTable(int32_t* aRowIndex,
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(!SelectionRefPtr()->RangeCount())) {
return NS_ERROR_FAILURE; // XXX Should return NS_OK?
}
*aRowIndex = 0;
*aColumnIndex = 0;
*aCellElement = nullptr;
RefPtr<Element> firstSelectedCellElement =
HTMLEditUtils::GetFirstSelectedTableCellElement(*SelectionRefPtr());
if (!firstSelectedCellElement) {
return NS_OK;
}
ErrorResult error;
CellAndIndexes result(*this, MOZ_KnownLive(*SelectionRefPtr()), error);
RefPtr<PresShell> presShell = GetPresShell();
CellIndexes indexes(*firstSelectedCellElement, presShell, error);
if (error.Failed()) {
NS_WARNING("CellAndIndexes failed");
return EditorBase::ToGenericNSResult(error.StealNSResult());
NS_WARNING("CellIndexes failed");
return error.StealNSResult();
}
result.mElement.forget(aCellElement);
*aRowIndex = std::max(result.mIndexes.mRow, 0);
*aColumnIndex = std::max(result.mIndexes.mColumn, 0);
firstSelectedCellElement.forget(aCellElement);
*aRowIndex = indexes.mRow;
*aColumnIndex = indexes.mColumn;
return NS_OK;
}
void HTMLEditor::CellAndIndexes::Update(HTMLEditor& aHTMLEditor,
Selection& aSelection,
ErrorResult& aRv) {
MOZ_ASSERT(!aRv.Failed());
mIndexes.mRow = -1;
mIndexes.mColumn = -1;
mElement = aHTMLEditor.GetFirstSelectedTableCellElement(aRv);
if (aRv.Failed()) {
NS_WARNING("HTMLEditor::GetFirstSelectedTableCellElement() failed");
return;
}
if (!mElement) {
return;
}
const RefPtr<PresShell> presShell{aHTMLEditor.GetPresShell()};
const RefPtr<Element> element{mElement};
mIndexes.Update(*element, presShell, aRv);
NS_WARNING_ASSERTION(!aRv.Failed(), "CellIndexes::Update() failed");
}
void HTMLEditor::SetSelectionAfterTableEdit(Element* aTable, int32_t aRow,
int32_t aCol, int32_t aDirection,
bool aSelected) {