[iOS DnD] Elements in the DOM with the `draggable` attribute should be draggable
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2017 19:06:00 +0000 (19:06 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2017 19:06:00 +0000 (19:06 +0000)
commit375bc2e85cf235dd9bf2adf93ef7c5584eedea15
tree49360b29f3dbfd81e97ba3c62ed2bbedb7a8e5c1
parent8f9bcc94122ed3ff4239b120078c2c30fd3b1fe5
[iOS DnD] Elements in the DOM with the `draggable` attribute should be draggable
https://bugs.webkit.org/show_bug.cgi?id=176664
<rdar://problem/32596156>

Reviewed by Tim Horton.

Source/WebKit:

Makes a simple adjustment in DragDropInteractionState::previewForDragItem to respect the drag image supplied to
the UI process during a "DHTML"-defined drag (i.e. DragSourceActionDHTML).

Test: DataInteractionTests.CanStartDragOnDivWithDraggableAttribute

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _simulateDataInteractionEntered:]): Deleted.
(-[WKWebView _simulateDataInteractionUpdated:]): Deleted.
(-[WKWebView _simulateDataInteractionPerformOperation:]): Deleted.
(-[WKWebView _simulateDataInteractionEnded:]): Deleted.
(-[WKWebView _simulateDataInteractionSessionDidEnd:]): Deleted.
(-[WKWebView _simulateWillBeginDataInteractionWithSession:]): Deleted.
(-[WKWebView _simulatedItemsForSession:]): Deleted.
(-[WKWebView _simulateItemsForAddingToSession:atLocation:completion:]): Deleted.
(-[WKWebView _simulatePrepareForDataInteractionSession:completion:]): Deleted.

Remove all -_simulate*: testing helpers on WKWebView.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/DragDropInteractionState.mm:
(WebKit::shouldUseDragImageToCreatePreviewForDragSource):
(WebKit::shouldUseTextIndicatorToCreatePreviewForDragSource):

Add shouldUseDragImageToCreatePreviewForDragSource, which returns YES when dragging an image or DHTML-defined
draggable element and the drag image exists. This is called from previewForDragItem when constructing the drag
preview for a given UIDragItem.

(WebKit::DragDropInteractionState::previewForDragItem const):
(WebKit::shouldUseTextIndicatorToCreatePreviewForDragAction): Deleted.
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _simulateDataInteractionEntered:]): Deleted.
(-[WKContentView _simulateDataInteractionUpdated:]): Deleted.
(-[WKContentView _simulateDataInteractionEnded:]): Deleted.
(-[WKContentView _simulateDataInteractionPerformOperation:]): Deleted.
(-[WKContentView _simulateDataInteractionSessionDidEnd:]): Deleted.
(-[WKContentView _simulateWillBeginDataInteractionWithSession:]): Deleted.
(-[WKContentView _simulatedItemsForSession:]): Deleted.
(-[WKContentView _simulatePrepareForDataInteractionSession:completion:]): Deleted.
(-[WKContentView _simulateItemsForAddingToSession:atLocation:completion:]): Deleted.

Remove all -_simulate*: testing helpers on WKContentView.

Tools:

Adds a new API test checking that elements marked as drag sources via the `draggable` attribute can be dragged
with a non-null drag preview. Additionally, refactor the drag and drop simulator to not plumb drag/drop
interaction delegate calls through to the WKContentView via -_simulate*-prefixed testing SPI, but rather
by grabbing the WKWebView's drag and drop interaction delegates (i.e. the WKContentView) and calling delegate
methods directly. This avoids requiring boilerplate plumbing on WKWebView and WKContentView for each of the drag
and drop delegate methods, so these have been removed from WKWebView and WKContentView.

Additionally, renames MockDataOperationSession and MockDataInteractionSession to MockDragSession and
MockDropSession, respectively, and adjusts their ivars on DataInteractionSimulator to match.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/custom-draggable-div.html: Added.

Add a new test harness covering dragging and dropping elements with the draggable attribute, using DataTransfer
API (setData and getData) as well.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/DataInteractionSimulator.h:
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
(-[WKWebView dropInteractionDelegate]):
(-[WKWebView dragInteractionDelegate]):
(-[WKWebView dropInteraction]):
(-[WKWebView dragInteraction]):

Add testing utilities to ask a WKWebView for information about its drag/drop interactions and delegates. In this
case, this will return the WKWebView's WKContentView.

(-[DataInteractionSimulator _resetSimulatedState]):
(-[DataInteractionSimulator simulateAllTouchesCanceled:]):
(-[DataInteractionSimulator runFrom:to:additionalItemRequestLocations:]):
(-[DataInteractionSimulator _concludeDataInteractionAndPerformOperationIfNecessary]):
(-[DataInteractionSimulator _sendQueuedAdditionalItemRequest]):
(-[DataInteractionSimulator _advanceProgress]):

When beginning a drag session, ask the delegate for targeted lift previews and verify that these are non-null.
This check would fail prior to the tweak in DragDropInteractionState in this patch.

(-[DataInteractionSimulator _webView:showCustomSheetForElement:]):
(-[MockDataOperationSession initWithProviders:location:window:allowMove:]): Deleted.
(-[MockDataOperationSession session]): Deleted.
(-[MockDataOperationSession isLocal]): Deleted.
(-[MockDataOperationSession progress]): Deleted.
(-[MockDataOperationSession setProgressIndicatorStyle:]): Deleted.
(-[MockDataOperationSession progressIndicatorStyle]): Deleted.
(-[MockDataOperationSession operationMask]): Deleted.
(-[MockDataOperationSession localDragSession]): Deleted.
(-[MockDataOperationSession hasItemsConformingToTypeIdentifier:]): Deleted.
(-[MockDataOperationSession canCreateItemsOfClass:]): Deleted.
(-[MockDataOperationSession loadObjectsOfClass:completion:]): Deleted.
(-[MockDataInteractionSession initWithWindow:allowMove:]): Deleted.
(-[MockDataInteractionSession localOperationMask]): Deleted.
(-[MockDataInteractionSession externalOperationMask]): Deleted.

Replace various places where we called -_simulate* methods on WKWebView with calls to the
UIDragInteractionDelegate or UIDropInteractionDelegate (the WKContentView) instead. Also, adjust for some
mechanical renaming of drag and drop sessions.

(-[MockDataInteractionSession session]): Deleted.
* TestWebKitAPI/ios/UIKitSPI.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221870 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/ios/DragDropInteractionState.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/custom-draggable-div.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
Tools/TestWebKitAPI/ios/DataInteractionSimulator.h
Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm
Tools/TestWebKitAPI/ios/UIKitSPI.h