1 // Copyright (c) 2012 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_AURA_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_
8 #include "base/memory/weak_ptr.h"
9 #include "ui/aura/client/focus_change_observer.h"
10 #include "ui/aura/window_delegate.h"
11 #include "ui/aura/window_observer.h"
12 #include "ui/base/cursor/cursor.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/views/views_export.h"
15 #include "ui/views/widget/native_widget_private.h"
16 #include "ui/wm/public/activation_change_observer.h"
17 #include "ui/wm/public/activation_delegate.h"
18 #include "ui/wm/public/drag_drop_delegate.h"
30 class TooltipManagerAura
;
31 class WindowReorderer
;
33 class VIEWS_EXPORT NativeWidgetAura
34 : public internal::NativeWidgetPrivate
,
35 public aura::WindowDelegate
,
36 public aura::WindowObserver
,
37 public aura::client::ActivationDelegate
,
38 public aura::client::ActivationChangeObserver
,
39 public aura::client::FocusChangeObserver
,
40 public aura::client::DragDropDelegate
{
42 explicit NativeWidgetAura(internal::NativeWidgetDelegate
* delegate
);
44 // Called internally by NativeWidgetAura and DesktopNativeWidgetAura to
45 // associate |native_widget| with |window|.
46 static void RegisterNativeWidgetForWindow(
47 internal::NativeWidgetPrivate
* native_widget
,
48 aura::Window
* window
);
50 // Overridden from internal::NativeWidgetPrivate:
51 void InitNativeWidget(const Widget::InitParams
& params
) override
;
52 NonClientFrameView
* CreateNonClientFrameView() override
;
53 bool ShouldUseNativeFrame() const override
;
54 bool ShouldWindowContentsBeTransparent() const override
;
55 void FrameTypeChanged() override
;
56 Widget
* GetWidget() override
;
57 const Widget
* GetWidget() const override
;
58 gfx::NativeView
GetNativeView() const override
;
59 gfx::NativeWindow
GetNativeWindow() const override
;
60 Widget
* GetTopLevelWidget() override
;
61 const ui::Compositor
* GetCompositor() const override
;
62 const ui::Layer
* GetLayer() const override
;
63 void ReorderNativeViews() override
;
64 void ViewRemoved(View
* view
) override
;
65 void SetNativeWindowProperty(const char* name
, void* value
) override
;
66 void* GetNativeWindowProperty(const char* name
) const override
;
67 TooltipManager
* GetTooltipManager() const override
;
68 void SetCapture() override
;
69 void ReleaseCapture() override
;
70 bool HasCapture() const override
;
71 ui::InputMethod
* GetInputMethod() override
;
72 void CenterWindow(const gfx::Size
& size
) override
;
73 void GetWindowPlacement(gfx::Rect
* bounds
,
74 ui::WindowShowState
* maximized
) const override
;
75 bool SetWindowTitle(const base::string16
& title
) override
;
76 void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
77 const gfx::ImageSkia
& app_icon
) override
;
78 void InitModalType(ui::ModalType modal_type
) override
;
79 gfx::Rect
GetWindowBoundsInScreen() const override
;
80 gfx::Rect
GetClientAreaBoundsInScreen() const override
;
81 gfx::Rect
GetRestoredBounds() const override
;
82 void SetBounds(const gfx::Rect
& bounds
) override
;
83 void SetSize(const gfx::Size
& size
) override
;
84 void StackAbove(gfx::NativeView native_view
) override
;
85 void StackAtTop() override
;
86 void StackBelow(gfx::NativeView native_view
) override
;
87 void SetShape(SkRegion
* shape
) override
;
88 void Close() override
;
89 void CloseNow() override
;
92 void ShowMaximizedWithBounds(const gfx::Rect
& restored_bounds
) override
;
93 void ShowWithWindowState(ui::WindowShowState state
) override
;
94 bool IsVisible() const override
;
95 void Activate() override
;
96 void Deactivate() override
;
97 bool IsActive() const override
;
98 void SetAlwaysOnTop(bool always_on_top
) override
;
99 bool IsAlwaysOnTop() const override
;
100 void SetVisibleOnAllWorkspaces(bool always_visible
) override
;
101 void Maximize() override
;
102 void Minimize() override
;
103 bool IsMaximized() const override
;
104 bool IsMinimized() const override
;
105 void Restore() override
;
106 void SetFullscreen(bool fullscreen
) override
;
107 bool IsFullscreen() const override
;
108 void SetOpacity(unsigned char opacity
) override
;
109 void SetUseDragFrame(bool use_drag_frame
) override
;
110 void FlashFrame(bool flash_frame
) override
;
111 void RunShellDrag(View
* view
,
112 const ui::OSExchangeData
& data
,
113 const gfx::Point
& location
,
115 ui::DragDropTypes::DragEventSource source
) override
;
116 void SchedulePaintInRect(const gfx::Rect
& rect
) override
;
117 void SetCursor(gfx::NativeCursor cursor
) override
;
118 bool IsMouseEventsEnabled() const override
;
119 void ClearNativeFocus() override
;
120 gfx::Rect
GetWorkAreaBoundsInScreen() const override
;
121 Widget::MoveLoopResult
RunMoveLoop(
122 const gfx::Vector2d
& drag_offset
,
123 Widget::MoveLoopSource source
,
124 Widget::MoveLoopEscapeBehavior escape_behavior
) override
;
125 void EndMoveLoop() override
;
126 void SetVisibilityChangedAnimationsEnabled(bool value
) override
;
127 void SetVisibilityAnimationDuration(const base::TimeDelta
& duration
) override
;
128 void SetVisibilityAnimationTransition(
129 Widget::VisibilityTransition transition
) override
;
130 ui::NativeTheme
* GetNativeTheme() const override
;
131 void OnRootViewLayout() override
;
132 bool IsTranslucentWindowOpacitySupported() const override
;
133 void OnSizeConstraintsChanged() override
;
134 void RepostNativeEvent(gfx::NativeEvent native_event
) override
;
136 // Overridden from aura::WindowDelegate:
137 gfx::Size
GetMinimumSize() const override
;
138 gfx::Size
GetMaximumSize() const override
;
139 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
140 const gfx::Rect
& new_bounds
) override
;
141 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
142 int GetNonClientComponent(const gfx::Point
& point
) const override
;
143 bool ShouldDescendIntoChildForEventHandling(
145 const gfx::Point
& location
) override
;
146 bool CanFocus() override
;
147 void OnCaptureLost() override
;
148 void OnPaint(const ui::PaintContext
& context
) override
;
149 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
150 void OnWindowDestroying(aura::Window
* window
) override
;
151 void OnWindowDestroyed(aura::Window
* window
) override
;
152 void OnWindowTargetVisibilityChanged(bool visible
) override
;
153 bool HasHitTestMask() const override
;
154 void GetHitTestMask(gfx::Path
* mask
) const override
;
156 // Overridden from aura::WindowObserver:
157 void OnWindowPropertyChanged(aura::Window
* window
,
159 intptr_t old
) override
;
161 // Overridden from ui::EventHandler:
162 void OnKeyEvent(ui::KeyEvent
* event
) override
;
163 void OnMouseEvent(ui::MouseEvent
* event
) override
;
164 void OnScrollEvent(ui::ScrollEvent
* event
) override
;
165 void OnGestureEvent(ui::GestureEvent
* event
) override
;
167 // Overridden from aura::client::ActivationDelegate:
168 bool ShouldActivate() const override
;
170 // Overridden from aura::client::ActivationChangeObserver:
171 void OnWindowActivated(
172 aura::client::ActivationChangeObserver::ActivationReason reason
,
173 aura::Window
* gained_active
,
174 aura::Window
* lost_active
) override
;
176 // Overridden from aura::client::FocusChangeObserver:
177 void OnWindowFocused(aura::Window
* gained_focus
,
178 aura::Window
* lost_focus
) override
;
180 // Overridden from aura::client::DragDropDelegate:
181 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
182 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
183 void OnDragExited() override
;
184 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
187 ~NativeWidgetAura() override
;
189 internal::NativeWidgetDelegate
* delegate() { return delegate_
; }
192 class ActiveWindowObserver
;
194 bool IsDocked() const;
195 void SetInitialFocus(ui::WindowShowState show_state
);
197 internal::NativeWidgetDelegate
* delegate_
;
199 // WARNING: set to NULL when destroyed. As the Widget is not necessarily
200 // destroyed along with |window_| all usage of |window_| should first verify
202 aura::Window
* window_
;
204 // See class documentation for Widget in widget.h for a note about ownership.
205 Widget::InitParams::Ownership ownership_
;
207 // Are we in the destructor?
210 gfx::NativeCursor cursor_
;
212 // The saved window state for exiting full screen state.
213 ui::WindowShowState saved_window_state_
;
215 scoped_ptr
<TooltipManagerAura
> tooltip_manager_
;
217 // Reorders child windows of |window_| associated with a view based on the
218 // order of the associated views in the widget's view hierarchy.
219 scoped_ptr
<WindowReorderer
> window_reorderer_
;
221 scoped_ptr
<DropHelper
> drop_helper_
;
222 int last_drop_operation_
;
224 // The following factory is used for calls to close the NativeWidgetAura
226 base::WeakPtrFactory
<NativeWidgetAura
> close_widget_factory_
;
228 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura
);
233 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_