Bug 1460509 - part 53: Make HTMLEditRules::WillInsertText() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r=m_kato

MozReview-Commit-ID: 22xxFFECNbi

--HG--
extra : rebase_source : 2dfe0cf975be32e729f7c22e97ff1a177cb9ab29
This commit is contained in:
Masayuki Nakano 2018-05-16 14:05:10 +09:00
parent fc5224c601
commit b646b85754
2 changed files with 49 additions and 11 deletions

View File

@ -1440,6 +1440,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
nsresult rv =
HTMLEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
nsIEditor::eNoStrip);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1496,6 +1499,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
if (inString->IsEmpty()) {
rv = HTMLEditorRef().InsertTextWithTransaction(
*doc, *inString, EditorRawDOMPoint(pointToInsert));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1504,6 +1510,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
WSRunObject wsObj(&HTMLEditorRef(), pointToInsert);
rv = wsObj.InsertText(*doc, *inString, pointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1564,6 +1573,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
currentPoint,
nsIEditor::eNone);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -1589,6 +1601,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
*doc, subStr,
EditorRawDOMPoint(currentPoint),
&pointAfterInsertedString);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1625,6 +1640,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
EditorRawDOMPoint pointAfterInsertedSpaces;
rv = wsObj.InsertText(*doc, spacesStr, currentPoint,
&pointAfterInsertedSpaces);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1636,6 +1654,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
else if (subStr.Equals(newlineStr)) {
RefPtr<Element> newBRElement =
wsObj.InsertBreak(SelectionRef(), currentPoint, nsIEditor::eNone);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(!newBRElement)) {
return NS_ERROR_FAILURE;
}
@ -1659,6 +1680,9 @@ HTMLEditRules::WillInsertText(EditAction aAction,
EditorRawDOMPoint pointAfterInsertedString;
rv = wsObj.InsertText(*doc, subStr, currentPoint,
&pointAfterInsertedString);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1677,12 +1701,13 @@ HTMLEditRules::WillInsertText(EditAction aAction,
"Failed to unset interline position");
if (currentPoint.IsSet()) {
ErrorResult error;
SelectionRef().Collapse(currentPoint, error);
if (error.Failed()) {
NS_WARNING("Failed to collapse at current point");
error.SuppressException();
IgnoredErrorResult ignoredError;
SelectionRef().Collapse(currentPoint, ignoredError);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to collapse at current point");
}
// manually update the doc changed range so that AfterEdit will clean up

View File

@ -151,12 +151,25 @@ protected:
void InitFields();
void WillInsert(bool* aCancel);
nsresult WillInsertText(EditAction aAction,
bool* aCancel,
bool* aHandled,
const nsAString* inString,
nsAString* outString,
int32_t aMaxLength);
/**
* Called before inserting text.
* This method may actually inserts text into the editor. Therefore, this
* might cause destroying the editor.
*
* @param aAction Must be EditAction::insertIMEText or
* EditAction::insertText.
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.
* @param inString String to be inserted.
* @param outString String actually inserted.
* @param aMaxLength The maximum string length which the editor
* allows to set.
*/
MOZ_MUST_USE nsresult
WillInsertText(EditAction aAction, bool* aCancel, bool* aHandled,
const nsAString* inString, nsAString* outString,
int32_t aMaxLength);
/**
* WillLoadHTML() is called before loading enter document from source.