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