Bug 1431041: Fix placeholder-shown when the value of the input is invalid. r=smaug

Wow, the setup for <input type="number"> is really weird :(.

Looking at the callers, this should be sane.

MozReview-Commit-ID: C0ZNNSdg0Hb
This commit is contained in:
Emilio Cobos Álvarez
2018-01-17 18:30:59 +01:00
parent 4ddc45d084
commit f68231c053
4 changed files with 55 additions and 1 deletions

View File

@@ -6600,7 +6600,7 @@ HTMLInputElement::IntrinsicState() const
if (PlaceholderApplies() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) &&
IsValueEmpty()) {
ShouldShowPlaceholder()) {
state |= NS_EVENT_STATE_PLACEHOLDERSHOWN;
}
@@ -6611,6 +6611,24 @@ HTMLInputElement::IntrinsicState() const
return state;
}
bool
HTMLInputElement::ShouldShowPlaceholder() const
{
MOZ_ASSERT(PlaceholderApplies());
if (!IsValueEmpty()) {
return false;
}
// For number controls, even though the (sanitized) value is empty, there may
// be text in the anon text control.
if (nsNumberControlFrame* frame = do_QueryFrame(GetPrimaryFrame())) {
return frame->AnonTextControlIsEmpty();
}
return true;
}
void
HTMLInputElement::AddStates(EventStates aStates)
{