WebKit Bugzilla
Attachment 348443 Details for
Bug 189106
: [Datalist] Display prefix-matched suggestions first
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189106-20180829160605.patch (text/plain), 9.21 KB, created by
Aditya Keerthi
on 2018-08-29 16:06:06 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Aditya Keerthi
Created:
2018-08-29 16:06:06 PDT
Size:
9.21 KB
patch
obsolete
>Subversion Revision: 235471 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d17dc740f5a79bf25e3711dbecc3d0e70b21f1ea..8a19cfd8abb5d4f84ea25fb0e017aeeacdf38ac4 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,33 @@ >+2018-08-29 Aditya Keerthi <akeerthi@apple.com> >+ >+ [Datalist] Display prefix-matched suggestions first >+ https://bugs.webkit.org/show_bug.cgi?id=189106 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ In order to increase suggestion relevancy, we should display suggestions that have >+ the same prefix as the input value first. In order to achieve this, we can place >+ the suggestions into two buckets, one that contains prefix-matched values and >+ another that contains only substring-matched values. >+ >+ TextFieldInputType::suggestions() can be called up to three times before we >+ display the values. In order to avoid generating the same suggestions multiple >+ times, the most recent values can be stored and reused. We clear the cached values >+ whenever the datalist element is modified or when the suggestions view is hidden. >+ >+ Finally, removed logic to de-duplicate the list of suggested values. This behavior >+ is not a part of the specification and leads to unnecessary slowdown when >+ populating the suggestions view. >+ >+ Test: fast/forms/datalist/datalist-textinput-suggestions-order.html >+ >+ * html/TextFieldInputType.cpp: >+ (WebCore::TextFieldInputType::listAttributeTargetChanged): >+ (WebCore::TextFieldInputType::suggestions): >+ (WebCore::TextFieldInputType::didCloseSuggestions): >+ * html/TextFieldInputType.h: >+ * platform/DataListSuggestionsClient.h: >+ > 2018-08-29 David Kilzer <ddkilzer@apple.com> > > Remove empty directories from from svn.webkit.org repository >diff --git a/Source/WebCore/html/TextFieldInputType.cpp b/Source/WebCore/html/TextFieldInputType.cpp >index 13c31ba61aa2accf320e63d20a1314d0485fffbb..420253fd7b2c8399fc3918e8daafeed471e94c2f 100644 >--- a/Source/WebCore/html/TextFieldInputType.cpp >+++ b/Source/WebCore/html/TextFieldInputType.cpp >@@ -799,6 +799,8 @@ void TextFieldInputType::updateAutoFillButton() > > void TextFieldInputType::listAttributeTargetChanged() > { >+ m_cachedSuggestions = std::make_pair(String(), Vector<String>()); >+ > if (!m_dataListDropdownIndicator) > return; > >@@ -823,9 +825,15 @@ IntRect TextFieldInputType::elementRectInRootViewCoordinates() const > return element()->document().view()->contentsToRootView(element()->renderer()->absoluteBoundingBoxRect()); > } > >-Vector<String> TextFieldInputType::suggestions() const >+Vector<String> TextFieldInputType::suggestions() > { > Vector<String> suggestions; >+ Vector<String> matchesContainingValue; >+ >+ String elementValue = element()->value(); >+ >+ if (!m_cachedSuggestions.first.isNull() && equalIgnoringASCIICase(m_cachedSuggestions.first, elementValue)) >+ return m_cachedSuggestions.second; > > if (auto dataList = element()->dataList()) { > Ref<HTMLCollection> options = dataList->options(); >@@ -834,11 +842,18 @@ Vector<String> TextFieldInputType::suggestions() const > continue; > > String value = sanitizeValue(option->value()); >- if (!suggestions.contains(value) && (element()->value().isEmpty() || value.containsIgnoringASCIICase(element()->value()))) >+ if (elementValue.isEmpty()) > suggestions.append(value); >+ else if (value.startsWithIgnoringASCIICase(elementValue)) >+ suggestions.append(value); >+ else if (value.containsIgnoringASCIICase(elementValue)) >+ matchesContainingValue.append(value); > } > } > >+ suggestions.appendVector(matchesContainingValue); >+ m_cachedSuggestions = std::make_pair(elementValue, suggestions); >+ > return suggestions; > } > >@@ -849,6 +864,7 @@ void TextFieldInputType::didSelectDataListOption(const String& selectedOption) > > void TextFieldInputType::didCloseSuggestions() > { >+ m_cachedSuggestions = std::make_pair(String(), Vector<String>()); > m_suggestionPicker = nullptr; > if (element()->renderer()) > element()->renderer()->repaint(); >diff --git a/Source/WebCore/html/TextFieldInputType.h b/Source/WebCore/html/TextFieldInputType.h >index 75d96c7f8f93b079dc15e7b20b02c4d7b375b063..291f8fbc74c9ce1e7a6eabf37263b867831fa1e9 100644 >--- a/Source/WebCore/html/TextFieldInputType.h >+++ b/Source/WebCore/html/TextFieldInputType.h >@@ -131,13 +131,14 @@ private: > > // DataListSuggestionsClient > IntRect elementRectInRootViewCoordinates() const final; >- Vector<String> suggestions() const final; >+ Vector<String> suggestions() final; > void didSelectDataListOption(const String&) final; > void didCloseSuggestions() final; > > void dataListButtonElementWasClicked() final; > RefPtr<DataListButtonElement> m_dataListDropdownIndicator; > >+ std::pair<String, Vector<String>> m_cachedSuggestions; > std::unique_ptr<DataListSuggestionPicker> m_suggestionPicker; > #endif > >diff --git a/Source/WebCore/platform/DataListSuggestionsClient.h b/Source/WebCore/platform/DataListSuggestionsClient.h >index abf5c6b0cc35014b8588162bf6b0c3afb2422b68..7b32b33d315ab95d2a0be98d3e2f0a50ba0b9ed3 100644 >--- a/Source/WebCore/platform/DataListSuggestionsClient.h >+++ b/Source/WebCore/platform/DataListSuggestionsClient.h >@@ -37,7 +37,7 @@ public: > virtual ~DataListSuggestionsClient() = default; > > virtual IntRect elementRectInRootViewCoordinates() const = 0; >- virtual Vector<String> suggestions() const = 0; >+ virtual Vector<String> suggestions() = 0; > > virtual void didSelectDataListOption(const String&) = 0; > virtual void didCloseSuggestions() = 0; >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 4b4ed54d784f72ee68683dba08ee4096769b2e81..e976cbe4525cef953f8bd173993eba2014c5dbc6 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,17 @@ >+2018-08-29 Aditya Keerthi <akeerthi@apple.com> >+ >+ [Datalist] Display prefix-matched suggestions first >+ https://bugs.webkit.org/show_bug.cgi?id=189106 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Added a test to verify that prefix-matched suggestions are shown before other >+ matches. >+ >+ * fast/forms/datalist/datalist-textinput-suggestions-order-expected.txt: Added. >+ * fast/forms/datalist/datalist-textinput-suggestions-order.html: Added. >+ * platform/ios/TestExpectations: >+ > 2018-08-29 Ali Juma <ajuma@chromium.org> > > [mac-wk1] Mark three IntersectionObserver web platform tests as flaky >diff --git a/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order-expected.txt b/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..ead9e5cc2013bdc94c34ae7f179ca8783c8e6e94 >--- /dev/null >+++ b/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order-expected.txt >@@ -0,0 +1,11 @@ >+Test to verify that prefix-matched values are displayed first >+ >+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". >+ >+ >+PASS input.value is "Orange" >+PASS input.value is "Apple" >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order.html b/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order.html >new file mode 100644 >index 0000000000000000000000000000000000000000..4aeee8c379c572e46934ac250dbac2d4099a3434 >--- /dev/null >+++ b/LayoutTests/fast/forms/datalist/datalist-textinput-suggestions-order.html >@@ -0,0 +1,38 @@ >+<!DOCTYPE html> >+<html> >+<head> >+<script src="../../../resources/js-test-pre.js"></script> >+<script src="../../../resources/ui-helper.js"></script> >+</head> >+<body> >+ >+<input id="fruit" list="fruits" type="text"/> >+<datalist id="fruits"> >+ <option>Orange</option> >+ <option>Pear</option> >+ <option>Apple</option> >+</datalist> >+ >+<script> >+ >+description('Test to verify that prefix-matched values are displayed first'); >+ >+var input = document.getElementById("fruit"); >+ >+UIHelper.activateElement(input); >+eventSender.keyDown("downArrow"); >+eventSender.keyDown("\r"); >+shouldBe('input.value', '"Orange"'); >+ >+input.value = "a"; >+ >+UIHelper.activateElement(input); >+eventSender.keyDown("downArrow"); >+eventSender.keyDown("\r"); >+shouldBe('input.value', '"Apple"'); >+ >+</script> >+ >+<script src="../../../resources/js-test-post.js"></script> >+</body> >+</html> >diff --git a/LayoutTests/platform/ios/TestExpectations b/LayoutTests/platform/ios/TestExpectations >index 3f13de8d2aa2a07ef845194fe31bdd7366dfdc49..91dbfe06355c72fb2c74ad057f9ed8dfe0a95cce 100644 >--- a/LayoutTests/platform/ios/TestExpectations >+++ b/LayoutTests/platform/ios/TestExpectations >@@ -3125,6 +3125,7 @@ webkit.org/b/186714 fast/forms/datalist/datalist-show-hide.html [ Skip ] > webkit.org/b/186714 fast/forms/datalist/datalist-textinput-keydown.html [ Skip ] > fast/forms/datalist/datalist-searchinput-appearance.html [ Skip ] > fast/forms/datalist/datalist-textinput-appearance.html [ Skip ] >+fast/forms/datalist/datalist-textinput-suggestions-order.html [ Skip ] > > # We are only accepting GLSL3 for macOS. > webkit.org/b/187982 webgl/2.0.0/conformance2/glsl3 [ Skip ]
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189106
: 348443