1 // Copyright 2014 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_BRIDGED_NATIVE_WIDGET_H_
6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
8 #import <Cocoa/Cocoa.h>
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "ui/views/focus/focus_manager.h"
13 #include "ui/views/ime/input_method_delegate.h"
14 #include "ui/views/views_export.h"
15 #include "ui/views/widget/widget.h"
17 @
class BridgedContentView
;
18 @
class ViewsNSWindowDelegate
;
27 class NativeWidgetMac
;
30 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or
31 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the
32 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window.
33 class VIEWS_EXPORT BridgedNativeWidget
: public internal::InputMethodDelegate
,
34 public FocusChangeListener
{
36 // Creates one side of the bridge. |parent| must not be NULL.
37 explicit BridgedNativeWidget(NativeWidgetMac
* parent
);
38 virtual ~BridgedNativeWidget();
40 // Initialize the bridge, "retains" ownership of |window|.
41 void Init(base::scoped_nsobject
<NSWindow
> window
,
42 const Widget::InitParams
& params
);
44 // Sets or clears the focus manager to use for tracking focused views.
45 // This does NOT take ownership of |focus_manager|.
46 void SetFocusManager(FocusManager
* focus_manager
);
48 // Set or clears the views::View bridged by the content view. This does NOT
49 // take ownership of |view|.
50 void SetRootView(views::View
* view
);
52 // Called internally by the NSWindowDelegate when the window is closing.
53 void OnWindowWillClose();
55 // See widget.h for documentation.
56 InputMethod
* CreateInputMethod();
57 ui::InputMethod
* GetHostInputMethod();
59 NativeWidgetMac
* native_widget_mac() { return native_widget_mac_
; }
60 BridgedContentView
* ns_view() { return bridged_view_
; }
61 NSWindow
* ns_window() { return window_
; }
63 // Overridden from internal::InputMethodDelegate:
64 virtual void DispatchKeyEventPostIME(const ui::KeyEvent
& key
) OVERRIDE
;
67 // Closes all child windows. BridgedNativeWidget children will be destroyed.
68 void RemoveOrDestroyChildren();
70 views::NativeWidgetMac
* native_widget_mac_
; // Weak. Owns this.
71 base::scoped_nsobject
<NSWindow
> window_
;
72 base::scoped_nsobject
<ViewsNSWindowDelegate
> window_delegate_
;
73 base::scoped_nsobject
<BridgedContentView
> bridged_view_
;
74 scoped_ptr
<ui::InputMethod
> input_method_
;
75 FocusManager
* focus_manager_
; // Weak. Owned by our Widget.
77 // Overridden from FocusChangeListener:
78 virtual void OnWillChangeFocus(View
* focused_before
,
79 View
* focused_now
) OVERRIDE
;
80 virtual void OnDidChangeFocus(View
* focused_before
,
81 View
* focused_now
) OVERRIDE
;
83 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget
);
88 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_