Skip to content

Commit aed724e

Browse files
committed
Bug 1992551 - Simplify text editor value getter. r=smaug
Textarea no longer creates newlines in the middle (it only has a trailing newline for caret positioning purposes), so this is equivalent but avoids going through nsDocumentEncoder, nsPlainTextSerializer and so on... Differential Revision: https://phabricator.services.mozilla.com/D267509 UltraBlame original commit: a099475af71c851f2352f87c9a380b9ed156a392
1 parent 561c0e5 commit aed724e

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

dom/html/TextControlState.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,26 +2468,8 @@ void TextControlState::GetValue(nsAString& aValue, bool aForDisplay) const {
24682468
}
24692469

24702470
aValue.Truncate();
2471-
2472-
uint32_t flags = nsIDocumentEncoder::OutputLFLineBreak |
2473-
nsIDocumentEncoder::OutputPreformatted |
2474-
nsIDocumentEncoder::OutputPersistNBSP |
2475-
nsIDocumentEncoder::OutputBodyOnly;
2476-
2477-
2478-
2479-
2480-
2481-
2482-
2483-
2484-
2485-
2486-
2487-
24882471
if (mEditorInitialized) {
2489-
AutoNoJSAPI nojsapi;
2490-
DebugOnly<nsresult> rv = mTextEditor->ComputeTextValue(flags, aValue);
2472+
DebugOnly<nsresult> rv = mTextEditor->ComputeTextValue(aValue);
24912473
MOZ_ASSERT(aValue.FindChar(u'\r') == -1);
24922474
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to get value");
24932475
}
@@ -2829,7 +2811,7 @@ bool TextControlState::SetValueWithTextEditor(
28292811
IMEContentObserver* observer = GetIMEContentObserver();
28302812
if (observer && observer->WasInitializedWith(*textEditor)) {
28312813
nsAutoString currentValue;
2832-
textEditor->ComputeTextValue(0, currentValue);
2814+
textEditor->ComputeTextValue(currentValue);
28332815
observer->OnTextControlValueChangedWhileNotObservable(currentValue);
28342816
}
28352817
}

editor/libeditor/TextEditor.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,22 @@ NS_IMETHODIMP TextEditor::InsertLineBreak() {
372372
return EditorBase::ToGenericNSResult(rv);
373373
}
374374

375+
nsresult TextEditor::ComputeTextValue(nsAString& aString) const {
376+
Element* anonymousDivElement = GetRoot();
377+
if (NS_WARN_IF(!anonymousDivElement)) {
378+
return NS_ERROR_NOT_INITIALIZED;
379+
}
380+
381+
auto* text = Text::FromNodeOrNull(anonymousDivElement->GetFirstChild());
382+
if (MOZ_UNLIKELY(!text)) {
383+
MOZ_ASSERT_UNREACHABLE("how?");
384+
return NS_ERROR_UNEXPECTED;
385+
}
386+
387+
text->GetData(aString);
388+
return NS_OK;
389+
}
390+
375391
nsresult TextEditor::InsertLineBreakAsAction(nsIPrincipal* aPrincipal) {
376392
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertLineBreak,
377393
aPrincipal);

editor/libeditor/TextEditor.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,7 @@ class TextEditor final : public EditorBase,
185185

186186

187187

188-
189-
190-
191-
192-
nsresult ComputeTextValue(uint32_t aDocumentEncoderFlags,
193-
nsAString& aOutputString) const {
194-
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
195-
if (NS_WARN_IF(!editActionData.CanHandle())) {
196-
return NS_ERROR_NOT_INITIALIZED;
197-
}
198-
nsresult rv = ComputeValueInternal(u"text/plain"_ns, aDocumentEncoderFlags,
199-
aOutputString);
200-
if (NS_WARN_IF(NS_FAILED(rv))) {
201-
return EditorBase::ToGenericNSResult(rv);
202-
}
203-
return NS_OK;
204-
}
188+
nsresult ComputeTextValue(nsAString&) const;
205189

206190

207191

0 commit comments

Comments
 (0)