[Datalist][macOS] Display suggestions for input[type=color]
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jul 2018 21:46:36 +0000 (21:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jul 2018 21:46:36 +0000 (21:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187794

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

Source/WebCore:

* html/ColorInputType.cpp:
(WebCore::ColorInputType::shouldRespectListAttribute):

Source/WebCore/PAL:

Added methods to enable customization of NSPopoverColorWell.

* PAL.xcodeproj/project.pbxproj:
* pal/spi/mac/NSColorWellSPI.h: Added.
* pal/spi/mac/NSPopoverColorWellSPI.h: Added.
* pal/spi/mac/NSPopoverSPI.h:

Source/WebKit:

An input[type=color] element that has an associated datalist element should
display the color values provided. We now support 1-12 suggested colors, that
will be displayed at the top of the color selection popover. If no suggestions
are specified we keep the existing default colors.

Created an NSPopoverColorWell subclass that allows custom colors to be specified
in the form of an NSColorList.

Also fixed a bug where an additional color well was displayed when clicking on
the input element.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<Color>::decode):
* Shared/WebCoreArgumentCoders.h:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::createColorPicker):
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::showColorPicker):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::createColorPicker):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::createColorPicker):
* UIProcess/mac/WebColorPickerMac.h:
* UIProcess/mac/WebColorPickerMac.mm:
(WebKit::WebColorPickerMac::create):
(WebKit::WebColorPickerMac::WebColorPickerMac):
(WebKit::WebColorPickerMac::showColorPicker):
(+[WKPopoverColorWell _colorPopoverCreateIfNecessary:]):
(-[WKPopoverColorWell _showPopover]):
(-[WKPopoverColorWell setSuggestedColors:]):
(-[WKColorPopoverMac initWithFrame:inView:]):
(-[WKColorPopoverMac setAndShowPicker:withColor:suggestions:]):
(-[WKColorPanelMac setAndShowPicker:withColor:suggestions:]):
* WebProcess/WebCoreSupport/WebColorChooser.cpp:
(WebKit::WebColorChooser::WebColorChooser):
(WebKit::WebColorChooser::reattachColorChooser):

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

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/spi/mac/NSColorWellSPI.h [new file with mode: 0644]
Source/WebCore/PAL/pal/spi/mac/NSPopoverColorWellSPI.h [new file with mode: 0644]
Source/WebCore/PAL/pal/spi/mac/NSPopoverSPI.h
Source/WebCore/html/ColorInputType.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/ios/PageClientImplIOS.h
Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit/UIProcess/mac/PageClientImplMac.h
Source/WebKit/UIProcess/mac/PageClientImplMac.mm
Source/WebKit/UIProcess/mac/WebColorPickerMac.h
Source/WebKit/UIProcess/mac/WebColorPickerMac.mm
Source/WebKit/WebProcess/WebCoreSupport/WebColorChooser.cpp

index c9e08a6..ea17de3 100644 (file)
@@ -1,3 +1,13 @@
+2018-07-24  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist][macOS] Display suggestions for input[type=color]
+        https://bugs.webkit.org/show_bug.cgi?id=187794
+
+        Reviewed by Tim Horton.
+
+        * html/ColorInputType.cpp:
+        (WebCore::ColorInputType::shouldRespectListAttribute):
+
 2018-07-24  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r234121.
index 3d03aa5..32d8779 100644 (file)
@@ -1,3 +1,17 @@
+2018-07-24  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist][macOS] Display suggestions for input[type=color]
+        https://bugs.webkit.org/show_bug.cgi?id=187794
+
+        Reviewed by Tim Horton.
+
+        Added methods to enable customization of NSPopoverColorWell.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/spi/mac/NSColorWellSPI.h: Added.
+        * pal/spi/mac/NSPopoverColorWellSPI.h: Added.
+        * pal/spi/mac/NSPopoverSPI.h:
+
 2018-07-23  Tim Horton  <timothy_horton@apple.com>
 
         Creating and loading content in a WKWebView triggers Main Thread Checker warnings under ServicesController
index 446f2d0..dea1eb3 100644 (file)
                A3AB6E651F3D217F009C14B1 /* SystemSleepListenerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A3AB6E631F3D217F009C14B1 /* SystemSleepListenerMac.mm */; };
                A3C66CDC1F462D6A009E6EE9 /* SessionID.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */; };
                A3C66CDD1F462D6A009E6EE9 /* SessionID.h in Headers */ = {isa = PBXBuildFile; fileRef = A3C66CDB1F462D6A009E6EE9 /* SessionID.h */; };
+               E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D112106A07400D2B738 /* NSColorWellSPI.h */; };
+               E5D45D142106A18700D2B738 /* NSPopoverColorWellSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */; };
                F442915E1FA52473002CC93E /* NSFileSizeFormatterSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */; };
                F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = F442915F1FA5261E002CC93E /* FileSizeFormatter.h */; };
                F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F44291621FA52670002CC93E /* FileSizeFormatter.cpp */; };
                A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SessionID.cpp; sourceTree = "<group>"; };
                A3C66CDB1F462D6A009E6EE9 /* SessionID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SessionID.h; sourceTree = "<group>"; };
                C2147A4A1EFD0AA600056FA5 /* CopyPALHeaders.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CopyPALHeaders.xcconfig; sourceTree = "<group>"; };
+               E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
+               E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
                F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
                F442915F1FA5261E002CC93E /* FileSizeFormatter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileSizeFormatter.h; sourceTree = "<group>"; };
                F44291621FA52670002CC93E /* FileSizeFormatter.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FileSizeFormatter.cpp; sourceTree = "<group>"; };
                                1CCEE4F620D8743F0047B097 /* NSAppearanceSPI.h */,
                                0C7785751F45130F00F4EBB6 /* NSApplicationSPI.h */,
                                A1175B4A1F6B2D7E00C4B9F0 /* NSCellSPI.h */,
+                               E5D45D112106A07400D2B738 /* NSColorWellSPI.h */,
                                0C7785761F45130F00F4EBB6 /* NSEventSPI.h */,
                                0C7785771F45130F00F4EBB6 /* NSFontSPI.h */,
                                A10826FD1F58A433004772AC /* NSGraphicsSPI.h */,
                                0C7785781F45130F00F4EBB6 /* NSImmediateActionGestureRecognizerSPI.h */,
                                0C7785791F45130F00F4EBB6 /* NSMenuSPI.h */,
                                0C77857A1F45130F00F4EBB6 /* NSPasteboardSPI.h */,
+                               E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */,
                                0C77857B1F45130F00F4EBB6 /* NSPopoverSPI.h */,
                                A10826F01F573BCA004772AC /* NSResponderSPI.h */,
                                0C77857C1F45130F00F4EBB6 /* NSScrollerImpSPI.h */,
                                0C2DA14C1F3BEB4900DBC317 /* NSCalendarDateSPI.h in Headers */,
                                A1175B4B1F6B2D7E00C4B9F0 /* NSCellSPI.h in Headers */,
                                0C2DA14D1F3BEB4900DBC317 /* NSColorSPI.h in Headers */,
+                               E5D45D122106A07400D2B738 /* NSColorWellSPI.h in Headers */,
                                0C77858F1F45130F00F4EBB6 /* NSEventSPI.h in Headers */,
                                0C2DA14E1F3BEB4900DBC317 /* NSExtensionSPI.h in Headers */,
                                0C2DA14F1F3BEB4900DBC317 /* NSFileManagerSPI.h in Headers */,
                                7A1656441F97B2B900BA3CE4 /* NSKeyedArchiverSPI.h in Headers */,
                                0C7785921F45130F00F4EBB6 /* NSMenuSPI.h in Headers */,
                                0C7785931F45130F00F4EBB6 /* NSPasteboardSPI.h in Headers */,
+                               E5D45D142106A18700D2B738 /* NSPopoverColorWellSPI.h in Headers */,
                                0C7785941F45130F00F4EBB6 /* NSPopoverSPI.h in Headers */,
                                A10826F11F573BCA004772AC /* NSResponderSPI.h in Headers */,
                                0C7785951F45130F00F4EBB6 /* NSScrollerImpSPI.h in Headers */,
diff --git a/Source/WebCore/PAL/pal/spi/mac/NSColorWellSPI.h b/Source/WebCore/PAL/pal/spi/mac/NSColorWellSPI.h
new file mode 100644 (file)
index 0000000..6164e01
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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 USE(APPKIT)
+
+@interface NSColorWell ()
++ (NSColorWell *)_exclusiveColorPanelOwner;
+@end
+
+#endif // USE(APPKIT)
diff --git a/Source/WebCore/PAL/pal/spi/mac/NSPopoverColorWellSPI.h b/Source/WebCore/PAL/pal/spi/mac/NSPopoverColorWellSPI.h
new file mode 100644 (file)
index 0000000..193b1c1
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 USE(APPKIT)
+
+@interface NSPopoverColorWell : NSColorWell<NSPopoverDelegate>
+- (void)_showPopover;
+@end
+
+@interface NSColorPickerMatrixView : NSView
+@end
+
+@interface NSColorPickerMatrixView ()
+- (void)setColorList:(NSColorList *)list;
+- (void)setSwatchSize:(NSSize)size;
+- (void)setNumberOfColumns:(NSUInteger)columns;
+@end
+
+@interface NSColorPopoverController : NSViewController
+@end
+
+@interface NSColorPopoverController ()
+@property (assign) id delegate;
+@property (assign) NSPopover *popover;
+@property (assign) NSColorPickerMatrixView *topBarMatrixView;
+@end
+
+#endif // USE(APPKIT)
index b9db405..fc7dc4d 100644 (file)
@@ -42,5 +42,6 @@ typedef NS_OPTIONS(NSUInteger, NSPopoverPositioningOptions) {
 };
 
 @interface NSPopover (WKDetails)
+- (void)_setRequiresCorrectContentAppearance:(BOOL)requiresCorrectAppearance;
 @property NSPopoverPositioningOptions positioningOptions;
 @end
index 543e37a..2a135f9 100644 (file)
@@ -187,7 +187,7 @@ void ColorInputType::detach()
 
 bool ColorInputType::shouldRespectListAttribute()
 {
-    return InputType::themeSupportsDataListUI(this);
+    return true;
 }
 
 bool ColorInputType::typeMismatchFor(const String& value) const
index 2833d5d..e2035cf 100644 (file)
@@ -1,3 +1,53 @@
+2018-07-24  Aditya Keerthi  <akeerthi@apple.com>
+
+        [Datalist][macOS] Display suggestions for input[type=color]
+        https://bugs.webkit.org/show_bug.cgi?id=187794
+
+        Reviewed by Tim Horton.
+
+        An input[type=color] element that has an associated datalist element should
+        display the color values provided. We now support 1-12 suggested colors, that
+        will be displayed at the top of the color selection popover. If no suggestions
+        are specified we keep the existing default colors.
+
+        Created an NSPopoverColorWell subclass that allows custom colors to be specified
+        in the form of an NSColorList.
+
+        Also fixed a bug where an additional color well was displayed when clicking on
+        the input element.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<Color>::decode):
+        * Shared/WebCoreArgumentCoders.h:
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::createColorPicker):
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::showColorPicker):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::createColorPicker):
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::createColorPicker):
+        * UIProcess/mac/WebColorPickerMac.h:
+        * UIProcess/mac/WebColorPickerMac.mm:
+        (WebKit::WebColorPickerMac::create):
+        (WebKit::WebColorPickerMac::WebColorPickerMac):
+        (WebKit::WebColorPickerMac::showColorPicker):
+        (+[WKPopoverColorWell _colorPopoverCreateIfNecessary:]):
+        (-[WKPopoverColorWell _showPopover]):
+        (-[WKPopoverColorWell setSuggestedColors:]):
+        (-[WKColorPopoverMac initWithFrame:inView:]):
+        (-[WKColorPopoverMac setAndShowPicker:withColor:suggestions:]):
+        (-[WKColorPanelMac setAndShowPicker:withColor:suggestions:]):
+        * WebProcess/WebCoreSupport/WebColorChooser.cpp:
+        (WebKit::WebColorChooser::WebColorChooser):
+        (WebKit::WebColorChooser::reattachColorChooser):
+
 2018-07-24  Alex Christensen  <achristensen@webkit.org>
 
         Modernize NavigationState
index c0dfb29..92d324c 100644 (file)
@@ -1515,6 +1515,15 @@ bool ArgumentCoder<Color>::decode(Decoder& decoder, Color& color)
     return true;
 }
 
+std::optional<Color> ArgumentCoder<Color>::decode(Decoder& decoder)
+{
+    Color color;
+    if (!decode(decoder, color))
+        return std::nullopt;
+
+    return color;
+}
+
 #if ENABLE(DRAG_SUPPORT)
 void ArgumentCoder<DragData>::encode(Encoder& encoder, const DragData& dragData)
 {
index 45c7c01..3a5cc68 100644 (file)
@@ -379,6 +379,7 @@ template<> struct ArgumentCoder<WebCore::WindowFeatures> {
 template<> struct ArgumentCoder<WebCore::Color> {
     static void encode(Encoder&, const WebCore::Color&);
     static bool decode(Decoder&, WebCore::Color&);
+    static std::optional<WebCore::Color> decode(Decoder&);
 };
 
 #if ENABLE(DRAG_SUPPORT)
index c9f2034..d2ac9e6 100644 (file)
@@ -217,7 +217,7 @@ Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& pa
     return WebContextMenuProxyGtk::create(m_viewWidget, page, WTFMove(context), userData);
 }
 
-RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect)
+RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect& rect, Vector<WebCore::Color>&&)
 {
     if (WEBKIT_IS_WEB_VIEW(m_viewWidget))
         return WebKitColorChooser::create(*page, color, rect);
index 5305057..890b62a 100644 (file)
@@ -84,7 +84,7 @@ private:
     RefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy&) override;
     Ref<WebContextMenuProxy> createContextMenuProxy(WebPageProxy&, ContextMenuContextData&&, const UserData&) override;
 #if ENABLE(INPUT_TYPE_COLOR)
-    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& intialColor, const WebCore::IntRect&) override;
+    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) override;
 #endif
     void selectionDidChange() override;
 #if ENABLE(DRAG_SUPPORT)
index 6205950..1add80f 100644 (file)
@@ -224,7 +224,7 @@ public:
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    virtual RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&) = 0;
+    virtual RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) = 0;
 #endif
 
 #if ENABLE(DATALIST_ELEMENT)
index 8dac6de..5df3744 100644 (file)
@@ -4697,7 +4697,7 @@ void WebPageProxy::didChangeContentSize(const IntSize& size)
 }
 
 #if ENABLE(INPUT_TYPE_COLOR)
-void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const IntRect& elementRect)
+void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const IntRect& elementRect, Vector<WebCore::Color>&& suggestions)
 {
 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
     // A new popover color well needs to be created (and the previous one destroyed) for
@@ -4705,7 +4705,7 @@ void WebPageProxy::showColorPicker(const WebCore::Color& initialColor, const Int
     m_colorPicker = nullptr;
 #endif
     if (!m_colorPicker)
-        m_colorPicker = m_pageClient.createColorPicker(this, initialColor, elementRect);
+        m_colorPicker = m_pageClient.createColorPicker(this, initialColor, elementRect, WTFMove(suggestions));
     m_colorPicker->showColorPicker(initialColor);
 }
 
index 77090c1..68a2d09 100644 (file)
@@ -1517,7 +1517,7 @@ private:
     void didChangeContentSize(const WebCore::IntSize&);
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    void showColorPicker(const WebCore::Color& initialColor, const WebCore::IntRect&);
+    void showColorPicker(const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&);
     void didChooseColor(const WebCore::Color&) override;
     void didEndColorPicker() override;
 #endif
index 6cf61c3..41b1732 100644 (file)
@@ -93,7 +93,7 @@ messages -> WebPageProxy {
     DidChangeContentSize(WebCore::IntSize newSize)
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    ShowColorPicker(WebCore::Color initialColor, WebCore::IntRect elementRect);
+    ShowColorPicker(WebCore::Color initialColor, WebCore::IntRect elementRect, Vector<WebCore::Color> suggestions);
     SetColorPickerColor(WebCore::Color color);
     EndColorPicker();
 #endif
index 5bdd9bc..7ccca9a 100644 (file)
@@ -101,7 +101,7 @@ private:
     Ref<WebCore::ValidationBubble> createValidationBubble(const String& message, const WebCore::ValidationBubble::Settings&) final;
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&) final;
+    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) final;
 #endif
 
 #if ENABLE(DATALIST_ELEMENT)
index 3104772..176adb6 100644 (file)
@@ -765,7 +765,7 @@ Ref<ValidationBubble> PageClientImpl::createValidationBubble(const String& messa
 }
 
 #if ENABLE(INPUT_TYPE_COLOR)
-RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&)
+RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&)
 {
     return nullptr;
 }
index ed12a84..fd998be 100644 (file)
@@ -129,7 +129,7 @@ private:
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
-    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&) override;
+    RefPtr<WebColorPicker> createColorPicker(WebPageProxy*, const WebCore::Color& initialColor, const WebCore::IntRect&, Vector<WebCore::Color>&&) override;
 #endif
 
 #if ENABLE(DATALIST_ELEMENT)
index 8840bb5..f6fc25b 100644 (file)
@@ -453,9 +453,9 @@ Ref<WebContextMenuProxy> PageClientImpl::createContextMenuProxy(WebPageProxy& pa
 #endif
 
 #if ENABLE(INPUT_TYPE_COLOR)
-RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& initialColor,  const WebCore::IntRect& rect)
+RefPtr<WebColorPicker> PageClientImpl::createColorPicker(WebPageProxy* page, const WebCore::Color& initialColor, const WebCore::IntRect& rect, Vector<WebCore::Color>&& suggestions)
 {
-    return WebColorPickerMac::create(page, initialColor, rect, m_view);
+    return WebColorPickerMac::create(page, initialColor, rect, WTFMove(suggestions), m_view);
 }
 #endif
 
index c1732c4..ae5e7b9 100644 (file)
@@ -29,8 +29,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebColorPickerMac_h
-#define WebColorPickerMac_h
+#pragma once
 
 #if ENABLE(INPUT_TYPE_COLOR)
 
@@ -49,7 +48,7 @@ class WebColorPickerMac;
 }
 
 @protocol WKColorPickerUIMac <NSObject>
-- (void)setAndShowPicker:(WebKit::WebColorPickerMac*)picker withColor:(NSColor *)color;
+- (void)setAndShowPicker:(WebKit::WebColorPickerMac*)picker withColor:(NSColor *)color suggestions:(Vector<WebCore::Color>&&)suggestions;
 - (void)invalidate;
 - (void)setColor:(NSColor *)color;
 - (void)didChooseColor:(id)sender;
@@ -59,7 +58,7 @@ namespace WebKit {
     
 class WebColorPickerMac : public WebColorPicker {
 public:        
-    static Ref<WebColorPickerMac> create(WebColorPicker::Client*, const WebCore::Color&, const WebCore::IntRect&, NSView*);
+    static Ref<WebColorPickerMac> create(WebColorPicker::Client*, const WebCore::Color&, const WebCore::IntRect&, Vector<WebCore::Color>&&, NSView *);
     ~WebColorPickerMac();
 
     void endPicker() override;
@@ -69,8 +68,9 @@ public:
     void didChooseColor(const WebCore::Color&);
 
 private:
-    WebColorPickerMac(WebColorPicker::Client*, const WebCore::Color&, const WebCore::IntRect&, NSView*);
+    WebColorPickerMac(WebColorPicker::Client*, const WebCore::Color&, const WebCore::IntRect&, Vector<WebCore::Color>&&, NSView *);
     RetainPtr<NSObject<WKColorPickerUIMac> > m_colorPickerUI;
+    Vector<WebCore::Color> m_suggestions;
 };
 
 } // namespace WebKit
@@ -78,5 +78,3 @@ private:
 #endif // ENABLE(INPUT_TYPE_COLOR)
 
 #endif // USE(APPKIT)
-
-#endif // WebContextMenuProxyMac_h
index 8e00270..9505564 100644 (file)
 
 #if USE(APPKIT)
 
+#import <WebCore/Color.h>
 #import <WebCore/ColorMac.h>
 
 using namespace WebKit;
 
 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
 
-// The methods we use from NSPopoverColorWell aren't declared in its header
-// so there's no benefit to trying to include them. Instead we just declare
-// the class and methods here.
-@interface NSPopoverColorWell : NSColorWell
-@end
+#import <pal/spi/mac/NSColorWellSPI.h>
+#import <pal/spi/mac/NSPopoverColorWellSPI.h>
+#import <pal/spi/mac/NSPopoverSPI.h>
+
+static const size_t maxColorSuggestions = 12;
+static const CGFloat colorPickerMatrixNumColumns = 12.0;
+static const CGFloat colorPickerMatrixSwatchWidth = 12.0;
+static const CGFloat colorPickerMatrixBorderWidth = 1.0;
+
+@interface WKPopoverColorWell : NSPopoverColorWell {
+    RetainPtr<NSColorList> _suggestedColors;
+}
 
-@interface NSPopoverColorWell (AppKitSecretsIKnow)
-- (void)_showPopover;
+- (void)setSuggestedColors:(NSColorList *)suggestedColors;
 @end
 
 @interface WKColorPopoverMac : NSObject<WKColorPickerUIMac, NSWindowDelegate> {
 @private
     BOOL _lastChangedByUser;
     WebColorPickerMac *_picker;
-    RetainPtr<NSPopoverColorWell> _popoverWell;
+    RetainPtr<WKPopoverColorWell> _popoverWell;
 }
 - (id)initWithFrame:(const WebCore::IntRect &)rect inView:(NSView *)view;
 @end
@@ -75,9 +82,9 @@ using namespace WebKit;
 
 namespace WebKit {
 
-Ref<WebColorPickerMac> WebColorPickerMac::create(WebColorPicker::Client* client, const WebCore::Color& initialColor, const WebCore::IntRect& rect, NSView* view)
+Ref<WebColorPickerMac> WebColorPickerMac::create(WebColorPicker::Client* client, const WebCore::Color& initialColor, const WebCore::IntRect& rect, Vector<WebCore::Color>&& suggestions, NSView *view)
 {
-    return adoptRef(*new WebColorPickerMac(client, initialColor, rect, view));
+    return adoptRef(*new WebColorPickerMac(client, initialColor, rect, WTFMove(suggestions), view));
 }
 
 WebColorPickerMac::~WebColorPickerMac()
@@ -86,8 +93,9 @@ WebColorPickerMac::~WebColorPickerMac()
         endPicker();
 }
 
-WebColorPickerMac::WebColorPickerMac(WebColorPicker::Client* client, const WebCore::Color& initialColor, const WebCore::IntRect& rect, NSView* view)
+WebColorPickerMac::WebColorPickerMac(WebColorPicker::Client* client, const WebCore::Color& initialColor, const WebCore::IntRect& rect, Vector<WebCore::Color>&& suggestions, NSView *view)
     : WebColorPicker(client)
+    , m_suggestions(WTFMove(suggestions))
 {
 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
     m_colorPickerUI = adoptNS([[WKColorPopoverMac alloc] initWithFrame:rect inView:view]);
@@ -128,35 +136,107 @@ void WebColorPickerMac::showColorPicker(const WebCore::Color& color)
         m_colorPickerUI = adoptNS([[WKColorPanelMac alloc] init]);
 #endif
 
-    [m_colorPickerUI setAndShowPicker:this withColor:nsColor(color)];
+    [m_colorPickerUI setAndShowPicker:this withColor:nsColor(color) suggestions:WTFMove(m_suggestions)];
 }
 
 } // namespace WebKit
 
 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
 
+@implementation WKPopoverColorWell
+
++ (NSPopover *)_colorPopoverCreateIfNecessary:(BOOL)forceCreation
+{
+    static NSPopover *colorPopover = nil;
+    if (forceCreation) {
+        NSPopover *popover = [[NSPopover alloc] init];
+        [popover _setRequiresCorrectContentAppearance:YES];
+        popover.behavior = NSPopoverBehaviorTransient;
+
+        NSColorPopoverController *controller = [[NSClassFromString(@"NSColorPopoverController") alloc] init];
+        popover.contentViewController = controller;
+        controller.popover = popover;
+        [controller release];
+
+        colorPopover = popover;
+    }
+
+    return colorPopover;
+}
+
+- (void)_showPopover
+{
+    NSPopover *popover = [[self class] _colorPopoverCreateIfNecessary:YES];
+    popover.delegate = self;
+
+    [self deactivate];
+
+    // Deactivate previous NSPopoverColorWell
+    NSColorWell *owner = [NSColorWell _exclusiveColorPanelOwner];
+    if ([owner isKindOfClass:[NSPopoverColorWell class]])
+        [owner deactivate];
+
+    NSColorPopoverController *controller = (NSColorPopoverController *)[popover contentViewController];
+    controller.delegate = self;
+
+    if (_suggestedColors) {
+        NSUInteger numColors = [[_suggestedColors allKeys] count];
+        CGFloat swatchWidth = (colorPickerMatrixNumColumns * colorPickerMatrixSwatchWidth + (colorPickerMatrixNumColumns * colorPickerMatrixBorderWidth - numColors)) / numColors;
+        CGFloat swatchHeight = colorPickerMatrixSwatchWidth;
+
+        // topBarMatrixView cannot be accessed until view has been loaded
+        if (!controller.isViewLoaded)
+            [controller loadView];
+
+        NSColorPickerMatrixView *topMatrix = controller.topBarMatrixView;
+        [topMatrix setNumberOfColumns:numColors];
+        [topMatrix setSwatchSize:NSMakeSize(swatchWidth, swatchHeight)];
+        [topMatrix setColorList:_suggestedColors.get()];
+    }
+
+    [self activate:YES];
+    [popover showRelativeToRect:self.bounds ofView:self preferredEdge:NSMinYEdge];
+}
+
+- (void)setSuggestedColors:(NSColorList *)suggestedColors
+{
+    _suggestedColors = suggestedColors;
+}
+
+@end
+
 @implementation WKColorPopoverMac
 - (id)initWithFrame:(const WebCore::IntRect &)rect inView:(NSView *)view
 {
     if(!(self = [super init]))
         return self;
 
-    _popoverWell = adoptNS([[NSPopoverColorWell alloc] initWithFrame:[view convertRect:NSRectFromCGRect(rect) toView:nil]]);
+    _popoverWell = adoptNS([[WKPopoverColorWell alloc] initWithFrame:[view convertRect:NSRectFromCGRect(rect) toView:nil]]);
     if (!_popoverWell)
         return self;
 
+    [_popoverWell setAlphaValue:0.0];
     [[view window].contentView addSubview:_popoverWell.get()];
 
     return self;
 }
 
-- (void)setAndShowPicker:(WebKit::WebColorPickerMac*)picker withColor:(NSColor *)color
+- (void)setAndShowPicker:(WebKit::WebColorPickerMac*)picker withColor:(NSColor *)color suggestions:(Vector<WebCore::Color>&&)suggestions
 {
     _picker = picker;
 
     [_popoverWell setTarget:self];
     [_popoverWell setAction:@selector(didChooseColor:)];
     [_popoverWell setColor:color];
+
+    NSColorList *suggestedColors = nil;
+    if (suggestions.size()) {
+        suggestedColors = [[[NSColorList alloc] init] autorelease];
+        for (size_t i = 0; i < std::min(suggestions.size(), maxColorSuggestions); i++)
+            [suggestedColors insertColor:nsColor(suggestions.at(i)) key:@(i).stringValue atIndex:i];
+    }
+
+    [_popoverWell setSuggestedColors:suggestedColors];
     [_popoverWell _showPopover];
     
     _lastChangedByUser = YES;
@@ -216,7 +296,7 @@ void WebColorPickerMac::showColorPicker(const WebCore::Color& color)
     return self;
 }
 
-- (void)setAndShowPicker:(WebColorPickerMac*)picker withColor:(NSColor *)color
+- (void)setAndShowPicker:(WebColorPickerMac*)picker withColor:(NSColor *)color suggestions:(Vector<WebCore::Color>&&)suggestions
 {
     _picker = picker;
 
index 15854ae..bd7f864 100644 (file)
@@ -43,7 +43,7 @@ WebColorChooser::WebColorChooser(WebPage* page, ColorChooserClient* client, cons
     , m_page(page)
 {
     m_page->setActiveColorChooser(this);
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::ShowColorPicker(initialColor, client->elementRectRelativeToRootView()), m_page->pageID());
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::ShowColorPicker(initialColor, client->elementRectRelativeToRootView(), client->suggestions()), m_page->pageID());
 }
 
 WebColorChooser::~WebColorChooser()
@@ -75,7 +75,7 @@ void WebColorChooser::reattachColorChooser(const Color& color)
     m_page->setActiveColorChooser(this);
 
     ASSERT(m_colorChooserClient);
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::ShowColorPicker(color, m_colorChooserClient->elementRectRelativeToRootView()), m_page->pageID());
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::ShowColorPicker(color, m_colorChooserClient->elementRectRelativeToRootView(), m_colorChooserClient->suggestions()), m_page->pageID());
 }
 
 void WebColorChooser::setSelectedColor(const Color& color)