Commit 8ee053cd authored by sebsg's avatar sebsg Committed by Commit Bot

[Autofill] Update placeholder visibility on suggested value change.

Bug: 780403
Change-Id: I0af3cbbddced641844b29e059193fa666ce36729
Reviewed-on: https://chromium-review.googlesource.com/750061
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516044}
parent 13459ae6
......@@ -118,7 +118,7 @@ Input after setting suggestedValue:
| <div>
| id="placeholder"
| pseudo="-internal-input-suggested"
| style="display: none !important;"
| style="display: block !important;"
| shadow:pseudoId="-internal-input-suggested"
| "suggested value"
| <div>
......
......@@ -71,7 +71,7 @@ instead of "initial value".
| <div>
| id="placeholder"
| pseudo="-internal-input-suggested"
| style="display: none !important;"
| style="display: block !important;"
| shadow:pseudoId="-internal-input-suggested"
| "suggested value"
| <div>
......
<input id="input" placeholder="City" value="Springfield" style="width: 99px" >
<script>
input.focus();
internals.setAutofilled(input, true);
</script>
\ No newline at end of file
<input id="input" value="Springfield" placeholder="City">
<script>
// There was an issue where the placeholder would be visible along with the
// autofilled value. To repro, the field has to have a placeholder and a value.
// Then set the suggested value to the same value and then autofill that value.
input.focus();
internals.setSuggestedValue(input, 'Springfield');
internals.setAutofilled(input, true);
// recalcStyle calls UpdatePlaceholderVisibility and shows the placeholder element
input.offsetWidth; // To force style recalc.
internals.setAutofilledValue(input, 'Springfield');
input.style.width = '99px';
</script>
\ No newline at end of file
......@@ -71,7 +71,7 @@ instead of "initial value".
| <shadow:root>
| id="placeholder"
| pseudo="-internal-input-suggestedx"
| style="display: none !important;"
| style="display: block !important;"
| shadow:pseudoId="-internal-input-suggested"
| <div>
| <select>
......
......@@ -995,6 +995,7 @@ void TextControlElement::SetSuggestedValue(const String& value) {
HTMLElement* placeholder = PlaceholderElement();
if (!placeholder)
return;
UpdatePlaceholderVisibility();
// Change the pseudo-id to set the style for suggested values or reset the
// placeholder style depending on if there is a suggested value.
......
......@@ -533,8 +533,8 @@ void TextFieldInputType::UpdateView() {
// updated. In this case, updateView() is called but we should not
// update the view value.
GetElement().SetInnerEditorValue(VisibleValue());
GetElement().UpdatePlaceholderVisibility();
}
GetElement().UpdatePlaceholderVisibility();
}
void TextFieldInputType::FocusAndSelectSpinButtonOwner() {
......
......@@ -1379,6 +1379,35 @@ void Internals::setSuggestedValue(Element* element,
select->SetSuggestedValue(value);
}
void Internals::setAutofilledValue(Element* element,
const String& value,
ExceptionState& exception_state) {
DCHECK(element);
if (!element->IsFormControlElement()) {
exception_state.ThrowDOMException(
kInvalidNodeTypeError,
"The element provided is not a form control element.");
return;
}
if (auto* input = ToHTMLInputElementOrNull(*element)) {
input->DispatchScopedEvent(Event::CreateBubble(EventTypeNames::keydown));
input->setValue(value, kDispatchInputAndChangeEvent);
input->DispatchScopedEvent(Event::CreateBubble(EventTypeNames::keyup));
}
if (auto* textarea = ToHTMLTextAreaElementOrNull(*element)) {
textarea->DispatchScopedEvent(Event::CreateBubble(EventTypeNames::keydown));
textarea->setValue(value, kDispatchInputAndChangeEvent);
textarea->DispatchScopedEvent(Event::CreateBubble(EventTypeNames::keyup));
}
if (auto* select = ToHTMLSelectElementOrNull(*element))
select->setValue(value, kDispatchInputAndChangeEvent);
ToHTMLFormControlElement(element)->SetAutofilled(true);
}
void Internals::setEditingValue(Element* element,
const String& value,
ExceptionState& exception_state) {
......
......@@ -235,6 +235,7 @@ class Internals final : public ScriptWrappable {
bool elementShouldAutoComplete(Element* input_element, ExceptionState&);
String suggestedValue(Element*, ExceptionState&);
void setSuggestedValue(Element*, const String&, ExceptionState&);
void setAutofilledValue(Element*, const String&, ExceptionState&);
void setEditingValue(Element* input_element, const String&, ExceptionState&);
void setAutofilled(Element*, bool enabled, ExceptionState&);
......
......@@ -135,6 +135,7 @@ enum EffectiveConnectionType {
[RaisesException] boolean elementShouldAutoComplete(Element inputElement);
[RaisesException] DOMString suggestedValue(Element inputElement);
[RaisesException] void setSuggestedValue(Element inputElement, DOMString value);
[RaisesException] void setAutofilledValue(Element inputElement, DOMString value);
[RaisesException] void setEditingValue(Element inputElement, DOMString value);
[RaisesException] void setAutofilled(Element inputElement, boolean enabled);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment