Bug 1108425 - Fix dir=auto for textarea with rtl text. r=smaug

I copy-pasted all `SetDirectionFromValue`-related parts from HTMLInputElement to HTMLTextAreaElement

Differential Revision: https://phabricator.services.mozilla.com/D176999
This commit is contained in:
Vincent Hilla
2023-05-16 13:49:07 +00:00
parent 8735ca5d28
commit 22c182f844
8 changed files with 91 additions and 120 deletions

View File

@@ -667,6 +667,16 @@ nsresult HTMLTextAreaElement::SetValueFromSetRangeText(
ValueSetterOption::SetValueChanged});
}
void HTMLTextAreaElement::SetDirectionFromValue(bool aNotify,
const nsAString* aKnownValue) {
nsAutoString value;
if (!aKnownValue) {
GetValue(value);
aKnownValue = &value;
}
SetDirectionalityFromValue(this, *aKnownValue, aNotify);
}
nsresult HTMLTextAreaElement::Reset() {
nsAutoString resetVal;
GetDefaultValue(resetVal, IgnoreErrors());
@@ -797,6 +807,11 @@ nsresult HTMLTextAreaElement::BindToTree(BindContext& aContext,
nsGenericHTMLFormControlElementWithState::BindToTree(aContext, aParent);
NS_ENSURE_SUCCESS(rv, rv);
// Set direction based on value if dir=auto
if (HasDirAuto()) {
SetDirectionFromValue(false);
}
// If there is a disabled fieldset in the parent chain, the element is now
// barred from constraint validation and can't suffer from value missing.
UpdateValueMissingValidityState();
@@ -923,6 +938,9 @@ void HTMLTextAreaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (nsTextControlFrame* f = do_QueryFrame(GetPrimaryFrame())) {
f->PlaceholderChanged(aOldValue, aValue);
}
} else if (aName == nsGkAtoms::dir && aValue &&
aValue->Equals(nsGkAtoms::_auto, eIgnoreCase)) {
SetDirectionFromValue(aNotify);
}
}
@@ -1115,7 +1133,7 @@ void HTMLTextAreaElement::InitializeKeyboardEventListeners() {
void HTMLTextAreaElement::OnValueChanged(ValueChangeKind aKind,
bool aNewValueEmpty,
const nsAString*) {
const nsAString* aKnownNewValue) {
if (aKind != ValueChangeKind::Internal) {
mLastValueChangeWasInteractive = aKind == ValueChangeKind::UserInteraction;
}
@@ -1133,6 +1151,10 @@ void HTMLTextAreaElement::OnValueChanged(ValueChangeKind aKind,
UpdateTooShortValidityState();
UpdateValueMissingValidityState();
if (HasDirAuto()) {
SetDirectionFromValue(true, aKnownNewValue);
}
if (validBefore != IsValid() ||
(emptyBefore != IsValueEmpty() && HasAttr(nsGkAtoms::placeholder))) {
UpdateState(true);