1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_COCOA_WIDGET_OWNER_NSWINDOW_ADAPTER_H_
6 #define UI_VIEWS_COCOA_WIDGET_OWNER_NSWINDOW_ADAPTER_H_
8 #import "base/mac/scoped_nsobject.h"
9 #import "ui/views/cocoa/bridged_native_widget_owner.h"
13 @
class WidgetOwnerNSWindowAdapterBridge
;
17 // An adapter that allows a views::Widget to be owned by an NSWindow that is not
18 // backed by another BridgedNativeWidget.
19 class WidgetOwnerNSWindowAdapter
: public BridgedNativeWidgetOwner
{
21 // Create an adapter that will own |child|, tying its lifetime with the
22 // NSWindow containing |anchor_view|. The object is self-deleting, via a call
23 // to RemoveChildWindow() made in child->OnWindowWillClose().
24 WidgetOwnerNSWindowAdapter(BridgedNativeWidget
* child
, NSView
* anchor_view
);
26 // Called when the owning window is closing.
27 void OnWindowWillClose();
29 // Overridden from BridgedNativeWidgetOwner:
30 NSWindow
* GetNSWindow() override
;
31 gfx::Vector2d
GetChildWindowOffset() const override
;
32 bool IsVisibleParent() const override
;
33 void RemoveChildWindow(BridgedNativeWidget
* child
) override
;
37 ~WidgetOwnerNSWindowAdapter() override
;
39 BridgedNativeWidget
* child_
; // Weak. Owned by its NativeWidgetMac.
40 base::scoped_nsobject
<NSView
> anchor_view_
;
41 base::scoped_nsobject
<NSWindow
> anchor_window_
;
42 base::scoped_nsobject
<WidgetOwnerNSWindowAdapterBridge
> observer_bridge_
;
44 DISALLOW_COPY_AND_ASSIGN(WidgetOwnerNSWindowAdapter
);
49 #endif // UI_VIEWS_COCOA_WIDGET_OWNER_NSWINDOW_ADAPTER_H_