Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: ui/views/cocoa/widget_owner_nswindow_adapter.mm

Issue 1169063002: MacViews: Retain non-Widget parent NSWindows, as well as the anchor NSView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/widget_owner_nswindow_adapter.h ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/widget_owner_nswindow_adapter.mm
diff --git a/ui/views/cocoa/widget_owner_nswindow_adapter.mm b/ui/views/cocoa/widget_owner_nswindow_adapter.mm
index e3939fdd68cba0785b16c9e37ff3eff4c6ed59b5..0fbe5d545c29c9ea7262a4c7e46fa61f04d06c56 100644
--- a/ui/views/cocoa/widget_owner_nswindow_adapter.mm
+++ b/ui/views/cocoa/widget_owner_nswindow_adapter.mm
@@ -45,12 +45,19 @@ WidgetOwnerNSWindowAdapter::WidgetOwnerNSWindowAdapter(
anchor_view_([anchor_view retain]),
observer_bridge_(
[[WidgetOwnerNSWindowAdapterBridge alloc] initWithAdapter:this]) {
- DCHECK([anchor_view_ window]);
+
+ // Although the |anchor_view| must be in an NSWindow when the child dialog is
+ // created, it's permitted for the |anchor_view| to be removed from its view
+ // hierarchy before the child dialog window is fully removed from screen. When
+ // this happens, [anchor_view_ window] will become nil, so retain both.
+ anchor_window_.reset([[anchor_view_ window] retain]);
+ DCHECK(anchor_window_);
+
[[NSNotificationCenter defaultCenter]
addObserver:observer_bridge_
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
- object:[anchor_view_ window]];
+ object:anchor_window_];
}
void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
@@ -59,11 +66,10 @@ void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
}
NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() {
- return [anchor_view_ window];
+ return anchor_window_;
}
gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const {
- NSWindow* window = [anchor_view_ window];
NSRect rect_in_window =
[anchor_view_ convertRect:[anchor_view_ bounds] toView:nil];
// Ensure we anchor off the top-left of |anchor_view_| (rect_in_window.origin
@@ -71,13 +77,13 @@ gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const {
// TODO(tapted): Use -[NSWindow convertRectToScreen:] when we ditch 10.6.
NSRect rect_in_screen = NSZeroRect;
rect_in_screen.origin =
- [window convertBaseToScreen:NSMakePoint(NSMinX(rect_in_window),
- NSMaxY(rect_in_window))];
+ [anchor_window_ convertBaseToScreen:NSMakePoint(NSMinX(rect_in_window),
+ NSMaxY(rect_in_window))];
return gfx::ScreenRectFromNSRect(rect_in_screen).OffsetFromOrigin();
}
bool WidgetOwnerNSWindowAdapter::IsVisibleParent() const {
- return [[anchor_view_ window] isVisible];
+ return [anchor_window_ isVisible];
}
void WidgetOwnerNSWindowAdapter::RemoveChildWindow(BridgedNativeWidget* child) {
« no previous file with comments | « ui/views/cocoa/widget_owner_nswindow_adapter.h ('k') | ui/views/widget/native_widget_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698