Title: [235427] trunk
Revision
235427
Author
akeer...@apple.com
Date
2018-08-28 10:02:56 -0700 (Tue, 28 Aug 2018)

Log Message

[Datalist] Pressing enter without a selected option shouldn't change the input
https://bugs.webkit.org/show_bug.cgi?id=189010

Reviewed by Tim Horton.

Source/WebKit:

Currently, the value of an input field gets cleared if there is no selected
datalist suggestion when the enter key is pressed. The correct behavior is to
leave the value of the input as-is.

The incorrect behavior is a consequence of the fact that an empty string is
returned by [WKDataListSuggestionsView currentSelectedString] if there is no
selection. To fix the behavior, the method now returns an std::optional instead
of an empty string. If std::nullopt is returned, we do not make any modification
to the value of the input. This ensures that we can still change the value of
an input field to an empty string in the case that an empty string is part of
the suggestions.

Augmented test: fast/forms/datalist/datalist-textinput-keydown.html

* UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
(WebKit::WebDataListSuggestionsDropdownMac::selectOption):
(-[WKDataListSuggestionCell drawRect:]): Quick fix. The mouseover color was incorrect.
(-[WKDataListSuggestionsView currentSelectedString]):

LayoutTests:

Augmented test to verify that pressing enter when there is no selected datalist
suggestion does not change the value of the input field.

* fast/forms/datalist/datalist-textinput-keydown-expected.txt:
* fast/forms/datalist/datalist-textinput-keydown.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (235426 => 235427)


--- trunk/LayoutTests/ChangeLog	2018-08-28 16:34:25 UTC (rev 235426)
+++ trunk/LayoutTests/ChangeLog	2018-08-28 17:02:56 UTC (rev 235427)
@@ -1,5 +1,18 @@
 2018-08-28  Aditya Keerthi  <akeer...@apple.com>
 
+        [Datalist] Pressing enter without a selected option shouldn't change the input
+        https://bugs.webkit.org/show_bug.cgi?id=189010
+
+        Reviewed by Tim Horton.
+
+        Augmented test to verify that pressing enter when there is no selected datalist
+        suggestion does not change the value of the input field.
+
+        * fast/forms/datalist/datalist-textinput-keydown-expected.txt:
+        * fast/forms/datalist/datalist-textinput-keydown.html:
+
+2018-08-28  Aditya Keerthi  <akeer...@apple.com>
+
         [iOS] Support inputmode=none
         https://bugs.webkit.org/show_bug.cgi?id=188896
 

Modified: trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown-expected.txt (235426 => 235427)


--- trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown-expected.txt	2018-08-28 16:34:25 UTC (rev 235426)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown-expected.txt	2018-08-28 17:02:56 UTC (rev 235427)
@@ -5,6 +5,7 @@
 
 PASS input.value is "Apple"
 PASS input.value is "Pear"
+PASS input.value is "Appl"
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown.html (235426 => 235427)


--- trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown.html	2018-08-28 16:34:25 UTC (rev 235426)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-textinput-keydown.html	2018-08-28 17:02:56 UTC (rev 235427)
@@ -22,7 +22,6 @@
 UIHelper.activateElement(input);
 eventSender.keyDown("downArrow");
 eventSender.keyDown("\r");
-
 shouldBe('input.value', '"Apple"');
 
 input.value = "";
@@ -30,9 +29,14 @@
 UIHelper.activateElement(input);
 eventSender.keyDown("upArrow");
 eventSender.keyDown("\r");
-
 shouldBe('input.value', '"Pear"');
 
+input.value = "Appl";
+
+UIHelper.activateElement(input);
+eventSender.keyDown("\r");
+shouldBe('input.value', '"Appl"');
+
 </script>
 
 <script src=""

Modified: trunk/Source/WebKit/ChangeLog (235426 => 235427)


--- trunk/Source/WebKit/ChangeLog	2018-08-28 16:34:25 UTC (rev 235426)
+++ trunk/Source/WebKit/ChangeLog	2018-08-28 17:02:56 UTC (rev 235427)
@@ -1,5 +1,31 @@
 2018-08-28  Aditya Keerthi  <akeer...@apple.com>
 
+        [Datalist] Pressing enter without a selected option shouldn't change the input
+        https://bugs.webkit.org/show_bug.cgi?id=189010
+
+        Reviewed by Tim Horton.
+
+        Currently, the value of an input field gets cleared if there is no selected
+        datalist suggestion when the enter key is pressed. The correct behavior is to
+        leave the value of the input as-is.
+
+        The incorrect behavior is a consequence of the fact that an empty string is
+        returned by [WKDataListSuggestionsView currentSelectedString] if there is no
+        selection. To fix the behavior, the method now returns an std::optional instead
+        of an empty string. If std::nullopt is returned, we do not make any modification
+        to the value of the input. This ensures that we can still change the value of
+        an input field to an empty string in the case that an empty string is part of
+        the suggestions.
+
+        Augmented test: fast/forms/datalist/datalist-textinput-keydown.html
+
+        * UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
+        (WebKit::WebDataListSuggestionsDropdownMac::selectOption):
+        (-[WKDataListSuggestionCell drawRect:]): Quick fix. The mouseover color was incorrect.
+        (-[WKDataListSuggestionsView currentSelectedString]):
+
+2018-08-28  Aditya Keerthi  <akeer...@apple.com>
+
         [iOS] Support inputmode=none
         https://bugs.webkit.org/show_bug.cgi?id=188896
 

Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm (235426 => 235427)


--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm	2018-08-28 16:34:25 UTC (rev 235426)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm	2018-08-28 17:02:56 UTC (rev 235427)
@@ -77,7 +77,7 @@
 - (void)moveSelectionByDirection:(const String&)direction;
 - (void)invalidate;
 
-- (String)currentSelectedString;
+- (std::optional<String>)currentSelectedString;
 @end
 
 namespace WebKit {
@@ -120,8 +120,10 @@
     if (!m_client)
         return;
 
-    String selectedOption = [m_dropdownUI currentSelectedString];
-    m_client->didSelectOption(selectedOption);
+    std::optional<String> selectedOption = [m_dropdownUI currentSelectedString];
+    if (selectedOption)
+        m_client->didSelectOption(selectedOption.value());
+
     close();
 }
 
@@ -189,7 +191,7 @@
         [[NSColor alternateSelectedControlColor] setFill];
         [_textField setTextColor:[NSColor alternateSelectedControlTextColor]];
     } else if (_mouseIsOver) {
-        [[NSColor controlColor] setFill];
+        [[NSColor quaternaryLabelColor] setFill];
         [_textField setTextColor:[NSColor textColor]];
     } else {
         [[NSColor controlBackgroundColor] setFill];
@@ -327,13 +329,13 @@
     return self;
 }
 
-- (String)currentSelectedString
+- (std::optional<String>)currentSelectedString
 {
     std::optional<size_t> selectedRow = [_table currentActiveRow];
     if (selectedRow && selectedRow.value() < _suggestions.size())
         return _suggestions.at(selectedRow.value());
 
-    return emptyString();
+    return std::nullopt;
 }
 
 - (void)updateWithInformation:(WebCore::DataListSuggestionInformation&&)information
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to