Bug 1837375 - HTMLTextArea::Clone has two codepaths for cloning the value. r=smaug

Unify them into one. The static document codepath also was setting
mValueChanged, so this seems fine.

Differential Revision: https://phabricator.services.mozilla.com/D180311
This commit is contained in:
Emilio Cobos Álvarez
2023-06-08 15:14:41 +00:00
parent e119a62bff
commit 4a7153f5ab
3 changed files with 22 additions and 25 deletions

View File

@@ -113,19 +113,6 @@ nsresult HTMLTextAreaElement::Clone(dom::NodeInfo* aNodeInfo,
nsresult rv = const_cast<HTMLTextAreaElement*>(this)->CopyInnerTo(it);
NS_ENSURE_SUCCESS(rv, rv);
if (mValueChanged) {
// Set our value on the clone.
nsAutoString value;
GetValueInternal(value, true);
// SetValueInternal handles setting mValueChanged for us
if (NS_WARN_IF(
NS_FAILED(rv = it->SetValueInternal(
value, {ValueSetterOption::SetValueChanged})))) {
return rv;
}
}
it->SetLastValueChangeWasInteractive(mLastValueChangeWasInteractive);
it.forget(aResult);
return NS_OK;
@@ -956,18 +943,27 @@ nsresult HTMLTextAreaElement::CopyInnerTo(Element* aDest) {
nsresult rv = nsGenericHTMLFormControlElementWithState::CopyInnerTo(aDest);
NS_ENSURE_SUCCESS(rv, rv);
if (aDest->OwnerDoc()->IsStaticDocument()) {
if (mValueChanged || aDest->OwnerDoc()->IsStaticDocument()) {
// Set our value on the clone.
auto* dest = static_cast<HTMLTextAreaElement*>(aDest);
nsAutoString value;
GetValueInternal(value, true);
ErrorResult ret;
static_cast<HTMLTextAreaElement*>(aDest)->SetValue(value, ret);
return ret.StealNSResult();
// SetValueInternal handles setting mValueChanged for us. dest is a fresh
// element so setting its value can't really run script.
if (NS_WARN_IF(
NS_FAILED(rv = MOZ_KnownLive(dest)->SetValueInternal(
value, {ValueSetterOption::SetValueChanged})))) {
return rv;
}
}
return NS_OK;
}
bool HTMLTextAreaElement::IsMutable() const {
return (!HasAttr(kNameSpaceID_None, nsGkAtoms::readonly) && !IsDisabled());
return !HasAttr(nsGkAtoms::readonly) && !IsDisabled();
}
void HTMLTextAreaElement::SetCustomValidity(const nsAString& aError) {