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"
12 @
class WidgetOwnerNSWindowAdapterBridge
;
16 // An adapter that allows a views::Widget to be owned by an NSWindow that is not
17 // backed by another BridgedNativeWidget.
18 class WidgetOwnerNSWindowAdapter
: public BridgedNativeWidgetOwner
{
20 // Create an adapter that will own |child|, tying its lifetime with the
21 // NSWindow containing |anchor_view|. The object is self-deleting, via a call
22 // to RemoveChildWindow() made in child->OnWindowWillClose().
23 WidgetOwnerNSWindowAdapter(BridgedNativeWidget
* child
, NSView
* anchor_view
);
25 // Called when the owning window is closing.
26 void OnWindowWillClose();
28 // Overridden from BridgedNativeWidgetOwner:
29 NSWindow
* GetNSWindow() override
;
30 gfx::Vector2d
GetChildWindowOffset() const override
;
31 bool IsVisibleParent() const override
;
32 void RemoveChildWindow(BridgedNativeWidget
* child
) override
;
36 ~WidgetOwnerNSWindowAdapter() override
;
38 BridgedNativeWidget
* child_
; // Weak. Owned by its NativeWidgetMac.
39 base::scoped_nsobject
<NSView
> anchor_view_
;
40 base::scoped_nsobject
<WidgetOwnerNSWindowAdapterBridge
> observer_bridge_
;
42 DISALLOW_COPY_AND_ASSIGN(WidgetOwnerNSWindowAdapter
);
47 #endif // UI_VIEWS_COCOA_WIDGET_OWNER_NSWINDOW_ADAPTER_H_