Bug 1856156 - Recompute auto directionality on input type changes. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D198588
This commit is contained in:
Emilio Cobos Álvarez
2024-01-15 19:35:43 +00:00
parent 3b9c142e33
commit 08a8d2d9f1
7 changed files with 58 additions and 43 deletions

View File

@@ -1255,7 +1255,7 @@ void HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (!mValueChanged && GetValueMode() == VALUE_MODE_VALUE) {
SetDefaultValueAsValue();
} else if (GetValueMode() == VALUE_MODE_DEFAULT && HasDirAuto()) {
SetDirectionFromValue(aNotify);
SetAutoDirectionality(aNotify);
}
// GetStepBase() depends on the `value` attribute if `min` is not present,
// even if the value doesn't change.
@@ -1382,7 +1382,7 @@ void HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
"HTML5 spec does not allow underflow for type=range");
} else if (aName == nsGkAtoms::dir && aValue &&
aValue->Equals(nsGkAtoms::_auto, eIgnoreCase)) {
SetDirectionFromValue(aNotify);
SetAutoDirectionality(aNotify);
} else if (aName == nsGkAtoms::lang) {
// FIXME(emilio, bug 1651070): This doesn't account for lang changes on
// ancestors.
@@ -4352,7 +4352,7 @@ nsresult HTMLInputElement::BindToTree(BindContext& aContext, nsINode& aParent) {
// Set direction based on value if dir=auto
if (HasDirAuto()) {
SetDirectionFromValue(false);
SetAutoDirectionality(false);
}
// An element can't suffer from value missing if it is not in a document.
@@ -4642,11 +4642,16 @@ void HTMLInputElement::HandleTypeChange(FormControlType aNewType,
UpdateBarredFromConstraintValidation();
// Changing type may affect directionality because of the special-case for
// <input type=tel>, as specified in
// Changing type may affect auto directionality, or non-auto directionality
// because of the special-case for <input type=tel>, as specified in
// https://html.spec.whatwg.org/multipage/dom.html#the-directionality
if (!HasDirAuto() && (oldType == FormControlType::InputTel ||
mType == FormControlType::InputTel)) {
if (HasDirAuto()) {
const bool autoDirAssociated = IsAutoDirectionalityAssociated(mType);
if (IsAutoDirectionalityAssociated(oldType) != autoDirAssociated) {
SetAutoDirectionality(aNotify);
}
} else if (oldType == FormControlType::InputTel ||
mType == FormControlType::InputTel) {
RecomputeDirectionality(this, aNotify);
}
@@ -5895,10 +5900,11 @@ nsresult HTMLInputElement::SetDefaultValueAsValue() {
return SetValueInternal(resetVal, ValueSetterOption::ByInternalAPI);
}
void HTMLInputElement::SetDirectionFromValue(bool aNotify,
// https://html.spec.whatwg.org/#auto-directionality
void HTMLInputElement::SetAutoDirectionality(bool aNotify,
const nsAString* aKnownValue) {
if (!IsAutoDirectionalityAssociated()) {
return;
return SetDirectionality(GetParentDirectionality(this), aNotify);
}
nsAutoString value;
if (!aKnownValue) {
@@ -6967,7 +6973,7 @@ void HTMLInputElement::OnValueChanged(ValueChangeKind aKind,
UpdateAllValidityStates(true);
if (HasDirAuto()) {
SetDirectionFromValue(true, aKnownNewValue);
SetAutoDirectionality(true, aKnownNewValue);
}
}