Bug 1597679 - part 3: Create methods to compare given string with values of TextControlState, nsTextControlFrame, HTMLInputElement and HTMLTextAreaElement r=smaug
For avoiding unnecessary copy of string buffer only for comparing setting value and current value, especially with `nsAutoString`, this patch creates `*Equals()` methods for every class. And also this avoids to call `nsContentUtils::PlatformToDOMLineBreaks()` in most paths. Differential Revision: https://phabricator.services.mozilla.com/D54331
This commit is contained in:
@@ -1124,18 +1124,43 @@ nsresult nsTextControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
||||
}
|
||||
|
||||
void nsTextControlFrame::GetText(nsString& aText) {
|
||||
TextControlElement* textControlElement =
|
||||
TextControlElement::FromNode(GetContent());
|
||||
MOZ_ASSERT(textControlElement);
|
||||
if (IsSingleLineTextControl()) {
|
||||
// There will be no line breaks so we can ignore the wrap property.
|
||||
textControlElement->GetTextEditorValue(aText, true);
|
||||
} else {
|
||||
HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent);
|
||||
if (textArea) {
|
||||
textArea->GetValue(aText);
|
||||
if (HTMLInputElement* inputElement = HTMLInputElement::FromNode(mContent)) {
|
||||
if (IsSingleLineTextControl()) {
|
||||
// There will be no line breaks so we can ignore the wrap property.
|
||||
inputElement->GetTextEditorValue(aText, true);
|
||||
return;
|
||||
}
|
||||
aText.Truncate();
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!IsSingleLineTextControl());
|
||||
if (HTMLTextAreaElement* textAreaElement =
|
||||
HTMLTextAreaElement::FromNode(mContent)) {
|
||||
textAreaElement->GetValue(aText);
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aText.IsEmpty());
|
||||
aText.Truncate();
|
||||
}
|
||||
|
||||
bool nsTextControlFrame::TextEquals(const nsAString& aText) const {
|
||||
if (HTMLInputElement* inputElement = HTMLInputElement::FromNode(mContent)) {
|
||||
if (IsSingleLineTextControl()) {
|
||||
// There will be no line breaks so we can ignore the wrap property.
|
||||
return inputElement->TextEditorValueEquals(aText);
|
||||
}
|
||||
return aText.IsEmpty();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!IsSingleLineTextControl());
|
||||
if (HTMLTextAreaElement* textAreaElement =
|
||||
HTMLTextAreaElement::FromNode(mContent)) {
|
||||
return textAreaElement->ValueEquals(aText);
|
||||
}
|
||||
|
||||
return aText.IsEmpty();
|
||||
}
|
||||
|
||||
/// END NSIFRAME OVERLOADS
|
||||
|
||||
Reference in New Issue
Block a user