Bug 1540037 - part 38: Move `TextEditor::InsertTextAt()` into `EditorBase` r=m_kato

Depends on D116564

Differential Revision: https://phabricator.services.mozilla.com/D116565
This commit is contained in:
Masayuki Nakano 2021-06-03 21:00:07 +00:00
Родитель d6e973ee86
Коммит 957175245e
5 изменённых файлов: 32 добавлений и 33 удалений

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

@ -1764,6 +1764,24 @@ nsresult EditorBase::PrepareToInsertContent(
return error.StealNSResult();
}
nsresult EditorBase::InsertTextAt(const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
bool aDoDeleteSelection) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToInsert.IsSet());
nsresult rv = PrepareToInsertContent(aPointToInsert, aDoDeleteSelection);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::PrepareToInsertContent() failed");
return rv;
}
rv = InsertTextAsSubAction(aStringToInsert);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::InsertTextAsSubAction() failed");
return rv;
}
NS_IMETHODIMP EditorBase::PasteTransferable(nsITransferable* aTransferable) {
nsresult rv = PasteTransferableAsAction(aTransferable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),

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

@ -2135,6 +2135,18 @@ class EditorBase : public nsIEditor,
MOZ_CAN_RUN_SCRIPT nsresult PrepareToInsertContent(
const EditorDOMPoint& aPointToInsert, bool aDoDeleteSelection);
/**
* InsertTextAt() inserts aStringToInsert at aPointToInsert.
*
* @param aStringToInsert The string which you want to insert.
* @param aPointToInsert The insertion point.
* @param aDoDeleteSelection true if you want this to delete selected
* content. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT nsresult InsertTextAt(const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
bool aDoDeleteSelection);
protected: // Called by helper classes.
/**
* OnStartToHandleTopLevelEditSubAction() is called when

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

@ -1962,7 +1962,7 @@ nsresult HTMLEditor::InsertFromDataTransfer(const DataTransfer* aDataTransfer,
GetStringFromDataTransfer(aDataTransfer, type, aIndex, text);
nsresult rv = InsertTextAt(text, aDroppedAt, aDoDeleteSelection);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditor::InsertTextAt() failed");
"EditorBase::InsertTextAt() failed");
return rv;
}
}

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

@ -482,18 +482,6 @@ class TextEditor : public EditorBase, public nsITimerCallback, public nsINamed {
*/
MOZ_CAN_RUN_SCRIPT virtual nsresult SelectEntireDocument() override;
/**
* InsertTextAt() inserts aStringToInsert at aPointToInsert.
*
* @param aStringToInsert The string which you want to insert.
* @param aPointToInsert The insertion point.
* @param aDoDeleteSelection true if you want this to delete selected
* content. Otherwise, false.
*/
MOZ_CAN_RUN_SCRIPT nsresult InsertTextAt(const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
bool aDoDeleteSelection);
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
InsertWithQuotationsAsSubAction(const nsAString& aQuotedText) override;

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

@ -85,25 +85,6 @@ nsresult TextEditor::PrepareTransferable(nsITransferable** aOutTransferable) {
return NS_OK;
}
nsresult TextEditor::InsertTextAt(const nsAString& aStringToInsert,
const EditorDOMPoint& aPointToInsert,
bool aDoDeleteSelection) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToInsert.IsSet());
nsresult rv = PrepareToInsertContent(aPointToInsert, aDoDeleteSelection);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::PrepareToInsertContent() failed");
return rv;
}
rv = InsertTextAsSubAction(aStringToInsert);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::InsertTextAsSubAction() failed");
return rv;
}
nsresult TextEditor::InsertTextFromTransferable(
nsITransferable* aTransferable) {
MOZ_ASSERT(IsEditActionDataAvailable());
@ -460,7 +441,7 @@ nsresult TextEditor::OnDrop(DragEvent* aDropEvent) {
return NS_OK;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"TextEditor::InsertTextAt() failed, but ignored");
"EditorBase::InsertTextAt() failed, but ignored");
} else {
editActionData.InitializeDataTransfer(dataTransfer);
RefPtr<StaticRange> targetRange = StaticRange::Create(