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_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_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_tree_host_observer.h"
12 #include "ui/base/cursor/cursor.h"
13 #include "ui/views/ime/input_method_delegate.h"
14 #include "ui/views/widget/native_widget_private.h"
15 #include "ui/wm/core/compound_event_filter.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"
21 class WindowEventDispatcher
;
26 class ScreenPositionClient
;
27 class WindowTreeClient
;
32 class CompoundEventFilter
;
34 class FocusController
;
35 class InputMethodEventFilter
;
36 class ShadowController
;
37 class VisibilityController
;
38 class WindowModalityController
;
43 class TooltipController
;
45 class DesktopCaptureClient
;
46 class DesktopDispatcherClient
;
47 class DesktopEventClient
;
48 class DesktopNativeCursorManager
;
49 class DesktopWindowTreeHost
;
51 class FocusManagerEventHandler
;
52 class TooltipManagerAura
;
53 class WindowReorderer
;
55 class VIEWS_EXPORT DesktopNativeWidgetAura
56 : public internal::NativeWidgetPrivate
,
57 public aura::WindowDelegate
,
58 public aura::client::ActivationDelegate
,
59 public aura::client::ActivationChangeObserver
,
60 public aura::client::FocusChangeObserver
,
61 public views::internal::InputMethodDelegate
,
62 public aura::client::DragDropDelegate
,
63 public aura::WindowTreeHostObserver
{
65 explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate
* delegate
);
66 virtual ~DesktopNativeWidgetAura();
68 // Maps from window to DesktopNativeWidgetAura. |window| must be a root
70 static DesktopNativeWidgetAura
* ForWindow(aura::Window
* window
);
72 // Called by our DesktopWindowTreeHost after it has deleted native resources;
73 // this is the signal that we should start our shutdown.
74 virtual void OnHostClosed();
76 // TODO(beng): remove this method and replace with an implementation of
77 // WindowDestroying() that takes the window being destroyed.
78 // Called from ~DesktopWindowTreeHost. This takes the WindowEventDispatcher
79 // as by the time we get here |dispatcher_| is NULL.
80 virtual void OnDesktopWindowTreeHostDestroyed(aura::WindowTreeHost
* host
);
82 wm::InputMethodEventFilter
* input_method_event_filter() {
83 return input_method_event_filter_
.get();
85 wm::CompoundEventFilter
* root_window_event_filter() {
86 return root_window_event_filter_
.get();
88 aura::WindowTreeHost
* host() {
92 // Ensures that the correct window is activated/deactivated based on whether
93 // we are being activated/deactivated.
94 void HandleActivationChanged(bool active
);
97 // Overridden from internal::NativeWidgetPrivate:
98 virtual void InitNativeWidget(const Widget::InitParams
& params
) OVERRIDE
;
99 virtual NonClientFrameView
* CreateNonClientFrameView() OVERRIDE
;
100 virtual bool ShouldUseNativeFrame() const OVERRIDE
;
101 virtual bool ShouldWindowContentsBeTransparent() const OVERRIDE
;
102 virtual void FrameTypeChanged() OVERRIDE
;
103 virtual Widget
* GetWidget() OVERRIDE
;
104 virtual const Widget
* GetWidget() const OVERRIDE
;
105 virtual gfx::NativeView
GetNativeView() const OVERRIDE
;
106 virtual gfx::NativeWindow
GetNativeWindow() const OVERRIDE
;
107 virtual Widget
* GetTopLevelWidget() OVERRIDE
;
108 virtual const ui::Compositor
* GetCompositor() const OVERRIDE
;
109 virtual ui::Compositor
* GetCompositor() OVERRIDE
;
110 virtual ui::Layer
* GetLayer() OVERRIDE
;
111 virtual void ReorderNativeViews() OVERRIDE
;
112 virtual void ViewRemoved(View
* view
) OVERRIDE
;
113 virtual void SetNativeWindowProperty(const char* name
, void* value
) OVERRIDE
;
114 virtual void* GetNativeWindowProperty(const char* name
) const OVERRIDE
;
115 virtual TooltipManager
* GetTooltipManager() const OVERRIDE
;
116 virtual void SetCapture() OVERRIDE
;
117 virtual void ReleaseCapture() OVERRIDE
;
118 virtual bool HasCapture() const OVERRIDE
;
119 virtual InputMethod
* CreateInputMethod() OVERRIDE
;
120 virtual internal::InputMethodDelegate
* GetInputMethodDelegate() OVERRIDE
;
121 virtual ui::InputMethod
* GetHostInputMethod() OVERRIDE
;
122 virtual void CenterWindow(const gfx::Size
& size
) OVERRIDE
;
123 virtual void GetWindowPlacement(
125 ui::WindowShowState
* maximized
) const OVERRIDE
;
126 virtual bool SetWindowTitle(const base::string16
& title
) OVERRIDE
;
127 virtual void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
128 const gfx::ImageSkia
& app_icon
) OVERRIDE
;
129 virtual void InitModalType(ui::ModalType modal_type
) OVERRIDE
;
130 virtual gfx::Rect
GetWindowBoundsInScreen() const OVERRIDE
;
131 virtual gfx::Rect
GetClientAreaBoundsInScreen() const OVERRIDE
;
132 virtual gfx::Rect
GetRestoredBounds() const OVERRIDE
;
133 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
134 virtual void SetSize(const gfx::Size
& size
) OVERRIDE
;
135 virtual void StackAbove(gfx::NativeView native_view
) OVERRIDE
;
136 virtual void StackAtTop() OVERRIDE
;
137 virtual void StackBelow(gfx::NativeView native_view
) OVERRIDE
;
138 virtual void SetShape(gfx::NativeRegion shape
) OVERRIDE
;
139 virtual void Close() OVERRIDE
;
140 virtual void CloseNow() OVERRIDE
;
141 virtual void Show() OVERRIDE
;
142 virtual void Hide() OVERRIDE
;
143 virtual void ShowMaximizedWithBounds(
144 const gfx::Rect
& restored_bounds
) OVERRIDE
;
145 virtual void ShowWithWindowState(ui::WindowShowState state
) OVERRIDE
;
146 virtual bool IsVisible() const OVERRIDE
;
147 virtual void Activate() OVERRIDE
;
148 virtual void Deactivate() OVERRIDE
;
149 virtual bool IsActive() const OVERRIDE
;
150 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
151 virtual bool IsAlwaysOnTop() const OVERRIDE
;
152 virtual void SetVisibleOnAllWorkspaces(bool always_visible
) OVERRIDE
;
153 virtual void Maximize() OVERRIDE
;
154 virtual void Minimize() OVERRIDE
;
155 virtual bool IsMaximized() const OVERRIDE
;
156 virtual bool IsMinimized() const OVERRIDE
;
157 virtual void Restore() OVERRIDE
;
158 virtual void SetFullscreen(bool fullscreen
) OVERRIDE
;
159 virtual bool IsFullscreen() const OVERRIDE
;
160 virtual void SetOpacity(unsigned char opacity
) OVERRIDE
;
161 virtual void SetUseDragFrame(bool use_drag_frame
) OVERRIDE
;
162 virtual void FlashFrame(bool flash_frame
) OVERRIDE
;
163 virtual void RunShellDrag(View
* view
,
164 const ui::OSExchangeData
& data
,
165 const gfx::Point
& location
,
167 ui::DragDropTypes::DragEventSource source
) OVERRIDE
;
168 virtual void SchedulePaintInRect(const gfx::Rect
& rect
) OVERRIDE
;
169 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
170 virtual bool IsMouseEventsEnabled() const OVERRIDE
;
171 virtual void ClearNativeFocus() OVERRIDE
;
172 virtual gfx::Rect
GetWorkAreaBoundsInScreen() const OVERRIDE
;
173 virtual Widget::MoveLoopResult
RunMoveLoop(
174 const gfx::Vector2d
& drag_offset
,
175 Widget::MoveLoopSource source
,
176 Widget::MoveLoopEscapeBehavior escape_behavior
) OVERRIDE
;
177 virtual void EndMoveLoop() OVERRIDE
;
178 virtual void SetVisibilityChangedAnimationsEnabled(bool value
) OVERRIDE
;
179 virtual ui::NativeTheme
* GetNativeTheme() const OVERRIDE
;
180 virtual void OnRootViewLayout() OVERRIDE
;
181 virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE
;
182 virtual void RepostNativeEvent(gfx::NativeEvent native_event
) OVERRIDE
;
184 // Overridden from aura::WindowDelegate:
185 virtual gfx::Size
GetMinimumSize() const OVERRIDE
;
186 virtual gfx::Size
GetMaximumSize() const OVERRIDE
;
187 virtual void OnBoundsChanged(const gfx::Rect
& old_bounds
,
188 const gfx::Rect
& new_bounds
) OVERRIDE
{}
189 virtual gfx::NativeCursor
GetCursor(const gfx::Point
& point
) OVERRIDE
;
190 virtual int GetNonClientComponent(const gfx::Point
& point
) const OVERRIDE
;
191 virtual bool ShouldDescendIntoChildForEventHandling(
193 const gfx::Point
& location
) OVERRIDE
;
194 virtual bool CanFocus() OVERRIDE
;
195 virtual void OnCaptureLost() OVERRIDE
;
196 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
197 virtual void OnDeviceScaleFactorChanged(float device_scale_factor
) OVERRIDE
;
198 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
199 virtual void OnWindowDestroyed(aura::Window
* window
) OVERRIDE
;
200 virtual void OnWindowTargetVisibilityChanged(bool visible
) OVERRIDE
;
201 virtual bool HasHitTestMask() const OVERRIDE
;
202 virtual void GetHitTestMask(gfx::Path
* mask
) const OVERRIDE
;
204 // Overridden from ui::EventHandler:
205 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
;
206 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
207 virtual void OnScrollEvent(ui::ScrollEvent
* event
) OVERRIDE
;
208 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
210 // Overridden from aura::client::ActivationDelegate:
211 virtual bool ShouldActivate() const OVERRIDE
;
213 // Overridden from aura::client::ActivationChangeObserver:
214 virtual void OnWindowActivated(aura::Window
* gained_active
,
215 aura::Window
* lost_active
) OVERRIDE
;
217 // Overridden from aura::client::FocusChangeObserver:
218 virtual void OnWindowFocused(aura::Window
* gained_focus
,
219 aura::Window
* lost_focus
) OVERRIDE
;
221 // Overridden from views::internal::InputMethodDelegate:
222 virtual void DispatchKeyEventPostIME(const ui::KeyEvent
& key
) OVERRIDE
;
224 // Overridden from aura::client::DragDropDelegate:
225 virtual void OnDragEntered(const ui::DropTargetEvent
& event
) OVERRIDE
;
226 virtual int OnDragUpdated(const ui::DropTargetEvent
& event
) OVERRIDE
;
227 virtual void OnDragExited() OVERRIDE
;
228 virtual int OnPerformDrop(const ui::DropTargetEvent
& event
) OVERRIDE
;
230 // Overridden from aura::WindowTreeHostObserver:
231 virtual void OnHostCloseRequested(const aura::WindowTreeHost
* host
) OVERRIDE
;
232 virtual void OnHostResized(const aura::WindowTreeHost
* host
) OVERRIDE
;
233 virtual void OnHostMoved(const aura::WindowTreeHost
* host
,
234 const gfx::Point
& new_origin
) OVERRIDE
;
237 friend class FocusManagerEventHandler
;
238 friend class RootWindowDestructionObserver
;
240 // Installs the input method filter.
241 void InstallInputMethodEventFilter();
243 // To save a clear on platforms where the window is never transparent, the
244 // window is only set as transparent when the glass frame is in use.
245 void UpdateWindowTransparency();
247 void RootWindowDestroyed();
249 scoped_ptr
<aura::WindowTreeHost
> host_
;
250 DesktopWindowTreeHost
* desktop_window_tree_host_
;
252 // See class documentation for Widget in widget.h for a note about ownership.
253 Widget::InitParams::Ownership ownership_
;
255 scoped_ptr
<DesktopCaptureClient
> capture_client_
;
257 // The following factory is used for calls to close the NativeWidgetAura
259 base::WeakPtrFactory
<DesktopNativeWidgetAura
> close_widget_factory_
;
261 // Child of the root, contains |content_window_|.
262 aura::Window
* content_window_container_
;
264 // Child of |content_window_container_|. This is the return value from
266 // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
267 aura::Window
* content_window_
;
269 internal::NativeWidgetDelegate
* native_widget_delegate_
;
271 scoped_ptr
<wm::FocusController
> focus_client_
;
272 scoped_ptr
<DesktopDispatcherClient
> dispatcher_client_
;
273 scoped_ptr
<aura::client::ScreenPositionClient
> position_client_
;
274 scoped_ptr
<aura::client::DragDropClient
> drag_drop_client_
;
275 scoped_ptr
<aura::client::WindowTreeClient
> window_tree_client_
;
276 scoped_ptr
<DesktopEventClient
> event_client_
;
277 scoped_ptr
<FocusManagerEventHandler
> focus_manager_event_handler_
;
279 // Toplevel event filter which dispatches to other event filters.
280 scoped_ptr
<wm::CompoundEventFilter
> root_window_event_filter_
;
282 scoped_ptr
<wm::InputMethodEventFilter
> input_method_event_filter_
;
284 scoped_ptr
<DropHelper
> drop_helper_
;
285 int last_drop_operation_
;
287 scoped_ptr
<corewm::TooltipController
> tooltip_controller_
;
288 scoped_ptr
<TooltipManagerAura
> tooltip_manager_
;
290 scoped_ptr
<wm::VisibilityController
> visibility_controller_
;
292 scoped_ptr
<wm::WindowModalityController
>
293 window_modality_controller_
;
295 bool restore_focus_on_activate_
;
297 gfx::NativeCursor cursor_
;
298 // We must manually reference count the number of users of |cursor_manager_|
299 // because the cursors created by |cursor_manager_| are shared among the
300 // DNWAs. We can't just stuff this in a LazyInstance because we need to
301 // destroy this as the last DNWA happens; we can't put it off until
302 // (potentially) after we tear down the X11 connection because that's a
304 static int cursor_reference_count_
;
305 static wm::CursorManager
* cursor_manager_
;
306 static views::DesktopNativeCursorManager
* native_cursor_manager_
;
308 scoped_ptr
<wm::ShadowController
> shadow_controller_
;
310 // Reorders child windows of |window_| associated with a view based on the
311 // order of the associated views in the widget's view hierarchy.
312 scoped_ptr
<WindowReorderer
> window_reorderer_
;
314 // See class documentation for Widget in widget.h for a note about type.
315 Widget::InitParams::Type widget_type_
;
317 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura
);
322 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_