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

Unified Diff: third_party/WebKit/Source/web/WebInputElement.cpp

Issue 2174303002: Move filtering logic in GetDataListSuggestions() to Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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: third_party/WebKit/Source/web/WebInputElement.cpp
diff --git a/third_party/WebKit/Source/web/WebInputElement.cpp b/third_party/WebKit/Source/web/WebInputElement.cpp
index e8b4233335d845035dcc235a4a6b04be14f6b5e9..c116144aac83e38e3d7f2120ee68442af9a6e4ad 100644
--- a/third_party/WebKit/Source/web/WebInputElement.cpp
+++ b/third_party/WebKit/Source/web/WebInputElement.cpp
@@ -42,6 +42,7 @@
#include "platform/RuntimeEnabledFeatures.h"
#include "public/platform/WebString.h"
#include "public/web/WebElementCollection.h"
+#include "public/web/WebOptionElement.h"
#include "wtf/PassRefPtr.h"
namespace blink {
@@ -122,11 +123,33 @@ bool WebInputElement::isMultiple() const
return constUnwrap<HTMLInputElement>()->multiple();
}
-WebElementCollection WebInputElement::dataListOptions() const
-{
- if (HTMLDataListElement* dataList = toHTMLDataListElement(constUnwrap<HTMLInputElement>()->list()))
- return WebElementCollection(dataList->options());
- return WebElementCollection();
+WebVector<WebOptionElement> WebInputElement::filteredDataListOptions() const
+{
+ const HTMLInputElement* input = constUnwrap<HTMLInputElement>();
+ Vector<WebOptionElement> filtered;
+ HTMLDataListElement* dataList = input->dataList();
+ if (!dataList)
+ return filtered;
+
+ String prefix = input->innerEditorValue();
+ if (input->multiple() && input->type() == InputTypeNames::email) {
+ Vector<String> emails;
+ prefix.split(',', true, emails);
+ if (!emails.isEmpty())
+ prefix = emails.last().stripWhiteSpace();
+ }
+
+ HTMLDataListOptionsCollection* options = dataList->options();
+ filtered.reserveCapacity(options->length());
+ prefix = prefix.lower();
+ for (unsigned i = 0; i < options->length(); ++i) {
+ HTMLOptionElement* option = options->item(i);
+ DCHECK(option);
+ if (!option->value().lower().startsWith(prefix) || !input->isValidValue(option->value()))
+ continue;
+ filtered.append(WebOptionElement(option));
+ }
+ return filtered;
}
WebString WebInputElement::localizeValue(const WebString& proposedValue) const

Powered by Google App Engine
This is Rietveld 408576698