[Datalist] Allow TextFieldInputType to show and hide suggestions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2018 21:08:58 +0000 (21:08 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2018 21:08:58 +0000 (21:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186151

Patch by Aditya Keerthi <akeerthi@apple.com> on 2018-06-08
Reviewed by Tim Horton.

Source/WebCore:

TextFieldInputTypes with a list attribute should be able to display suggestions as the user
interacts with the input field. In order to display suggestions for an input field with a list
attribute, we need provide certain information - including the items to suggest and the location
to present the suggestions. TextFieldInputType can now provide this information by conforming to
the DataListSuggestionsClient interface.

In this initial patch, the suggestions can be shown in two ways. The first is by clicking on the
input field. The other is by typing text in the field. In a later patch, we will add a third way
to display suggestions, using a button. These ways to activate the suggestions are enumerated in
DataListSuggestionInformation.

We hide the suggestions if there are no more to show, or if the input has blurred.

Tests to be added once work has been done in the UIProcess.

* WebCore.xcodeproj/project.pbxproj:
* html/DataListSuggestionInformation.h: Added. Contains the information necessary to display suggestions.
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::~TextFieldInputType):
(WebCore::TextFieldInputType::handleClickEvent): Show suggestions when the element is clicked.
(WebCore::TextFieldInputType::handleKeydownEvent): Allow users to interact with the suggestions using the keyboard.
(WebCore::TextFieldInputType::elementDidBlur): Hide the suggestions.
(WebCore::TextFieldInputType::shouldRespectListAttribute):
(WebCore::TextFieldInputType::didSetValueByUserEdit): Update the suggestions if the text has changed.
(WebCore::TextFieldInputType::elementRectRelativeToRootView const): Provide the location where the suggestions should be shown.
(WebCore::TextFieldInputType::suggestions const): Provide the list of suggestions.
(WebCore::TextFieldInputType::didSelectDataListOption): Update the text once an suggestion has been selected.
(WebCore::TextFieldInputType::didCloseSuggestions):
(WebCore::TextFieldInputType::displaySuggestions):
(WebCore::TextFieldInputType::closeSuggestions):
* html/TextFieldInputType.h:
* loader/EmptyClients.cpp:
(WebCore::EmptyChromeClient::createDataListSuggestionPicker):
* loader/EmptyClients.h:
* page/Chrome.cpp:
(WebCore::Chrome::createDataListSuggestionPicker):
* page/Chrome.h:
* page/ChromeClient.h:
* platform/DataListSuggestionPicker.h: Added.
(WebCore::DataListSuggestionPicker::close):
(WebCore::DataListSuggestionPicker::handleKeydownWithIdentifier):
(WebCore::DataListSuggestionPicker::displayWithActivationType):
* platform/DataListSuggestionsClient.h: Added.

Source/WebKit:

Added WebDataListSuggestionPicker to send messages to the UIProcess in order to update the suggestions view.
This object is also responsible for forwarding messages from WebKit into the DataListSuggestionsClient, which
is the TextFieldInputType in this case. The client needs to know when the suggestions are hidden or if an
suggestion has been selected.

* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::createDataListSuggestionPicker): Responsible for creating WebDataListSuggestionPicker to send/receive messages.
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebCoreSupport/WebDataListSuggestionPicker.cpp: Added. Responsible for sending messages to UIProcess and updating the DataListSuggestionsClient.
(WebKit::WebDataListSuggestionPicker::WebDataListSuggestionPicker):
(WebKit::WebDataListSuggestionPicker::~WebDataListSuggestionPicker):
(WebKit::WebDataListSuggestionPicker::handleKeydownWithIdentifier):
(WebKit::WebDataListSuggestionPicker::didSelectOption):
(WebKit::WebDataListSuggestionPicker::didCloseSuggestions):
(WebKit::WebDataListSuggestionPicker::close):
(WebKit::WebDataListSuggestionPicker::displayWithActivationType):
* WebProcess/WebCoreSupport/WebDataListSuggestionPicker.h: Added.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setActiveDataListSuggestionPicker):
(WebKit::WebPage::didSelectDataListOption): Called by UIProcess when option selected.
(WebKit::WebPage::didCloseSuggestions): Called by UIProcess if the suggestions view is closed.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebChromeClient.h:
* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::createDataListSuggestionPicker):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232640 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/DataListSuggestionInformation.h [new file with mode: 0644]
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/TextFieldInputType.h
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/Chrome.h
Source/WebCore/page/ChromeClient.h
Source/WebCore/platform/DataListSuggestionPicker.h [new file with mode: 0644]
Source/WebCore/platform/DataListSuggestionsClient.h [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.cpp [new file with mode: 0644]
Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.h [new file with mode: 0644]
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.h
Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.mm

index 0e4a257..7ad212e 100644 (file)
@@ -1,3 +1,54 @@
+2018-06-08  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist] Allow TextFieldInputType to show and hide suggestions
+        https://bugs.webkit.org/show_bug.cgi?id=186151
+
+        Reviewed by Tim Horton.
+
+        TextFieldInputTypes with a list attribute should be able to display suggestions as the user
+        interacts with the input field. In order to display suggestions for an input field with a list
+        attribute, we need provide certain information - including the items to suggest and the location
+        to present the suggestions. TextFieldInputType can now provide this information by conforming to
+        the DataListSuggestionsClient interface.
+
+        In this initial patch, the suggestions can be shown in two ways. The first is by clicking on the
+        input field. The other is by typing text in the field. In a later patch, we will add a third way
+        to display suggestions, using a button. These ways to activate the suggestions are enumerated in
+        DataListSuggestionInformation.
+
+        We hide the suggestions if there are no more to show, or if the input has blurred.
+
+        Tests to be added once work has been done in the UIProcess.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/DataListSuggestionInformation.h: Added. Contains the information necessary to display suggestions.
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::~TextFieldInputType):
+        (WebCore::TextFieldInputType::handleClickEvent): Show suggestions when the element is clicked.
+        (WebCore::TextFieldInputType::handleKeydownEvent): Allow users to interact with the suggestions using the keyboard.
+        (WebCore::TextFieldInputType::elementDidBlur): Hide the suggestions.
+        (WebCore::TextFieldInputType::shouldRespectListAttribute):
+        (WebCore::TextFieldInputType::didSetValueByUserEdit): Update the suggestions if the text has changed.
+        (WebCore::TextFieldInputType::elementRectRelativeToRootView const): Provide the location where the suggestions should be shown.
+        (WebCore::TextFieldInputType::suggestions const): Provide the list of suggestions.
+        (WebCore::TextFieldInputType::didSelectDataListOption): Update the text once an suggestion has been selected.
+        (WebCore::TextFieldInputType::didCloseSuggestions):
+        (WebCore::TextFieldInputType::displaySuggestions):
+        (WebCore::TextFieldInputType::closeSuggestions):
+        * html/TextFieldInputType.h:
+        * loader/EmptyClients.cpp:
+        (WebCore::EmptyChromeClient::createDataListSuggestionPicker):
+        * loader/EmptyClients.h:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::createDataListSuggestionPicker):
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * platform/DataListSuggestionPicker.h: Added.
+        (WebCore::DataListSuggestionPicker::close):
+        (WebCore::DataListSuggestionPicker::handleKeydownWithIdentifier):
+        (WebCore::DataListSuggestionPicker::displayWithActivationType):
+        * platform/DataListSuggestionsClient.h: Added.
+
 2018-06-07  Ryosuke Niwa  <rniwa@webkit.org>
 
         REGRESSION(macOS Mojave): move-by-word-visually-inline-block-positioned-element.html fails
index 5f747df..7d51a06 100644 (file)
                E4E9B1191810916F003ACCDF /* SimpleLineLayoutResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B1181810916F003ACCDF /* SimpleLineLayoutResolver.h */; };
                E4E9B11D1814569C003ACCDF /* SimpleLineLayoutFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */; };
                E4F9EEF3156DA00700D23E7E /* StyleSheetContents.h in Headers */ = {isa = PBXBuildFile; fileRef = E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E517670320B88C1400D41167 /* DataListSuggestionInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = E517670220B88C1400D41167 /* DataListSuggestionInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E52CF54D20A268AC00DADA27 /* DataListSuggestionsClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E52CF54C20A268AC00DADA27 /* DataListSuggestionsClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E52CF54F20A35A2800DADA27 /* DataListSuggestionPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = E52CF54E20A35A2800DADA27 /* DataListSuggestionPicker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E5BA7D63151437CA00FE1E3F /* LengthFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E5BA7D62151437CA00FE1E3F /* LengthFunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */; };
                EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */ = {isa = PBXBuildFile; fileRef = EBF5121B1696496C0056BD25 /* JSTypeConversions.h */; };
                E4E9B11C1814569C003ACCDF /* SimpleLineLayoutFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutFunctions.h; sourceTree = "<group>"; };
                E4F9EEF0156D84C400D23E7E /* StyleSheetContents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSheetContents.cpp; sourceTree = "<group>"; };
                E4F9EEF1156D84C400D23E7E /* StyleSheetContents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSheetContents.h; sourceTree = "<group>"; };
+               E517670220B88C1400D41167 /* DataListSuggestionInformation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataListSuggestionInformation.h; sourceTree = "<group>"; };
                E51A81DE17298D7700BFCA61 /* JSPerformance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPerformance.cpp; sourceTree = "<group>"; };
                E526AF3E1727F8F200E41781 /* Performance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Performance.cpp; sourceTree = "<group>"; };
+               E52CF54C20A268AC00DADA27 /* DataListSuggestionsClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataListSuggestionsClient.h; sourceTree = "<group>"; };
+               E52CF54E20A35A2800DADA27 /* DataListSuggestionPicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataListSuggestionPicker.h; sourceTree = "<group>"; };
                E55F4979151B888000BB67DB /* LengthFunctions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LengthFunctions.cpp; sourceTree = "<group>"; };
                E5BA7D62151437CA00FE1E3F /* LengthFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthFunctions.h; sourceTree = "<group>"; };
                EB081CD81696084400553730 /* TypeConversions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeConversions.h; sourceTree = "<group>"; };
                                93C441FF0F813AE100C1A634 /* CollectionType.h */,
                                BC29935C17A1DD5800BCE880 /* ColorInputType.cpp */,
                                F55B3D801251F12D003EF269 /* ColorInputType.h */,
+                               E517670220B88C1400D41167 /* DataListSuggestionInformation.h */,
                                F55B3D811251F12D003EF269 /* DateInputType.cpp */,
                                F55B3D821251F12D003EF269 /* DateInputType.h */,
                                F55B3D831251F12D003EF269 /* DateTimeInputType.cpp */,
                                46C696C91E7205E400597937 /* CPUMonitor.h */,
                                E11AF15011B9A1A300805103 /* Cursor.cpp */,
                                F587868402DE3B8601EA4122 /* Cursor.h */,
+                               E52CF54E20A35A2800DADA27 /* DataListSuggestionPicker.h */,
+                               E52CF54C20A268AC00DADA27 /* DataListSuggestionsClient.h */,
                                A5732B08136A161D005C8D7C /* DateComponents.cpp */,
                                A5732B09136A161D005C8D7C /* DateComponents.h */,
                                37C738F11EDBDE87003F2B0B /* DateTimeChooser.h */,
                                BE23480D18A9871400E4B6E8 /* DataCue.h in Headers */,
                                C5227DF11C3C6DF100F5ED54 /* DataDetection.h in Headers */,
                                7C7941E51C56C29300A4C58E /* DataDetectorsCoreSoftLink.h in Headers */,
+                               E517670320B88C1400D41167 /* DataListSuggestionInformation.h in Headers */,
+                               E52CF54F20A35A2800DADA27 /* DataListSuggestionPicker.h in Headers */,
+                               E52CF54D20A268AC00DADA27 /* DataListSuggestionsClient.h in Headers */,
                                BC22746F0E83664500E7F975 /* DataRef.h in Headers */,
                                BC64641C11D7F416006455B0 /* DatasetDOMStringMap.h in Headers */,
                                85031B3E0A44EFC700F992E0 /* DataTransfer.h in Headers */,
diff --git a/Source/WebCore/html/DataListSuggestionInformation.h b/Source/WebCore/html/DataListSuggestionInformation.h
new file mode 100644 (file)
index 0000000..8c449ef
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "IntRect.h"
+
+#if ENABLE(DATALIST_ELEMENT)
+namespace WebCore {
+
+enum class DataListSuggestionActivationType {
+    ControlClicked,
+    IndicatorClicked,
+    TextChanged,
+};
+
+struct DataListSuggestionInformation {
+    DataListSuggestionActivationType activationType;
+    Vector<String> suggestions;
+    IntRect elementRect;
+};
+
+}
+#endif
index dc054fe..4ab5b39 100644 (file)
 #include "TextNodeTraversal.h"
 #include "WheelEvent.h"
 
+#if ENABLE(DATALIST_ELEMENT)
+#include "HTMLDataListElement.h"
+#include "HTMLOptionElement.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -71,6 +76,9 @@ TextFieldInputType::~TextFieldInputType()
 {
     if (m_innerSpinButton)
         m_innerSpinButton->removeSpinButtonOwner();
+#if ENABLE(DATALIST_ELEMENT)
+    closeSuggestions();
+#endif
 }
 
 bool TextFieldInputType::isKeyboardFocusable(KeyboardEvent*) const
@@ -161,11 +169,24 @@ void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange
         input->setTextAsOfLastFormControlChangeEvent(sanitizedValue);
 }
 
+#if ENABLE(DATALIST_ELEMENT)
+void TextFieldInputType::handleClickEvent(MouseEvent&)
+{
+    if (element()->focused() && element()->list())
+        displaySuggestions(DataListSuggestionActivationType::ControlClicked);
+}
+#endif
+
 void TextFieldInputType::handleKeydownEvent(KeyboardEvent& event)
 {
     ASSERT(element());
     if (!element()->focused())
         return;
+#if ENABLE(DATALIST_ELEMENT)
+    const String& key = event.keyIdentifier();
+    if (m_suggestionPicker && (key == "Enter" || key == "Up" || key == "Down"))
+        m_suggestionPicker->handleKeydownWithIdentifier(key);
+#endif
     RefPtr<Frame> frame = element()->document().frame();
     if (!frame || !frame->editor().doTextFieldCommandFromEvent(element(), &event))
         return;
@@ -223,6 +244,10 @@ void TextFieldInputType::elementDidBlur()
     bool isLeftToRightDirection = downcast<RenderTextControlSingleLine>(*renderer).style().isLeftToRightDirection();
     ScrollOffset scrollOffset(isLeftToRightDirection ? 0 : innerLayer->scrollWidth(), 0);
     innerLayer->scrollToOffset(scrollOffset);
+
+#if ENABLE(DATALIST_ELEMENT)
+    closeSuggestions();
+#endif
 }
 
 void TextFieldInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirection)
@@ -536,7 +561,11 @@ void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent&
 
 bool TextFieldInputType::shouldRespectListAttribute()
 {
+#if ENABLE(DATALIST_ELEMENT)
+    return true;
+#else
     return InputType::themeSupportsDataListUI(this);
+#endif
 }
 
 void TextFieldInputType::updatePlaceholderText()
@@ -607,6 +636,10 @@ void TextFieldInputType::didSetValueByUserEdit()
         return;
     if (RefPtr<Frame> frame = element()->document().frame())
         frame->editor().textDidChangeInTextField(element());
+#if ENABLE(DATALIST_ELEMENT)
+    if (element()->list())
+        displaySuggestions(DataListSuggestionActivationType::TextChanged);
+#endif
 }
 
 void TextFieldInputType::spinButtonStepDown()
@@ -751,4 +784,67 @@ void TextFieldInputType::updateAutoFillButton()
         m_autoFillButton->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);        
 }
 
+#if ENABLE(DATALIST_ELEMENT)
+
+IntRect TextFieldInputType::elementRectInRootViewCoordinates() const
+{
+    if (!element()->renderer())
+        return IntRect();
+    return element()->document().view()->contentsToRootView(element()->renderer()->absoluteBoundingBoxRect());
+}
+
+Vector<String> TextFieldInputType::suggestions() const
+{
+    Vector<String> suggestions;
+
+    if (auto dataList = element()->dataList()) {
+        Ref<HTMLCollection> options = dataList->options();
+        for (unsigned i = 0; auto* option = downcast<HTMLOptionElement>(options->item(i)); ++i) {
+            if (!element()->isValidValue(option->value()))
+                continue;
+
+            String value = sanitizeValue(option->value());
+            if (!suggestions.contains(value) && (element()->value().isEmpty() || value.containsIgnoringASCIICase(element()->value())))
+                suggestions.append(value);
+        }
+    }
+
+    return suggestions;
+}
+
+void TextFieldInputType::didSelectDataListOption(const String& selectedOption)
+{
+    element()->setValue(selectedOption, DispatchInputAndChangeEvent);
+}
+
+void TextFieldInputType::didCloseSuggestions()
+{
+    m_suggestionPicker = nullptr;
+}
+
+void TextFieldInputType::displaySuggestions(DataListSuggestionActivationType type)
+{
+    if (element()->isDisabledFormControl() || !element()->renderer())
+        return;
+
+    if (!UserGestureIndicator::processingUserGesture())
+        return;
+
+    if (!m_suggestionPicker && suggestions().size() > 0)
+        m_suggestionPicker = chrome()->createDataListSuggestionPicker(*this);
+
+    if (!m_suggestionPicker)
+        return;
+
+    m_suggestionPicker->displayWithActivationType(type);
+}
+
+void TextFieldInputType::closeSuggestions()
+{
+    if (m_suggestionPicker)
+        m_suggestionPicker->close();
+}
+
+#endif
+
 } // namespace WebCore
index a8954b5..34081bb 100644 (file)
@@ -32,6 +32,8 @@
 #pragma once
 
 #include "AutoFillButtonElement.h"
+#include "DataListSuggestionPicker.h"
+#include "DataListSuggestionsClient.h"
 #include "InputType.h"
 #include "SpinButtonElement.h"
 
@@ -42,12 +44,19 @@ class TextControlInnerTextElement;
 
 // The class represents types of which UI contain text fields.
 // It supports not only the types for BaseTextInputType but also type=number.
-class TextFieldInputType : public InputType, protected SpinButtonElement::SpinButtonOwner, protected AutoFillButtonElement::AutoFillButtonOwner {
+class TextFieldInputType : public InputType, protected SpinButtonElement::SpinButtonOwner, protected AutoFillButtonElement::AutoFillButtonOwner
+#if ENABLE(DATALIST_ELEMENT)
+    , private DataListSuggestionsClient
+#endif
+{
 protected:
     explicit TextFieldInputType(HTMLInputElement&);
     virtual ~TextFieldInputType();
     void handleKeydownEvent(KeyboardEvent&) override;
     void handleKeydownEventForSpinButton(KeyboardEvent&);
+#if ENABLE(DATALIST_ELEMENT)
+    void handleClickEvent(MouseEvent&) final;
+#endif
 
     HTMLElement* containerElement() const final;
     HTMLElement* innerBlockElement() const final;
@@ -110,6 +119,19 @@ private:
     void createContainer();
     void createAutoFillButton(AutoFillButtonType);
 
+#if ENABLE(DATALIST_ELEMENT)
+    void displaySuggestions(DataListSuggestionActivationType);
+    void closeSuggestions();
+
+    // DataListSuggestionsClient
+    IntRect elementRectInRootViewCoordinates() const final;
+    Vector<String> suggestions() const final;
+    void didSelectDataListOption(const String&) final;
+    void didCloseSuggestions() final;
+
+    std::unique_ptr<DataListSuggestionPicker> m_suggestionPicker;
+#endif
+
     RefPtr<HTMLElement> m_container;
     RefPtr<HTMLElement> m_innerBlock;
     RefPtr<TextControlInnerTextElement> m_innerText;
index c6e5eee..6053b87 100644 (file)
@@ -32,6 +32,7 @@
 #include "BackForwardClient.h"
 #include "ColorChooser.h"
 #include "ContextMenuClient.h"
+#include "DataListSuggestionPicker.h"
 #include "DatabaseProvider.h"
 #include "DiagnosticLoggingClient.h"
 #include "DocumentFragment.h"
@@ -423,6 +424,15 @@ std::unique_ptr<ColorChooser> EmptyChromeClient::createColorChooser(ColorChooser
 
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+
+std::unique_ptr<DataListSuggestionPicker> EmptyChromeClient::createDataListSuggestionPicker(DataListSuggestionsClient&)
+{
+    return nullptr;
+}
+
+#endif
+
 void EmptyChromeClient::runOpenPanel(Frame&, FileChooser&)
 {
 }
index e285f63..9d052b0 100644 (file)
@@ -132,6 +132,10 @@ class EmptyChromeClient : public ChromeClient {
     std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient&, const Color&) final;
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&) final;
+#endif
+
     void runOpenPanel(Frame&, FileChooser&) final;
     void loadIconForFiles(const Vector<String>&, FileIconLoader&) final { }
 
index 770a96b..ff69ede 100644 (file)
 #include "ColorChooser.h"
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+#include "DataListSuggestionPicker.h"
+#endif
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -422,6 +426,16 @@ std::unique_ptr<ColorChooser> Chrome::createColorChooser(ColorChooserClient& cli
 
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+
+std::unique_ptr<DataListSuggestionPicker> Chrome::createDataListSuggestionPicker(DataListSuggestionsClient& client)
+{
+    notifyPopupOpeningObservers();
+    return m_client.createDataListSuggestionPicker(client);
+}
+
+#endif
+
 void Chrome::runOpenPanel(Frame& frame, FileChooser& fileChooser)
 {
     notifyPopupOpeningObservers();
index 2174cbe..ccbce93 100644 (file)
@@ -37,6 +37,8 @@ namespace WebCore {
 class ChromeClient;
 class ColorChooser;
 class ColorChooserClient;
+class DataListSuggestionPicker;
+class DataListSuggestionsClient;
 class DateTimeChooser;
 class DateTimeChooserClient;
 class FileChooser;
@@ -152,6 +154,10 @@ public:
     std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient&, const Color& initialColor);
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&);
+#endif
+
     void runOpenPanel(Frame&, FileChooser&);
     void loadIconForFiles(const Vector<String>&, FileIconLoader&);
 
index e242237..bea0d8f 100644 (file)
@@ -68,6 +68,8 @@ namespace WebCore {
 class AccessibilityObject;
 class ColorChooser;
 class ColorChooserClient;
+class DataListSuggestionPicker;
+class DataListSuggestionsClient;
 class DateTimeChooser;
 class DateTimeChooserClient;
 class Element;
@@ -275,6 +277,10 @@ public:
     virtual std::unique_ptr<ColorChooser> createColorChooser(ColorChooserClient&, const Color&) = 0;
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    virtual std::unique_ptr<DataListSuggestionPicker> createDataListSuggestionPicker(DataListSuggestionsClient&) = 0;
+#endif
+
     virtual void runOpenPanel(Frame&, FileChooser&) = 0;
     // Asynchronous request to load an icon for specified filenames.
     virtual void loadIconForFiles(const Vector<String>&, FileIconLoader&) = 0;
diff --git a/Source/WebCore/platform/DataListSuggestionPicker.h b/Source/WebCore/platform/DataListSuggestionPicker.h
new file mode 100644 (file)
index 0000000..9ce192a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(DATALIST_ELEMENT)
+
+#import "DataListSuggestionInformation.h"
+#import "IntRect.h"
+
+#import <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class DataListSuggestionPicker {
+public:
+    virtual ~DataListSuggestionPicker() = default;
+
+    virtual void close() { }
+    virtual void handleKeydownWithIdentifier(const String&) { }
+    virtual void displayWithActivationType(DataListSuggestionActivationType) { }
+};
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/platform/DataListSuggestionsClient.h b/Source/WebCore/platform/DataListSuggestionsClient.h
new file mode 100644 (file)
index 0000000..abf5c6b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(DATALIST_ELEMENT)
+
+#include "IntRect.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class DataListSuggestionsClient {
+public:
+    virtual ~DataListSuggestionsClient() = default;
+
+    virtual IntRect elementRectInRootViewCoordinates() const = 0;
+    virtual Vector<String> suggestions() const = 0;
+
+    virtual void didSelectDataListOption(const String&) = 0;
+    virtual void didCloseSuggestions() = 0;
+};
+
+}
+
+#endif // ENABLE(DATALIST_ELEMENT)
index 07fa35e..4563ec8 100644 (file)
@@ -1,3 +1,35 @@
+2018-06-08  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist] Allow TextFieldInputType to show and hide suggestions
+        https://bugs.webkit.org/show_bug.cgi?id=186151
+
+        Reviewed by Tim Horton.
+
+        Added WebDataListSuggestionPicker to send messages to the UIProcess in order to update the suggestions view.
+        This object is also responsible for forwarding messages from WebKit into the DataListSuggestionsClient, which
+        is the TextFieldInputType in this case. The client needs to know when the suggestions are hidden or if an
+        suggestion has been selected.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::createDataListSuggestionPicker): Responsible for creating WebDataListSuggestionPicker to send/receive messages.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebCoreSupport/WebDataListSuggestionPicker.cpp: Added. Responsible for sending messages to UIProcess and updating the DataListSuggestionsClient.
+        (WebKit::WebDataListSuggestionPicker::WebDataListSuggestionPicker):
+        (WebKit::WebDataListSuggestionPicker::~WebDataListSuggestionPicker):
+        (WebKit::WebDataListSuggestionPicker::handleKeydownWithIdentifier):
+        (WebKit::WebDataListSuggestionPicker::didSelectOption):
+        (WebKit::WebDataListSuggestionPicker::didCloseSuggestions):
+        (WebKit::WebDataListSuggestionPicker::close):
+        (WebKit::WebDataListSuggestionPicker::displayWithActivationType):
+        * WebProcess/WebCoreSupport/WebDataListSuggestionPicker.h: Added.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setActiveDataListSuggestionPicker):
+        (WebKit::WebPage::didSelectDataListOption): Called by UIProcess when option selected.
+        (WebKit::WebPage::didCloseSuggestions): Called by UIProcess if the suggestions view is closed.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2018-06-08  Basuke Suzuki  <Basuke.Suzuki@sony.com>
 
         [Win] Fix initial value of HANDLE to INVALID_HANDLE_VALUE
index c931110..ea51b78 100644 (file)
                E49D40D91AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49D40D81AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp */; };
                E4E864921B16750100C82F40 /* VersionChecks.mm in Sources */ = {isa = PBXBuildFile; fileRef = E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */; };
                E4E864931B16750700C82F40 /* VersionChecks.h in Headers */ = {isa = PBXBuildFile; fileRef = E4E8648E1B1673FB00C82F40 /* VersionChecks.h */; };
+               E52CF55220A35C3A00DADA27 /* WebDataListSuggestionPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = E52CF55020A35C3A00DADA27 /* WebDataListSuggestionPicker.h */; };
+               E52CF55320A35C3A00DADA27 /* WebDataListSuggestionPicker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E52CF55120A35C3A00DADA27 /* WebDataListSuggestionPicker.cpp */; };
                ECA680D81E690E2500731D20 /* WebProcessCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = ECA680D71E690DF800731D20 /* WebProcessCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
                ED82A7F2128C6FAF004477B3 /* WKBundlePageOverlay.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A22F0FF1289FCD90085E74F /* WKBundlePageOverlay.h */; settings = {ATTRIBUTES = (Private, ); }; };
                EDCA71B7128DDA8C00201B26 /* WKBundlePageOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A22F1001289FCD90085E74F /* WKBundlePageOverlay.cpp */; };
                E49D40D81AD3FB210066B7B9 /* NetworkCacheBlobStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheBlobStorage.cpp; sourceTree = "<group>"; };
                E4E8648E1B1673FB00C82F40 /* VersionChecks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VersionChecks.h; sourceTree = "<group>"; };
                E4E8648F1B1673FB00C82F40 /* VersionChecks.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VersionChecks.mm; sourceTree = "<group>"; };
+               E52CF55020A35C3A00DADA27 /* WebDataListSuggestionPicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebDataListSuggestionPicker.h; sourceTree = "<group>"; };
+               E52CF55120A35C3A00DADA27 /* WebDataListSuggestionPicker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebDataListSuggestionPicker.cpp; sourceTree = "<group>"; };
                ECA680D31E6904B500731D20 /* ExtraPrivateSymbolsForTAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtraPrivateSymbolsForTAPI.h; sourceTree = "<group>"; };
                ECA680D71E690DF800731D20 /* WebProcessCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebProcessCocoa.h; sourceTree = "<group>"; };
                ECBFC1DB1E6A4D66000300C7 /* ExtraPublicSymbolsForTAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtraPublicSymbolsForTAPI.h; sourceTree = "<group>"; };
                                3F87B9BB15893F630090FF62 /* WebColorChooser.h */,
                                BC111A54112F4FBB00337BAB /* WebContextMenuClient.cpp */,
                                BC032D6210F4378D0058C15A /* WebContextMenuClient.h */,
+                               E52CF55120A35C3A00DADA27 /* WebDataListSuggestionPicker.cpp */,
+                               E52CF55020A35C3A00DADA27 /* WebDataListSuggestionPicker.h */,
                                CD19A2691A13E820008D650E /* WebDiagnosticLoggingClient.cpp */,
                                CD19A26A1A13E821008D650E /* WebDiagnosticLoggingClient.h */,
                                BC111A56112F4FBB00337BAB /* WebDragClient.cpp */,
                                5760829D202D2C4000116678 /* WebCredentialsMessengerMessages.h in Headers */,
                                5760829F202D2C4600116678 /* WebCredentialsMessengerProxyMessages.h in Headers */,
                                1AA83F6D1A5B63FF00026EC6 /* WebDatabaseProvider.h in Headers */,
+                               E52CF55220A35C3A00DADA27 /* WebDataListSuggestionPicker.h in Headers */,
                                CD19A26E1A13E834008D650E /* WebDiagnosticLoggingClient.h in Headers */,
                                1A5B1C5518987EDF004FCF9B /* WebDocumentLoader.h in Headers */,
                                BC032D7B10F4378D0058C15A /* WebDragClient.h in Headers */,
                                57608298202BD8BA00116678 /* WebCredentialsMessengerProxy.cpp in Sources */,
                                5760829E202D2C4300116678 /* WebCredentialsMessengerProxyMessageReceiver.cpp in Sources */,
                                1AA83F6C1A5B63FF00026EC6 /* WebDatabaseProvider.cpp in Sources */,
+                               E52CF55320A35C3A00DADA27 /* WebDataListSuggestionPicker.cpp in Sources */,
                                CD19A26D1A13E82A008D650E /* WebDiagnosticLoggingClient.cpp in Sources */,
                                1A5B1C5418987EDF004FCF9B /* WebDocumentLoader.cpp in Sources */,
                                BC111A5D112F4FBB00337BAB /* WebDragClient.cpp in Sources */,
index 64ef63e..0c955f6 100644 (file)
@@ -40,6 +40,7 @@
 #include "UserData.h"
 #include "WebColorChooser.h"
 #include "WebCoreArgumentCoders.h"
+#include "WebDataListSuggestionPicker.h"
 #include "WebFrame.h"
 #include "WebFrameLoaderClient.h"
 #include "WebFullScreenManager.h"
@@ -57,6 +58,7 @@
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/AXObjectCache.h>
 #include <WebCore/ColorChooser.h>
+#include <WebCore/DataListSuggestionPicker.h>
 #include <WebCore/DatabaseTracker.h>
 #include <WebCore/DocumentLoader.h>
 #include <WebCore/FileChooser.h>
@@ -789,6 +791,15 @@ std::unique_ptr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserCl
 
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+
+std::unique_ptr<DataListSuggestionPicker> WebChromeClient::createDataListSuggestionPicker(DataListSuggestionsClient& client)
+{
+    return std::make_unique<WebDataListSuggestionPicker>(&m_page, &client);
+}
+
+#endif
+
 void WebChromeClient::runOpenPanel(Frame& frame, FileChooser& fileChooser)
 {
     if (m_page.activeOpenPanelResultListener())
index 5846ae3..811a822 100644 (file)
@@ -148,6 +148,10 @@ private:
     std::unique_ptr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient&, const WebCore::Color&) final;
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    std::unique_ptr<WebCore::DataListSuggestionPicker> createDataListSuggestionPicker(WebCore::DataListSuggestionsClient&) final;
+#endif
+
 #if ENABLE(IOS_TOUCH_EVENTS)
     void didPreventDefaultForEvent() final;
 #endif
diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.cpp b/Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.cpp
new file mode 100644 (file)
index 0000000..6844527
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebDataListSuggestionPicker.h"
+
+#if ENABLE(DATALIST_ELEMENT)
+
+#include "WebPage.h"
+#include "WebPageProxyMessages.h"
+#include "WebProcess.h"
+#include <WebCore/DataListSuggestionsClient.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebDataListSuggestionPicker::WebDataListSuggestionPicker(WebPage* page, DataListSuggestionsClient* client)
+    : m_dataListSuggestionsClient(client)
+    , m_page(page)
+{
+}
+
+WebDataListSuggestionPicker::~WebDataListSuggestionPicker() { }
+
+void WebDataListSuggestionPicker::handleKeydownWithIdentifier(const WTF::String& key)
+{
+
+}
+
+void WebDataListSuggestionPicker::didSelectOption(const WTF::String& selectedOption)
+{
+
+}
+
+void WebDataListSuggestionPicker::didCloseSuggestions()
+{
+
+}
+
+void WebDataListSuggestionPicker::close()
+{
+
+}
+
+void WebDataListSuggestionPicker::displayWithActivationType(DataListSuggestionActivationType type)
+{
+
+}
+
+} // namespace WebKit
+
+#endif
diff --git a/Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.h b/Source/WebKit/WebProcess/WebCoreSupport/WebDataListSuggestionPicker.h
new file mode 100644 (file)
index 0000000..e5b3818
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(DATALIST_ELEMENT)
+
+#include <WebCore/DataListSuggestionPicker.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+class DataListSuggestionsClient;
+}
+
+namespace WebKit {
+
+class WebPage;
+
+class WebDataListSuggestionPicker : public WebCore::DataListSuggestionPicker {
+public:
+    WebDataListSuggestionPicker(WebPage*, WebCore::DataListSuggestionsClient*);
+    virtual ~WebDataListSuggestionPicker();
+
+    void handleKeydownWithIdentifier(const String&) override;
+    void didSelectOption(const String&);
+    void didCloseSuggestions();
+    void close() override;
+    void displayWithActivationType(WebCore::DataListSuggestionActivationType) override;
+private:
+    __unused WebCore::DataListSuggestionsClient* m_dataListSuggestionsClient;
+    __unused WebPage* m_page;
+};
+
+} // namespace WebKit
+
+#endif
index 8d37707..f91a36f 100644 (file)
@@ -76,6 +76,7 @@
 #include "WebContextMenu.h"
 #include "WebContextMenuClient.h"
 #include "WebCoreArgumentCoders.h"
+#include "WebDataListSuggestionPicker.h"
 #include "WebDatabaseProvider.h"
 #include "WebDiagnosticLoggingClient.h"
 #include "WebDocumentLoader.h"
@@ -3556,6 +3557,26 @@ void WebPage::didChooseColor(const WebCore::Color& color)
 
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+
+void WebPage::setActiveDataListSuggestionPicker(WebDataListSuggestionPicker* dataListSuggestionPicker)
+{
+    m_activeDataListSuggestionPicker = dataListSuggestionPicker;
+}
+
+void WebPage::didSelectDataListOption(const String& selectedOption)
+{
+    m_activeDataListSuggestionPicker->didSelectOption(selectedOption);
+}
+
+void WebPage::didCloseSuggestions()
+{
+    m_activeDataListSuggestionPicker->didCloseSuggestions();
+    m_activeDataListSuggestionPicker = nullptr;
+}
+
+#endif
+
 void WebPage::setActiveOpenPanelResultListener(Ref<WebOpenPanelResultListener>&& openPanelResultListener)
 {
     m_activeOpenPanelResultListener = WTFMove(openPanelResultListener);
index 3f27cfb..5634d11 100644 (file)
@@ -200,6 +200,7 @@ class VisibleContentRectUpdateInfo;
 class WebColorChooser;
 class WebContextMenu;
 class WebContextMenuItemData;
+class WebDataListSuggestionPicker;
 class WebDocumentLoader;
 class WebEvent;
 class WebFrame;
@@ -362,6 +363,12 @@ public:
     void didEndColorPicker();
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    void setActiveDataListSuggestionPicker(WebDataListSuggestionPicker*);
+    void didSelectDataListOption(const String&);
+    void didCloseSuggestions();
+#endif
+
     WebOpenPanelResultListener* activeOpenPanelResultListener() const { return m_activeOpenPanelResultListener.get(); }
     void setActiveOpenPanelResultListener(Ref<WebOpenPanelResultListener>&&);
 
@@ -1547,6 +1554,10 @@ private:
     WebColorChooser* m_activeColorChooser { nullptr };
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    WebDataListSuggestionPicker* m_activeDataListSuggestionPicker { nullptr };
+#endif
+
     RefPtr<WebOpenPanelResultListener> m_activeOpenPanelResultListener;
     RefPtr<NotificationPermissionRequestManager> m_notificationPermissionRequestManager;
 
index ea42e30..369fceb 100644 (file)
@@ -126,6 +126,11 @@ messages -> WebPage LegacyReceiver {
     DidChooseColor(WebCore::Color color)
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    DidSelectDataListOption(String selectedOption);
+    DidCloseSuggestions();
+#endif
+
 #if ENABLE(CONTEXT_MENUS)
     ContextMenuHidden()
     ContextMenuForKeyEvent()
index f4c5949..2b3ae50 100644 (file)
@@ -1,3 +1,14 @@
+2018-06-08  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist] Allow TextFieldInputType to show and hide suggestions
+        https://bugs.webkit.org/show_bug.cgi?id=186151
+
+        Reviewed by Tim Horton.
+
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::createDataListSuggestionPicker):
+
 2018-06-07  Chris Dumez  <cdumez@apple.com>
 
         Add base class to get WeakPtrFactory member and avoid some boilerplate code
index 424c91a..4355a86 100644 (file)
@@ -138,6 +138,10 @@ private:
     std::unique_ptr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient&, const WebCore::Color&) final;
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+    std::unique_ptr<WebCore::DataListSuggestionPicker> createDataListSuggestionPicker(WebCore::DataListSuggestionsClient&) final;
+#endif
+
 #if ENABLE(POINTER_LOCK)
     bool requestPointerLock() final;
     void requestPointerUnlock() final;
index 7d5ff5a..2884dfd 100644 (file)
@@ -58,6 +58,7 @@
 #import <WebCore/ContextMenu.h>
 #import <WebCore/ContextMenuController.h>
 #import <WebCore/Cursor.h>
+#import <WebCore/DataListSuggestionPicker.h>
 #import <WebCore/DeprecatedGlobalSettings.h>
 #import <WebCore/Element.h>
 #import <WebCore/FileChooser.h>
@@ -723,6 +724,14 @@ std::unique_ptr<ColorChooser> WebChromeClient::createColorChooser(ColorChooserCl
 
 #endif
 
+#if ENABLE(DATALIST_ELEMENT)
+std::unique_ptr<DataListSuggestionPicker> WebChromeClient::createDataListSuggestionPicker(DataListSuggestionsClient& client)
+{
+    ASSERT_NOT_REACHED();
+    return nullptr;
+}
+#endif
+
 #if ENABLE(POINTER_LOCK)
 bool WebChromeClient::requestPointerLock()
 {