Bug 1370806 - Part 1. Use RAII class for StartBatchChanges and EndBatchChanges. r?masayuki
Although we use StartBatchChanges and EndBatchChanges in nsTextEditorState::SetValue, we have a path that EndBatchChanges isn't called. So we should use RAII class to call EndBatchChanges correctly.
MozReview-Commit-ID: 6bjtTT9wItA
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -2611,26 +2611,20 @@ nsTextEditorState::SetValue(const nsAStr
// Time to mess with our security context... See comments in GetValue()
// for why this is needed. Note that we have to do this up here, because
// otherwise SelectAll() will fail.
{
AutoNoJSAPI nojsapi;
nsCOMPtr<nsISelection> domSel;
- nsCOMPtr<nsISelectionPrivate> selPriv;
mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
getter_AddRefs(domSel));
- if (domSel)
- {
- selPriv = do_QueryInterface(domSel);
- if (selPriv) {
- selPriv->StartBatchChanges();
- }
- }
+ SelectionBatcher selectionBatcher(domSel ? domSel->AsSelection() :
+ nullptr);
nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(mEditor);
if (!plaintextEditor || !weakFrame.IsAlive()) {
NS_WARNING("Somehow not a plaintext editor?");
return true;
}
valueSetter.Init();
@@ -2687,20 +2681,16 @@ nsTextEditorState::SetValue(const nsAStr
return true;
}
if (!IsSingleLineTextControl()) {
if (!mCachedValue.Assign(newValue, fallible)) {
return false;
}
}
-
- if (selPriv) {
- selPriv->EndBatchChanges();
- }
}
}
} else {
if (!mValue) {
mValue.emplace();
}
// We can't just early-return here if mValue->Equals(newValue), because