Changeset 234930 in webkit


Ignore:
Timestamp:
Aug 16, 2018 9:44:17 AM (6 years ago)
Author:
Aditya Keerthi
Message:

Support drag-and-drop for input[type=color]
https://bugs.webkit.org/show_bug.cgi?id=188464

Reviewed by Wenson Hsieh.

Source/WebCore:

input[type=color] should support native drag and drop on both macOS and iOS.

Added methods to Pasteboard and PlatformPasteboard to enable colors to be read
from and written to the pasteboard. On macOS, colors are managed through the
NSColorPboardType, whereas on iOS, colors are managed through the
'com.apple.uikit.color' identifier.

DragSourceActionColor was added to the list of DragSourceActions to identify
when a color input is being dragged.

Tests: editing/pasteboard/drag-and-drop-color-input-events.html

editing/pasteboard/drag-and-drop-color-input.html

  • page/DragActions.h:
  • page/DragController.cpp:

(WebCore::DragController::dragEnteredOrUpdated):
(WebCore::isEnabledColorInput):
(WebCore::DragController::concludeEditDrag):
(WebCore::DragController::canProcessDrag):
(WebCore::DragController::draggableElement const):
(WebCore::DragController::startDrag):

  • page/EventHandler.cpp:

(WebCore::EventHandler::dragHysteresisExceeded const):
(WebCore::EventHandler::handleDrag):

  • page/EventHandler.h:
  • page/mac/DragControllerMac.mm:

(WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod const):

  • platform/DragData.h:
  • platform/DragImage.cpp:

(WebCore::DragImage::operator=):

  • platform/DragImage.h: Added the visiblePath property to DragImage, in order for

us to be able to clip images in the UITargetedDragPreview on iOS.

  • platform/DragItem.h:

(WebCore::DragItem::encode const):
(WebCore::DragItem::decode):

  • platform/Pasteboard.h:
  • platform/PasteboardStrategy.h:
  • platform/PlatformPasteboard.h:
  • platform/gtk/DragImageGtk.cpp:

(WebCore::createDragImageForColor):

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::write):

  • platform/ios/DragImageIOS.mm:

(WebCore::createDragImageForColor):

  • platform/ios/PasteboardIOS.mm:

(WebCore::Pasteboard::write):

  • platform/ios/PlatformPasteboardIOS.mm:

(WebCore::PlatformPasteboard::color):
(WebCore::PlatformPasteboard::setColor):

  • platform/mac/DragDataMac.mm:

(WebCore::colorPasteboardType):
(WebCore::DragData::containsCompatibleContent const):

  • platform/mac/DragImageMac.mm:

(WebCore::createDragImageForColor): Draw a rounded rectangle with a fill color
matching the value of the dragged color input. The rendered image is designed to
mimic the preview shown when dragging an NSColorWell.

  • platform/mac/PasteboardMac.mm:

(WebCore::Pasteboard::write):

  • platform/mac/PlatformPasteboardMac.mm:

(WebCore::PlatformPasteboard::setColor):

  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::write):

  • platform/wpe/PasteboardWPE.cpp:

(WebCore::Pasteboard::write):

Source/WebKit:

On iOS, the drag preview for the color input is a rounded rectangle. In order to
ensure that the corners appear transparent, the visiblePath property of the
UIDragPreviewParameters was set to match the preview's shape. This also required
the creation of an additional ArgumentCoder for Path.

When beginning the drag session, the preview should appear centered about the
color input. This is managed in createTargetedDragPreview. However, once the
preview is dragged, the preview should be at the center of the touch location.
Consequently, DragSourceActionColor was added to the list of sources that could
update the drag preview after lifting.

  • Shared/WebCoreArgumentCoders.cpp:

(IPC::ArgumentCoder<Path>::decode):

  • Shared/WebCoreArgumentCoders.h:
  • UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:

(WebKit::WebPasteboardProxy::setPasteboardColor):

  • UIProcess/WebPasteboardProxy.h:
  • UIProcess/WebPasteboardProxy.messages.in:
  • UIProcess/ios/DragDropInteractionState.h:
  • UIProcess/ios/DragDropInteractionState.mm:

(WebKit::createTargetedDragPreview):
(WebKit::shouldUseDragImageToCreatePreviewForDragSource):
(WebKit::shouldUseVisiblePathToCreatePreviewForDragSource):
(WebKit::canUpdatePreviewForActiveDragSource):
(WebKit::DragDropInteractionState::previewForDragItem const):
(WebKit::DragDropInteractionState::stageDragItem):
(WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources):

  • UIProcess/ios/forms/WKFormColorPicker.mm:

(-[WKColorPicker initWithView:]):

  • UIProcess/mac/WebColorPickerMac.h:
  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

(WebKit::WebPlatformStrategies::setColor):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.h:

Source/WebKitLegacy/mac:

  • WebCoreSupport/WebPlatformStrategies.h:
  • WebCoreSupport/WebPlatformStrategies.mm:

(WebPlatformStrategies::setColor):

Tools:

Added five cross-platform API tests, to verify that dragging and dropping with
color inputs changes the value of the drop target if and only if both inputs are
enabled. Also tests that the change and input events are fired when changing the
value of a color input through drag and drop.

Additionally, added a macOS-specific test to verify that dropping an item with
NSColorPboardType changes the value of the color input.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/color-drop.html: Added.
  • TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:

(TestWebKitAPI::TEST):

LayoutTests:

Added tests to verify that dragging from one color input to another behaves as
expected in WK1. The tests consider disabled and read-only inputs in addition to
default color inputs. The WK2 implementation is tested through API tests.

  • editing/pasteboard/drag-and-drop-color-input-events-expected.txt: Added.
  • editing/pasteboard/drag-and-drop-color-input-events.html: Added.
  • editing/pasteboard/drag-and-drop-color-input-expected.txt: Added.
  • editing/pasteboard/drag-and-drop-color-input.html: Added.
  • platform/ios/TestExpectations:
  • platform/mac/TestExpectations:
  • platform/wk2/TestExpectations:
Location:
trunk
Files:
5 added
47 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234928 r234930  
     12018-08-16  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Support drag-and-drop for input[type=color]
     4        https://bugs.webkit.org/show_bug.cgi?id=188464
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Added tests to verify that dragging from one color input to another behaves as
     9        expected in WK1. The tests consider disabled and read-only inputs in addition to
     10        default color inputs. The WK2 implementation is tested through API tests.
     11
     12        * editing/pasteboard/drag-and-drop-color-input-events-expected.txt: Added.
     13        * editing/pasteboard/drag-and-drop-color-input-events.html: Added.
     14        * editing/pasteboard/drag-and-drop-color-input-expected.txt: Added.
     15        * editing/pasteboard/drag-and-drop-color-input.html: Added.
     16        * platform/ios/TestExpectations:
     17        * platform/mac/TestExpectations:
     18        * platform/wk2/TestExpectations:
     19
    1202018-08-16  Simon Fraser  <simon.fraser@apple.com>
    221
  • trunk/LayoutTests/platform/ios/TestExpectations

    r234898 r234930  
    10091009editing/pasteboard/drop-link.html [ Skip ]
    10101010editing/pasteboard/drop-text-events.html [ Skip ]
     1011editing/pasteboard/drag-and-drop-color-input.html [ Skip ]
     1012editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ]
    10111013editing/pasteboard/drag-and-drop-image-contenteditable.html [ Skip ]
    10121014editing/pasteboard/drag-and-drop-inputimage-contenteditable.html [ Skip ]
  • trunk/LayoutTests/platform/mac/TestExpectations

    r234821 r234930  
    17281728accessibility/color-well.html [ Skip ]
    17291729fast/forms/color [ Skip ]
     1730editing/pasteboard/drag-and-drop-color-input.html [ Skip ]
     1731editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ]
    17301732imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/color.html [ Skip ]
    17311733fast/css/read-only-read-write-input-basics.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r234718 r234930  
    571571editing/pasteboard/datatransfer-items-drop-plaintext-file.html
    572572editing/pasteboard/datatransfer-types-dropping-text-file.html
     573editing/pasteboard/drag-and-drop-color-input.html
     574editing/pasteboard/drag-and-drop-color-input-events.html
    573575editing/pasteboard/drag-and-drop-image-contenteditable.html
    574576editing/pasteboard/drag-and-drop-inputimage-contenteditable.html
  • trunk/Source/WebCore/ChangeLog

    r234927 r234930  
     12018-08-16  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Support drag-and-drop for input[type=color]
     4        https://bugs.webkit.org/show_bug.cgi?id=188464
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        input[type=color] should support native drag and drop on both macOS and iOS.
     9
     10        Added methods to Pasteboard and PlatformPasteboard to enable colors to be read
     11        from and written to the pasteboard. On macOS, colors are managed through the
     12        NSColorPboardType, whereas on iOS, colors are managed through the
     13        'com.apple.uikit.color' identifier.
     14
     15        DragSourceActionColor was added to the list of DragSourceActions to identify
     16        when a color input is being dragged.
     17
     18        Tests: editing/pasteboard/drag-and-drop-color-input-events.html
     19               editing/pasteboard/drag-and-drop-color-input.html
     20
     21        * page/DragActions.h:
     22        * page/DragController.cpp:
     23        (WebCore::DragController::dragEnteredOrUpdated):
     24        (WebCore::isEnabledColorInput):
     25        (WebCore::DragController::concludeEditDrag):
     26        (WebCore::DragController::canProcessDrag):
     27        (WebCore::DragController::draggableElement const):
     28        (WebCore::DragController::startDrag):
     29        * page/EventHandler.cpp:
     30        (WebCore::EventHandler::dragHysteresisExceeded const):
     31        (WebCore::EventHandler::handleDrag):
     32        * page/EventHandler.h:
     33        * page/mac/DragControllerMac.mm:
     34        (WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod const):
     35        * platform/DragData.h:
     36        * platform/DragImage.cpp:
     37        (WebCore::DragImage::operator=):
     38        * platform/DragImage.h: Added the visiblePath property to DragImage, in order for
     39        us to be able to clip images in the UITargetedDragPreview on iOS.
     40        * platform/DragItem.h:
     41        (WebCore::DragItem::encode const):
     42        (WebCore::DragItem::decode):
     43        * platform/Pasteboard.h:
     44        * platform/PasteboardStrategy.h:
     45        * platform/PlatformPasteboard.h:
     46        * platform/gtk/DragImageGtk.cpp:
     47        (WebCore::createDragImageForColor):
     48        * platform/gtk/PasteboardGtk.cpp:
     49        (WebCore::Pasteboard::write):
     50        * platform/ios/DragImageIOS.mm:
     51        (WebCore::createDragImageForColor):
     52        * platform/ios/PasteboardIOS.mm:
     53        (WebCore::Pasteboard::write):
     54        * platform/ios/PlatformPasteboardIOS.mm:
     55        (WebCore::PlatformPasteboard::color):
     56        (WebCore::PlatformPasteboard::setColor):
     57        * platform/mac/DragDataMac.mm:
     58        (WebCore::colorPasteboardType):
     59        (WebCore::DragData::containsCompatibleContent const):
     60        * platform/mac/DragImageMac.mm:
     61        (WebCore::createDragImageForColor): Draw a rounded rectangle with a fill color
     62        matching the value of the dragged color input. The rendered image is designed to
     63        mimic the preview shown when dragging an NSColorWell.
     64        * platform/mac/PasteboardMac.mm:
     65        (WebCore::Pasteboard::write):
     66        * platform/mac/PlatformPasteboardMac.mm:
     67        (WebCore::PlatformPasteboard::setColor):
     68        * platform/win/PasteboardWin.cpp:
     69        (WebCore::Pasteboard::write):
     70        * platform/wpe/PasteboardWPE.cpp:
     71        (WebCore::Pasteboard::write):
     72
    1732018-08-16  Zalan Bujtas  <zalan@apple.com>
    274
  • trunk/Source/WebCore/page/DragActions.h

    r221900 r234930  
    4949        DragSourceActionAttachment   = 16,
    5050#endif
     51#if ENABLE(INPUT_TYPE_COLOR)
     52        DragSourceActionColor        = 32,
     53#endif
    5154        DragSourceActionAny          = UINT_MAX
    5255    } DragSourceAction;
  • trunk/Source/WebCore/page/DragController.cpp

    r234885 r234930  
    322322        if (dragOperation != DragOperationNone)
    323323            m_dragHandlingMethod = DragHandlingMethod::PageLoad;
    324     }
     324    } else if (m_dragHandlingMethod == DragHandlingMethod::SetColor)
     325        dragOperation = DragOperationCopy;
    325326
    326327    updateSupportedTypeIdentifiersForDragHandlingMethod(m_dragHandlingMethod, dragData);
     
    343344    return inputElement && inputElement->isFileUpload() ? inputElement : nullptr;
    344345}
     346
     347#if ENABLE(INPUT_TYPE_COLOR)
     348static bool isEnabledColorInput(Node& node, bool setToShadowAncestor)
     349{
     350    Node* candidate = setToShadowAncestor ? node.deprecatedShadowAncestorNode() : &node;
     351    if (is<HTMLInputElement>(*candidate)) {
     352        auto& input = downcast<HTMLInputElement>(*candidate);
     353        if (input.isColorControl() && !input.isDisabledFormControl())
     354            return true;
     355    }
     356
     357    return false;
     358}
     359#endif
    345360
    346361// This can return null if an empty document is loaded.
     
    540555        if (!color.isValid())
    541556            return false;
     557#if ENABLE(INPUT_TYPE_COLOR)
     558        if (isEnabledColorInput(*element, false)) {
     559            auto& input = downcast<HTMLInputElement>(*element);
     560            input.setValue(color.serialized(), DispatchInputAndChangeEvent);
     561            return true;
     562        }
     563#endif
    542564        auto innerRange = innerFrame->selection().toNormalizedRange();
    543565        if (!innerRange)
     
    644666    if (asFileInput(*result.innerNonSharedNode()))
    645667        dragPurpose = DragData::DraggingPurpose::ForFileUpload;
     668#if ENABLE(INPUT_TYPE_COLOR)
     669    else if (isEnabledColorInput(*result.innerNonSharedNode(), true))
     670        dragPurpose = DragData::DraggingPurpose::ForColorControl;
     671#endif
    646672
    647673    if (!dragData.containsCompatibleContent(dragPurpose))
     
    650676    if (dragPurpose == DragData::DraggingPurpose::ForFileUpload)
    651677        return true;
     678
     679#if ENABLE(INPUT_TYPE_COLOR)
     680    if (dragPurpose == DragData::DraggingPurpose::ForColorControl)
     681        return true;
     682#endif
    652683
    653684    if (is<HTMLPlugInElement>(*result.innerNonSharedNode())) {
     
    786817            }
    787818#endif
     819#if ENABLE(INPUT_TYPE_COLOR)
     820            if ((m_dragSourceAction & DragSourceActionColor)
     821                && isEnabledColorInput(*element, false)) {
     822                state.type = static_cast<DragSourceAction>(state.type | DragSourceActionColor);
     823                return element;
     824            }
     825#endif
    788826        }
    789827    }
     
    875913#if ENABLE(ATTACHMENT_ELEMENT)
    876914    includeShadowDOM = includeShadowDOM || is<HTMLAttachmentElement>(state.source.get());
     915#endif
     916#if ENABLE(INPUT_TYPE_COLOR)
     917    bool isColorControl = is<HTMLInputElement>(state.source) && downcast<HTMLInputElement>(*state.source).isColorControl();
     918    includeShadowDOM = includeShadowDOM || isColorControl;
    877919#endif
    878920    bool sourceContainsHitNode;
     
    11271169            src.selection().setSelection(previousSelection);
    11281170        src.editor().setIgnoreSelectionChanges(false);
     1171        return true;
     1172    }
     1173#endif
     1174
     1175#if ENABLE(INPUT_TYPE_COLOR)
     1176    if (isColorControl && m_dragSourceAction & DragSourceActionColor) {
     1177        auto& input = downcast<HTMLInputElement>(*state.source);
     1178        auto color = input.valueAsColor();
     1179
     1180        Path visiblePath;
     1181        dragImage = DragImage { createDragImageForColor(color, input.boundsInRootViewSpace(), input.document().page()->pageScaleFactor(), visiblePath) };
     1182        dragImage.setVisiblePath(visiblePath);
     1183        dataTransfer.pasteboard().write(color);
     1184        dragImageOffset = IntPoint { dragImageSize(dragImage.get()) };
     1185        dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, false);
     1186
     1187        m_client.willPerformDragSourceAction(DragSourceActionColor, dragOrigin, dataTransfer);
     1188        doSystemDrag(WTFMove(dragImage), dragLoc, dragOrigin, src, state, { });
    11291189        return true;
    11301190    }
  • trunk/Source/WebCore/page/EventHandler.cpp

    r234718 r234930  
    135135const int ImageDragHysteresis = 5;
    136136const int TextDragHysteresis = 3;
     137const int ColorDragHystersis = 3;
    137138const int GeneralDragHysteresis = 3;
    138139#if PLATFORM(COCOA)
     
    35113512        threshold = LinkDragHysteresis;
    35123513        break;
     3514#if ENABLE(INPUT_TYPE_COLOR)
     3515    case DragSourceActionColor:
     3516        threshold = ColorDragHystersis;
     3517        break;
     3518#endif
    35133519    case DragSourceActionDHTML:
    35143520        break;
     
    36913697    if (!ExactlyOneBitSet(dragState().type)) {
    36923698        ASSERT((dragState().type & DragSourceActionSelection));
    3693 #if ENABLE(ATTACHMENT_ELEMENT)
    3694         ASSERT((dragState().type & ~DragSourceActionSelection) == DragSourceActionDHTML
    3695                || (dragState().type & ~DragSourceActionSelection) == DragSourceActionImage
    3696                || (dragState().type & ~DragSourceActionSelection) == DragSourceActionAttachment
    3697                || (dragState().type & ~DragSourceActionSelection) == DragSourceActionLink);
    3698 #else
    36993699        ASSERT((dragState().type & ~DragSourceActionSelection) == DragSourceActionDHTML
    37003700            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionImage
     3701#if ENABLE(ATTACHMENT_ELEMENT)
     3702            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionAttachment
     3703#endif
     3704#if ENABLE(INPUT_TYPE_COLOR)
     3705            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionColor
     3706#endif
    37013707            || (dragState().type & ~DragSourceActionSelection) == DragSourceActionLink);
    3702 #endif
     3708
    37033709        dragState().type = DragSourceActionSelection;
    37043710    }
  • trunk/Source/WebCore/page/EventHandler.h

    r233022 r234930  
    101101extern const int ImageDragHysteresis;
    102102extern const int TextDragHysteresis;
     103extern const int ColorDragHystersis;
    103104extern const int GeneralDragHysteresis;
    104105#endif
  • trunk/Source/WebCore/page/mac/DragControllerMac.mm

    r230211 r234930  
    145145        }
    146146        break;
     147    case DragHandlingMethod::SetColor:
     148        supportedTypes.append(UIColorPboardType);
     149        break;
    147150    default:
    148151        for (NSString *type in Pasteboard::supportedFileUploadPasteboardTypes())
  • trunk/Source/WebCore/platform/DragData.h

    r228974 r234930  
    7474public:
    7575    enum FilenameConversionPolicy { DoNotConvertFilenames, ConvertFilenames };
    76     enum class DraggingPurpose { ForEditing, ForFileUpload };
     76    enum class DraggingPurpose { ForEditing, ForFileUpload, ForColorControl };
    7777
    7878    // clientPosition is taken to be the position of the drag event within the target window, with (0,0) at the top left
  • trunk/Source/WebCore/platform/DragImage.cpp

    r226425 r234930  
    3939namespace WebCore {
    4040
     41#if PLATFORM(COCOA)
     42const float ColorSwatchCornerRadius = 4;
     43const float ColorSwatchStrokeSize = 4;
     44const float ColorSwatchWidth = 24;
     45#endif
     46
    4147DragImageRef fitDragImageToMaxSize(DragImageRef image, const IntSize& layoutSize, const IntSize& maxSize)
    4248{
     
    260266{
    261267    m_indicatorData = other.m_indicatorData;
     268    m_visiblePath = other.m_visiblePath;
    262269}
    263270
     
    269276    m_dragImageRef = std::exchange(other.m_dragImageRef, nullptr);
    270277    m_indicatorData = other.m_indicatorData;
     278    m_visiblePath = other.m_visiblePath;
    271279
    272280    return *this;
  • trunk/Source/WebCore/platform/DragImage.h

    r218837 r234930  
    2929#include "ImageOrientation.h"
    3030#include "IntSize.h"
     31#include "Path.h"
    3132#include "TextFlags.h"
    3233#include "TextIndicator.h"
     
    7071
    7172#if PLATFORM(COCOA)
    72 static const float SelectionDragImagePadding = 15;
     73extern const float ColorSwatchCornerRadius;
     74extern const float ColorSwatchStrokeSize;
     75extern const float ColorSwatchWidth;
    7376#endif
    7477
     
    8992WEBCORE_EXPORT DragImageRef createDragImageForSelection(Frame&, TextIndicatorData&, bool forceBlackText = false);
    9093WEBCORE_EXPORT DragImageRef createDragImageForRange(Frame&, Range&, bool forceBlackText = false);
     94DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&);
    9195DragImageRef createDragImageForImage(Frame&, Node&, IntRect& imageRect, IntRect& elementRect);
    9296DragImageRef createDragImageForLink(Element&, URL&, const String& label, TextIndicatorData&, FontRenderingMode, float deviceScaleFactor);
     
    109113    std::optional<TextIndicatorData> indicatorData() const { return m_indicatorData; }
    110114
     115    void setVisiblePath(const Path& path) { m_visiblePath = path; }
     116    bool hasVisiblePath() const { return !!m_visiblePath; }
     117    std::optional<Path> visiblePath() const { return m_visiblePath; }
     118
    111119    explicit operator bool() const { return !!m_dragImageRef; }
    112120    DragImageRef get() const { return m_dragImageRef; }
     
    115123    DragImageRef m_dragImageRef;
    116124    std::optional<TextIndicatorData> m_indicatorData;
     125    std::optional<Path> m_visiblePath;
    117126};
    118127
  • trunk/Source/WebCore/platform/DragItem.h

    r234333 r234930  
    6868    if (hasIndicatorData)
    6969        encoder << image.indicatorData().value();
     70    bool hasVisiblePath = image.hasVisiblePath();
     71    encoder << hasVisiblePath;
     72    if (hasVisiblePath)
     73        encoder << image.visiblePath().value();
    7074    encoder << promisedBlob;
    7175}
     
    100104        result.image.setIndicatorData(*indicatorData);
    101105    }
     106    bool hasVisiblePath;
     107    if (!decoder.decode(hasVisiblePath))
     108        return false;
     109    if (hasVisiblePath) {
     110        std::optional<Path> visiblePath;
     111        decoder >> visiblePath;
     112        if (!visiblePath)
     113            return false;
     114        result.image.setVisiblePath(*visiblePath);
     115    }
    102116    if (!decoder.decode(result.promisedBlob))
    103117        return false;
  • trunk/Source/WebCore/platform/Pasteboard.h

    r229503 r234930  
    214214    virtual WEBCORE_EXPORT void read(PasteboardFileReader&);
    215215
     216    virtual WEBCORE_EXPORT void write(const Color&);
    216217    virtual WEBCORE_EXPORT void write(const PasteboardURL&);
    217218    virtual WEBCORE_EXPORT void writeTrustworthyWebURLsPboardType(const PasteboardURL&);
     
    332333#if PLATFORM(IOS)
    333334extern NSString *WebArchivePboardType;
     335extern NSString *UIColorPboardType;
    334336#endif
    335337
  • trunk/Source/WebCore/platform/PasteboardStrategy.h

    r233753 r234930  
    7272    virtual long setBufferForType(SharedBuffer*, const String& pasteboardType, const String& pasteboardName) = 0;
    7373    virtual long setURL(const PasteboardURL&, const String& pasteboardName) = 0;
     74    virtual long setColor(const Color&, const String& pasteboardName) = 0;
    7475    virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
    7576#endif
  • trunk/Source/WebCore/platform/PlatformPasteboard.h

    r233753 r234930  
    8686    WEBCORE_EXPORT long setBufferForType(SharedBuffer*, const String& pasteboardType);
    8787    WEBCORE_EXPORT long setURL(const PasteboardURL&);
     88    WEBCORE_EXPORT long setColor(const Color&);
    8889    WEBCORE_EXPORT long setStringForType(const String&, const String& pasteboardType);
    8990    WEBCORE_EXPORT void write(const PasteboardWebContent&);
  • trunk/Source/WebCore/platform/gtk/DragImageGtk.cpp

    r212669 r234930  
    9898}
    9999
     100DragImageRef createDragImageForColor(const Color&, const FloatRect&, float, Path&)
     101{
     102    return nullptr;
    100103}
     104
     105}
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r233122 r234930  
    2121#include "Pasteboard.h"
    2222
     23#include "Color.h"
    2324#include "DragData.h"
    2425#include "Image.h"
     
    333334}
    334335
    335 }
     336void Pasteboard::write(const Color&)
     337{
     338}
     339
     340}
  • trunk/Source/WebCore/platform/ios/DragImageIOS.mm

    r219998 r234930  
    252252}
    253253
     254DragImageRef createDragImageForColor(const Color& color, const FloatRect& elementRect, float pageScaleFactor, Path& visiblePath)
     255{
     256    FloatRect imageRect { 0, 0, elementRect.width() * pageScaleFactor, elementRect.height() * pageScaleFactor };
     257    FloatRoundedRect swatch { imageRect, FloatRoundedRect::Radii(ColorSwatchCornerRadius * pageScaleFactor) };
     258
     259    auto render = adoptNS([allocUIGraphicsImageRendererInstance() initWithSize:imageRect.size()]);
     260    UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) {
     261        GraphicsContext context { rendererContext.CGContext };
     262        context.translate(0, CGRectGetHeight(imageRect));
     263        context.scale({ 1, -1 });
     264        context.fillRoundedRect(swatch, color);
     265    }];
     266
     267    visiblePath.addRoundedRect(swatch);
     268    return image.CGImage;
     269}
     270
    254271#else
    255272
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r234809 r234930  
    8484// FIXME: Does this need to be declared in the header file?
    8585WEBCORE_EXPORT NSString *WebArchivePboardType = @"Apple Web Archive pasteboard type";
     86NSString *UIColorPboardType = @"com.apple.uikit.color";
    8687
    8788Pasteboard::Pasteboard()
     
    138139    // URLs.
    139140    ASSERT_NOT_REACHED();
     141}
     142
     143void Pasteboard::write(const Color& color)
     144{
     145    platformStrategies()->pasteboardStrategy()->setColor(color, m_pasteboardName);
    140146}
    141147
  • trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r233753 r234930  
    3838#import "WebItemProviderPasteboard.h"
    3939#import <MobileCoreServices/MobileCoreServices.h>
     40#import <UIKit/UIColor.h>
    4041#import <UIKit/UIImage.h>
    4142#import <UIKit/UIPasteboard.h>
     
    5051
    5152SOFT_LINK_FRAMEWORK(UIKit)
     53SOFT_LINK_CLASS(UIKit, UIColor)
    5254SOFT_LINK_CLASS(UIKit, UIImage)
    5355SOFT_LINK_CLASS(UIKit, UIPasteboard)
     
    222224Color PlatformPasteboard::color()
    223225{
    224     return Color();
     226    NSData *data = [m_pasteboard dataForPasteboardType:UIColorPboardType];
     227    UIColor *uiColor = [NSKeyedUnarchiver unarchivedObjectOfClass:getUIColorClass() fromData:data error:nil];
     228    return Color(uiColor.CGColor);
    225229}
    226230
     
    307311#endif
    308312   
     313}
     314
     315long PlatformPasteboard::setColor(const Color& color)
     316{
     317    auto representationsToRegister = adoptNS([[WebItemProviderRegistrationInfoList alloc] init]);
     318    UIColor *uiColor = [getUIColorClass() colorWithCGColor:cachedCGColor(color)];
     319    [representationsToRegister addData:[NSKeyedArchiver archivedDataWithRootObject:uiColor requiringSecureCoding:NO error:nil] forType:UIColorPboardType];
     320    registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get());
     321    return 0;
    309322}
    310323
  • trunk/Source/WebCore/platform/mac/DragDataMac.mm

    r230221 r234930  
    9292{
    9393#if PLATFORM(IOS)
    94     return "com.apple.uikit.color";
     94    return String { UIColorPboardType };
    9595#else
    9696    return String(legacyColorPasteboardType());
     
    226226    if (purpose == DraggingPurpose::ForFileUpload)
    227227        return containsFiles();
     228
     229    if (purpose == DraggingPurpose::ForColorControl)
     230        return containsColor();
    228231
    229232    if (purpose == DraggingPurpose::ForEditing && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && containsFiles())
  • trunk/Source/WebCore/platform/mac/DragImageMac.mm

    r233552 r234930  
    337337    return dragImage;
    338338}
     339
     340DragImageRef createDragImageForColor(const Color& color, const FloatRect&, float, Path&)
     341{
     342    auto dragImage = adoptNS([[NSImage alloc] initWithSize:NSMakeSize(ColorSwatchWidth, ColorSwatchWidth)]);
     343
     344    [dragImage lockFocus];
     345
     346    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(0, 0, ColorSwatchWidth, ColorSwatchWidth) xRadius:ColorSwatchCornerRadius yRadius:ColorSwatchCornerRadius];
     347    [path setLineWidth:ColorSwatchStrokeSize];
     348
     349    [nsColor(color) setFill];
     350    [path fill];
     351
     352    [[NSColor quaternaryLabelColor] setStroke];
     353    [path stroke];
     354
     355    [dragImage unlockFocus];
     356
     357    return dragImage;
     358}
    339359   
    340360} // namespace WebCore
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r233753 r234930  
    224224}
    225225
     226void Pasteboard::write(const Color& color)
     227{
     228    Vector<String> types = { legacyColorPasteboardType() };
     229    platformStrategies()->pasteboardStrategy()->setTypes(types, m_pasteboardName);
     230    m_changeCount = platformStrategies()->pasteboardStrategy()->setColor(color, m_pasteboardName);
     231}
     232
    226233static NSFileWrapper* fileWrapper(const PasteboardImage& pasteboardImage)
    227234{
  • trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm

    r233753 r234930  
    275275}
    276276
     277long PlatformPasteboard::setColor(const Color& color)
     278{
     279    NSColor *pasteboardColor = nsColor(color);
     280    [pasteboardColor writeToPasteboard:m_pasteboard.get()];
     281    return changeCount();
     282}
     283
    277284long PlatformPasteboard::setStringForType(const String& string, const String& pasteboardType)
    278285{
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r232198 r234930  
    3131#include "CachedImage.h"
    3232#include "ClipboardUtilitiesWin.h"
     33#include "Color.h"
    3334#include "Document.h"
    3435#include "DocumentFragment.h"
     
    10861087}
    10871088
     1089void Pasteboard::write(const Color&)
     1090{
     1091}
     1092
    10881093} // namespace WebCore
  • trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp

    r229503 r234930  
    150150}
    151151
     152void Pasteboard::write(const Color&)
     153{
     154}
     155
    152156} // namespace WebCore
  • trunk/Source/WebKit/ChangeLog

    r234929 r234930  
     12018-08-16  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Support drag-and-drop for input[type=color]
     4        https://bugs.webkit.org/show_bug.cgi?id=188464
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        On iOS, the drag preview for the color input is a rounded rectangle. In order to
     9        ensure that the corners appear transparent, the visiblePath property of the
     10        UIDragPreviewParameters was set to match the preview's shape. This also required
     11        the creation of an additional ArgumentCoder for Path.
     12
     13        When beginning the drag session, the preview should appear centered about the
     14        color input. This is managed in createTargetedDragPreview. However, once the
     15        preview is dragged, the preview should be at the center of the touch location.
     16        Consequently, DragSourceActionColor was added to the list of sources that could
     17        update the drag preview after lifting.
     18
     19        * Shared/WebCoreArgumentCoders.cpp:
     20        (IPC::ArgumentCoder<Path>::decode):
     21        * Shared/WebCoreArgumentCoders.h:
     22        * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
     23        (WebKit::WebPasteboardProxy::setPasteboardColor):
     24        * UIProcess/WebPasteboardProxy.h:
     25        * UIProcess/WebPasteboardProxy.messages.in:
     26        * UIProcess/ios/DragDropInteractionState.h:
     27        * UIProcess/ios/DragDropInteractionState.mm:
     28        (WebKit::createTargetedDragPreview):
     29        (WebKit::shouldUseDragImageToCreatePreviewForDragSource):
     30        (WebKit::shouldUseVisiblePathToCreatePreviewForDragSource):
     31        (WebKit::canUpdatePreviewForActiveDragSource):
     32        (WebKit::DragDropInteractionState::previewForDragItem const):
     33        (WebKit::DragDropInteractionState::stageDragItem):
     34        (WebKit::DragDropInteractionState::updatePreviewsForActiveDragSources):
     35        * UIProcess/ios/forms/WKFormColorPicker.mm:
     36        (-[WKColorPicker initWithView:]):
     37        * UIProcess/mac/WebColorPickerMac.h:
     38        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
     39        (WebKit::WebPlatformStrategies::setColor):
     40        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
     41
    1422018-08-16  Per Arne Vollan  <pvollan@apple.com>
    243
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp

    r234172 r234930  
    853853}
    854854
     855std::optional<Path> ArgumentCoder<Path>::decode(Decoder& decoder)
     856{
     857    Path path;
     858    if (!decode(decoder, path))
     859        return std::nullopt;
     860
     861    return path;
     862}
     863
    855864void ArgumentCoder<RecentSearch>::encode(Encoder& encoder, const RecentSearch& recentSearch)
    856865{
  • trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h

    r234172 r234930  
    307307    static void encode(Encoder&, const WebCore::Path&);
    308308    static bool decode(Decoder&, WebCore::Path&);
     309    static std::optional<WebCore::Path> decode(Decoder&);
    309310};
    310311
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm

    r233753 r234930  
    139139}
    140140
     141void WebPasteboardProxy::setPasteboardColor(const String& pasteboardName, const WebCore::Color& color, uint64_t& newChangeCount)
     142{
     143    newChangeCount = PlatformPasteboard(pasteboardName).setColor(color);
     144}
     145
    141146void WebPasteboardProxy::setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String& string, uint64_t& newChangeCount)
    142147{
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h

    r233753 r234930  
    9797    void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount);
    9898    void setPasteboardURL(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName, uint64_t& newChangeCount);
     99    void setPasteboardColor(const String&, const WebCore::Color&, uint64_t&);
    99100    void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount);
    100101    void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in

    r233753 r234930  
    5555    SetPasteboardTypes(String pasteboardName, Vector<String> pasteboardTypes) -> (uint64_t changeCount)
    5656    SetPasteboardURL(struct WebCore::PasteboardURL pasteboardURL, String pasteboardName) -> (uint64_t changeCount) WantsConnection
     57    SetPasteboardColor(String pasteboardName, WebCore::Color color) -> (uint64_t changeCount)
    5758    SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount)
    5859    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount)
  • trunk/Source/WebKit/UIProcess/ios/DragDropInteractionState.h

    r221907 r234930  
    3131#import <WebCore/DragActions.h>
    3232#import <WebCore/DragData.h>
     33#import <WebCore/Path.h>
    3334#import <WebCore/TextIndicator.h>
    3435#import <WebCore/URL.h>
     
    5051    RetainPtr<UIImage> image;
    5152    std::optional<WebCore::TextIndicatorData> indicatorData;
     53    std::optional<WebCore::Path> visiblePath;
    5254    String linkTitle;
    5355    WebCore::URL linkURL;
  • trunk/Source/WebKit/UIProcess/ios/DragDropInteractionState.mm

    r222253 r234930  
    4747}
    4848
    49 static UITargetedDragPreview *createTargetedDragPreview(UIImage *image, UIView *rootView, UIView *previewContainer, const FloatRect& frameInRootViewCoordinates, const Vector<FloatRect>& clippingRectsInFrameCoordinates, UIColor *backgroundColor)
     49static UITargetedDragPreview *createTargetedDragPreview(UIImage *image, UIView *rootView, UIView *previewContainer, const FloatRect& frameInRootViewCoordinates, const Vector<FloatRect>& clippingRectsInFrameCoordinates, UIColor *backgroundColor, UIBezierPath *visiblePath)
    5050{
    5151    if (frameInRootViewCoordinates.isEmpty() || !image)
     
    7676        [parameters setBackgroundColor:backgroundColor];
    7777
     78    if (visiblePath)
     79        [parameters setVisiblePath:visiblePath];
     80
    7881    CGPoint centerInContainerCoordinates = { CGRectGetMidX(frameInContainerCoordinates), CGRectGetMidY(frameInContainerCoordinates) };
    7982    auto target = adoptNS([[UIDragPreviewTarget alloc] initWithContainer:previewContainer center:centerInContainerCoordinates]);
     
    99102        return false;
    100103
     104#if ENABLE(INPUT_TYPE_COLOR)
     105    if (source.action & DragSourceActionColor)
     106        return true;
     107#endif
     108
    101109    return source.action & (DragSourceActionDHTML | DragSourceActionImage);
     110}
     111
     112static bool shouldUseVisiblePathToCreatePreviewForDragSource(const DragSourceState& source)
     113{
     114    if (!source.visiblePath)
     115        return false;
     116
     117#if ENABLE(INPUT_TYPE_COLOR)
     118    if (source.action & DragSourceActionColor)
     119        return true;
     120#endif
     121
     122    return false;
    102123}
    103124
     
    114135        return true;
    115136#endif
     137
     138    return false;
     139}
     140
     141static bool canUpdatePreviewForActiveDragSource(const DragSourceState& source)
     142{
     143    if (!source.possiblyNeedsDragPreviewUpdate)
     144        return false;
     145
     146#if ENABLE(INPUT_TYPE_COLOR)
     147    if (source.action & DragSourceActionColor)
     148        return true;
     149#endif
     150
     151    if (source.action & DragSourceActionLink && !(source.action & DragSourceActionImage))
     152        return true;
    116153
    117154    return false;
     
    159196
    160197    auto& source = foundSource.value();
    161     if (shouldUseDragImageToCreatePreviewForDragSource(source))
    162         return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil);
     198    if (shouldUseDragImageToCreatePreviewForDragSource(source)) {
     199        if (shouldUseVisiblePathToCreatePreviewForDragSource(source)) {
     200            auto path = source.visiblePath.value();
     201            UIBezierPath *visiblePath = [UIBezierPath bezierPathWithCGPath:path.ensurePlatformPath()];
     202            return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil, visiblePath);
     203        }
     204        return createTargetedDragPreview(source.image.get(), contentView, previewContainer, source.dragPreviewFrameInRootViewCoordinates, { }, nil, nil);
     205    }
    163206
    164207    if (shouldUseTextIndicatorToCreatePreviewForDragSource(source)) {
    165208        auto indicator = source.indicatorData.value();
    166209        auto textIndicatorImage = uiImageForImage(indicator.contentImage.get());
    167         return createTargetedDragPreview(textIndicatorImage.get(), contentView, previewContainer, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)]);
     210        return createTargetedDragPreview(textIndicatorImage.get(), contentView, previewContainer, indicator.textBoundingRectInRootViewCoordinates, indicator.textRectsInBoundingRectCoordinates, [UIColor colorWithCGColor:cachedCGColor(indicator.estimatedBackgroundColor)], nil);
    168211    }
    169212
     
    204247        dragImage,
    205248        item.image.indicatorData(),
     249        item.image.visiblePath(),
    206250        item.title.isEmpty() ? nil : (NSString *)item.title,
    207251        item.url.isEmpty() ? nil : (NSURL *)item.url,
     
    240284{
    241285    for (auto& source : m_activeDragSources) {
    242         if (!source.possiblyNeedsDragPreviewUpdate)
     286        if (!canUpdatePreviewForActiveDragSource(source))
    243287            continue;
    244 
    245         if (source.action & DragSourceActionImage || !(source.action & DragSourceActionLink)) {
    246             // Currently, non-image links are the only type of source for which we need to update
    247             // drag preview providers after the initial lift. All other dragged content should maintain
    248             // the same targeted drag preview used during the lift animation.
    249             continue;
    250         }
    251288
    252289        UIDragItem *dragItem = dragItemMatchingIdentifier(m_dragSession.get(), source.itemIdentifier);
     
    254291            continue;
    255292
    256         auto linkDraggingCenter = source.adjustedOrigin;
    257         RetainPtr<NSString> title = (NSString *)source.linkTitle;
    258         RetainPtr<NSURL> url = (NSURL *)source.linkURL;
    259         dragItem.previewProvider = [title, url, linkDraggingCenter] () -> UIDragPreview * {
    260             UIURLDragPreviewView *previewView = [UIURLDragPreviewView viewWithTitle:title.get() URL:url.get()];
    261             previewView.center = linkDraggingCenter;
    262             UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:previewView.bounds] ]] autorelease];
    263             return [[[UIDragPreview alloc] initWithView:previewView parameters:parameters] autorelease];
    264         };
     293        if (source.action & DragSourceActionLink) {
     294            dragItem.previewProvider = [title = retainPtr((NSString *)source.linkTitle), url = retainPtr((NSURL *)source.linkURL), center = source.adjustedOrigin] () -> UIDragPreview * {
     295                UIURLDragPreviewView *previewView = [UIURLDragPreviewView viewWithTitle:title.get() URL:url.get()];
     296                previewView.center = center;
     297                UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:previewView.bounds] ]] autorelease];
     298                return [[[UIDragPreview alloc] initWithView:previewView parameters:parameters] autorelease];
     299            };
     300        }
     301#if ENABLE(INPUT_TYPE_COLOR)
     302        else if (source.action & DragSourceActionColor) {
     303            dragItem.previewProvider = [image = source.image] () -> UIDragPreview * {
     304                UIImageView *imageView = [[[UIImageView alloc] initWithImage:image.get()] autorelease];
     305                UIDragPreviewParameters *parameters = [[[UIDragPreviewParameters alloc] initWithTextLineRects:@[ [NSValue valueWithCGRect:[imageView bounds]] ]] autorelease];
     306                return [[[UIDragPreview alloc] initWithView:imageView parameters:parameters] autorelease];
     307            };
     308        }
     309#endif
    265310
    266311        source.possiblyNeedsDragPreviewUpdate = false;
  • trunk/Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm

    r234461 r234930  
    181181    }
    182182
    183     _colorPicker = adoptNS([[UIView alloc] initWithSize:colorPickerSize]);
     183    _colorPicker = adoptNS([[UIView alloc] initWithFrame:CGRectMake(0, 0, colorPickerSize.width, colorPickerSize.height)]);
    184184
    185185    CGFloat totalRows = [[getPKColorMatrixViewClass() defaultColorMatrix] count] + 1;
  • trunk/Source/WebKit/UIProcess/mac/WebColorPickerMac.h

    r234172 r234930  
    3939#import <WebCore/IntRect.h>
    4040#include <wtf/RetainPtr.h>
     41#include <wtf/Vector.h>
    4142
    4243namespace WebCore {
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r234376 r234930  
    275275}
    276276
     277long WebPlatformStrategies::setColor(const Color& color, const String& pasteboardName)
     278{
     279    uint64_t newChangeCount { 0 };
     280    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardColor(pasteboardName, color), Messages::WebPasteboardProxy::SetPasteboardColor::Reply(newChangeCount), 0);
     281    return newChangeCount;
     282}
     283
    277284long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
    278285{
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h

    r233753 r234930  
    8686    long setBufferForType(WebCore::SharedBuffer*, const String& pasteboardType, const String& pasteboardName) override;
    8787    long setURL(const WebCore::PasteboardURL&, const String& pasteboardName) override;
     88    long setColor(const WebCore::Color&, const String& pasteboardName) override;
    8889    long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
    8990#endif
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r234900 r234930  
     12018-08-16  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Support drag-and-drop for input[type=color]
     4        https://bugs.webkit.org/show_bug.cgi?id=188464
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebCoreSupport/WebPlatformStrategies.h:
     9        * WebCoreSupport/WebPlatformStrategies.mm:
     10        (WebPlatformStrategies::setColor):
     11
    1122018-08-15  Tim Horton  <timothy_horton@apple.com>
    213
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h

    r233753 r234930  
    8989    long setBufferForType(WebCore::SharedBuffer*, const String& pasteboardType, const String& pasteboardName) override;
    9090    long setURL(const WebCore::PasteboardURL&, const String& pasteboardName) override;
     91    long setColor(const WebCore::Color&, const String& pasteboardName) override;
    9192    long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
    9293};
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm

    r234376 r234930  
    169169}
    170170
     171long WebPlatformStrategies::setColor(const Color& color, const String& pasteboardName)
     172{
     173    return PlatformPasteboard(pasteboardName).setColor(color);
     174}
     175
    171176long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
    172177{
  • trunk/Tools/ChangeLog

    r234920 r234930  
     12018-08-16  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Support drag-and-drop for input[type=color]
     4        https://bugs.webkit.org/show_bug.cgi?id=188464
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Added five cross-platform API tests, to verify that dragging and dropping with
     9        color inputs changes the value of the drop target if and only if both inputs are
     10        enabled. Also tests that the change and input events are fired when changing the
     11        value of a color input through drag and drop.
     12
     13        Additionally, added a macOS-specific test to verify that dropping an item with
     14        NSColorPboardType changes the value of the color input.
     15
     16        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     17        * TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm:
     18        (TestWebKitAPI::TEST):
     19        * TestWebKitAPI/Tests/WebKitCocoa/color-drop.html: Added.
     20        * TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:
     21        (TestWebKitAPI::TEST):
     22
    1232018-08-16  Antti Koivisto  <antti@apple.com>
    224
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r234875 r234930  
    774774                E38A0D351FD50CC300E98C8B /* Threading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38A0D341FD50CBC00E98C8B /* Threading.cpp */; };
    775775                E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3DEA8101F0A588000CBC2E8 /* ThreadGroup.cpp */; };
     776                E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E5036F77211BC22800BFDBE2 /* color-drop.html */; };
    776777                ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = ECA680CD1E68CC0900731D20 /* StringUtilities.mm */; };
    777778                F407FE391F1D0DFC0017CF25 /* enormous.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = F407FE381F1D0DE60017CF25 /* enormous.svg */; };
     
    965966                                1A50AA201A2A51FC00F4C345 /* close-from-within-create-page.html in Copy Resources */,
    966967                                9B270FEE1DDC2C0B002D53F3 /* closed-shadow-tree-test.html in Copy Resources */,
     968                                E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */,
    967969                                F4B825D81EF4DBFB006E417F /* compressed-files.zip in Copy Resources */,
    968970                                5C9E56871DF914AE00C9EE33 /* contentBlockerCheck.html in Copy Resources */,
     
    20072009                E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; };
    20082010                E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
     2011                E5036F77211BC22800BFDBE2 /* color-drop.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "color-drop.html"; sourceTree = "<group>"; };
    20092012                ECA680CD1E68CC0900731D20 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
    20102013                F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
     
    26112614                                2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */,
    26122615                                2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */,
     2616                                E5036F77211BC22800BFDBE2 /* color-drop.html */,
    26132617                                F4B825D61EF4DBD4006E417F /* compressed-files.zip */,
    26142618                                F469FB231F01803500401539 /* contenteditable-and-target.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm

    r234816 r234930  
    4444}
    4545
     46#if ENABLE(INPUT_TYPE_COLOR)
     47
     48TEST(DragAndDropTests, ColorInputToColorInput)
     49{
     50    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
     51    auto webView = [simulator webView];
     52
     53    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     54    [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)];
     55    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]);
     56    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]);
     57}
     58
     59TEST(DragAndDropTests, ColorInputToDisabledColorInput)
     60{
     61    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
     62    auto webView = [simulator webView];
     63
     64    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     65    [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").disabled = true"];
     66    [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)];
     67    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]);
     68    EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]);
     69}
     70
     71TEST(DragAndDropTests, DisabledColorInputToColorInput)
     72{
     73    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
     74    auto webView = [simulator webView];
     75
     76    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     77    [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").disabled = true"];
     78    [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)];
     79    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]);
     80    EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]);
     81}
     82
     83TEST(DragAndDropTests, ReadOnlyColorInputToReadOnlyColorInput)
     84{
     85    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
     86    auto webView = [simulator webView];
     87
     88    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     89    [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").readOnly = true"];
     90    [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").readOnly = true"];
     91    [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)];
     92    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drag-target\").value"]);
     93    EXPECT_WK_STREQ(@"#000000", [webView stringByEvaluatingJavaScript:@"document.getElementById(\"drop-target\").value"]);
     94}
     95
     96TEST(DragAndDropTests, ColorInputEvents)
     97{
     98    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:CGRectMake(0, 0, 320, 500)]);
     99    auto webView = [simulator webView];
     100
     101    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     102
     103    __block bool changeEventFired = false;
     104    [webView performAfterReceivingMessage:@"change" action:^() {
     105        changeEventFired = true;
     106    }];
     107
     108    __block bool inputEventFired = false;
     109    [webView performAfterReceivingMessage:@"input" action:^() {
     110        inputEventFired = true;
     111    }];
     112
     113    [simulator runFrom:CGPointMake(50, 50) to:CGPointMake(150, 50)];
     114    TestWebKitAPI::Util::run(&inputEventFired);
     115    TestWebKitAPI::Util::run(&changeEventFired);
     116}
     117
     118#endif
     119
    46120#endif // WK_API_ENABLED && ENABLE(DRAG_SUPPORT)
  • trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm

    r234816 r234930  
    5959}
    6060
     61#if ENABLE(INPUT_TYPE_COLOR)
     62TEST(DragAndDropTests, DropColor)
     63{
     64    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
     65    [pasteboard declareTypes:@[NSColorPboardType] owner:nil];
     66    [[NSColor redColor] writeToPasteboard:pasteboard];
     67
     68    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:NSMakeRect(0, 0, 400, 400)]);
     69    TestWKWebView *webView = [simulator webView];
     70    [simulator setExternalDragPasteboard:pasteboard];
     71
     72    [webView synchronouslyLoadTestPageNamed:@"color-drop"];
     73    [simulator runFrom:NSMakePoint(0, 0) to:NSMakePoint(50, 50)];
     74    EXPECT_WK_STREQ(@"#ff0000", [webView stringByEvaluatingJavaScript:@"document.querySelector(\"input\").value"]);
     75}
     76#endif // ENABLE(INPUT_TYPE_COLOR)
     77
    6178#endif // WK_API_ENABLED && ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.