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

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

Issue 2448243003: MacViews: Reattach children of native windows when they are exposed. (Closed)
Patch Set: respond to comments Created 4 years, 2 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 63cc4468d95449b86bbb6a2a2a8ab06cf9dd2c54..5259c7e25b209c1288fc77dd7e7c171cba41fa78 100644
--- a/ui/views/cocoa/widget_owner_nswindow_adapter.mm
+++ b/ui/views/cocoa/widget_owner_nswindow_adapter.mm
@@ -14,13 +14,14 @@
#import "ui/views/cocoa/bridged_native_widget.h"
// Bridges an AppKit observer to observe when the (non-views) NSWindow owning a
-// views::Widget will close.
+// views::Widget will close or change occlusion state.
@interface WidgetOwnerNSWindowAdapterBridge : NSObject {
@private
views::WidgetOwnerNSWindowAdapter* adapter_; // Weak. Owns us.
}
- (instancetype)initWithAdapter:(views::WidgetOwnerNSWindowAdapter*)adapter;
- (void)windowWillClose:(NSNotification*)notification;
+- (void)windowDidChangeOcclusionState:(NSNotification*)notification;
@end
@implementation WidgetOwnerNSWindowAdapterBridge
@@ -35,6 +36,10 @@
adapter_->OnWindowWillClose();
}
+- (void)windowDidChangeOcclusionState:(NSNotification*)notification {
+ adapter_->OnWindowDidChangeOcclusionState();
+}
+
@end
namespace views {
@@ -59,6 +64,15 @@ WidgetOwnerNSWindowAdapter::WidgetOwnerNSWindowAdapter(
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
object:anchor_window_];
+
+ // BridgedNativeWidget removes NSWindow parent/child relationships for hidden
+ // windows. Observe when the parent's visibility changes so they can be
+ // reconnected.
+ [[NSNotificationCenter defaultCenter]
+ addObserver:observer_bridge_
+ selector:@selector(windowDidChangeOcclusionState:)
+ name:NSWindowDidChangeOcclusionStateNotification
+ object:anchor_window_];
}
void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
@@ -80,6 +94,32 @@ void WidgetOwnerNSWindowAdapter::OnWindowWillClose() {
DCHECK(![child_window delegate]);
}
+void WidgetOwnerNSWindowAdapter::OnWindowDidChangeOcclusionState() {
+ // The adapter only needs to handle a parent "show", since the only way it
+ // should be hidden is via -[NSApp hide], and all BridgedNativeWidgets
+ // subscribe to NSApplicationDidHideNotification already.
+ if (![anchor_window_ isVisible])
+ return;
+
+ if (child_->window_visible()) {
+ DCHECK([child_->ns_window() parentWindow]);
+ DCHECK(child_->wants_to_be_visible());
+ return;
+ }
+
+ // The parent relationship should have been removed when the child was hidden.
+ DCHECK(![child_->ns_window() parentWindow]);
+ if (!child_->wants_to_be_visible())
+ return;
+
+ [child_->ns_window() orderWindow:NSWindowAbove
+ relativeTo:[anchor_window_ windowNumber]];
+
+ // Ordering the window should add back the relationship.
+ DCHECK([child_->ns_window() parentWindow]);
+ DCHECK(child_->window_visible());
+}
+
NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() {
return anchor_window_;
}
« 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