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_WIDGET_NATIVE_WIDGET_MAC_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_MAC_H_
8 #include "ui/gfx/native_widget_types.h"
9 #include "ui/views/widget/native_widget_private.h"
13 class MockNativeWidgetMac
;
16 class BridgedNativeWidget
;
18 class VIEWS_EXPORT NativeWidgetMac
: public internal::NativeWidgetPrivate
{
20 NativeWidgetMac(internal::NativeWidgetDelegate
* delegate
);
21 ~NativeWidgetMac() override
;
23 // Retrieves the bridge associated with the given NSWindow. Returns null if
24 // the supplied handle has no associated Widget.
25 static BridgedNativeWidget
* GetBridgeForNativeWindow(
26 gfx::NativeWindow window
);
28 // Deletes |bridge_| and informs |delegate_| that the native widget is
30 // This is usually called from the NSWindowDelegate. A derived class can
31 // override this method for an early hook into the native window teardown.
32 virtual void OnWindowWillClose();
34 // internal::NativeWidgetPrivate:
35 void InitNativeWidget(const Widget::InitParams
& params
) override
;
36 NonClientFrameView
* CreateNonClientFrameView() override
;
37 bool ShouldUseNativeFrame() const override
;
38 bool ShouldWindowContentsBeTransparent() const override
;
39 void FrameTypeChanged() override
;
40 Widget
* GetWidget() override
;
41 const Widget
* GetWidget() const override
;
42 gfx::NativeView
GetNativeView() const override
;
43 gfx::NativeWindow
GetNativeWindow() const override
;
44 Widget
* GetTopLevelWidget() override
;
45 const ui::Compositor
* GetCompositor() const override
;
46 const ui::Layer
* GetLayer() const override
;
47 void ReorderNativeViews() override
;
48 void ViewRemoved(View
* view
) override
;
49 void SetNativeWindowProperty(const char* name
, void* value
) override
;
50 void* GetNativeWindowProperty(const char* name
) const override
;
51 TooltipManager
* GetTooltipManager() const override
;
52 void SetCapture() override
;
53 void ReleaseCapture() override
;
54 bool HasCapture() const override
;
55 InputMethod
* CreateInputMethod() override
;
56 internal::InputMethodDelegate
* GetInputMethodDelegate() override
;
57 ui::InputMethod
* GetHostInputMethod() override
;
58 void CenterWindow(const gfx::Size
& size
) override
;
59 void GetWindowPlacement(gfx::Rect
* bounds
,
60 ui::WindowShowState
* maximized
) const override
;
61 bool SetWindowTitle(const base::string16
& title
) override
;
62 void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
63 const gfx::ImageSkia
& app_icon
) override
;
64 void InitModalType(ui::ModalType modal_type
) override
;
65 gfx::Rect
GetWindowBoundsInScreen() const override
;
66 gfx::Rect
GetClientAreaBoundsInScreen() const override
;
67 gfx::Rect
GetRestoredBounds() const override
;
68 void SetBounds(const gfx::Rect
& bounds
) override
;
69 void SetSize(const gfx::Size
& size
) override
;
70 void StackAbove(gfx::NativeView native_view
) override
;
71 void StackAtTop() override
;
72 void StackBelow(gfx::NativeView native_view
) override
;
73 void SetShape(gfx::NativeRegion shape
) override
;
74 void Close() override
;
75 void CloseNow() override
;
78 void ShowMaximizedWithBounds(const gfx::Rect
& restored_bounds
) override
;
79 void ShowWithWindowState(ui::WindowShowState state
) override
;
80 bool IsVisible() const override
;
81 void Activate() override
;
82 void Deactivate() override
;
83 bool IsActive() const override
;
84 void SetAlwaysOnTop(bool always_on_top
) override
;
85 bool IsAlwaysOnTop() const override
;
86 void SetVisibleOnAllWorkspaces(bool always_visible
) override
;
87 void Maximize() override
;
88 void Minimize() override
;
89 bool IsMaximized() const override
;
90 bool IsMinimized() const override
;
91 void Restore() override
;
92 void SetFullscreen(bool fullscreen
) override
;
93 bool IsFullscreen() const override
;
94 void SetOpacity(unsigned char opacity
) override
;
95 void SetUseDragFrame(bool use_drag_frame
) override
;
96 void FlashFrame(bool flash_frame
) override
;
97 void RunShellDrag(View
* view
,
98 const ui::OSExchangeData
& data
,
99 const gfx::Point
& location
,
101 ui::DragDropTypes::DragEventSource source
) override
;
102 void SchedulePaintInRect(const gfx::Rect
& rect
) override
;
103 void SetCursor(gfx::NativeCursor cursor
) override
;
104 bool IsMouseEventsEnabled() const override
;
105 void ClearNativeFocus() override
;
106 gfx::Rect
GetWorkAreaBoundsInScreen() const override
;
107 Widget::MoveLoopResult
RunMoveLoop(
108 const gfx::Vector2d
& drag_offset
,
109 Widget::MoveLoopSource source
,
110 Widget::MoveLoopEscapeBehavior escape_behavior
) override
;
111 void EndMoveLoop() override
;
112 void SetVisibilityChangedAnimationsEnabled(bool value
) override
;
113 void SetVisibilityAnimationDuration(const base::TimeDelta
& duration
) override
;
114 void SetVisibilityAnimationTransition(
115 Widget::VisibilityTransition transition
) override
;
116 ui::NativeTheme
* GetNativeTheme() const override
;
117 void OnRootViewLayout() override
;
118 bool IsTranslucentWindowOpacitySupported() const override
;
119 void OnSizeConstraintsChanged() override
;
120 void RepostNativeEvent(gfx::NativeEvent native_event
) override
;
123 // Creates the NSWindow that will be passed to the BridgedNativeWidget.
124 // Called by InitNativeWidget. The return value will be autoreleased.
125 virtual gfx::NativeWindow
CreateNSWindow(const Widget::InitParams
& params
);
127 internal::NativeWidgetDelegate
* delegate() { return delegate_
; }
130 friend class test::MockNativeWidgetMac
;
132 internal::NativeWidgetDelegate
* delegate_
;
133 scoped_ptr
<BridgedNativeWidget
> bridge_
;
135 Widget::InitParams::Ownership ownership_
;
137 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMac
);
142 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_MAC_H_