12017-09-13 Wenson Hsieh <wenson_hsieh@apple.com>
2
3 [iOS DnD] Support DataTransfer.setDragImage when starting a drag on iOS
4 https://bugs.webkit.org/show_bug.cgi?id=176721
5 <rdar://problem/34373660>
6
7 Reviewed by NOBODY (OOPS!).
8
9 Adds support for setting the drag lift preview frame in the case where DataTransfer.setDragImage is being used
10 to override the default drag preview. Currently, the frame of the drag preview we supply in this case is the
11 same as the bounds of the source element in root view coordinates, but this means that any custom drag image
12 the page supplies will be stretched to fill the frame of the source element. Instead, when handling a DHTML drag,
13 position the lift and cancel drag previews relative to the event location, respecting any drag offset specified
14 in setDragImage. The size of this preview matches the size of the drag image source (since this is all in root
15 view coordinates, this means the drag preview will also enlarge if the user pinches to zoom in). If a
16 disconnected image source element was provided, then we just fall back to the image size.
17
18 Additionally, renames DragItem's elementBounds to dragPreviewFrameInRootViewCoordinates to better reflect the
19 purpose of this variable. This patch also introduces API test plumbing to grab targeted drag previews from the
20 drag interaction delegate (i.e. WKContentView), and uses this in a new API test that checks the frame of the
21 resulting UITargetedDragPreview after initiating a drag in various circumstances (see changes in Tools/ for more
22 detail).
23
24 Test: DataInteractionTests.DragLiftPreviewDataTransferSetDragImage
25
26 * dom/DataTransfer.cpp:
27 (WebCore::DataTransfer::dragImageElement const):
28 * dom/DataTransfer.h:
29 * page/DragController.cpp:
30 (WebCore::dragLocForDHTMLDrag):
31
32 The logic to flip the y offset when computing the drag location is only relevant on Mac, but currently, this is
33 guarded by #if PLATFORM(COCOA), which causes the y offset to shift the drag image in the opposite direction on
34 iOS. To fix this, simply change the platform define to Mac.
35
36 (WebCore::DragController::doSystemDrag):
37 * platform/DragItem.h:
38 (WebCore::DragItem::encode const):
39 (WebCore::DragItem::decode):
40