Bug 1358025 - Part 3. Use nsIEditor.setText when input.value setter isn't user interaction. r=masayuki

When not using eSetValue_BySetUserInput, we should use SetText transaction instead for fast path.  For backward compatibility, when input.value setter is by user interaction, I keep original way.  Because the original way doesn't replace all text when some string matches.

MozReview-Commit-ID: IDm7Y1NBmaK

--HG--
extra : rebase_source : 625085737f5c110dac11f9bc8a38c98a703ce2b1
This commit is contained in:
Makoto Kato 2017-05-18 16:32:21 +09:00
Родитель da0ebf60c0
Коммит 5b36447061
1 изменённых файлов: 22 добавлений и 17 удалений

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

@ -2603,20 +2603,6 @@ nsTextEditorState::SetValue(const nsAString& aValue, uint32_t aFlags)
}
}
nsCOMPtr<nsISelectionController> kungFuDeathGrip = mSelCon.get();
uint32_t currentLength = currentValue.Length();
uint32_t newlength = newValue.Length();
if (!currentLength ||
!StringBeginsWith(newValue, currentValue)) {
// Replace the whole text.
currentLength = 0;
kungFuDeathGrip->SelectAll();
} else {
// Collapse selection to the end so that we can append data.
mBoundFrame->SelectAllOrCollapseToEndOfText(false);
}
const nsAString& insertValue =
StringTail(newValue, newlength - currentLength);
nsCOMPtr<nsIPlaintextEditor> plaintextEditor = do_QueryInterface(mEditor);
if (!plaintextEditor || !weakFrame.IsAlive()) {
NS_WARNING("Somehow not a plaintext editor?");
@ -2634,10 +2620,29 @@ nsTextEditorState::SetValue(const nsAString& aValue, uint32_t aFlags)
bool notifyValueChanged = !!(aFlags & eSetValue_Notify);
mTextListener->SetValueChanged(notifyValueChanged);
if (insertValue.IsEmpty()) {
mEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
if (aFlags & eSetValue_BySetUserInput) {
nsCOMPtr<nsISelectionController> kungFuDeathGrip = mSelCon.get();
uint32_t currentLength = currentValue.Length();
uint32_t newlength = newValue.Length();
if (!currentLength ||
!StringBeginsWith(newValue, currentValue)) {
// Replace the whole text.
currentLength = 0;
kungFuDeathGrip->SelectAll();
} else {
// Collapse selection to the end so that we can append data.
mBoundFrame->SelectAllOrCollapseToEndOfText(false);
}
const nsAString& insertValue =
StringTail(newValue, newlength - currentLength);
if (insertValue.IsEmpty()) {
mEditor->DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
} else {
plaintextEditor->InsertText(insertValue);
}
} else {
plaintextEditor->InsertText(insertValue);
plaintextEditor->SetText(newValue);
}
mTextListener->SetValueChanged(true);