Bug 1702670 - Fix state management for "last value change was interactive" for inputs / textareas. r=smaug

This and "value changed" affect the "too long" and "too short" validity
states.

The validity state tracking code is quite messy...

Differential Revision: https://phabricator.services.mozilla.com/D111254
This commit is contained in:
Emilio Cobos Álvarez
2021-04-08 16:02:17 +00:00
parent 276b517317
commit 393cf02d79
5 changed files with 79 additions and 16 deletions

View File

@@ -127,7 +127,7 @@ nsresult HTMLTextAreaElement::Clone(dom::NodeInfo* aNodeInfo,
}
}
it->mLastValueChangeWasInteractive = mLastValueChangeWasInteractive;
it->SetLastValueChangeWasInteractive(mLastValueChangeWasInteractive);
it.forget(aResult);
return NS_OK;
}
@@ -320,12 +320,30 @@ nsresult HTMLTextAreaElement::SetValueChanged(bool aValueChanged) {
}
if (mValueChanged != previousValue) {
UpdateState(true);
ValueChangedOrLastValueChangeWasInteractiveChanged();
}
return NS_OK;
}
void HTMLTextAreaElement::ValueChangedOrLastValueChangeWasInteractiveChanged() {
const bool wasValid = IsValid();
UpdateTooLongValidityState();
UpdateTooShortValidityState();
if (wasValid != IsValid()) {
UpdateState(true);
}
}
void HTMLTextAreaElement::SetLastValueChangeWasInteractive(
bool aWasInteractive) {
if (aWasInteractive == mLastValueChangeWasInteractive) {
return;
}
mLastValueChangeWasInteractive = aWasInteractive;
ValueChangedOrLastValueChangeWasInteractiveChanged();
}
void HTMLTextAreaElement::GetDefaultValue(nsAString& aDefaultValue,
ErrorResult& aError) {
if (!nsContentUtils::GetNodeTextContent(this, false, aDefaultValue,
@@ -733,8 +751,7 @@ bool HTMLTextAreaElement::RestoreState(PresState* aState) {
SetValue(state.get_TextContentData().value(), rv);
ENSURE_SUCCESS(rv, false);
if (state.get_TextContentData().lastValueChangeWasInteractive()) {
mLastValueChangeWasInteractive = true;
UpdateState(true);
SetLastValueChangeWasInteractive(true);
}
}
if (aState->disabledSet() && !aState->disabled()) {
@@ -928,7 +945,7 @@ void HTMLTextAreaElement::SetCustomValidity(const nsAString& aError) {
bool HTMLTextAreaElement::IsTooLong() {
if (!mValueChanged || !mLastValueChangeWasInteractive ||
!HasAttr(kNameSpaceID_None, nsGkAtoms::maxlength)) {
!HasAttr(nsGkAtoms::maxlength)) {
return false;
}
@@ -946,7 +963,7 @@ bool HTMLTextAreaElement::IsTooLong() {
bool HTMLTextAreaElement::IsTooShort() {
if (!mValueChanged || !mLastValueChangeWasInteractive ||
!HasAttr(kNameSpaceID_None, nsGkAtoms::minlength)) {
!HasAttr(nsGkAtoms::minlength)) {
return false;
}