Changeset 252874 in webkit


Ignore:
Timestamp:
Nov 25, 2019 10:08:58 PM (4 years ago)
Author:
Wenson Hsieh
Message:

[macOS] Dragged images are only available as .tiff when dropping onto macCatalyst apps
https://bugs.webkit.org/show_bug.cgi?id=204598
<rdar://problem/57093920>

Reviewed by Tim Horton.

Source/WebKit:

On macOS, writing dragged images to the pasteboard only as file promises is mostly sufficient for the purposes
of dropping into Finder, Photos, and other apps. However, when dropping into a macCatalyst app, the contents of
NSPasteboard will only contain a file URL, which most Catalyst apps aren't able to handle. The only other valid
image representation that is written to the pasteboard in this case is "public.tiff", which loses fidelity in
the case of animated GIFs.

Instead, if the dragged image has a corresponding UTI and corresponding decoded image data, declare the UTI when
writing promised data to the pasteboard, and later provide data for the UTI, if the drop destination asks, by
using the promised image's data.

Test: DragAndDropTests.ProvideImageDataAsTypeIdentifiers

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::setPromisedDataForImage):
(WebKit::WebViewImpl::provideDataForPasteboard):

Tools:

Verify that WKWebView is able to provide data in non-TIFF formats when dragging several types of images using a
new API test.

  • TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r252873 r252874  
     12019-11-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Dragged images are only available as .tiff when dropping onto macCatalyst apps
     4        https://bugs.webkit.org/show_bug.cgi?id=204598
     5        <rdar://problem/57093920>
     6
     7        Reviewed by Tim Horton.
     8
     9        On macOS, writing dragged images to the pasteboard only as file promises is mostly sufficient for the purposes
     10        of dropping into Finder, Photos, and other apps. However, when dropping into a macCatalyst app, the contents of
     11        NSPasteboard will only contain a file URL, which most Catalyst apps aren't able to handle. The only other valid
     12        image representation that is written to the pasteboard in this case is "public.tiff", which loses fidelity in
     13        the case of animated GIFs.
     14
     15        Instead, if the dragged image has a corresponding UTI and corresponding decoded image data, declare the UTI when
     16        writing promised data to the pasteboard, and later provide data for the UTI, if the drop destination asks, by
     17        using the promised image's data.
     18
     19        Test: DragAndDropTests.ProvideImageDataAsTypeIdentifiers
     20
     21        * UIProcess/Cocoa/WebViewImpl.mm:
     22        (WebKit::WebViewImpl::setPromisedDataForImage):
     23        (WebKit::WebViewImpl::provideDataForPasteboard):
     24
    1252019-11-25  Fujii Hironori  <Hironori.Fujii@sony.com>
    226
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r252762 r252874  
    42384238    RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:WebCore::legacyFilesPromisePasteboardType(), nil]);
    42394239
     4240    if (image && !image->uti().isEmpty() && image->data() && !image->data()->isEmpty())
     4241        [types addObject:image->uti()];
     4242
    42404243    [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
    42414244    [pasteboard declareTypes:types.get() owner:m_view.getAutoreleased()];
     
    42654268void WebViewImpl::provideDataForPasteboard(NSPasteboard *pasteboard, NSString *type)
    42664269{
     4270    if (!m_promisedImage)
     4271        return;
     4272
     4273    if ([type isEqual:m_promisedImage->uti()] && m_promisedImage->data()) {
     4274        if (auto platformData = m_promisedImage->data()->createNSData())
     4275            [pasteboard setData:(__bridge NSData *)platformData.get() forType:type];
     4276    }
     4277
    42674278    // FIXME: Need to support NSRTFDPboardType.
    4268     if ([type isEqual:WebCore::legacyTIFFPasteboardType()] && m_promisedImage)
     4279    if ([type isEqual:WebCore::legacyTIFFPasteboardType()])
    42694280        [pasteboard setData:(__bridge NSData *)m_promisedImage->tiffRepresentation() forType:WebCore::legacyTIFFPasteboardType()];
    42704281}
  • trunk/Tools/ChangeLog

    r252872 r252874  
     12019-11-25  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Dragged images are only available as .tiff when dropping onto macCatalyst apps
     4        https://bugs.webkit.org/show_bug.cgi?id=204598
     5        <rdar://problem/57093920>
     6
     7        Reviewed by Tim Horton.
     8
     9        Verify that WKWebView is able to provide data in non-TIFF formats when dragging several types of images using a
     10        new API test.
     11
     12        * TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:
     13
    1142019-11-25  Ross Kirsling  <ross.kirsling@sony.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm

    r248166 r252874  
    2828#import "DragAndDropSimulator.h"
    2929#import "PlatformUtilities.h"
     30#import <WebKit/WKPreferencesPrivate.h>
    3031
    3132#if ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)
     
    159160}
    160161
     162TEST(DragAndDropTests, ProvideImageDataAsTypeIdentifiers)
     163{
     164    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     165    [[configuration preferences] _setLargeImageAsyncDecodingEnabled:NO];
     166
     167    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:NSMakeRect(0, 0, 400, 400) configuration:configuration.get()]);
     168    TestWKWebView *webView = [simulator webView];
     169
     170    auto uniquePasteboard = retainPtr(NSPasteboard.pasteboardWithUniqueName);
     171
     172    [webView synchronouslyLoadHTMLString:@"<img src='sunset-in-cupertino-600px.jpg'></img>"];
     173    [simulator runFrom:NSMakePoint(25, 25) to:NSMakePoint(300, 300)];
     174    [webView pasteboard:uniquePasteboard.get() provideDataForType:(__bridge NSString *)kUTTypeJPEG];
     175    EXPECT_GT([uniquePasteboard dataForType:(__bridge NSString *)kUTTypeJPEG].length, 0u);
     176
     177    [webView synchronouslyLoadHTMLString:@"<img src='icon.png'></img>"];
     178    [simulator runFrom:NSMakePoint(25, 25) to:NSMakePoint(300, 300)];
     179    [webView pasteboard:uniquePasteboard.get() provideDataForType:(__bridge NSString *)kUTTypePNG];
     180    EXPECT_GT([uniquePasteboard dataForType:(__bridge NSString *)kUTTypePNG].length, 0u);
     181
     182    [webView synchronouslyLoadHTMLString:@"<img src='apple.gif'></img>"];
     183    [simulator runFrom:NSMakePoint(25, 25) to:NSMakePoint(300, 300)];
     184    [webView pasteboard:uniquePasteboard.get() provideDataForType:(__bridge NSString *)kUTTypeGIF];
     185    EXPECT_GT([uniquePasteboard dataForType:(__bridge NSString *)kUTTypeGIF].length, 0u);
     186}
     187
    161188#endif // ENABLE(DRAG_SUPPORT) && PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.