Bug 1698315 - Manage placeholder and autofill preview visibility using CSS rather than custom code. r=masayuki

Should be much simpler and doesn't need to deal with the different
stuff. We already have pseudo-classes for this, :autofill and
:placeholder-shown.

I initially wrote this because this is the only limitation that forces
us to have the placeholder text as a direct child of the text control
frame. In the end I kept that as-is, but this simplification is still
worth it.

We remove dom.placeholder.show_on_focus because it doesn't behave
correctly (it doesn't match the :placeholder-shown pseudo-class and it
should). It was introduced in bug 807613 and never turned to false by
default. I suspect nobody will miss this, but if somebody complains
about it we can reintroduce it properly (handling the pref in DOM
instead, changing the right state bits).

Differential Revision: https://phabricator.services.mozilla.com/D108304
This commit is contained in:
Emilio Cobos Álvarez
2021-03-15 08:52:43 +00:00
parent acb1d16531
commit e1e13fa181
14 changed files with 66 additions and 276 deletions

View File

@@ -120,10 +120,9 @@ nsresult HTMLTextAreaElement::Clone(dom::NodeInfo* aNodeInfo,
GetValueInternal(value, true);
// SetValueInternal handles setting mValueChanged for us
if (NS_WARN_IF(NS_FAILED(
rv = it->SetValueInternal(
value, ValueSetterOption::
UpdateOverlayTextVisibilityAndInvalidateFrame)))) {
if (NS_WARN_IF(
NS_FAILED(rv = it->SetValueInternal(
value, {ValueSetterOption::SetValueChanged})))) {
return rv;
}
}
@@ -236,16 +235,6 @@ nsresult HTMLTextAreaElement::CreateEditor() {
return mState->PrepareEditor();
}
void HTMLTextAreaElement::UpdateOverlayTextVisibility(bool aNotify) {
MOZ_ASSERT(mState);
mState->UpdateOverlayTextVisibility(aNotify);
}
bool HTMLTextAreaElement::GetPlaceholderVisibility() {
MOZ_ASSERT(mState);
return mState->GetPlaceholderVisibility();
}
void HTMLTextAreaElement::SetPreviewValue(const nsAString& aValue) {
MOZ_ASSERT(mState);
mState->SetPreviewText(aValue, true);
@@ -269,21 +258,14 @@ void HTMLTextAreaElement::EnablePreview() {
bool HTMLTextAreaElement::IsPreviewEnabled() { return mIsPreviewEnabled; }
bool HTMLTextAreaElement::GetPreviewVisibility() {
MOZ_ASSERT(mState);
return mState->GetPreviewVisibility();
}
nsresult HTMLTextAreaElement::SetValueInternal(
const nsAString& aValue, const ValueSetterOptions& aOptions) {
MOZ_ASSERT(mState);
// Need to set the value changed flag here if our value has in fact changed
// (i.e. if ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame
// is in aOptions), so that nsTextControlFrame::UpdateValueDisplay retrieves
// the correct value if needed.
if (aOptions.contains(
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame)) {
// (i.e. if ValueSetterOption::SetValueChanged is in aOptions), so that
// retrieves the correct value if needed.
if (aOptions.contains(ValueSetterOption::SetValueChanged)) {
SetValueChanged(true);
}
@@ -307,9 +289,9 @@ void HTMLTextAreaElement::SetValue(const nsAString& aValue,
GetValueInternal(currentValue, true);
nsresult rv = SetValueInternal(
aValue, {ValueSetterOption::ByContentAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame,
ValueSetterOption::MoveCursorToEndIfValueChanged});
aValue,
{ValueSetterOption::ByContentAPI, ValueSetterOption::SetValueChanged,
ValueSetterOption::MoveCursorToEndIfValueChanged});
if (NS_WARN_IF(NS_FAILED(rv))) {
aError.Throw(rv);
return;
@@ -322,10 +304,9 @@ void HTMLTextAreaElement::SetValue(const nsAString& aValue,
void HTMLTextAreaElement::SetUserInput(const nsAString& aValue,
nsIPrincipal& aSubjectPrincipal) {
SetValueInternal(
aValue, {ValueSetterOption::BySetUserInputAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame,
ValueSetterOption::MoveCursorToEndIfValueChanged});
SetValueInternal(aValue, {ValueSetterOption::BySetUserInputAPI,
ValueSetterOption::SetValueChanged,
ValueSetterOption::MoveCursorToEndIfValueChanged});
}
nsresult HTMLTextAreaElement::SetValueChanged(bool aValueChanged) {
@@ -660,10 +641,8 @@ void HTMLTextAreaElement::GetValueFromSetRangeText(nsAString& aValue) {
nsresult HTMLTextAreaElement::SetValueFromSetRangeText(
const nsAString& aValue) {
return SetValueInternal(
aValue,
{ValueSetterOption::ByContentAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame});
return SetValueInternal(aValue, {ValueSetterOption::ByContentAPI,
ValueSetterOption::SetValueChanged});
}
nsresult HTMLTextAreaElement::Reset() {