Support drag-and-drop for input[type=color]
authorakeerthi@apple.com <akeerthi@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2018 16:44:17 +0000 (16:44 +0000)
committerakeerthi@apple.com <akeerthi@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Aug 2018 16:44:17 +0000 (16:44 +0000)
commitd23016d026e09998b581a7d5ebf666e865bd61d2
treeddc1c54f056aa80598efc0daed4129e4914043dc
parent5a1688e81dbfbf47016c93023834155413242b25
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234930 268f45cc-cd09-0410-ab3c-d52691b4dbfc
52 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/drag-and-drop-color-input-events-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/drag-and-drop-color-input-events.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/drag-and-drop-color-input-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/drag-and-drop-color-input.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/DragActions.h
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h
Source/WebCore/page/mac/DragControllerMac.mm
Source/WebCore/platform/DragData.h
Source/WebCore/platform/DragImage.cpp
Source/WebCore/platform/DragImage.h
Source/WebCore/platform/DragItem.h
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/PasteboardStrategy.h
Source/WebCore/platform/PlatformPasteboard.h
Source/WebCore/platform/gtk/DragImageGtk.cpp
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/ios/DragImageIOS.mm
Source/WebCore/platform/ios/PasteboardIOS.mm
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
Source/WebCore/platform/mac/DragDataMac.mm
Source/WebCore/platform/mac/DragImageMac.mm
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/mac/PlatformPasteboardMac.mm
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/platform/wpe/PasteboardWPE.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
Source/WebKit/UIProcess/WebPasteboardProxy.h
Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
Source/WebKit/UIProcess/ios/DragDropInteractionState.h
Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
Source/WebKit/UIProcess/ios/forms/WKFormColorPicker.mm
Source/WebKit/UIProcess/mac/WebColorPickerMac.h
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/DragAndDropTests.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/color-drop.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm