Diff
Modified: trunk/LayoutTests/ChangeLog (259329 => 259330)
--- trunk/LayoutTests/ChangeLog 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/LayoutTests/ChangeLog 2020-04-01 01:22:59 UTC (rev 259330)
@@ -1,3 +1,20 @@
+2020-03-31 Wenson Hsieh <[email protected]>
+
+ Datalist option's label not used
+ https://bugs.webkit.org/show_bug.cgi?id=201768
+ <rdar://problem/55361186>
+
+ Reviewed by Darin Adler.
+
+ Add a test to verify that when datalist suggestions incorporate option labels into the displayed text
+ suggestions, they are matched against when changing the value of the input field, and can be selected. This is
+ expected to be the case on macOS, but not on other platforms (for the time being).
+
+ * fast/forms/datalist/datalist-option-labels-expected.txt: Added.
+ * fast/forms/datalist/datalist-option-labels.html: Added.
+ * platform/gtk/fast/forms/datalist/datalist-option-labels-expected.txt: Added.
+ * platform/ios/fast/forms/datalist/datalist-option-labels-expected.txt: Added.
+
2020-03-31 Per Arne Vollan <[email protected]>
[macOS] Deny mach-lookup access to "com.apple.lsd.mapdb" in sandbox
Added: trunk/LayoutTests/fast/forms/datalist/datalist-option-labels-expected.txt (0 => 259330)
--- trunk/LayoutTests/fast/forms/datalist/datalist-option-labels-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-option-labels-expected.txt 2020-04-01 01:22:59 UTC (rev 259330)
@@ -0,0 +1,11 @@
+This test verifies that when option element labels are included in datalist suggestions, the text of the label is considered when computing matching datalist suggestions. Otherwise, if labels are not included in suggestions, there should be no datalist suggestions shown. To manually run the test, focus the input element and type 'e'. There should either be no matches or two matches (and selecting the second match should set the value to 'baz').
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value became 'e'
+PASS input.value is "baz"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/datalist/datalist-option-labels.html (0 => 259330)
--- trunk/LayoutTests/fast/forms/datalist/datalist-option-labels.html (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-option-labels.html 2020-04-01 01:22:59 UTC (rev 259330)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src=""
+ <script src=""
+ <script>
+ jsTestIsAsync = true;
+
+ addEventListener("load", async () => {
+ description("This test verifies that when option element labels are included in datalist suggestions, the text of the label is considered when computing matching datalist suggestions. Otherwise, if labels are not included in suggestions, there should be no datalist suggestions shown. To manually run the test, focus the input element and type 'e'. There should either be no matches or two matches (and selecting the second match should set the value to 'baz').");
+ input = document.querySelector("input");
+
+ await UIHelper.activateElementAndWaitForInputSession(input);
+ await UIHelper.typeCharacter("e");
+ await new Promise(resolve => shouldBecomeEqual("input.value", "'e'", resolve));
+ if (await UIHelper.isShowingDataListSuggestions()) {
+ await UIHelper.activateDataListSuggestion(1);
+ shouldBeEqualToString("input.value", "baz");
+ } else
+ testPassed("Not showing suggestions.");
+
+ input.blur();
+ await UIHelper.waitForKeyboardToHide();
+ finishJSTest();
+ });
+ </script>
+ </head>
+ <body>
+ <input list="list" autocapitalize="none">
+ <datalist id="list">
+ <option value="foo" label="one"></option>
+ <option value="bar">two</option>
+ <option value="baz" label="three">four</option>
+ <option value="garply"></option>
+ <option value="qux" label="qux">qux</option>
+ <option label="five"></option>
+ </datalist>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/LayoutTests/platform/gtk/fast/forms/datalist/datalist-option-labels-expected.txt (0 => 259330)
--- trunk/LayoutTests/platform/gtk/fast/forms/datalist/datalist-option-labels-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/gtk/fast/forms/datalist/datalist-option-labels-expected.txt 2020-04-01 01:22:59 UTC (rev 259330)
@@ -0,0 +1,11 @@
+This test verifies that when option element labels are included in datalist suggestions, the text of the label is considered when computing matching datalist suggestions. Otherwise, if labels are not included in suggestions, there should be no datalist suggestions shown. To manually run the test, focus the input element and type 'e'. There should either be no matches or two matches (and selecting the second match should set the value to 'baz').
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value became 'e'
+PASS Not showing suggestions.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/platform/ios/fast/forms/datalist/datalist-option-labels-expected.txt (0 => 259330)
--- trunk/LayoutTests/platform/ios/fast/forms/datalist/datalist-option-labels-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/ios/fast/forms/datalist/datalist-option-labels-expected.txt 2020-04-01 01:22:59 UTC (rev 259330)
@@ -0,0 +1,11 @@
+This test verifies that when option element labels are included in datalist suggestions, the text of the label is considered when computing matching datalist suggestions. Otherwise, if labels are not included in suggestions, there should be no datalist suggestions shown. To manually run the test, focus the input element and type 'e'. There should either be no matches or two matches (and selecting the second match should set the value to 'baz').
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value became 'e'
+PASS Not showing suggestions.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Modified: trunk/Source/WebCore/ChangeLog (259329 => 259330)
--- trunk/Source/WebCore/ChangeLog 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/ChangeLog 2020-04-01 01:22:59 UTC (rev 259330)
@@ -1,3 +1,47 @@
+2020-03-31 Wenson Hsieh <[email protected]>
+
+ Datalist option's label not used
+ https://bugs.webkit.org/show_bug.cgi?id=201768
+ <rdar://problem/55361186>
+
+ Reviewed by Darin Adler.
+
+ Refactor DataListSuggestionInformation's suggestions to include label text as well as values, and then adjust
+ TextFieldInputType::suggestions() to match label text as well as values for ports that are capable of showing
+ label text in datalist suggestion UI.
+
+ Test: fast/forms/datalist/datalist-option-labels.html
+
+ * html/DataListSuggestionInformation.h:
+
+ Introduce DataListSuggestion, a wrapper around a value and label. Currently, the list of datalist suggestions
+ is only a `Vector<String>`; change it to be a `Vector<DataListSuggestion>` instead.
+
+ (WebCore::DataListSuggestion::encode const):
+ (WebCore::DataListSuggestion::decode):
+ (WebCore::DataListSuggestionInformation::encode const):
+ (WebCore::DataListSuggestionInformation::decode):
+
+ Move encoding and decoding for DataListSuggestionInformation out of WebCoreArgumentCoders and into WebCore.
+
+ * html/TextFieldInputType.cpp:
+ (WebCore::TextFieldInputType::listAttributeTargetChanged):
+ (WebCore::TextFieldInputType::suggestions):
+
+ When computing suggestions, match label text in addition to values on ports that display label text in the
+ chrome; for the time being, this is only the case for macOS, but will be extended to iOS as well in a future
+ patch. Note that we don't plumb label text if it is already the same as the value, to avoid duplicate strings
+ from showing up.
+
+ (WebCore::TextFieldInputType::didCloseSuggestions):
+ * html/TextFieldInputType.h:
+ * loader/EmptyClients.h:
+ * page/ChromeClient.h:
+
+ Add a chrome client hook to return whether or not the client shows label text in its datalist UI.
+
+ * platform/DataListSuggestionsClient.h:
+
2020-03-31 Don Olmstead <[email protected]>
[PlayStation] Fix build breaks after r259112
Modified: trunk/Source/WebCore/html/DataListSuggestionInformation.h (259329 => 259330)
--- trunk/Source/WebCore/html/DataListSuggestionInformation.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/html/DataListSuggestionInformation.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -29,19 +29,83 @@
#include <wtf/Vector.h>
#if ENABLE(DATALIST_ELEMENT)
+
namespace WebCore {
-enum class DataListSuggestionActivationType {
+enum class DataListSuggestionActivationType : uint8_t {
ControlClicked,
IndicatorClicked,
TextChanged,
};
+struct DataListSuggestion {
+ String value;
+ String label;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<DataListSuggestion> decode(Decoder&);
+};
+
+template<class Encoder>
+void DataListSuggestion::encode(Encoder& encoder) const
+{
+ encoder << value;
+ encoder << label;
+}
+
+template<class Decoder>
+Optional<DataListSuggestion> DataListSuggestion::decode(Decoder& decoder)
+{
+ Optional<String> value;
+ decoder >> value;
+ if (!value)
+ return WTF::nullopt;
+
+ Optional<String> label;
+ decoder >> label;
+ if (!label)
+ return WTF::nullopt;
+
+ return {{ *value, *label }};
+}
+
struct DataListSuggestionInformation {
DataListSuggestionActivationType activationType;
- Vector<String> suggestions;
+ Vector<DataListSuggestion> suggestions;
IntRect elementRect;
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static Optional<DataListSuggestionInformation> decode(Decoder&);
};
+template<class Encoder>
+void DataListSuggestionInformation::encode(Encoder& encoder) const
+{
+ encoder.encodeEnum(activationType);
+ encoder << suggestions;
+ encoder << elementRect;
}
+
+template<class Decoder>
+Optional<DataListSuggestionInformation> DataListSuggestionInformation::decode(Decoder& decoder)
+{
+ DataListSuggestionActivationType activationType;
+ if (!decoder.decodeEnum(activationType))
+ return WTF::nullopt;
+
+ Optional<Vector<DataListSuggestion>> suggestions;
+ decoder >> suggestions;
+ if (!suggestions)
+ return WTF::nullopt;
+
+ Optional<IntRect> elementRect;
+ decoder >> elementRect;
+ if (!elementRect)
+ return WTF::nullopt;
+
+ return {{ activationType, *suggestions, *elementRect }};
+}
+
+} // namespace WebCore
+
#endif
Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (259329 => 259330)
--- trunk/Source/WebCore/html/TextFieldInputType.cpp 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp 2020-04-01 01:22:59 UTC (rev 259330)
@@ -828,7 +828,7 @@
void TextFieldInputType::listAttributeTargetChanged()
{
- m_cachedSuggestions = std::make_pair(String(), Vector<String>());
+ m_cachedSuggestions = { };
if (!m_dataListDropdownIndicator)
createDataListDropdownIndicator();
@@ -856,12 +856,12 @@
return element()->document().view()->contentsToRootView(element()->renderer()->absoluteBoundingBoxRect());
}
-Vector<String> TextFieldInputType::suggestions()
+Vector<DataListSuggestion> TextFieldInputType::suggestions()
{
// FIXME: Suggestions are "typing completions" and so should probably use the findPlainText algorithm rather than the simplistic "ignoring ASCII case" rules.
- Vector<String> suggestions;
- Vector<String> matchesContainingValue;
+ Vector<DataListSuggestion> suggestions;
+ Vector<DataListSuggestion> matchesContainingValue;
String elementValue = element()->value();
@@ -868,22 +868,27 @@
if (!m_cachedSuggestions.first.isNull() && equalIgnoringASCIICase(m_cachedSuggestions.first, elementValue))
return m_cachedSuggestions.second;
+ auto* page = element()->document().page();
+ bool canShowLabels = page && page->chrome().client().canShowDataListSuggestionLabels();
if (auto dataList = element()->dataList()) {
for (auto& option : dataList->suggestions()) {
- String value = option.value();
- if (!element()->isValidValue(value))
+ DataListSuggestion suggestion;
+ suggestion.value = option.value();
+ if (!element()->isValidValue(suggestion.value))
continue;
- value = sanitizeValue(value);
- if (elementValue.isEmpty())
- suggestions.append(value);
- else if (value.startsWithIgnoringASCIICase(elementValue))
- suggestions.append(value);
- else if (value.containsIgnoringASCIICase(elementValue))
- matchesContainingValue.append(value);
+ suggestion.value = sanitizeValue(suggestion.value);
+ suggestion.label = option.label();
+ if (suggestion.value == suggestion.label)
+ suggestion.label = { };
+
+ if (elementValue.isEmpty() || suggestion.value.startsWithIgnoringASCIICase(elementValue))
+ suggestions.append(WTFMove(suggestion));
+ else if (suggestion.value.containsIgnoringASCIICase(elementValue) || (canShowLabels && suggestion.label.containsIgnoringASCIICase(elementValue)))
+ matchesContainingValue.append(WTFMove(suggestion));
}
}
- suggestions.appendVector(matchesContainingValue);
+ suggestions.appendVector(WTFMove(matchesContainingValue));
m_cachedSuggestions = std::make_pair(elementValue, suggestions);
return suggestions;
@@ -896,7 +901,7 @@
void TextFieldInputType::didCloseSuggestions()
{
- m_cachedSuggestions = std::make_pair(String(), Vector<String>());
+ m_cachedSuggestions = { };
m_suggestionPicker = nullptr;
if (element()->renderer())
element()->renderer()->repaint();
Modified: trunk/Source/WebCore/html/TextFieldInputType.h (259329 => 259330)
--- trunk/Source/WebCore/html/TextFieldInputType.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/html/TextFieldInputType.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -132,7 +132,7 @@
// DataListSuggestionsClient
IntRect elementRectInRootViewCoordinates() const final;
- Vector<String> suggestions() final;
+ Vector<DataListSuggestion> suggestions() final;
void didSelectDataListOption(const String&) final;
void didCloseSuggestions() final;
@@ -139,7 +139,7 @@
void dataListButtonElementWasClicked() final;
RefPtr<DataListButtonElement> m_dataListDropdownIndicator;
- std::pair<String, Vector<String>> m_cachedSuggestions;
+ std::pair<String, Vector<DataListSuggestion>> m_cachedSuggestions;
std::unique_ptr<DataListSuggestionPicker> m_suggestionPicker;
#endif
Modified: trunk/Source/WebCore/loader/EmptyClients.h (259329 => 259330)
--- trunk/Source/WebCore/loader/EmptyClients.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/loader/EmptyClients.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -133,6 +133,7 @@
#if ENABLE(DATALIST_ELEMENT)
std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&) final;
+ bool canShowDataListSuggestionLabels() const final { return false; }
#endif
void runOpenPanel(Frame&, FileChooser&) final;
Modified: trunk/Source/WebCore/page/ChromeClient.h (259329 => 259330)
--- trunk/Source/WebCore/page/ChromeClient.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/page/ChromeClient.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -279,6 +279,7 @@
#if ENABLE(DATALIST_ELEMENT)
virtual std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&) = 0;
+ virtual bool canShowDataListSuggestionLabels() const = 0;
#endif
virtual void runOpenPanel(Frame&, FileChooser&) = 0;
Modified: trunk/Source/WebCore/platform/DataListSuggestionsClient.h (259329 => 259330)
--- trunk/Source/WebCore/platform/DataListSuggestionsClient.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebCore/platform/DataListSuggestionsClient.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -32,6 +32,7 @@
namespace WebCore {
class IntRect;
+struct DataListSuggestion;
class DataListSuggestionsClient {
public:
@@ -38,7 +39,7 @@
virtual ~DataListSuggestionsClient() = default;
virtual IntRect elementRectInRootViewCoordinates() const = 0;
- virtual Vector<String> suggestions() = 0;
+ virtual Vector<DataListSuggestion> suggestions() = 0;
virtual void didSelectDataListOption(const String&) = 0;
virtual void didCloseSuggestions() = 0;
Modified: trunk/Source/WebKit/ChangeLog (259329 => 259330)
--- trunk/Source/WebKit/ChangeLog 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/ChangeLog 2020-04-01 01:22:59 UTC (rev 259330)
@@ -1,3 +1,91 @@
+2020-03-31 Wenson Hsieh <[email protected]>
+
+ Datalist option's label not used
+ https://bugs.webkit.org/show_bug.cgi?id=201768
+ <rdar://problem/55361186>
+
+ Reviewed by Darin Adler.
+
+ Add support on macOS for showing option labels in datalist suggestions.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<DataListSuggestionInformation>::encode): Deleted.
+ (IPC::ArgumentCoder<DataListSuggestionInformation>::decode): Deleted.
+ * Shared/WebCoreArgumentCoders.h:
+
+ Remove WebCoreArgumentCoders logic for encoding and decoding DataListSuggestionInformation. See
+ DataListSuggestionInformation.h in WebCore for more detail.
+
+ * UIProcess/gtk/WebDataListSuggestionsDropdownGtk.cpp:
+ (WebKit::WebDataListSuggestionsDropdownGtk::show):
+
+ Tweak GTK code to adjust for the change from `String` to `DataListSuggestion`.
+
+ * UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm:
+ (-[WKDataListSuggestionsControl didSelectOptionAtIndex:]):
+ (-[WKDataListSuggestionsControl textSuggestions]):
+ (-[WKDataListSuggestionsControl suggestionAtIndex:]):
+
+ Adjust some iOS codepaths to use DataListSuggestion::value as the value string to display.
+
+ * UIProcess/mac/WebDataListSuggestionsDropdownMac.mm:
+
+ Tweak several UI constants. A suggestion cell may now be either 20 or 40pt tall, depending on whether it has
+ label text to show.
+
+ Currently, the maximum combined height of the table view cells is 120 (not including spacing between cells and
+ vertical padding around the top and bottom of the table view), since the maximum number of cells to show is 6
+ and each cell is 20pt tall. Maintain this constant by making the maximum cell height 120, which accomodates
+ either three labeled cells, or 6 unlabeled cells (i.e. to match shipping behavior).
+
+ (-[WKDataListSuggestionView initWithFrame:]):
+ (-[WKDataListSuggestionView layout]):
+
+ Maintain two text fields or value and (optionally) label text: `_valueField` and `_labelField`. The value field
+ fills the bounds of the cell in the case where there is no label text, but fills only the top half of the cell
+ in the case where there is label text. The label field takes the bottom half of the cell in this case.
+
+ Additionally, add a divider view that may appear at the very bottom of each cell. This divider view is present
+ when one or more suggestions in the datalist are labeled.
+
+ (-[WKDataListSuggestionView setValue:label:]):
+
+ Renamed from -setText:. Add a label string argument as well.
+
+ (-[WKDataListSuggestionView setShouldShowBottomDivider:]):
+
+ Add getters and setters for the -shouldShowBottomDivider property, which can be used to make the divider view
+ visible or hidden.
+
+ (-[WKDataListSuggestionView shouldShowBottomDivider]):
+ (-[WKDataListSuggestionView setBackgroundStyle:]):
+
+ Use -[NSColor secondaryLabelColor] for the label text field.
+
+ (shouldShowDividersBetweenCells):
+
+ Add a helper method to determine whether the table view should be showing clear dividers between each item.
+ We only do so if there are one or more labels to be shown.
+
+ (-[WKDataListSuggestionsController initWithInformation:inView:]):
+ (-[WKDataListSuggestionsController currentSelectedString]):
+ (-[WKDataListSuggestionsController updateWithInformation:]):
+ (-[WKDataListSuggestionsController moveSelectionByDirection:]):
+
+ Drive-by fix: scroll to reveal each selected row when using the arrow keys to navigate between items.
+
+ (-[WKDataListSuggestionsController dropdownRectForElementRect:]):
+ (-[WKDataListSuggestionsController tableView:heightOfRow:]):
+
+ Return either `dropdownRowHeightWithoutLabel` or `dropdownRowHeightWithLabel`, depending on whether there is
+ label text to be shown in that suggestion cell.
+
+ (-[WKDataListSuggestionsController tableView:viewForTableColumn:row:]):
+ (-[WKDataListSuggestionView setText:]): Deleted.
+ * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+ (WebKit::WebChromeClient::canShowDataListSuggestionLabels const):
+ * WebProcess/WebCoreSupport/WebChromeClient.h:
+
2020-03-31 Per Arne Vollan <[email protected]>
[macOS] Deny mach-lookup access to "com.apple.lsd.mapdb" in sandbox
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (259329 => 259330)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2020-04-01 01:22:59 UTC (rev 259330)
@@ -39,7 +39,6 @@
#include <WebCore/CompositionUnderline.h>
#include <WebCore/Credential.h>
#include <WebCore/Cursor.h>
-#include <WebCore/DataListSuggestionPicker.h>
#include <WebCore/DatabaseDetails.h>
#include <WebCore/DictationAlternative.h>
#include <WebCore/DictionaryPopupInfo.h>
@@ -1721,29 +1720,6 @@
return true;
}
-#if ENABLE(DATALIST_ELEMENT)
-void ArgumentCoder<DataListSuggestionInformation>::encode(Encoder& encoder, const WebCore::DataListSuggestionInformation& info)
-{
- encoder.encodeEnum(info.activationType);
- encoder << info.suggestions;
- encoder << info.elementRect;
-}
-
-bool ArgumentCoder<DataListSuggestionInformation>::decode(Decoder& decoder, WebCore::DataListSuggestionInformation& info)
-{
- if (!decoder.decodeEnum(info.activationType))
- return false;
-
- if (!decoder.decode(info.suggestions))
- return false;
-
- if (!decoder.decode(info.elementRect))
- return false;
-
- return true;
-}
-#endif
-
template<> struct ArgumentCoder<PasteboardCustomData::Entry> {
static void encode(Encoder&, const PasteboardCustomData::Entry&);
static bool decode(Decoder&, PasteboardCustomData::Entry&);
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (259329 => 259330)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -163,10 +163,6 @@
struct ViewportArguments;
#endif
-#if ENABLE(DATALIST_ELEMENT)
-struct DataListSuggestionInformation;
-#endif
-
#if USE(SOUP)
struct SoupNetworkProxySettings;
#endif
@@ -543,13 +539,6 @@
static bool decode(Decoder&, WebCore::DatabaseDetails&);
};
-#if ENABLE(DATALIST_ELEMENT)
-template<> struct ArgumentCoder<WebCore::DataListSuggestionInformation> {
- static void encode(Encoder&, const WebCore::DataListSuggestionInformation&);
- static bool decode(Decoder&, WebCore::DataListSuggestionInformation&);
-};
-#endif
-
template<> struct ArgumentCoder<WebCore::DictationAlternative> {
static void encode(Encoder&, const WebCore::DictationAlternative&);
static Optional<WebCore::DictationAlternative> decode(Decoder&);
Modified: trunk/Source/WebKit/UIProcess/gtk/WebDataListSuggestionsDropdownGtk.cpp (259329 => 259330)
--- trunk/Source/WebKit/UIProcess/gtk/WebDataListSuggestionsDropdownGtk.cpp 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/UIProcess/gtk/WebDataListSuggestionsDropdownGtk.cpp 2020-04-01 01:22:59 UTC (rev 259330)
@@ -120,7 +120,7 @@
for (const auto& suggestion : information.suggestions) {
GtkTreeIter iter;
gtk_list_store_append(model, &iter);
- gtk_list_store_set(model, &iter, 0, suggestion.utf8().data(), -1);
+ gtk_list_store_set(model, &iter, 0, suggestion.value.utf8().data(), -1);
}
GtkRequisition treeViewRequisition;
Modified: trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm (259329 => 259330)
--- trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/UIProcess/ios/WebDataListSuggestionsDropdownIOS.mm 2020-04-01 01:22:59 UTC (rev 259330)
@@ -42,7 +42,7 @@
@interface WKDataListSuggestionsControl : NSObject {
WeakPtr<WebKit::WebDataListSuggestionsDropdownIOS> _dropdown;
- Vector<String> _suggestions;
+ Vector<WebCore::DataListSuggestion> _suggestions;
}
@property (nonatomic, weak) WKContentView *view;
@@ -159,7 +159,7 @@
- (void)didSelectOptionAtIndex:(NSInteger)index
{
- _dropdown->didSelectOption(_suggestions[index]);
+ _dropdown->didSelectOption(_suggestions[index].value);
}
- (void)invalidate
@@ -171,7 +171,7 @@
NSMutableArray *suggestions = [NSMutableArray array];
for (const auto& suggestion : _suggestions) {
- [suggestions addObject:[WKDataListTextSuggestion textSuggestionWithInputText:suggestion]];
+ [suggestions addObject:[WKDataListTextSuggestion textSuggestionWithInputText:suggestion.value]];
if (suggestions.count == 3)
break;
}
@@ -186,7 +186,7 @@
- (String)suggestionAtIndex:(NSInteger)index
{
- return _suggestions[index];
+ return _suggestions[index].value;
}
- (NSTextAlignment)textAlignment
Modified: trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm (259329 => 259330)
--- trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/UIProcess/mac/WebDataListSuggestionsDropdownMac.mm 2020-04-01 01:22:59 UTC (rev 259330)
@@ -34,10 +34,11 @@
#import <WebCore/LocalizedStrings.h>
#import <pal/spi/cocoa/NSColorSPI.h>
-static const CGFloat dropdownTopMargin = 3;
-static const CGFloat dropdownVerticalPadding = 4;
-static const CGFloat dropdownRowHeight = 20;
-static const size_t dropdownMaxSuggestions = 6;
+constexpr CGFloat dropdownTopMargin = 3;
+constexpr CGFloat dropdownVerticalPadding = 4;
+constexpr CGFloat dropdownRowHeightWithoutLabel = 20;
+constexpr CGFloat dropdownRowHeightWithLabel = 40;
+constexpr CGFloat maximumTotalHeightForDropdownCells = 120;
static NSString * const suggestionCellReuseIdentifier = @"WKDataListSuggestionView";
@interface WKDataListSuggestionWindow : NSWindow
@@ -44,6 +45,7 @@
@end
@interface WKDataListSuggestionView : NSTableCellView
+@property (nonatomic) BOOL shouldShowBottomDivider;
@end
@interface WKDataListSuggestionTableRowView : NSTableRowView
@@ -169,7 +171,9 @@
@end
@implementation WKDataListSuggestionView {
- RetainPtr<NSTextField> _textField;
+ RetainPtr<NSTextField> _valueField;
+ RetainPtr<NSTextField> _labelField;
+ RetainPtr<NSView> _bottomDivider;
}
- (id)initWithFrame:(NSRect)frameRect
@@ -177,31 +181,78 @@
if (!(self = [super initWithFrame:frameRect]))
return self;
- _textField = adoptNS([[NSTextField alloc] initWithFrame:frameRect]);
- self.textField = _textField.get();
+ _valueField = adoptNS([[NSTextField alloc] init]);
+ _labelField = adoptNS([[NSTextField alloc] init]);
+ _bottomDivider = adoptNS([[NSView alloc] init]);
+ [_bottomDivider setWantsLayer:YES];
+ [_bottomDivider setHidden:YES];
+ [_bottomDivider layer].backgroundColor = NSColor.separatorColor.CGColor;
+ [self addSubview:_bottomDivider.get()];
- [self addSubview:self.textField];
+ auto setUpTextField = [&](NSTextField *textField) {
+ textField.editable = NO;
+ textField.bezeled = NO;
+ textField.font = [NSFont menuFontOfSize:0];
+ textField.drawsBackground = NO;
+ [self addSubview:textField];
+ };
+ setUpTextField(_valueField.get());
+ setUpTextField(_labelField.get());
self.identifier = suggestionCellReuseIdentifier;
- self.textField.editable = NO;
- self.textField.bezeled = NO;
- self.textField.font = [NSFont menuFontOfSize:0];
- self.textField.drawsBackground = NO;
return self;
}
-- (void)setText:(NSString *)text
+- (void)layout
{
- self.textField.stringValue = text;
+ [super layout];
+
+ auto bounds = self.bounds;
+ auto width = bounds.size.width;
+ if (![_labelField isHidden]) {
+ auto halfOfHeight = bounds.size.height / 2;
+ [_valueField setFrame:NSMakeRect(0, halfOfHeight, width, halfOfHeight)];
+ [_labelField setFrame:NSMakeRect(0, 0, width, halfOfHeight)];
+ } else
+ [_valueField setFrame:bounds];
+
+ if (![_bottomDivider isHidden])
+ [_bottomDivider setFrame:NSMakeRect(0, 0, width, 0.5)];
}
+- (void)setValue:(NSString *)value label:(NSString *)label
+{
+ if ([[_valueField stringValue] isEqualToString:value] && [[_labelField stringValue] isEqualToString:label])
+ return;
+
+ [_valueField setStringValue:value];
+ [_labelField setStringValue:label];
+ [_labelField setHidden:!label.length];
+ self.needsLayout = YES;
+}
+
+- (void)setShouldShowBottomDivider:(BOOL)showBottomDivider
+{
+ if ([_bottomDivider isHidden] == !showBottomDivider)
+ return;
+
+ [_bottomDivider setHidden:!showBottomDivider];
+ self.needsLayout = YES;
+}
+
+- (BOOL)shouldShowBottomDivider
+{
+ return [_bottomDivider isHidden];
+}
+
- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle
{
[super setBackgroundStyle:backgroundStyle];
- ALLOW_DEPRECATED_DECLARATIONS_BEGIN
- self.textField.textColor = backgroundStyle == NSBackgroundStyleLight ? [NSColor textColor] : [NSColor alternateSelectedControlTextColor];
- ALLOW_DEPRECATED_DECLARATIONS_END
+ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+ [_valueField setTextColor:backgroundStyle == NSBackgroundStyleLight ? NSColor.textColor : NSColor.alternateSelectedControlTextColor];
+ [_labelField setTextColor:NSColor.secondaryLabelColor];
+ALLOW_DEPRECATED_DECLARATIONS_END
}
- (BOOL)acceptsFirstResponder
@@ -251,14 +302,22 @@
@end
+static BOOL shouldShowDividersBetweenCells(const Vector<WebCore::DataListSuggestion>& suggestions)
+{
+ return notFound != suggestions.findMatching([](auto& suggestion) {
+ return !suggestion.label.isEmpty();
+ });
+}
+
@implementation WKDataListSuggestionsController {
WeakPtr<WebKit::WebDataListSuggestionsDropdownMac> _dropdown;
- Vector<String> _suggestions;
+ Vector<WebCore::DataListSuggestion> _suggestions;
NSView *_presentingView;
RetainPtr<NSScrollView> _scrollView;
RetainPtr<WKDataListSuggestionWindow> _enclosingWindow;
RetainPtr<WKDataListSuggestionTableView> _table;
+ BOOL _showDividersBetweenCells;
}
- (id)initWithInformation:(WebCore::DataListSuggestionInformation&&)information inView:(NSView *)presentingView
@@ -268,6 +327,7 @@
_presentingView = presentingView;
_suggestions = WTFMove(information.suggestions);
+ _showDividersBetweenCells = shouldShowDividersBetweenCells(_suggestions);
_table = adoptNS([[WKDataListSuggestionTableView alloc] initWithElementRect:information.elementRect]);
_enclosingWindow = adoptNS([[WKDataListSuggestionWindow alloc] initWithContentRect:NSZeroRect styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
@@ -302,7 +362,7 @@
NSInteger selectedRow = [_table selectedRow];
if (selectedRow >= 0 && static_cast<size_t>(selectedRow) < _suggestions.size())
- return _suggestions.at(selectedRow);
+ return _suggestions.at(selectedRow).value;
return String();
}
@@ -310,6 +370,7 @@
- (void)updateWithInformation:(WebCore::DataListSuggestionInformation&&)information
{
_suggestions = WTFMove(information.suggestions);
+ _showDividersBetweenCells = shouldShowDividersBetweenCells(_suggestions);
[_table reload];
[_enclosingWindow setFrame:[self dropdownRectForElementRect:information.elementRect] display:YES];
@@ -339,6 +400,7 @@
newSelection = (direction == "Up") ? (size - 1) : 0;
[_table selectRowIndexes:[NSIndexSet indexSetWithIndex:newSelection] byExtendingSelection:NO];
+ [_table scrollRowToVisible:newSelection];
// Notify accessibility clients of new selection.
NSString *currentSelectedString = [self currentSelectedString];
@@ -369,8 +431,16 @@
- (NSRect)dropdownRectForElementRect:(const WebCore::IntRect&)rect
{
NSRect windowRect = [[_presentingView window] convertRectToScreen:[_presentingView convertRect:rect toView:nil]];
- auto visibleSuggestionCount = std::min(_suggestions.size(), dropdownMaxSuggestions);
- CGFloat height = visibleSuggestionCount * (dropdownRowHeight + [_table intercellSpacing].height) + (dropdownVerticalPadding * 2);
+
+ CGFloat totalCellHeight = 0;
+ for (auto& suggestion : _suggestions)
+ totalCellHeight += suggestion.label.isEmpty() ? dropdownRowHeightWithoutLabel : dropdownRowHeightWithLabel;
+
+ CGFloat totalIntercellSpacingAndPadding = dropdownVerticalPadding * 2;
+ if (_suggestions.size() > 1)
+ totalIntercellSpacingAndPadding += (_suggestions.size() - 1) * [_table intercellSpacing].height;
+
+ CGFloat height = totalIntercellSpacingAndPadding + std::min(totalCellHeight, maximumTotalHeightForDropdownCells);
return NSMakeRect(NSMinX(windowRect), NSMinY(windowRect) - height - dropdownTopMargin, rect.width(), height);
}
@@ -404,7 +474,13 @@
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
- return dropdownRowHeight;
+ auto suggestionIndex = static_cast<size_t>(row);
+ if (suggestionIndex >= _suggestions.size()) {
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+
+ return _suggestions.at(suggestionIndex).label.isEmpty() ? dropdownRowHeightWithoutLabel : dropdownRowHeightWithLabel;
}
- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
@@ -417,11 +493,13 @@
WKDataListSuggestionView *result = [tableView makeViewWithIdentifier:suggestionCellReuseIdentifier owner:self];
if (!result) {
- result = [[[WKDataListSuggestionView alloc] initWithFrame:NSMakeRect(0, 0, tableView.frame.size.width, dropdownRowHeight)] autorelease];
+ result = [[[WKDataListSuggestionView alloc] init] autorelease];
[result setIdentifier:suggestionCellReuseIdentifier];
}
- result.text = _suggestions.at(row);
+ auto& suggestion = _suggestions.at(row);
+ result.shouldShowBottomDivider = _showDividersBetweenCells && row < static_cast<NSInteger>(_suggestions.size() - 1);
+ [result setValue:suggestion.value label:suggestion.label];
return result;
}
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (259329 => 259330)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2020-04-01 01:22:59 UTC (rev 259330)
@@ -796,8 +796,17 @@
return makeUnique<WebDataListSuggestionPicker>(m_page, client);
}
+bool WebChromeClient::canShowDataListSuggestionLabels() const
+{
+#if PLATFORM(MAC)
+ return true;
+#else
+ return false;
#endif
+}
+#endif
+
void WebChromeClient::runOpenPanel(Frame& frame, FileChooser& fileChooser)
{
if (m_page.activeOpenPanelResultListener())
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (259329 => 259330)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -149,6 +149,7 @@
#if ENABLE(DATALIST_ELEMENT)
std::unique_ptr<WebCore::DataListSuggestionPicker> createDataListSuggestionPicker(WebCore::DataListSuggestionsClient&) final;
+ bool canShowDataListSuggestionLabels() const final;
#endif
#if ENABLE(IOS_TOUCH_EVENTS)
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (259329 => 259330)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2020-04-01 01:22:59 UTC (rev 259330)
@@ -1,3 +1,15 @@
+2020-03-31 Wenson Hsieh <[email protected]>
+
+ Datalist option's label not used
+ https://bugs.webkit.org/show_bug.cgi?id=201768
+ <rdar://problem/55361186>
+
+ Reviewed by Darin Adler.
+
+ See WebCore/ChangeLog and WebKit/ChangeLog for more details.
+
+ * WebCoreSupport/WebChromeClient.h:
+
2020-03-30 Devin Rousso <[email protected]>
Web Inspector: provide a way to log messages from the network process
Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.h (259329 => 259330)
--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.h 2020-04-01 00:55:30 UTC (rev 259329)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.h 2020-04-01 01:22:59 UTC (rev 259330)
@@ -144,6 +144,7 @@
#if ENABLE(DATALIST_ELEMENT)
std::unique_ptr<WebCore::DataListSuggestionPicker> createDataListSuggestionPicker(WebCore::DataListSuggestionsClient&) final;
+ bool canShowDataListSuggestionLabels() const final { return false; }
#endif
#if ENABLE(POINTER_LOCK)