Changeset 260667 in webkit
- Timestamp:
- Apr 24, 2020 2:02:48 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r260666 r260667 1 2020-04-24 David Kilzer <ddkilzer@apple.com> 2 3 Use CocoaImage platform abstraction for NSImage/UIImage 4 <https://webkit.org/b/210974> 5 6 Reviewed by Darin Adler. 7 8 * Platform/cocoa/CocoaImage.h: Add. 9 - Define CocoaImage here for cross-platform use. Don't use 10 OBJC_CLASS() here because this is an Objective-C header. 11 * UIProcess/API/Cocoa/WKWebView.mm: 12 (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]): 13 - Combine separate platform-specific methods into one method. 14 * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: 15 - Combine separate platform-specific instance variables into 16 one instance variable. 17 (-[_WKActivatedElementInfo image]): 18 - Combine separate methods into one platform-specific method. 19 * UIProcess/QuickLookThumbnailLoader.h: 20 - Move cross-platform definition to CocoaImge.h. 21 * UIProcess/QuickLookThumbnailLoader.mm: 22 - Drive-by fix of soft-linking header include order. 23 * WebKit.xcodeproj/project.pbxproj: 24 - Add CocoaImage.h to the project. 25 * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm: 26 (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]): 27 (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:width:]): 28 - Combine separate platform-specific methods into one method. 29 1 30 2020-04-24 David Kilzer <ddkilzer@apple.com> 2 31 -
trunk/Source/WebKit/Platform/cocoa/CocoaImage.h
r260666 r260667 24 24 */ 25 25 26 #if HAVE(QUICKLOOK_THUMBNAILING)27 28 26 #if USE(APPKIT) 29 27 @class NSImage; … … 33 31 using CocoaImage = UIImage; 34 32 #endif 35 36 @interface WKQLThumbnailQueueManager : NSObject37 38 @property (nonatomic, readonly, retain) NSOperationQueue *queue;39 40 - (instancetype)init;41 + (WKQLThumbnailQueueManager *)sharedInstance;42 43 @end44 45 @interface WKQLThumbnailLoadOperation : NSOperation46 47 @property (atomic, readonly, getter=isAsynchronous) BOOL asynchronous;48 @property (atomic, readonly, getter=isExecuting) BOOL executing;49 @property (atomic, readonly, getter=isFinished) BOOL finished;50 51 @property (nonatomic, readonly, copy) NSString *identifier;52 @property (nonatomic, readonly, retain) CocoaImage *thumbnail;53 54 - (instancetype)initWithAttachment:(NSFileWrapper *)fileWrapper identifier:(NSString *)identifier;55 - (instancetype)initWithURL:(NSString *)fileURL identifier:(NSString *)identifier;56 57 @end58 59 #endif // HAVE(QUICKLOOK_THUMBNAILING) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r260485 r260667 32 32 #import "APISerializedScriptValue.h" 33 33 #import "AttributedString.h" 34 #import "CocoaImage.h" 34 35 #import "CompletionHandlerCallChecker.h" 35 36 #import "ContentAsStringIncludesChildFrames.h" … … 980 981 } 981 982 982 #if PLATFORM(MAC) 983 - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(NSImage *, NSError *))completionHandler 983 - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(CocoaImage *, NSError *))completionHandler 984 984 { 985 985 CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds; … … 991 991 992 992 auto handler = makeBlockPtr(completionHandler); 993 994 #if USE(APPKIT) 993 995 CGFloat imageScale = snapshotWidth / rectInViewCoordinates.size.width; 994 996 CGFloat imageHeight = imageScale * rectInViewCoordinates.size.height; … … 1012 1014 auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly); 1013 1015 RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr; 1014 RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);1015 handler( nsImage.get(), nil);1016 auto image = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]); 1017 handler(image.get(), nil); 1016 1018 }); 1017 } 1018 1019 #elif PLATFORM(IOS_FAMILY) 1020 - (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(UIImage *, NSError *))completionHandler 1021 { 1022 CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds; 1023 CGFloat snapshotWidth; 1024 if (snapshotConfiguration) 1025 snapshotWidth = snapshotConfiguration.snapshotWidth.doubleValue ?: rectInViewCoordinates.size.width; 1026 else 1027 snapshotWidth = self.bounds.size.width; 1028 1029 auto handler = makeBlockPtr(completionHandler); 1019 #else 1030 1020 CGFloat deviceScale = _page->deviceScaleFactor(); 1031 1021 RetainPtr<WKWebView> strongSelf = self; … … 1033 1023 [strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) { 1034 1024 RetainPtr<NSError> error; 1035 RetainPtr<UIImage> uiImage;1025 RetainPtr<UIImage> image; 1036 1026 1037 1027 if (!snapshotImage) 1038 1028 error = createNSError(WKErrorUnknown); 1039 1029 else 1040 uiImage = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);1030 image = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]); 1041 1031 1042 handler( uiImage.get(), error.get());1032 handler(image.get(), error.get()); 1043 1033 }]; 1044 1034 }; … … 1056 1046 callSnapshotRect(); 1057 1047 }); 1058 } 1059 #endif 1048 #endif 1049 } 1060 1050 1061 1051 - (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
r252309 r260667 27 27 #import "_WKActivatedElementInfoInternal.h" 28 28 29 #import "CocoaImage.h" 29 30 #import "ShareableBitmap.h" 30 31 #import <wtf/RetainPtr.h> 31 32 32 #if PLATFORM(IOS_FAMILY) 33 #if USE(APPKIT) 34 #import <AppKit/NSImage.h> 35 #else 33 36 #import <UIKit/UIImage.h> 34 #endif35 36 #if PLATFORM(MAC)37 #import <AppKit/NSImage.h>38 37 #endif 39 38 … … 45 44 RetainPtr<NSString> _ID; 46 45 RefPtr<WebKit::ShareableBitmap> _image; 46 RetainPtr<CocoaImage> _cocoaImage; 47 47 #if PLATFORM(IOS_FAMILY) 48 RetainPtr<UIImage> _uiImage;49 48 RetainPtr<NSDictionary> _userInfo; 50 #endif51 #if PLATFORM(MAC)52 RetainPtr<NSImage> _nsImage;53 49 #endif 54 50 BOOL _animatedImage; … … 151 147 return _userInfo.get(); 152 148 } 149 #endif 153 150 154 - ( UIImage *)image151 - (CocoaImage *)image 155 152 { 156 if (_ uiImage)157 return [[_ uiImage copy] autorelease];153 if (_cocoaImage) 154 return [[_cocoaImage copy] autorelease]; 158 155 159 156 if (!_image) 160 157 return nil; 161 158 162 _uiImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]); 159 #if USE(APPKIT) 160 _cocoaImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]); 161 #else 162 _cocoaImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]); 163 #endif 163 164 _image = nullptr; 164 165 165 return [[_ uiImage copy] autorelease];166 return [[_cocoaImage copy] autorelease]; 166 167 } 167 #endif168 169 #if PLATFORM(MAC)170 - (NSImage *)image171 {172 if (_nsImage)173 return [[_nsImage copy] autorelease];174 175 if (!_image)176 return nil;177 178 _nsImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);179 _image = nullptr;180 181 return [[_nsImage copy] autorelease];182 }183 #endif184 168 185 169 @end -
trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h
r260611 r260667 26 26 #if HAVE(QUICKLOOK_THUMBNAILING) 27 27 28 #if USE(APPKIT) 29 @class NSImage; 30 using CocoaImage = NSImage; 31 #else 32 @class UIImage; 33 using CocoaImage = UIImage; 34 #endif 28 #import "CocoaImage.h" 35 29 36 30 @interface WKQLThumbnailQueueManager : NSObject -
trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm
r260611 r260667 29 29 #if HAVE(QUICKLOOK_THUMBNAILING) 30 30 31 #import <wtf/FileSystem.h> 32 31 33 #import "QuickLookThumbnailingSoftLink.h" 32 33 #import <wtf/FileSystem.h>34 34 35 35 @implementation WKQLThumbnailQueueManager -
trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj
r260653 r260667 933 933 41FAF5F81E3C1021001AE678 /* LibWebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */; }; 934 934 4459984222833E8700E61373 /* SyntheticEditingCommandType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4459984122833E6000E61373 /* SyntheticEditingCommandType.h */; }; 935 4482734724528F6000A95493 /* CocoaImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4482734624528F6000A95493 /* CocoaImage.h */; }; 935 936 449D90DA21FDC30B00F677C0 /* LocalAuthenticationSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */; }; 936 937 44E936FD2447C2D8009FA3E3 /* LegacyCustomProtocolID.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E936FC2447C256009FA3E3 /* LegacyCustomProtocolID.h */; }; … … 3525 3526 4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedMemoryCocoa.cpp; sourceTree = "<group>"; }; 3526 3527 4459984122833E6000E61373 /* SyntheticEditingCommandType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SyntheticEditingCommandType.h; sourceTree = "<group>"; }; 3528 4482734624528F6000A95493 /* CocoaImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoaImage.h; sourceTree = "<group>"; }; 3527 3529 449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalAuthenticationSoftLink.mm; sourceTree = "<group>"; }; 3528 3530 44A481C621F2D27B00F2F919 /* ClientCertificateAuthenticationXPCConstants.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClientCertificateAuthenticationXPCConstants.cpp; sourceTree = "<group>"; }; … … 7691 7693 isa = PBXGroup; 7692 7694 children = ( 7695 4482734624528F6000A95493 /* CocoaImage.h */, 7693 7696 BCE0937614FB128B001138D9 /* LayerHostingContext.h */, 7694 7697 BCE0937514FB128B001138D9 /* LayerHostingContext.mm */, … … 10738 10741 1AA2E51D12E4C05E00BC4966 /* CGUtilities.h in Headers */, 10739 10742 57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */, 10743 4482734724528F6000A95493 /* CocoaImage.h in Headers */, 10740 10744 CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */, 10741 10745 37BEC4E119491486008B4286 /* CompletionHandlerCallChecker.h in Headers */, -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm
r248373 r260667 27 27 #import "WKWebProcessPlugInNodeHandleInternal.h" 28 28 29 #import "CocoaImage.h" 29 30 #import "WKSharedAPICast.h" 30 31 #import "WKWebProcessPlugInFrameInternal.h" … … 55 56 } 56 57 57 #if PLATFORM(IOS_FAMILY) 58 - (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options 58 - (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options 59 59 { 60 60 return [self renderedImageWithOptions:options width:nil]; 61 61 } 62 62 63 - ( UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width63 - (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width 64 64 { 65 65 Optional<float> optionalWidth; … … 71 71 return nil; 72 72 73 #if USE(APPKIT) 74 return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease]; 75 #else 73 76 return [[[UIImage alloc] initWithCGImage:image->bitmap().makeCGImage().get()] autorelease]; 74 }75 77 #endif 76 77 #if PLATFORM(MAC) 78 - (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options 79 { 80 return [self renderedImageWithOptions:options width:nil]; 81 } 82 83 - (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width 84 { 85 Optional<float> optionalWidth; 86 if (width) 87 optionalWidth = width.floatValue; 88 89 RefPtr<WebKit::WebImage> image = _nodeHandle->renderedImage(WebKit::toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow, optionalWidth); 90 if (!image) 91 return nil; 92 93 return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease]; 94 } 95 #endif 78 } 96 79 97 80 - (CGRect)elementBounds
Note: See TracChangeset
for help on using the changeset viewer.