Bug 1388638 - Use RAII class for StartBatchChanges/EndBatchChanges. r=masayuki

CompositionTransaction forgets to call EndBatchChanges when GetSelectionController returns error, so we should use RAII class instead.

MozReview-Commit-ID: HI9kutRVzx6

--HG--
extra : rebase_source : d276f4349c5a64d4610581ae1a76d160841f7d7b
This commit is contained in:
Makoto Kato 2017-08-09 18:06:36 +09:00
parent a0b8a2c68d
commit b04d5091db
2 changed files with 6 additions and 12 deletions

View File

@ -198,8 +198,7 @@ CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
RefPtr<Selection> selection = aEditorBase.GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
nsresult rv = selection->StartBatchChanges();
NS_ENSURE_SUCCESS(rv, rv);
SelectionBatcher selectionBatcher(selection);
// First, remove all selections of IME composition.
static const RawSelectionType kIMESelections[] = {
@ -213,6 +212,7 @@ CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
aEditorBase.GetSelectionController(getter_AddRefs(selCon));
NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
nsresult rv = NS_OK;
for (uint32_t i = 0; i < ArrayLength(kIMESelections); ++i) {
nsCOMPtr<nsISelection> selectionOfIME;
if (NS_FAILED(selCon->GetSelection(kIMESelections[i],
@ -335,9 +335,6 @@ CompositionTransaction::SetIMESelection(EditorBase& aEditorBase,
}
}
rv = selection->EndBatchChangesInternal();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to end batch changes");
return rv;
}

View File

@ -723,7 +723,7 @@ EditorBase::DoTransaction(Selection* aSelection, nsITransaction* aTxn)
RefPtr<Selection> selection = aSelection ? aSelection : GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
selection->StartBatchChanges();
SelectionBatcher selectionBatcher(selection);
nsresult rv;
if (mTxnMgr) {
@ -732,14 +732,11 @@ EditorBase::DoTransaction(Selection* aSelection, nsITransaction* aTxn)
} else {
rv = aTxn->DoTransaction();
}
if (NS_SUCCEEDED(rv)) {
DoAfterDoTransaction(aTxn);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// no need to check rv here, don't lose result of operation
selection->EndBatchChanges();
NS_ENSURE_SUCCESS(rv, rv);
DoAfterDoTransaction(aTxn);
}
return NS_OK;