Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions Sources/BrowserWindowPortal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,8 @@ final class WindowBrowserSlotView: NSView {
private let paneDropTargetView = BrowserPaneDropTargetView(frame: .zero)
private let dropZoneOverlayView = BrowserDropZoneOverlayView(frame: .zero)
private var searchOverlayHostingView: NSHostingView<BrowserSearchOverlay>?
private weak var hostedWebView: WKWebView?
private var hostedWebViewConstraints: [NSLayoutConstraint] = []
private var forwardedDropZone: DropZone?
private var portalDragDropZone: DropZone?
private var displayedDropZone: DropZone?
Expand Down Expand Up @@ -1460,6 +1462,34 @@ final class WindowBrowserSlotView: NSView {
searchOverlayHostingView = overlay
}

func pinHostedWebView(_ webView: WKWebView) {
guard webView.superview === self else { return }

let needsNewConstraints =
hostedWebView !== webView ||
hostedWebViewConstraints.isEmpty ||
webView.translatesAutoresizingMaskIntoConstraints
guard needsNewConstraints else {
needsLayout = true
layoutSubtreeIfNeeded()
return
}

NSLayoutConstraint.deactivate(hostedWebViewConstraints)
hostedWebView = webView
webView.translatesAutoresizingMaskIntoConstraints = false
webView.autoresizingMask = []
hostedWebViewConstraints = [
webView.topAnchor.constraint(equalTo: topAnchor),
webView.bottomAnchor.constraint(equalTo: bottomAnchor),
webView.leadingAnchor.constraint(equalTo: leadingAnchor),
webView.trailingAnchor.constraint(equalTo: trailingAnchor),
]
NSLayoutConstraint.activate(hostedWebViewConstraints)
needsLayout = true
layoutSubtreeIfNeeded()
}

func effectivePaneTopChromeHeight() -> CGFloat {
paneTopChromeHeight
}
Expand Down Expand Up @@ -2241,11 +2271,11 @@ final class WindowBrowserPortal: NSObject {
} else {
containerView.addSubview(webView, positioned: .above, relativeTo: nil)
}
webView.translatesAutoresizingMaskIntoConstraints = true
webView.autoresizingMask = [.width, .height]
webView.frame = containerView.bounds
containerView.pinHostedWebView(webView)
webView.needsLayout = true
webView.layoutSubtreeIfNeeded()
} else {
containerView.pinHostedWebView(webView)
}

if containerView.superview !== hostView {
Expand Down Expand Up @@ -2496,10 +2526,10 @@ final class WindowBrowserPortal: NSObject {
} else {
containerView.addSubview(webView, positioned: .above, relativeTo: nil)
}
webView.translatesAutoresizingMaskIntoConstraints = true
webView.autoresizingMask = [.width, .height]
webView.frame = containerView.bounds
containerView.pinHostedWebView(webView)
refreshReasons.append("syncAttachWebView")
} else {
containerView.pinHostedWebView(webView)
}

_ = synchronizeHostFrameToReference()
Expand Down Expand Up @@ -2626,12 +2656,23 @@ final class WindowBrowserPortal: NSObject {
}
#endif
if shouldPreserveVisibleOnTransientGeometry {
let hasExistingVisibleFrame =
oldFrame.width > 1 &&
oldFrame.height > 1 &&
containerView.bounds.width > 1 &&
containerView.bounds.height > 1
#if DEBUG
dlog(
"browser.portal.hidden.deferKeep web=\(browserPortalDebugToken(webView)) " +
"reason=\(transientRecoveryReason ?? "unknown") frame=\(browserPortalDebugFrame(containerView.frame))"
"reason=\(transientRecoveryReason ?? "unknown") frame=\(browserPortalDebugFrame(containerView.frame)) " +
"keepFrame=\(hasExistingVisibleFrame ? 1 : 0)"
)
#endif
if hasExistingVisibleFrame {
containerView.setDropZoneOverlay(zone: nil)
containerView.setPaneDropContext(nil)
return
}
}
if !Self.rectApproximatelyEqual(oldFrame, targetFrame) {
CATransaction.begin()
Expand Down
Loading