diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 58939680b6e31..36669ae07eb6d 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1795,8 +1795,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { NativeWindow::SetParentWindow(parent); // Do not remove/add if we are already properly attached. - if (attach && parent && - [window_ parentWindow] == parent->GetNativeWindow().GetNativeNSWindow()) + auto* native_window = parent->GetNativeWindow().GetNativeNSWindow(); + if (attach && parent && [window_ parentWindow] == native_window) return; // Remove current parent window. @@ -1805,10 +1805,13 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) { // Set new parent window. // Note that this method will force the window to become visible. - if (parent && attach) - [parent->GetNativeWindow().GetNativeNSWindow() - addChildWindow:window_ - ordered:NSWindowAbove]; + if (parent && attach) { + // Attaching a window as a child window resets its window level, so + // save and restore it afterwards. + NSInteger level = window_.level; + [native_window addChildWindow:window_ ordered:NSWindowAbove]; + [window_ setLevel:level]; + } } void NativeWindowMac::SetForwardMouseMessages(bool forward) {