Changeset 206802 in webkit


Ignore:
Timestamp:
Oct 4, 2016, 6:52:35 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

The dragged image should be the current frame only of the animated image
https://bugs.webkit.org/show_bug.cgi?id=162109

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2016-10-04
Reviewed by Tim Horton.

Source/WebCore:

Instead of creating an NSImage with all the frames for the dragImage,
create an NSImage with the current frame only.

  • dom/DataTransferMac.mm:

(WebCore::DataTransfer::createDragImage): Call snapshotNSImage() to create the dragImage.

  • editing/cocoa/HTMLConverter.mm:

(fileWrapperForElement): Call the Image function with its new name.

  • platform/graphics/BitmapImage.h:
  • platform/graphics/Image.h:

(WebCore::Image::nsImage): Rename getNSImage() to nsImage().
(WebCore::Image::snapshotNSImage): Returns the NSImage of the current frame.
(WebCore::Image::tiffRepresentation): Rename getTIFFRepresentation() to tiffRepresentation().
(WebCore::Image::getNSImage): Deleted.
(WebCore::Image::getTIFFRepresentation): Deleted.

  • platform/graphics/mac/ImageMac.mm:

(WebCore::BitmapImage::tiffRepresentation): Rename getTIFFRepresentation() to tiffRepresentation().
(WebCore::BitmapImage::nsImage): Rename getNSImage() to nsImage().
(WebCore::BitmapImage::snapshotNSImage): Returns the NSImage of the current frame.
(WebCore::BitmapImage::getTIFFRepresentation): Deleted.
(WebCore::BitmapImage::getNSImage): Deleted.

  • platform/mac/CursorMac.mm:

(WebCore::createCustomCursor): Call snapshotNSImage() since the cursor does not animate anyway.

  • platform/mac/DragImageMac.mm:

(WebCore::createDragImageFromImage): Use snapshotNSImage() for the dragImage.

  • platform/mac/PasteboardMac.mm:

(WebCore::Pasteboard::write): Call the Image function with its new name.

Source/WebKit/mac:

  • DOM/DOM.mm:

(-[DOMElement image]): Call the Image function with its new name.
(-[DOMElement _imageTIFFRepresentation]): Ditto.

  • Misc/WebElementDictionary.mm:

(-[WebElementDictionary _image]): Call the Image function with its new name.

  • Misc/WebIconDatabase.mm:

(-[WebIconDatabase defaultIconWithSize:]): Call snapshotNSImage() to create the icon image.
(webGetNSImage): Call the Image function with its new name.

  • WebCoreSupport/WebContextMenuClient.mm:

(WebContextMenuClient::imageForCurrentSharingServicePickerItem): Call snapshotNSImage() instead of nsImage()..
(WebContextMenuClient::contextMenuForEvent): Ditto.

  • WebView/WebHTMLView.mm:

(-[WebHTMLView pasteboard:provideDataForType:]): Call the Image function with its new name.

Source/WebKit2:

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::provideDataForPasteboard): Call the Image function with its new name.

Location:
trunk/Source
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206801 r206802  
     12016-10-04  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        The dragged image should be the current frame only of the animated image
     4        https://bugs.webkit.org/show_bug.cgi?id=162109
     5
     6        Reviewed by Tim Horton.
     7
     8        Instead of creating an NSImage with all the frames for the dragImage,
     9        create an NSImage with the current frame only.
     10
     11        * dom/DataTransferMac.mm:
     12        (WebCore::DataTransfer::createDragImage): Call snapshotNSImage() to create the dragImage.
     13        * editing/cocoa/HTMLConverter.mm:
     14        (fileWrapperForElement):  Call the Image function with its new name.
     15        * platform/graphics/BitmapImage.h:
     16        * platform/graphics/Image.h:
     17        (WebCore::Image::nsImage): Rename getNSImage() to nsImage().
     18        (WebCore::Image::snapshotNSImage): Returns the NSImage of the current frame.
     19        (WebCore::Image::tiffRepresentation): Rename getTIFFRepresentation() to tiffRepresentation().
     20        (WebCore::Image::getNSImage): Deleted.
     21        (WebCore::Image::getTIFFRepresentation): Deleted.
     22        * platform/graphics/mac/ImageMac.mm:
     23        (WebCore::BitmapImage::tiffRepresentation): Rename getTIFFRepresentation() to tiffRepresentation().
     24        (WebCore::BitmapImage::nsImage): Rename getNSImage() to nsImage().
     25        (WebCore::BitmapImage::snapshotNSImage): Returns the NSImage of the current frame.
     26        (WebCore::BitmapImage::getTIFFRepresentation): Deleted.
     27        (WebCore::BitmapImage::getNSImage): Deleted.
     28        * platform/mac/CursorMac.mm:
     29        (WebCore::createCustomCursor): Call snapshotNSImage() since the cursor does not animate anyway.
     30        * platform/mac/DragImageMac.mm:
     31        (WebCore::createDragImageFromImage): Use snapshotNSImage() for the dragImage.
     32        * platform/mac/PasteboardMac.mm:
     33        (WebCore::Pasteboard::write): Call the Image function with its new name.
     34
    1352016-10-04  Andy Estes  <aestes@apple.com>
    236
  • trunk/Source/WebCore/dom/DataTransferMac.mm

    r206720 r206802  
    5050        }
    5151    } else if (m_dragImage) {
    52         result = m_dragImage->image()->getNSImage();
     52        result = m_dragImage->image()->snapshotNSImage();
    5353       
    5454        location = m_dragLocation;
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r206720 r206802  
    24652465        auto* image = downcast<RenderImage>(*renderer).cachedImage();
    24662466        if (image && !image->errorOccurred()) {
    2467             RetainPtr<NSFileWrapper> wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:(NSData *)image->imageForRenderer(renderer)->getTIFFRepresentation()]);
     2467            RetainPtr<NSFileWrapper> wrapper = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:(NSData *)image->imageForRenderer(renderer)->tiffRepresentation()]);
    24682468            [wrapper setPreferredFilename:@"image.tiff"];
    24692469            return wrapper;
  • trunk/Source/WebCore/platform/graphics/BitmapImage.h

    r206742 r206802  
    9797    // Accessors for native image formats.
    9898#if USE(APPKIT)
    99     NSImage* getNSImage() override;
     99    NSImage *nsImage() override;
     100    RetainPtr<NSImage> snapshotNSImage() override;
    100101#endif
    101102
    102103#if PLATFORM(COCOA)
    103     CFDataRef getTIFFRepresentation() override;
     104    CFDataRef tiffRepresentation() override;
    104105#endif
    105106
     
    179180#endif
    180181
     182#if PLATFORM(COCOA)
     183    RetainPtr<CFDataRef> tiffRepresentation(const Vector<NativeImagePtr>&);
     184#endif
     185
    181186private:
    182187    void clearTimer();
     
    195200
    196201#if USE(APPKIT)
    197     mutable RetainPtr<NSImage> m_nsImage; // A cached NSImage of frame 0. Only built lazily if someone actually queries for one.
     202    mutable RetainPtr<NSImage> m_nsImage; // A cached NSImage of all the frames. Only built lazily if someone actually queries for one.
    198203#endif
    199204#if USE(CG)
    200     mutable RetainPtr<CFDataRef> m_tiffRep; // Cached TIFF rep for frame 0. Only built lazily if someone queries for one.
     205    mutable RetainPtr<CFDataRef> m_tiffRep; // Cached TIFF rep for all the frames. Only built lazily if someone queries for one.
    201206#endif
    202207    RefPtr<Image> m_cachedImage;
  • trunk/Source/WebCore/platform/graphics/Image.h

    r206720 r206802  
    147147
    148148#if USE(APPKIT)
    149     virtual NSImage* getNSImage() { return nullptr; }
     149    virtual NSImage *nsImage() { return nullptr; }
     150    virtual RetainPtr<NSImage> snapshotNSImage() { return nullptr; }
    150151#endif
    151152
    152153#if PLATFORM(COCOA)
    153     virtual CFDataRef getTIFFRepresentation() { return nullptr; }
     154    virtual CFDataRef tiffRepresentation() { return nullptr; }
    154155#endif
    155156
     
    194195    // Supporting tiled drawing
    195196    virtual Color singlePixelSolidColor() const { return Color(); }
    196    
     197
    197198private:
    198199    RefPtr<SharedBuffer> m_encodedImageData;
  • trunk/Source/WebCore/platform/graphics/mac/ImageMac.mm

    r206720 r206802  
    7575}
    7676
    77 CFDataRef BitmapImage::getTIFFRepresentation()
     77RetainPtr<CFDataRef> BitmapImage::tiffRepresentation(const Vector<NativeImagePtr>& nativeImages)
    7878{
    79     if (m_tiffRep)
    80         return m_tiffRep.get();
    81 
    82     auto nativeImages = this->framesNativeImages();
    83 
    84     // If framesImages.size() is zero, we know for certain this image doesn't have valid data
     79    // If nativeImages.size() is zero, we know for certain this image doesn't have valid data
    8580    // Even though the call to CGImageDestinationCreateWithData will fail and we'll handle it gracefully,
    8681    // in certain circumstances that call will spam the console with an error message
     
    9893
    9994    CGImageDestinationFinalize(destination.get());
     95    return data;
     96}
     97
     98CFDataRef BitmapImage::tiffRepresentation()
     99{
     100    if (m_tiffRep)
     101        return m_tiffRep.get();
     102
     103    auto data = tiffRepresentation(framesNativeImages());
     104    if (!data)
     105        return nullptr;
    100106
    101107    m_tiffRep = data;
    102108    return m_tiffRep.get();
     109
     110   
    103111}
    104112
    105113#if USE(APPKIT)
    106 NSImage* BitmapImage::getNSImage()
     114NSImage* BitmapImage::nsImage()
    107115{
    108116    if (m_nsImage)
    109117        return m_nsImage.get();
    110118
    111     CFDataRef data = getTIFFRepresentation();
     119    CFDataRef data = tiffRepresentation();
    112120    if (!data)
    113         return 0;
     121        return nullptr;
    114122   
    115123    m_nsImage = adoptNS([[NSImage alloc] initWithData:(NSData*)data]);
    116124    return m_nsImage.get();
    117125}
     126
     127RetainPtr<NSImage> BitmapImage::snapshotNSImage()
     128{
     129    auto nativeImage = this->nativeImageForCurrentFrame();
     130    if (!nativeImage)
     131        return nullptr;
     132
     133    auto data = tiffRepresentation({ nativeImage });
     134    if (!data)
     135        return nullptr;
     136
     137    return adoptNS([[NSImage alloc] initWithData:(NSData*)data.get()]);
     138}
    118139#endif
    119140
  • trunk/Source/WebCore/platform/mac/CursorMac.mm

    r206720 r206802  
    4949{
    5050    // FIXME: The cursor won't animate.  Not sure if that's a big deal.
    51     NSImage* nsImage = image->getNSImage();
     51    auto nsImage = image->snapshotNSImage();
    5252    if (!nsImage)
    53         return 0;
     53        return nullptr;
    5454    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    5555
     
    7979#endif
    8080
    81     return adoptNS([[NSCursor alloc] initWithImage:nsImage hotSpot:hotSpot]);
     81    return adoptNS([[NSCursor alloc] initWithImage:nsImage.get() hotSpot:hotSpot]);
    8282    END_BLOCK_OBJC_EXCEPTIONS;
    8383    return nullptr;
  • trunk/Source/WebCore/platform/mac/DragImageMac.mm

    r206720 r206802  
    122122#pragma clang diagnostic push
    123123#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    124             [image->getNSImage() drawInRect:destRect fromRect:NSMakeRect(0, 0, size.width(), size.height()) operation:NSCompositeSourceOver fraction:1.0];
     124            [image->snapshotNSImage() drawInRect:destRect fromRect:NSMakeRect(0, 0, size.width(), size.height()) operation:NSCompositeSourceOver fraction:1.0];
    125125#pragma clang diagnostic pop
    126126            [rotatedDragImage.get() unlockFocus];
     
    130130    }
    131131
    132     RetainPtr<NSImage> dragImage = adoptNS([image->getNSImage() copy]);
     132    auto dragImage = image->snapshotNSImage();
    133133    [dragImage.get() setSize:(NSSize)size];
    134134    return dragImage;
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r206720 r206802  
    256256void Pasteboard::write(const PasteboardImage& pasteboardImage)
    257257{
    258     CFDataRef imageData = pasteboardImage.image->getTIFFRepresentation();
     258    CFDataRef imageData = pasteboardImage.image->tiffRepresentation();
    259259    if (!imageData)
    260260        return;
  • trunk/Source/WebKit/mac/ChangeLog

    r206720 r206802  
     12016-10-04  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        The dragged image should be the current frame only of the animated image
     4        https://bugs.webkit.org/show_bug.cgi?id=162109
     5
     6        Reviewed by Tim Horton.
     7
     8        * DOM/DOM.mm:
     9        (-[DOMElement image]): Call the Image function with its new name.
     10        (-[DOMElement _imageTIFFRepresentation]): Ditto.
     11        * Misc/WebElementDictionary.mm:
     12        (-[WebElementDictionary _image]): Call the Image function with its new name.
     13        * Misc/WebIconDatabase.mm:
     14        (-[WebIconDatabase defaultIconWithSize:]): Call snapshotNSImage() to create the icon image.
     15        (webGetNSImage): Call the Image function with its new name.
     16        * WebCoreSupport/WebContextMenuClient.mm:
     17        (WebContextMenuClient::imageForCurrentSharingServicePickerItem): Call snapshotNSImage() instead of nsImage()..
     18        (WebContextMenuClient::contextMenuForEvent): Ditto.
     19        * WebView/WebHTMLView.mm:
     20        (-[WebHTMLView pasteboard:provideDataForType:]): Call the Image function with its new name.
     21
    1222016-10-02  Ryan Haddad  <ryanhaddad@apple.com>
    223
  • trunk/Source/WebKit/mac/DOM/DOM.mm

    r206720 r206802  
    671671    if (!cachedImage || cachedImage->errorOccurred())
    672672        return nil;
    673     return cachedImage->imageForRenderer(renderer)->getNSImage();
     673    return cachedImage->imageForRenderer(renderer)->nsImage();
    674674}
    675675
     
    699699    if (!cachedImage || cachedImage->errorOccurred())
    700700        return nil;
    701     return (NSData *)cachedImage->imageForRenderer(renderer)->getTIFFRepresentation();
     701    return (NSData *)cachedImage->imageForRenderer(renderer)->tiffRepresentation();
    702702}
    703703
  • trunk/Source/WebKit/mac/Misc/WebElementDictionary.mm

    r206720 r206802  
    205205{
    206206    Image* image = _result->image();
    207     return image ? image->getNSImage() : nil;
     207    return image ? image->nsImage() : nil;
    208208}
    209209
  • trunk/Source/WebKit/mac/Misc/WebIconDatabase.mm

    r206720 r206802  
    164164   
    165165    Image* image = iconDatabase().defaultIcon(IntSize(size));
    166     return image ? image->getNSImage() : nil;
     166    return image ? image->snapshotNSImage().autorelease() : nil;
    167167}
    168168
     
    471471    if (!image)
    472472        return nil;
    473     NSImage* nsImage = image->getNSImage();
     473    NSImage* nsImage = image->nsImage();
    474474    if (!nsImage)
    475475        return nil;
  • trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm

    r206720 r206802  
    227227        return nil;
    228228
    229     return [[image->getNSImage() retain] autorelease];
     229    return image->snapshotNSImage();
    230230}
    231231#endif
     
    243243        ASSERT(page->contextMenuController().context().hitTestResult().innerNode());
    244244
    245         RetainPtr<NSItemProvider> itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:image->getNSImage() typeIdentifier:@"public.image"]);
     245        RetainPtr<NSItemProvider> itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:image->snapshotNSImage().autorelease() typeIdentifier:@"public.image"]);
    246246
    247247        bool isContentEditable = page->contextMenuController().context().hitTestResult().innerNode()->isContentEditable();
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r206720 r206802  
    22112211    } else if ([type isEqual:NSTIFFPboardType] && [self promisedDragTIFFDataSource]) {
    22122212        if (Image* image = [self promisedDragTIFFDataSource]->image())
    2213             [pasteboard setData:(NSData *)image->getTIFFRepresentation() forType:NSTIFFPboardType];
     2213            [pasteboard setData:(NSData *)image->tiffRepresentation() forType:NSTIFFPboardType];
    22142214        [self setPromisedDragTIFFDataSource:0];
    22152215    }
  • trunk/Source/WebKit2/ChangeLog

    r206799 r206802  
     12016-10-04  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        The dragged image should be the current frame only of the animated image
     4        https://bugs.webkit.org/show_bug.cgi?id=162109
     5
     6        Reviewed by Tim Horton.
     7
     8        * UIProcess/Cocoa/WebViewImpl.mm:
     9        (WebKit::WebViewImpl::provideDataForPasteboard): Call the Image function with its new name.
     10
    1112016-10-04  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm

    r206720 r206802  
    30393039
    30403040    if ([type isEqual:NSTIFFPboardType] && m_promisedImage) {
    3041         [pasteboard setData:(NSData *)m_promisedImage->getTIFFRepresentation() forType:NSTIFFPboardType];
     3041        [pasteboard setData:(NSData *)m_promisedImage->tiffRepresentation() forType:NSTIFFPboardType];
    30423042        m_promisedImage = nullptr;
    30433043    }
Note: See TracChangeset for help on using the changeset viewer.