|
@@ -389,6 +389,9 @@ void NativeWindowMac::Close() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // Ensure we're detached from the parent window before closing.
|
|
|
+ RemoveChildFromParentWindow(this);
|
|
|
+
|
|
|
// If a sheet is attached to the window when we call
|
|
|
// [window_ performClose:nil], the window won't close properly
|
|
|
// even after the user has ended the sheet.
|
|
@@ -406,6 +409,8 @@ void NativeWindowMac::Close() {
|
|
|
}
|
|
|
|
|
|
void NativeWindowMac::CloseImmediately() {
|
|
|
+ RemoveChildFromParentWindow(this);
|
|
|
+
|
|
|
// Retain the child window before closing it. If the last reference to the
|
|
|
// NSWindow goes away inside -[NSWindow close], then bad stuff can happen.
|
|
|
// See e.g. http://crbug.com/616701.
|
|
@@ -599,6 +604,11 @@ void NativeWindowMac::RemoveChildWindow(NativeWindow* child) {
|
|
|
[window_ removeChildWindow:child->GetNativeWindow().GetNativeNSWindow()];
|
|
|
}
|
|
|
|
|
|
+void NativeWindowMac::RemoveChildFromParentWindow(NativeWindow* child) {
|
|
|
+ if (parent())
|
|
|
+ parent()->RemoveChildWindow(child);
|
|
|
+}
|
|
|
+
|
|
|
void NativeWindowMac::AttachChildren() {
|
|
|
for (auto* child : child_windows_) {
|
|
|
auto* child_nswindow = child->GetNativeWindow().GetNativeNSWindow();
|
|
@@ -1779,27 +1789,27 @@ void NativeWindowMac::InternalSetWindowButtonVisibility(bool visible) {
|
|
|
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:!visible];
|
|
|
}
|
|
|
|
|
|
-void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
|
|
|
+void NativeWindowMac::InternalSetParentWindow(NativeWindow* new_parent,
|
|
|
bool attach) {
|
|
|
if (is_modal())
|
|
|
return;
|
|
|
|
|
|
- NativeWindow::SetParentWindow(parent);
|
|
|
-
|
|
|
// Do not remove/add if we are already properly attached.
|
|
|
- if (attach && parent &&
|
|
|
- [window_ parentWindow] == parent->GetNativeWindow().GetNativeNSWindow())
|
|
|
+ if (attach && new_parent &&
|
|
|
+ [window_ parentWindow] ==
|
|
|
+ new_parent->GetNativeWindow().GetNativeNSWindow())
|
|
|
return;
|
|
|
|
|
|
// Remove current parent window.
|
|
|
- if ([window_ parentWindow])
|
|
|
- parent->RemoveChildWindow(this);
|
|
|
+ RemoveChildFromParentWindow(this);
|
|
|
|
|
|
// Set new parent window.
|
|
|
- if (parent && attach) {
|
|
|
- parent->add_child_window(this);
|
|
|
- parent->AttachChildren();
|
|
|
+ if (new_parent && attach) {
|
|
|
+ new_parent->add_child_window(this);
|
|
|
+ new_parent->AttachChildren();
|
|
|
}
|
|
|
+
|
|
|
+ NativeWindow::SetParentWindow(new_parent);
|
|
|
}
|
|
|
|
|
|
void NativeWindowMac::SetForwardMouseMessages(bool forward) {
|