Skip to content

Commit

Permalink
Cherry-pick ea1cc85. rdar://125040242
Browse files Browse the repository at this point in the history
    Update the PreviewWindowController to use PreviewItem
    https://bugs.webkit.org/show_bug.cgi?id=271291
    <rdar://125040242>

    Reviewed by Aditya Keerthi.

    Update the PreviewWindowController to use PreviewItem. Since this is a
    Swift type, WKSPreviewWindowController now takes a URL directly on init
    and instantiates the PreviewItem internally.

    * Source/WebKit/WebKitSwift/Preview/WKSPreviewWindowController.h:
    New designated initializer.
    * Source/WebKit/WebKitSwift/Preview/PreviewWindowController.swift:
    (PreviewWindowController.item):
    (PreviewWindowController.presentWindow):
    Update to the PreviewItem variant of the`open` method.

    * Source/WebKit/UIProcess/ios/fullscreen/WKFullScreenWindowControllerIOS.mm:
    (-[WKFullScreenWindowController _performSpatialFullScreenTransition:completionHandler:]):
    Use the new WKSPreviewWindowController initializer.

    Canonical link: https://commits.webkit.org/276381@main

Identifier: 276246.1@safari-7619.1.6-branch
  • Loading branch information
etiennesegonzac authored and MyahCobbs committed Mar 20, 2024
1 parent b2ec60c commit 0588068
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#import "MRUIKitSPI.h"
#if ENABLE(QUICKLOOK_FULLSCREEN)
#import "WKSPreviewWindowController.h"
#import <pal/ios/QuickLookSoftLink.h>
#import "WebKitSwiftSoftLink.h"
#endif // QUICKLOOK_FULLSCREEN
#endif
Expand Down Expand Up @@ -1870,8 +1869,7 @@ - (void)_performSpatialFullScreenTransition:(BOOL)enter completionHandler:(Compl
if (enter) {
inWindowAlpha = 0;
manager->prepareQuickLookImageURL([strongSelf = retainPtr(self), self] (URL&& url) mutable {
auto item = adoptNS([PAL::allocQLItemInstance() initWithURL:url]);
_previewWindowController = adoptNS([WebKit::allocWKSPreviewWindowControllerInstance() initWithItem:item.get()]);
_previewWindowController = adoptNS([WebKit::allocWKSPreviewWindowControllerInstance() initWithURL:url]);
[_previewWindowController setDelegate:self];
[_previewWindowController presentWindow];
});
Expand Down
12 changes: 6 additions & 6 deletions Source/WebKit/WebKitSwift/Preview/PreviewWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@

#if os(visionOS)

#if canImport(QuickLook, _version: 953)
#if canImport(QuickLook, _version: 956)
import OSLog
import WebKitSwift

@_spi(PreviewApplication) import QuickLook
import AssetViewer

@objc(WKSPreviewWindowController)
public final class PreviewWindowController: NSObject {
private static let logger = Logger(subsystem: "com.apple.WebKit", category: "Fullscreen")

private var item: QLItem
private var item: PreviewItem
private var previewSession: PreviewSession?
private var isClosing = false

@objc public weak var delegate: WKSPreviewWindowControllerDelegate?

@objc public init(item: QLItem) {
self.item = item
@objc(initWithURL:) public init(url: URL) {
self.item = PreviewItem(url: url, displayName: nil, editingMode: .disabled);
super.init()
}

@objc public func presentWindow() {
previewSession = PreviewApplication.open(items: [self.item], selectedItemIndex: nil, editingMode: .disabled)
previewSession = PreviewApplication.open(items: [self.item], selectedItem: nil)

Task.detached { [weak self] in
guard let session = self?.previewSession else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

NS_ASSUME_NONNULL_BEGIN

@class QLItem;
@class WKSPreviewWindowController;

@protocol WKSPreviewWindowControllerDelegate <NSObject>
Expand All @@ -39,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface WKSPreviewWindowController : NSObject
@property (nonatomic, weak, nullable) id <WKSPreviewWindowControllerDelegate> delegate;

- (instancetype)initWithItem:(QLItem *)item NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithURL:(NSURL *)url NS_DESIGNATED_INITIALIZER;
- (void)presentWindow;
- (void)dismissWindow;
@end
Expand Down

0 comments on commit 0588068

Please sign in to comment.