Closed Bug 1225494 Opened 9 years ago Closed 9 years ago

Clipboard pastes first frame from GIF images (copied from Firefox) into other applications

Categories

(Firefox for iOS :: Browser, defect)

All
iOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
fxios + ---

People

(Reporter: caspy77, Unassigned)

Details

(Whiteboard: parity-safari)

Attachments

(1 file)

48 bytes, text/x-github-pull-request
fluffyemily
: review+
fluffyemily
: feedback+
Details | Review
A reddit users reports that gifs can be copied and pasted from Safari (and other apps?) into iMessage, but attempting to do so in Firefox only pastes a still image. https://www.reddit.com/r/firefox/comments/3t4dh8/not_able_to_copy_gifs_in_firefox_for_ios/ We should seek parity in this area.
I've seen this behaviour in other applications as well, e.g, copying an image from Safari into Discord (a chat communication) pastes the image using the first frame of the GIF image. I see the behaviour in Firefox. It looks like this works in Safari. https://github.com/mozilla/firefox-ios/blob/9d3241ce549fd2b802d427a1f154b5322baf46d7/Client/Frontend/Browser/BrowserViewController.swift#L2151 Animated GIF's only display the first frame in a UIImage (UIPasteboard image property). Not sure what sort of serialization or detection or changes we can do to detect if the incoming image is a GIF
Flags: needinfo?(etoop)
tracking-fxios: --- → ?
Component: General → Browser
Hardware: Other → All
Whiteboard: parity-safari
Summary: Firefox is unable to copy gifs into iMessage → Firefox is unable to copy cat gifs into iMessage
Summary: Firefox is unable to copy cat gifs into iMessage → Clipboard pastes first frame from GIF images (copied from Firefox) into other applications
To create a UIImage from a gif, you first have to create a CGImage using CGImageSourceCreateWithData and then convert that to a UIImage. There are a number of examples of how to do this, including here: https://github.com/bahlo/SwiftGif/blob/master/SwiftGifCommon/UIImage%2BGif.swift Then you have to ensure the right image type is used when adding the gif to the pasteboard (kUTTypeGIF). We would need to add gif type URL detection and then handle the downloaded data differently from standard images, but this is all possible.
Flags: needinfo?(etoop)
Attached file Pull request
The fix is basically as suggested by Emily but I took two shortcuts: 1) I called out to SDWebImage (which was already included as a dependency) to generate a UIImage from GIF data. 2) Instead of detecting GIF images based on their URLs, I look for the image header in the NSData object. Now, after I threw everything together, I realized that I can't actually test this since I cannot build to my device because of code signing issues. In addition, none of the apps that ship with the simulator support pasting images. Therefore, it would be great if someone that is enrolled in the Mozilla development team could test this on a device. Note that on top of the image copying I also made the image download handle GIFs properly. However, since the photos app doesn't support GIFs, I couldn't really verify that either. This would only make a difference when photos are exported from the device.
Attachment #8697878 - Flags: review?(etoop)
Comment on attachment 8697878 [details] [review] Pull request :hennes - This doesn't seem to work for me: STR: Open giphy.com Copy any gif from the home page Open messages Paste Only 1 image from the gif get's pasted, not the entire gif. Not sure why this is happening, everything you are doing in the code seems sensible.
Attachment #8697878 - Flags: feedback+
Any update on this?
Flags: needinfo?(johannesmarbach)
My sincere apologies. Apparently I forgot to add myself to the CC list of this ticket so I didn't get notified about Emily's review. I'll have a look again and try to figure it out.
Following Emily's steps in the debugger, I could verify that images from giphy.com are correctly recognized as GIFs and the UIImage instance is created through calling animatedImageWithImages. That means something must go wrong with putting the image into the pasteboard. Googling around, I get the impression that we'd actually have to set the NSData instance for kUTTypeGIF instead of the UIImage (see for instance [1]). I'm gonna put the relevant into a prototype app so that I can test this on a device. [1] http://stackoverflow.com/questions/33675297/copy-gif-to-uipasteboard
Flags: needinfo?(johannesmarbach)
Ok, I'm starting to think that this could be a limitation of the messages app. When I set the bare NSData of the image for the kUTTypeGIF key, I *do* get the animated image in the Apple mail and Gmail app. However, I do *not* get the animated image in the messages app or in WhatsApp. Interestingly, the same seems to be true when I copy the image from Safari. Are we really certain that it should work in the messages app as well?
Flags: needinfo?(etoop)
Emily, any news on this? I think the current PR can be easily adapted to make the GIF show up correctly in the mail apps. I'm not sure what to do about the messages app, however. To me it does not look like that one supports GIFs.
Sorry! This seemed to have gotten lost in my review queue. I'll take a look this afternoon. So sorry.
So, checking for parity with Safari, when pasting a gif from giphy.com into Messages, the gif remains unanimated until you tap on the image, in which case it moves to full screen and animated. When pasting from giphy.com from Firefox, the gif remains static even when tapped and in full screen. We are looking for parity with Safari here. Having had a bit of a look around, the solution, is appears, is to add the gif directly as NSData rather than turning it into an image first. See PR comments for details.
Flags: needinfo?(etoop)
Oh, I didn't try tapping it. Nice find. I updated the PR according to your comments. Thanks again for reviewing! :)
#merged target 4.0 d7d3287
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → 4.0
Attachment #8697878 - Flags: review?(etoop) → review+
thanks :hennes. It's merged now. Sorry it took so long for me to get to it.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: