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