Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Unified Diff: Source/core/html/HTMLSelectElement.cpp

Issue 138433002: Add Autofill preview support for <select> input fields (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update code and addressed all the review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLSelectElement.cpp
diff --git a/Source/core/html/HTMLSelectElement.cpp b/Source/core/html/HTMLSelectElement.cpp
index 710aff5591e54959d330111276ae8f5207eb4bde..9c49e329d4818f6546c585ab29025b8e7f8fa67a 100644
--- a/Source/core/html/HTMLSelectElement.cpp
+++ b/Source/core/html/HTMLSelectElement.cpp
@@ -253,6 +253,35 @@ void HTMLSelectElement::setValue(const String &value)
setSelectedIndex(-1);
}
+String HTMLSelectElement::suggestedValue() const
+{
+ return m_suggestedValue;
+}
+
+void HTMLSelectElement::setSuggestedValue(const String& value)
+{
+ m_suggestedValue = value;
+
+ if (value.isNull()) {
+ setSuggestedIndex(-1);
+ return;
+ }
+
+ const Vector<HTMLElement*>& items = listItems();
+ unsigned optionIndex = 0;
+ for (unsigned i = 0; i < items.size(); i++) {
+ if (items[i]->hasLocalName(optionTag)) {
+ if (toHTMLOptionElement(items[i])->value() == value) {
+ setSuggestedIndex(optionIndex);
+ return;
+ }
+ optionIndex++;
+ }
+ }
+
+ setSuggestedIndex(-1);
+}
+
bool HTMLSelectElement::isPresentationAttribute(const QualifiedName& name) const
{
if (name == alignAttr) {
@@ -792,6 +821,24 @@ void HTMLSelectElement::setSelectedIndex(int index)
selectOption(index, DeselectOtherOptions);
}
+int HTMLSelectElement::suggestedIndex() const
+{
+ return m_suggestedIndex;
+}
+
+void HTMLSelectElement::setSuggestedIndex(int suggestedIndex)
+{
+ m_suggestedIndex = suggestedIndex;
+
+ if (RenderObject* renderer = this->renderer()) {
+ renderer->updateFromElement();
+ if (renderer->isListBox())
+ toRenderListBox(renderer)->scrollToRevealElementAtListIndex(suggestedIndex);
+ }
+
+ setNeedsValidityCheck();
+}
+
void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, bool optionIsSelected)
{
ASSERT(option->ownerSelectElement() == this);

Powered by Google App Engine
This is Rietveld 408576698