[iOS] Make document marker assets not specific to particular scale factors
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Aug 2014 00:58:45 +0000 (00:58 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Aug 2014 00:58:45 +0000 (00:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135671

Reviewed by Simon Fraser.

No new tests.

* WebCore.xcodeproj/project.pbxproj:
* platform/ios/wak/WKGraphics.mm:
(imageResourcePath):
(WKGraphicsCreateImageFromBundleWithName):

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

Source/WebCore/ChangeLog
Source/WebCore/Resources/SpellingDot@3x.png [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/ios/wak/WKGraphics.mm

index 7b283b3..96d3599 100644 (file)
@@ -1,3 +1,17 @@
+2014-08-06  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [iOS] Make document marker assets not specific to particular scale factors
+        https://bugs.webkit.org/show_bug.cgi?id=135671
+
+        Reviewed by Simon Fraser.
+
+        No new tests.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/ios/wak/WKGraphics.mm:
+        (imageResourcePath):
+        (WKGraphicsCreateImageFromBundleWithName):
+
 2014-08-06  Enrica Casucci  <enrica@apple.com>
 
         Services menu doesn't show up after you defocus/refocus the Safari window.
diff --git a/Source/WebCore/Resources/SpellingDot@3x.png b/Source/WebCore/Resources/SpellingDot@3x.png
new file mode 100644 (file)
index 0000000..61b7f7a
Binary files /dev/null and b/Source/WebCore/Resources/SpellingDot@3x.png differ
index 619b812..ec8963a 100644 (file)
                1C18DA59181AF6A500C4EF22 /* TextPainter.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C18DA57181AF6A500C4EF22 /* TextPainter.h */; };
                1C21E57C183ED1FF001C289D /* IOSurfacePool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C21E57A183ED1FF001C289D /* IOSurfacePool.cpp */; };
                1C21E57D183ED1FF001C289D /* IOSurfacePool.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C21E57B183ED1FF001C289D /* IOSurfacePool.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1C2417BA1992C04100EF9938 /* SpellingDot@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1C2417B91992C04100EF9938 /* SpellingDot@3x.png */; };
                1C26497A0D7E248A00BD10F2 /* DocumentLoaderMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */; };
                1C26497C0D7E24EC00BD10F2 /* PageMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */; };
                1C4C8F020AD85D87009475CE /* DeleteButtonController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4C8F000AD85D87009475CE /* DeleteButtonController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C18DA57181AF6A500C4EF22 /* TextPainter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPainter.h; sourceTree = "<group>"; };
                1C21E57A183ED1FF001C289D /* IOSurfacePool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IOSurfacePool.cpp; path = ../cg/IOSurfacePool.cpp; sourceTree = "<group>"; };
                1C21E57B183ED1FF001C289D /* IOSurfacePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IOSurfacePool.h; path = ../cg/IOSurfacePool.h; sourceTree = "<group>"; };
+               1C2417B91992C04100EF9938 /* SpellingDot@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "SpellingDot@3x.png"; sourceTree = "<group>"; };
                1C2649790D7E248A00BD10F2 /* DocumentLoaderMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentLoaderMac.cpp; sourceTree = "<group>"; };
                1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageMac.cpp; sourceTree = "<group>"; };
                1C4C8EFF0AD85D87009475CE /* DeleteButtonController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeleteButtonController.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                65998A650E5F5FD3004E097A /* images */ = {
                        isa = PBXGroup;
                        children = (
+                               1C2417B91992C04100EF9938 /* SpellingDot@3x.png */,
                                D02B64B014089E56006EFA21 /* DictationPhraseWithAlternativesDot.png */,
                                D02B64B114089E56006EFA21 /* DictationPhraseWithAlternativesDot@2x.png */,
                                BE8C753010681324001E93F5 /* SpellingDot.png */,
                        buildActionMask = 2147483647;
                        files = (
                                46F9D5DD0B0D60170028EE36 /* aliasCursor.png in Resources */,
+                               1C2417BA1992C04100EF9938 /* SpellingDot@3x.png in Resources */,
                                46D4F2490AF97E810035385A /* cellCursor.png in Resources */,
                                93153BDE141959F400FCF5BE /* deleteButton.png in Resources */,
                                93153BCD1417FBBF00FCF5BE /* deleteButton@2x.png in Resources */,
index 3e7e68a..31c6ec0 100644 (file)
@@ -91,9 +91,9 @@ CGContextRef WKGetCurrentGraphicsContext(void)
     return threadContext->currentCGContext;
 }
 
-static NSString *imageResourcePath(const char* imageFile, bool is2x)
+static NSString *imageResourcePath(const char* imageFile, unsigned scaleFactor)
 {
-    NSString *fileName = is2x ? [NSString stringWithFormat:@"%s@2x", imageFile] : [NSString stringWithUTF8String:imageFile];
+    NSString *fileName = scaleFactor == 1 ? [NSString stringWithUTF8String:imageFile] : [NSString stringWithFormat:@"%s@%dx", imageFile, scaleFactor];
 #if PLATFORM(IOS_SIMULATOR)
     NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"];
     return [bundle pathForResource:fileName ofType:@"png"];
@@ -104,22 +104,18 @@ static NSString *imageResourcePath(const char* imageFile, bool is2x)
 #endif
 }
 
-CGImageRef WKGraphicsCreateImageFromBundleWithName (const char *image_file)
+CGImageRef WKGraphicsCreateImageFromBundleWithName(const char *image_file)
 {
     if (!image_file)
         return NULL;
 
     CGImageRef image = nullptr;
-    NSData *imageData = nil;
-
-    if (wkGetScreenScaleFactor() == 2) {
-        NSString* full2xPath = imageResourcePath(image_file, true);
-        imageData = [NSData dataWithContentsOfFile:full2xPath];
-    }
-    if (!imageData) {
-        // We got here either because we didn't request hi-dpi or the @2x file doesn't exist.
-        NSString* full1xPath = imageResourcePath(image_file, false);
-        imageData = [NSData dataWithContentsOfFile:full1xPath];
+    NSData *imageData = nullptr;
+    for (unsigned scaleFactor = wkGetScreenScaleFactor(); scaleFactor > 0; --scaleFactor) {
+        imageData = [NSData dataWithContentsOfFile:imageResourcePath(image_file, scaleFactor)];
+        ASSERT(scaleFactor != wkGetScreenScaleFactor() || imageData);
+        if (imageData)
+            break;
     }
     
     if (imageData) {