[iOS DnD] [WK1] Snapshots generated using -[DOMRange renderImageForcingBlackText...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jul 2017 07:31:06 +0000 (07:31 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jul 2017 07:31:06 +0000 (07:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174928
<rdar://problem/33584280>

Reviewed by Tim Horton.

Pulls the implementation of createDragImageForRange out into DragImageIOS, and use TextIndicator to generate a
snapshot instead of FrameSelection's snapshotting utilities. This makes snapshotting a DOMRange behave the same
way as snapshotting a dragged selection.

No way of testing TextIndicator-based snapshotting yet.

* platform/DragImage.cpp:

Guard createDragImageForRange for !PLATFORM(IOS).

* platform/ios/DragImageIOS.mm:
(WebCore::createDragImageForSelection):

Add a FIXME to point out that having an additional context flip inside the UIGraphicsImageRenderer block results
in an upside-down drag image being returned from createDragImageFromImage. This image is being flipped elsewhere
in drag initiation code, which eventually results in the correct orientation; we'll need further investigation
to remove this extraneous flip.

(WebCore::createDragImageForRange):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/DragImage.cpp
Source/WebCore/platform/ios/DragImageIOS.mm

index b77c492..a619434 100644 (file)
@@ -1,3 +1,31 @@
+2017-07-28  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS DnD] [WK1] Snapshots generated using -[DOMRange renderImageForcingBlackText:] are upside down
+        https://bugs.webkit.org/show_bug.cgi?id=174928
+        <rdar://problem/33584280>
+
+        Reviewed by Tim Horton.
+
+        Pulls the implementation of createDragImageForRange out into DragImageIOS, and use TextIndicator to generate a
+        snapshot instead of FrameSelection's snapshotting utilities. This makes snapshotting a DOMRange behave the same
+        way as snapshotting a dragged selection.
+
+        No way of testing TextIndicator-based snapshotting yet.
+
+        * platform/DragImage.cpp:
+
+        Guard createDragImageForRange for !PLATFORM(IOS).
+
+        * platform/ios/DragImageIOS.mm:
+        (WebCore::createDragImageForSelection):
+
+        Add a FIXME to point out that having an additional context flip inside the UIGraphicsImageRenderer block results
+        in an upside-down drag image being returned from createDragImageFromImage. This image is being flipped elsewhere
+        in drag initiation code, which eventually results in the correct orientation; we'll need further investigation
+        to remove this extraneous flip.
+
+        (WebCore::createDragImageForRange):
+
 2017-07-28  Jeremy Jones  <jeremyj@apple.com>
 
         Remove Web prefix from WebVideoFullscreen and WebPlaybackSession classes.
index 1133b99..cd2bd43 100644 (file)
@@ -152,6 +152,8 @@ struct ScopedFrameSelectionState {
     std::optional<unsigned> endOffset;
 };
 
+#if !PLATFORM(IOS)
+
 DragImageRef createDragImageForRange(Frame& frame, Range& range, bool forceBlackText)
 {
     frame.document()->updateLayout();
@@ -190,6 +192,8 @@ DragImageRef createDragImageForRange(Frame& frame, Range& range, bool forceBlack
     return createDragImageFromSnapshot(snapshotFrameRect(frame, view->selectionBounds(), options), nullptr);
 }
 
+#endif
+
 DragImageRef createDragImageForImage(Frame& frame, Node& node, IntRect& imageRect, IntRect& elementRect)
 {
     ScopedNodeDragEnabler enableDrag(frame, node);
index 0254917..a7996fd 100644 (file)
@@ -209,6 +209,8 @@ DragImageRef createDragImageForSelection(Frame& frame, TextIndicatorData& indica
     RetainPtr<UIGraphicsImageRenderer> render = adoptNS([allocUIGraphicsImageRendererInstance() initWithSize:imageRect.size()]);
     UIImage *finalImage = [render.get() imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) {
         GraphicsContext context(rendererContext.CGContext);
+        // FIXME: The context flip here should not be necessary, and suggests that somewhere else in the regular
+        // drag initiation flow, we unnecessarily flip the graphics context.
         context.translate(0, imageRect.height());
         context.scale({ 1, -1 });
         context.drawImage(*image, imageRect);
@@ -223,6 +225,32 @@ DragImageRef dissolveDragImageToFraction(DragImageRef image, float)
     return image;
 }
 
+DragImageRef createDragImageForRange(Frame& frame, Range& range, bool forceBlackText)
+{
+    if (auto document = frame.document())
+        document->updateLayout();
+
+    if (range.collapsed())
+        return nil;
+
+    TextIndicatorOptions options = defaultSelectionDragImageTextIndicatorOptions;
+    if (!forceBlackText)
+        options |= TextIndicatorOptionRespectTextColor;
+
+    auto textIndicator = TextIndicator::createWithRange(range, options, TextIndicatorPresentationTransition::None);
+    if (!textIndicator || !textIndicator->contentImage())
+        return nil;
+
+    auto& image = *textIndicator->contentImage();
+    auto render = adoptNS([allocUIGraphicsImageRendererInstance() initWithSize:image.size()]);
+    UIImage *finalImage = [render.get() imageWithActions:[&image](UIGraphicsImageRendererContext *rendererContext) {
+        GraphicsContext context(rendererContext.CGContext);
+        context.drawImage(image, FloatPoint());
+    }];
+
+    return finalImage.CGImage;
+}
+
 #else
 
 void deleteDragImage(RetainPtr<CGImageRef>)
@@ -247,6 +275,11 @@ RetainPtr<CGImageRef> createDragImageFromImage(Image*, ImageOrientationDescripti
     return nullptr;
 }
 
+DragImageRef createDragImageForRange(Frame&, Range&, bool)
+{
+    return nullptr;
+}
+
 #endif
 
 } // namespace WebCore