mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1460509 - part 10: Make TextEditRules::WillInsertText() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r=m_kato
MozReview-Commit-ID: RT0Bi9TBwt --HG-- extra : rebase_source : d3c9657649dbce9ab8f872db9748a2d66d876f15
This commit is contained in:
parent
d43e448993
commit
6f6c32762e
@ -681,7 +681,9 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
bool truncated = false;
|
||||
nsresult rv =
|
||||
TruncateInsertionIfNeeded(inString, outString, aMaxLength, &truncated);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// If we're exceeding the maxlength when composing IME, we need to clean up
|
||||
// the composing text, so we shouldn't return early.
|
||||
if (truncated && outString->IsEmpty() &&
|
||||
@ -704,6 +706,9 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
if (!SelectionRef().IsCollapsed()) {
|
||||
rv = TextEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
|
||||
nsIEditor::eStrip);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -800,6 +805,9 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
}
|
||||
rv = TextEditorRef().InsertTextWithTransaction(*doc, *outString,
|
||||
betterInsertionPoint);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -813,6 +821,9 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
rv = TextEditorRef().InsertTextWithTransaction(*doc, *outString,
|
||||
atStartOfSelection,
|
||||
&pointAfterStringInserted);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -832,6 +843,9 @@ TextEditRules::WillInsertText(EditAction aAction,
|
||||
"GetChild() should be nullptr");
|
||||
error = IgnoredErrorResult();
|
||||
SelectionRef().Collapse(pointAfterStringInserted, error);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
NS_WARNING_ASSERTION(!error.Failed(),
|
||||
"Failed to collapse selection after inserting string");
|
||||
}
|
||||
|
@ -130,12 +130,25 @@ protected:
|
||||
void InitFields();
|
||||
|
||||
// TextEditRules implementation methods
|
||||
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);
|
||||
|
||||
nsresult WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user