Fixed <rdar://problem/3926825> Safari ignores GIF loop count
[WebKit-https.git] / WebKit / WebCoreSupport.subproj / WebImageData.m
index a0a0bd21997b9253964a3c090d0f8bddd078e176..b28719e114f949d3763d85ef6be95e3802b87d5c 100644 (file)
@@ -77,6 +77,9 @@ static CFDictionaryRef imageSourceOptions;
     [self _invalidateImages];
     [self _invalidateImageProperties];
         
+    if (fileProperties)
+       CFRelease (fileProperties);
+       
     if (imageSource)
         CFRelease (imageSource); 
         
@@ -197,6 +200,15 @@ static CFDictionaryRef imageSourceOptions;
     return images[index];
 }
 
+- (CFDictionaryRef)fileProperties
+{
+    if (!fileProperties) {
+       fileProperties = CGImageSourceCopyProperties (imageSource, 0);
+    }
+    
+    return fileProperties;
+}
+
 - (CFDictionaryRef)propertiesAtIndex:(size_t)index
 {
     size_t num = [self numberOfImages];
@@ -556,7 +568,6 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
         return 0.f;
     }
     
-    // FIXME:  Use constant instead of DelayTime
     CFNumberRef num = CFDictionaryGetValue (typeProperties, property);
     if (!num) {
         [decodeLock unlock];
@@ -571,6 +582,38 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
     return value;
 }
 
+- (float)_floatFileProperty:(CFStringRef)property type:(CFStringRef)type 
+{
+    [decodeLock lock];
+    
+    CFDictionaryRef properties = [self fileProperties];
+    if (!properties) {
+        [decodeLock unlock];
+        return 0.f;
+    }
+    
+    if (type) {
+       properties = CFDictionaryGetValue (properties, type);
+       if (!properties) {
+           [decodeLock unlock];
+           return 0.f;
+       }
+    }
+    
+    CFNumberRef num = CFDictionaryGetValue (properties, property);
+    if (!num) {
+        [decodeLock unlock];
+        return 0.f;
+    }
+    
+    float value = 0.f;
+    CFNumberGetValue (num, kCFNumberFloat32Type, &value);
+
+    [decodeLock unlock];
+    
+    return value;
+}
+
 #define MINIMUM_DURATION (1.0/30.0)
 
 - (float)_frameDurationAt:(size_t)i
@@ -619,7 +662,7 @@ CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 
 - (int)_repetitionCount
 {
-    return [self _floatProperty:kCGImagePropertyGIFLoopCount type:kCGImagePropertyGIFDictionary at:0];
+    return [self _floatFileProperty:kCGImagePropertyGIFLoopCount type:kCGImagePropertyGIFDictionary];
 }
 
 - (BOOL)isAnimationFinished