Revert "[Autofill] Use ShadowDom placeholder to preview suggestions."
This reverts commit 0727466e09c7285f3c4fe6a7974bfc68fd9bbccb.
Reason for revert: Makes some passwords be visible when suggested to the user.
Bug: 771097
Original change's description:
> [Autofill] Use ShadowDom placeholder to preview suggestions.
>
> Bug: 753645
> Change-Id: Idabb4d01b45aa08a71f9fc8ad1dd89b192cfb0c5
> Reviewed-on: https://chromium-review.googlesource.com/646754
> Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
> Reviewed-by: Kent Tamura <tkent@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#505743}
TBR=yosin@chromium.org,tkent@chromium.org,sebsg@chromium.org
Change-Id: I3a874ea052f598724831bdfcf0e16576a09353b4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 753645
Reviewed-on: https://chromium-review.googlesource.com/697644
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506011}
diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc
index c82f0cb..c9f7d54f 100644
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc
@@ -598,10 +598,8 @@
// Verify preview selection.
WebInputElement firstname = GetInputElementById("firstname");
- // Since the suggestion is previewed as a placeholder, there should be no
- // selected text.
EXPECT_EQ(0, firstname.SelectionStart());
- EXPECT_EQ(0, firstname.SelectionEnd());
+ EXPECT_EQ(19, firstname.SelectionEnd());
}
void TestUnmatchedUnownedForm(const char* html, const char* url_override) {
@@ -1150,10 +1148,8 @@
form.fields[1].is_autofilled = true;
form.fields[2].is_autofilled = true;
PreviewForm(form, input_element);
- // Since the suggestion is previewed as a placeholder, there should be no
- // selected text.
- EXPECT_EQ(0, input_element.SelectionStart());
- EXPECT_EQ(0, input_element.SelectionEnd());
+ EXPECT_EQ(2, input_element.SelectionStart());
+ EXPECT_EQ(5, input_element.SelectionEnd());
// Fill the form.
FillForm(form, input_element);
diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
index ca7ebdd..81ddff0 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -1351,18 +1351,16 @@
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
selected_element, kAliceUsername, kAlicePassword));
CheckTextFieldsSuggestedState(kAliceUsername, true, kAlicePassword, true);
- // Since the suggestion is previewed as a placeholder, there should be no
- // selected text.
- CheckUsernameSelection(0, 0);
+ int username_length = strlen(kAliceUsername);
+ CheckUsernameSelection(0, username_length);
// Try previewing with a password different from the one that was initially
// sent to the renderer.
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
selected_element, kBobUsername, kCarolPassword));
CheckTextFieldsSuggestedState(kBobUsername, true, kCarolPassword, true);
- // Since the suggestion is previewed as a placeholder, there should be no
- // selected text.
- CheckUsernameSelection(0, 0);
+ username_length = strlen(kBobUsername);
+ CheckUsernameSelection(0, username_length);
ClearUsernameAndPasswordFields();
}
@@ -1435,9 +1433,8 @@
EXPECT_TRUE(password_autofill_agent_->PreviewSuggestion(
selected_element, kAliceUsername, kAlicePassword));
CheckTextFieldsSuggestedState(kAliceUsername, true, kAlicePassword, true);
- // Since the suggestion is previewed as a placeholder, there should be no
- // selected text.
- CheckUsernameSelection(0, 0);
+ int username_length = strlen(kAliceUsername);
+ CheckUsernameSelection(3, username_length);
}
}
diff --git a/third_party/WebKit/LayoutTests/fast/forms/javascript-cannot-access-suggested-value.html b/third_party/WebKit/LayoutTests/fast/forms/javascript-cannot-access-suggested-value.html
deleted file mode 100644
index 336d13b..0000000
--- a/third_party/WebKit/LayoutTests/fast/forms/javascript-cannot-access-suggested-value.html
+++ /dev/null
@@ -1,73 +0,0 @@
-<!DOCTYPE html>
-<script src="../../resources/testharness.js"></script>
-<script src="../../resources/testharnessreport.js"></script>
-<div id="log"></div>
-
-<form>
-<input id="ccname" name="ccname" autocomplete="cc-name" autofocus="">
-<input id="cardnumber" name="cardnumber" autocomplete="cc-number">
-<input id="cvc" name="cvc" autocomplete="cc-csc">
-<input id="ccexp" name="ccexp" autocomplete="cc-exp">
-<input type="submit">
-</form>
-<button onclick="document.forms[0].classList.toggle('hidden')">Hide form</button>
-<div id="info" style="position:absolute;left:400px"></div>
-<script>
-// Setup the JavaScript function that tries to access to the suggested values.
-function grabField(field) {
- // Simulate the user attempting to modify the suggested value.
- field.focus();
- field.setSelectionRange(0,0);
- var result = document.execCommand('insertText', false, ' ');
-
- var val = field.value.trim();
- field.value='';
- assert_equals(val, '', 'The JavaScript should not be able to access the suggested values.');
-}
-
-// Test that tries to grab the suggested value on empty fields.
-test(function() {
- assert_true(window.internals != null, 'This test requires internals object');
-
- // Set some suggested values.
- var ccname = document.getElementById('ccname');
- var cardnumber = document.getElementById('cardnumber');
- var cvc = document.getElementById('cvc');
- var ccexp = document.getElementById('ccexp');
- internals.setSuggestedValue(ccname, 'suggested ccname');
- internals.setSuggestedValue(cardnumber, 'suggested cardnumber');
- internals.setSuggestedValue(cvc, 'suggested cvc');
- internals.setSuggestedValue(ccexp, 'suggested ccexp');
-
- // Try to grab the suggested values in the fields.
- grabField(ccname);
- grabField(cardnumber);
- grabField(cvc);
- grabField(ccexp);
-
-}, "JavaScript should not be able to access the suggested values on empty fields.");
-
-// Test that tries to grab the suggested value on a field that contains a value.
-test(function() {
- assert_true(window.internals != null, 'This test requires internals object');
-
- // Setup the JavaScript that adds some values in the fields.
- function addValue(field) {
- // Add some value in the field.
- field.value = "Homer";
- }
-
- var ccname = document.getElementById('ccname');
-
- // Add some value in the field.
- ccname.value = "Homer";
-
- // Set the suggested value.
- internals.setSuggestedValue(ccname, 'suggested ccname');
-
- // Try to grab the suggested values in the field.
- grabField(ccname);
-
-}, "JavaScript should not be able to access the suggested value on a field that has some value.");
-
-</script>
\ No newline at end of file
diff --git a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value-expected.txt
deleted file mode 100644
index 2e6745e..0000000
--- a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value-expected.txt
+++ /dev/null
@@ -1,285 +0,0 @@
-This test verifies that setting an empty suggested value removes/resets the shadow placeholder value.
-
-Input before setting suggested values:
-| <input>
-| id="test"
-| type="text"
-| value="initial value"
-| this.value="initial value"
-| <shadow:root>
-| <div>
-| id="inner-editor"
-| "initial value"
-| <br>
-| "
-"
-| <input>
-| id="inputwithplaceholder"
-| placeholder="initial placeholder"
-| type="text"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important; text-overflow: clip;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "initial placeholder"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <textarea>
-| id="textarea"
-| this.value="initial value"
-| "initial value"
-| <shadow:root>
-| <div>
-| id="inner-editor"
-| "initial value"
-| <br>
-| "
-"
-| <textarea>
-| id="textareaWithPlaceholder"
-| placeholder="initial placeholder"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "initial placeholder"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <select>
-| id="select"
-| <option>
-| "CA"
-| <shadow:root>
-| "CA"
-| <option>
-| "TX"
-| <shadow:root>
-| "TX"
-| <shadow:root>
-| <content>
-| select="option,optgroup,hr"
-| "input.value: initial value"
-| "internals.suggestedValue(input): "
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): "
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): "
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): "
-| "select.value: "
-| "internals.suggestedValue(select): "
-
-Input after setting suggestedValue:
-| <input>
-| id="test"
-| type="text"
-| value="initial value"
-| this.value="initial value"
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <input>
-| id="inputwithplaceholder"
-| placeholder="initial placeholder"
-| type="text"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important; text-overflow: clip;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <textarea>
-| id="textarea"
-| this.value="initial value"
-| "initial value"
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <textarea>
-| id="textareaWithPlaceholder"
-| placeholder="initial placeholder"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <select>
-| id="select"
-| <option>
-| "CA"
-| <shadow:root>
-| "CA"
-| <option>
-| "TX"
-| <shadow:root>
-| "TX"
-| <shadow:root>
-| <content>
-| select="option,optgroup,hr"
-| "input.value: initial value"
-| "internals.suggestedValue(input): "
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): "
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): "
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): "
-| "select.value: "
-| "internals.suggestedValue(select): "
-| "input.value: initial value"
-| "internals.suggestedValue(input): suggested value"
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): suggested value"
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): suggested value"
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): suggested value"
-| "select.value: "
-| "internals.suggestedValue(select): TX"
-
-After resetting suggestedValue value:
-| <input>
-| id="test"
-| type="text"
-| value="initial value"
-| this.value="initial value"
-| <shadow:root>
-| <div>
-| id="inner-editor"
-| "initial value"
-| <br>
-| "
-"
-| <input>
-| id="inputwithplaceholder"
-| placeholder="initial placeholder"
-| type="text"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important; text-overflow: clip;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "initial placeholder"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <textarea>
-| id="textarea"
-| this.value="initial value"
-| "initial value"
-| <shadow:root>
-| <div>
-| id="inner-editor"
-| "initial value"
-| <br>
-| "
-"
-| <textarea>
-| id="textareaWithPlaceholder"
-| placeholder="initial placeholder"
-| this.value=""
-| <shadow:root>
-| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: block !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "initial placeholder"
-| <div>
-| id="inner-editor"
-| <br>
-| "
-"
-| <select>
-| id="select"
-| <option>
-| "CA"
-| <shadow:root>
-| "CA"
-| <option>
-| "TX"
-| <shadow:root>
-| "TX"
-| <shadow:root>
-| <content>
-| select="option,optgroup,hr"
-| "input.value: initial value"
-| "internals.suggestedValue(input): "
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): "
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): "
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): "
-| "select.value: "
-| "internals.suggestedValue(select): "
-| "input.value: initial value"
-| "internals.suggestedValue(input): suggested value"
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): suggested value"
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): suggested value"
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): suggested value"
-| "select.value: "
-| "internals.suggestedValue(select): TX"
-| "input.value: initial value"
-| "internals.suggestedValue(input): "
-| "inputWithPlaceholder.value: "
-| "internals.suggestedValue(inputWithPlaceholder): "
-| "textarea.value: initial value"
-| "internals.suggestedValue(textarea): "
-| "textareaWithPlaceholder.value: "
-| "internals.suggestedValue(textareaWithPlaceholder): "
-| "select.value: "
-| "internals.suggestedValue(select): "
-| "PASS"
diff --git a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value.html b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value.html
deleted file mode 100644
index d0451d4e..0000000
--- a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-empty-suggested-value.html
+++ /dev/null
@@ -1,92 +0,0 @@
-<!DOCTYPE html>
-<html>
-<body>
-<p id="description">This test verifies that setting an empty suggested value removes/resets the shadow placeholder value.</p>
-<pre><input id="test" type="text" value="initial value"><br>
-<input id="inputwithplaceholder" type="text" placeholder="initial placeholder"><br>
-<textarea id="textarea">initial value</textarea><br>
-<textarea id="textareaWithPlaceholder" placeholder="initial placeholder"></textarea><br>
-<select id="select"><option>CA</option><option>TX</option></select></pre>
-<script src="../../resources/dump-as-markup.js"></script>
-<script>
-
-var input = document.getElementById('test');
-var inputWithPlaceholder = document.getElementById('inputwithplaceholder');
-var textarea = document.getElementById('textarea');
-//textarea.value = "initial value"
-var textareaWithPlaceholder = document.getElementById('textareaWithPlaceholder');
-var select = document.getElementById('select');
-select.selectedIndex = -1;
-var result = document.getElementById('result');
-if (!window.internals)
- testFailed('This test requires internals object');
-else {
- input.focus();
- input.selectionStart = input.selectionEnd = 0;
-
- function addText(text) {
- input.parentNode.appendChild(document.createTextNode(text));
- }
-
- function log() {
- function addTextResult(value) { addText(value + ': ' + eval(value)); }
- addTextResult('input.value');
- addTextResult('internals.suggestedValue(input)');
- addTextResult('inputWithPlaceholder.value');
- addTextResult('internals.suggestedValue(inputWithPlaceholder)');
- addTextResult('textarea.value');
- addTextResult('internals.suggestedValue(textarea)');
- addTextResult('textareaWithPlaceholder.value');
- addTextResult('internals.suggestedValue(textareaWithPlaceholder)');
- addTextResult('select.value');
- addTextResult('internals.suggestedValue(select)');
- }
-
- function getSelectedValues(select) {
- var selectedValues = [];
- for (var i = 0; i < select.options.length; i++) {
- var option = select.options[i];
- if (option.selected)
- selectedValues.push(option.value);
- }
- return selectedValues.join(',');
- }
-
- Markup.description(document.getElementById('description').textContent)
-
- log();
- Markup.dump(input.parentNode, 'Input before setting suggested values');
-
- // Set some suggested value to all the fields.
- internals.setSuggestedValue(input, 'suggested value');
- internals.setSuggestedValue(inputWithPlaceholder, 'suggested value');
- internals.setSuggestedValue(textarea, 'suggested value');
- internals.setSuggestedValue(textareaWithPlaceholder, 'suggested value');
- internals.setSuggestedValue(select, 'TX');
- log();
- Markup.dump(input.parentNode, 'Input after setting suggestedValue');
-
- // Set an empty suggested value to all the fields.
- internals.setSuggestedValue(input, '');
- internals.setSuggestedValue(inputWithPlaceholder, '');
- internals.setSuggestedValue(textarea, '');
- internals.setSuggestedValue(textareaWithPlaceholder, '');
- internals.setSuggestedValue(select, '');
-
- log();
- var innerTextValue = internals.shadowRoot(input).lastChild.innerText;
- var innerTextWithPlaceholderValue = internals.shadowRoot(inputWithPlaceholder).lastChild.innerText;
- var innerTextAreaValue = internals.shadowRoot(textarea).lastChild.innerText;
- var innerTextAreaWithPlaceholderValue = internals.shadowRoot(textareaWithPlaceholder).lastChild.innerText;
- var selectedValues = getSelectedValues(select);
- addText(innerTextValue == 'initial value' &&
- innerTextWithPlaceholderValue == '' &&
- innerTextAreaValue == 'initial value' &&
- innerTextAreaWithPlaceholderValue == '' &&
- selectedValues == '' ? 'PASS' : 'FAIL');
- Markup.dump(input.parentNode, 'After resetting suggestedValue value');
-}
-
-</script>
-</body>
-</html>
diff --git a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue-expected.txt
index 13f7676..8473c61 100644
--- a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue-expected.txt
+++ b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue-expected.txt
@@ -8,13 +8,8 @@
| this.value="initial value"
| <shadow:root>
| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
| id="inner-editor"
+| "suggested value"
| "input.value: initial value"
| "internals.suggestedValue(input): suggested value"
| "input.selectionStart: 0"
diff --git a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue.html b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue.html
index 29936e7..811d0dde 100644
--- a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue.html
+++ b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-after-setvalue.html
@@ -62,11 +62,8 @@
select.value = 'CA';
log();
- // Make sure the InnerEditor value is set to the "new value". The
- // InnerEditor element is the second/last child of the shadow
- // input/textarea.
- var innerTextValue = internals.shadowRoot(input).lastChild.innerText;
- var innerTextAreaValue = internals.shadowRoot(textarea).lastChild.innerText;
+ var innerTextValue = internals.shadowRoot(input).firstChild.innerText;
+ var innerTextAreaValue = internals.shadowRoot(textarea).firstChild.innerText;
var selectedValues = getSelectedValues(select);
addText(innerTextValue == 'new value' &&
innerTextAreaValue == 'new value' &&
diff --git a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-expected.txt
index 1e515f9..ec844c9 100644
--- a/third_party/WebKit/LayoutTests/fast/forms/suggested-value-expected.txt
+++ b/third_party/WebKit/LayoutTests/fast/forms/suggested-value-expected.txt
@@ -8,13 +8,8 @@
| this.value="initial value"
| <shadow:root>
| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
| id="inner-editor"
+| "suggested value"
| <input>
| id="month"
| type="month"
@@ -70,13 +65,8 @@
| this.value="initial value"
| <shadow:root>
| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
| id="inner-editor"
+| "suggested value"
| <select>
| id="select"
| <option>
diff --git a/third_party/WebKit/LayoutTests/fast/forms/text/input-appearance-autocomplete-expected.html b/third_party/WebKit/LayoutTests/fast/forms/text/input-appearance-autocomplete-expected.html
index e7a680e..56c7f152 100644
--- a/third_party/WebKit/LayoutTests/fast/forms/text/input-appearance-autocomplete-expected.html
+++ b/third_party/WebKit/LayoutTests/fast/forms/text/input-appearance-autocomplete-expected.html
@@ -1,4 +1,4 @@
-<input id="input" placeholder="hello" style="width: 99px" >
+<input id="input" value="hello" style="width: 99px" >
<script>
input.select();
internals.setAutofilled(input, true);
diff --git a/third_party/WebKit/LayoutTests/platform/win7/fast/forms/suggested-value-expected.txt b/third_party/WebKit/LayoutTests/platform/win7/fast/forms/suggested-value-expected.txt
index 859ac6c..df440ee2 100644
--- a/third_party/WebKit/LayoutTests/platform/win7/fast/forms/suggested-value-expected.txt
+++ b/third_party/WebKit/LayoutTests/platform/win7/fast/forms/suggested-value-expected.txt
@@ -8,12 +8,6 @@
| this.value="initial value"
| <shadow:root>
| <div>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
-| "suggested value"
-| <div>
| id="inner-editor"
| "suggested value"
| <input>
@@ -70,12 +64,9 @@
| id="textarea"
| this.value="initial value"
| <shadow:root>
-| id="placeholder"
-| pseudo="-webkit-input-placeholder"
-| style="display: none !important;"
-| shadow:pseudoId="-webkit-input-placeholder"
| <div>
| id="inner-editor"
+| "suggested value"
| <select>
| id="select"
| <option>
diff --git a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
index 928d5434..a894755 100644
--- a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
@@ -1052,12 +1052,15 @@
setValue(value, kDispatchChangeEvent);
}
+const String& HTMLInputElement::SuggestedValue() const {
+ return suggested_value_;
+}
+
void HTMLInputElement::SetSuggestedValue(const String& value) {
if (!input_type_->CanSetSuggestedValue())
return;
-
- TextControlElement::SetSuggestedValue(SanitizeValue(value));
needs_to_update_view_value_ = true;
+ suggested_value_ = SanitizeValue(value);
SetNeedsStyleRecalc(
kSubtreeStyleChange,
StyleChangeReasonForTracing::Create(StyleChangeReason::kControlValue));
@@ -1101,16 +1104,14 @@
if (!input_type_->CanSetValue(value))
return;
- // Clear the suggested value. Use the base class version to not trigger a view
- // update.
- TextControlElement::SetSuggestedValue(String());
-
EventQueueScope scope;
String sanitized_value = SanitizeValue(value);
bool value_changed = sanitized_value != this->value();
SetLastChangeWasNotUserEdit();
needs_to_update_view_value_ = true;
+ // Prevent TextFieldInputType::setValue from using the suggested value.
+ suggested_value_ = String();
input_type_->SetValue(sanitized_value, value_changed, event_behavior,
selection);
@@ -1182,9 +1183,7 @@
// File upload controls will never use this.
DCHECK_NE(type(), InputTypeNames::file);
- // Clear the suggested value. Use the base class version to not trigger a view
- // update.
- TextControlElement::SetSuggestedValue(String());
+ suggested_value_ = String();
// Renderer and our event handler are responsible for sanitizing values.
DCHECK(value == input_type_->SanitizeUserInputValue(value) ||
@@ -1690,10 +1689,6 @@
return input_type_view_->UpdatePlaceholderText();
}
-String HTMLInputElement::GetPlaceholderValue() const {
- return !SuggestedValue().IsEmpty() ? SuggestedValue() : StrippedPlaceholder();
-}
-
bool HTMLInputElement::SupportsAutocapitalize() const {
return input_type_->SupportsAutocapitalize();
}
diff --git a/third_party/WebKit/Source/core/html/HTMLInputElement.h b/third_party/WebKit/Source/core/html/HTMLInputElement.h
index e7e3b4e..832a91ce 100644
--- a/third_party/WebKit/Source/core/html/HTMLInputElement.h
+++ b/third_party/WebKit/Source/core/html/HTMLInputElement.h
@@ -144,7 +144,8 @@
String LocalizeValue(const String&) const;
- void SetSuggestedValue(const String& value) override;
+ const String& SuggestedValue() const;
+ void SetSuggestedValue(const String&);
void SetEditingValue(const String&);
@@ -292,8 +293,6 @@
unsigned SizeOfRadioGroup() const;
- String GetPlaceholderValue() const final;
-
protected:
HTMLInputElement(Document&, bool created_by_parser);
@@ -368,6 +367,9 @@
bool SupportsPlaceholder() const final;
void UpdatePlaceholderText() final;
bool IsEmptyValue() const final { return InnerEditorValue().IsEmpty(); }
+ bool IsEmptySuggestedValue() const final {
+ return SuggestedValue().IsEmpty();
+ }
void HandleFocusEvent(Element* old_focused_element, WebFocusType) final;
void HandleBlurEvent() final;
void DispatchFocusInEvent(const AtomicString& event_type,
@@ -402,6 +404,7 @@
AtomicString name_;
// The value string in |value| value mode.
String non_attribute_value_;
+ String suggested_value_;
int size_;
// https://html.spec.whatwg.org/multipage/forms.html#concept-input-value-dirty-flag
unsigned has_dirty_value_ : 1;
diff --git a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
index 5ccd915..0f330b4 100644
--- a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
@@ -391,10 +391,6 @@
normalized_value.Replace("\r\n", "\n");
normalized_value.Replace('\r', '\n');
- // Clear the suggested value. Use the base class version to not trigger a view
- // update.
- TextControlElement::SetSuggestedValue(String());
-
// Return early because we don't want to trigger other side effects when the
// value isn't changing. This is interoperable.
if (normalized_value == value())
@@ -412,6 +408,7 @@
SetNeedsStyleRecalc(
kSubtreeStyleChange,
StyleChangeReasonForTracing::Create(StyleChangeReason::kControlValue));
+ suggested_value_ = String();
SetNeedsValidityCheck();
if (IsFinishedParsingChildren() &&
selection == TextControlSetValueSelection::kSetSelectionToEnd) {
@@ -471,8 +468,18 @@
SetNonDirtyValue(value);
}
+String HTMLTextAreaElement::SuggestedValue() const {
+ return suggested_value_;
+}
+
void HTMLTextAreaElement::SetSuggestedValue(const String& value) {
- TextControlElement::SetSuggestedValue(value);
+ suggested_value_ = value;
+
+ if (!value.IsNull())
+ SetInnerEditorValue(suggested_value_);
+ else
+ SetInnerEditorValue(value_);
+ UpdatePlaceholderVisibility();
SetNeedsStyleRecalc(
kSubtreeStyleChange,
StyleChangeReasonForTracing::Create(StyleChangeReason::kControlValue));
@@ -581,7 +588,7 @@
void HTMLTextAreaElement::UpdatePlaceholderText() {
HTMLElement* placeholder = PlaceholderElement();
- const String placeholder_text = GetPlaceholderValue();
+ const AtomicString& placeholder_text = FastGetAttribute(placeholderAttr);
if (placeholder_text.IsEmpty()) {
if (placeholder)
UserAgentShadowRoot()->RemoveChild(placeholder);
@@ -600,11 +607,6 @@
placeholder->setTextContent(placeholder_text);
}
-String HTMLTextAreaElement::GetPlaceholderValue() const {
- return !SuggestedValue().IsEmpty() ? SuggestedValue()
- : FastGetAttribute(placeholderAttr);
-}
-
bool HTMLTextAreaElement::IsInteractiveContent() const {
return true;
}
diff --git a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.h b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.h
index 70a347a..505edca 100644
--- a/third_party/WebKit/Source/core/html/HTMLTextAreaElement.h
+++ b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.h
@@ -52,7 +52,8 @@
void setDefaultValue(const String&);
int textLength() const { return value().length(); }
- void SetSuggestedValue(const String& value) override;
+ String SuggestedValue() const;
+ void SetSuggestedValue(const String&);
// For ValidityState
String validationMessage() const override;
@@ -86,9 +87,11 @@
bool IsPlaceholderVisible() const override { return is_placeholder_visible_; }
void SetPlaceholderVisibility(bool) override;
bool SupportsPlaceholder() const override { return true; }
- String GetPlaceholderValue() const final;
void UpdatePlaceholderText() override;
bool IsEmptyValue() const override { return value().IsEmpty(); }
+ bool IsEmptySuggestedValue() const final {
+ return SuggestedValue().IsEmpty();
+ }
bool SupportsAutocapitalize() const override { return true; }
const AtomicString& DefaultAutocapitalize() const override;
@@ -144,6 +147,7 @@
mutable String value_;
mutable bool is_dirty_;
unsigned is_placeholder_visible_ : 1;
+ String suggested_value_;
};
} // namespace blink
diff --git a/third_party/WebKit/Source/core/html/TextControlElement.cpp b/third_party/WebKit/Source/core/html/TextControlElement.cpp
index 7d4ae44..bc400ba3 100644
--- a/third_party/WebKit/Source/core/html/TextControlElement.cpp
+++ b/third_party/WebKit/Source/core/html/TextControlElement.cpp
@@ -46,7 +46,6 @@
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLBRElement.h"
-#include "core/html/HTMLDivElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/layout/LayoutBlock.h"
@@ -160,8 +159,8 @@
}
bool TextControlElement::PlaceholderShouldBeVisible() const {
- return SupportsPlaceholder() && InnerEditorValue().IsEmpty() &&
- (!IsPlaceholderEmpty() || !IsEmptySuggestedValue());
+ return SupportsPlaceholder() && IsEmptyValue() && IsEmptySuggestedValue() &&
+ !IsPlaceholderEmpty();
}
HTMLElement* TextControlElement::PlaceholderElement() const {
@@ -972,28 +971,6 @@
return "ltr";
}
-void TextControlElement::SetSuggestedValue(const String& value) {
- suggested_value_ = value;
- if (!suggested_value_.IsEmpty() && !InnerEditorValue().IsEmpty()) {
- // Save the value that is in the editor and set the editor value to an empty
- // string. This will allow the suggestion placeholder to be shown to the
- // user.
- value_before_set_suggested_value_ = InnerEditorValue();
- SetInnerEditorValue("");
- } else if (suggested_value_.IsEmpty() &&
- !value_before_set_suggested_value_.IsEmpty()) {
- // Reset the value that was in the editor before showing the suggestion.
- SetInnerEditorValue(value_before_set_suggested_value_);
- value_before_set_suggested_value_ = "";
- }
-
- UpdatePlaceholderText();
-}
-
-const String& TextControlElement::SuggestedValue() const {
- return suggested_value_;
-}
-
HTMLElement* TextControlElement::InnerEditorElement() const {
return ToHTMLElementOrDie(
UserAgentShadowRoot()->getElementById(ShadowElementNames::InnerEditor()));
diff --git a/third_party/WebKit/Source/core/html/TextControlElement.h b/third_party/WebKit/Source/core/html/TextControlElement.h
index 965f10d..fad00b1 100644
--- a/third_party/WebKit/Source/core/html/TextControlElement.h
+++ b/third_party/WebKit/Source/core/html/TextControlElement.h
@@ -141,14 +141,10 @@
String DirectionForFormData() const;
- virtual void SetSuggestedValue(const String& value);
- const String& SuggestedValue() const;
-
protected:
TextControlElement(const QualifiedName&, Document&);
bool IsPlaceholderEmpty() const;
virtual void UpdatePlaceholderText() = 0;
- virtual String GetPlaceholderValue() const = 0;
void ParseAttribute(const AttributeModificationParams&) override;
@@ -186,7 +182,7 @@
virtual bool IsEmptyValue() const = 0;
// Returns true if suggested value is empty. Used to check placeholder
// visibility.
- bool IsEmptySuggestedValue() const { return SuggestedValue().IsEmpty(); }
+ virtual bool IsEmptySuggestedValue() const { return true; }
// Called in dispatchFocusEvent(), after placeholder process, before calling
// parent's dispatchFocusEvent().
virtual void HandleFocusEvent(Element* /* oldFocusedNode */, WebFocusType) {}
@@ -206,9 +202,6 @@
unsigned cached_selection_end_;
TextFieldSelectionDirection cached_selection_direction_;
- String suggested_value_;
- String value_before_set_suggested_value_;
-
FRIEND_TEST_ALL_PREFIXES(TextControlElementTest, IndexForPosition);
};
diff --git a/third_party/WebKit/Source/core/html/forms/TextFieldInputType.cpp b/third_party/WebKit/Source/core/html/forms/TextFieldInputType.cpp
index 6bdab976..3182088 100644
--- a/third_party/WebKit/Source/core/html/forms/TextFieldInputType.cpp
+++ b/third_party/WebKit/Source/core/html/forms/TextFieldInputType.cpp
@@ -460,7 +460,7 @@
if (!SupportsPlaceholder())
return;
HTMLElement* placeholder = GetElement().PlaceholderElement();
- String placeholder_text = GetElement().GetPlaceholderValue();
+ String placeholder_text = GetElement().StrippedPlaceholder();
if (placeholder_text.IsEmpty()) {
if (placeholder)
placeholder->remove(ASSERT_NO_EXCEPTION);
@@ -525,8 +525,10 @@
}
void TextFieldInputType::UpdateView() {
- if (GetElement().SuggestedValue().IsEmpty() &&
- GetElement().NeedsToUpdateViewValue()) {
+ if (!GetElement().SuggestedValue().IsNull()) {
+ GetElement().SetInnerEditorValue(GetElement().SuggestedValue());
+ GetElement().UpdatePlaceholderVisibility();
+ } else if (GetElement().NeedsToUpdateViewValue()) {
// Update the view only if needsToUpdateViewValue is true. It protects
// an unacceptable view value from being overwritten with the DOM value.
//