Repair local-host devtools reparent geometry

This commit is contained in:
Lawrence Chen 2026-03-11 18:21:41 -07:00
parent ad31fb435a
commit 5d82a29f45

View file

@ -4992,6 +4992,8 @@ struct WebViewRepresentable: NSViewRepresentable {
return true
}
guard !relatedSubviews.isEmpty else { return }
let preserveSlotLocalFrames = sourceSuperview is WindowBrowserSlotView
let sourceSlotBoundsSize = sourceSuperview.bounds.size
#if DEBUG
dlog(
"browser.localHost.reparent.batch reason=\(reason) source=\(Self.objectID(sourceSuperview)) " +
@ -5000,11 +5002,17 @@ struct WebViewRepresentable: NSViewRepresentable {
)
#endif
for view in relatedSubviews {
let frameInWindow = sourceSuperview.convert(view.frame, to: nil)
let className = String(describing: type(of: view))
let targetFrame: NSRect
if preserveSlotLocalFrames {
targetFrame = view.frame
} else {
let frameInWindow = sourceSuperview.convert(view.frame, to: nil)
targetFrame = container.convert(frameInWindow, from: nil)
}
view.removeFromSuperview()
container.addSubview(view, positioned: .above, relativeTo: nil)
view.frame = container.convert(frameInWindow, from: nil)
view.frame = targetFrame
#if DEBUG
dlog(
"browser.localHost.reparent.batch.item reason=\(reason) class=\(className) " +
@ -5012,6 +5020,11 @@ struct WebViewRepresentable: NSViewRepresentable {
)
#endif
}
if preserveSlotLocalFrames, sourceSlotBoundsSize != container.bounds.size {
container.resizeSubviews(withOldSize: sourceSlotBoundsSize)
container.needsLayout = true
container.layoutSubtreeIfNeeded()
}
}
private static func installPortalAnchorView(_ anchorView: NSView, in host: NSView) {