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 ~DesktopNativeWidgetAura() override
;
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 void InitNativeWidget(const Widget::InitParams
& params
) override
;
99 NonClientFrameView
* CreateNonClientFrameView() override
;
100 bool ShouldUseNativeFrame() const override
;
101 bool ShouldWindowContentsBeTransparent() const override
;
102 void FrameTypeChanged() override
;
103 Widget
* GetWidget() override
;
104 const Widget
* GetWidget() const override
;
105 gfx::NativeView
GetNativeView() const override
;
106 gfx::NativeWindow
GetNativeWindow() const override
;
107 Widget
* GetTopLevelWidget() override
;
108 const ui::Compositor
* GetCompositor() const override
;
109 const ui::Layer
* GetLayer() const override
;
110 void ReorderNativeViews() override
;
111 void ViewRemoved(View
* view
) override
;
112 void SetNativeWindowProperty(const char* name
, void* value
) override
;
113 void* GetNativeWindowProperty(const char* name
) const override
;
114 TooltipManager
* GetTooltipManager() const override
;
115 void SetCapture() override
;
116 void ReleaseCapture() override
;
117 bool HasCapture() const override
;
118 InputMethod
* CreateInputMethod() override
;
119 internal::InputMethodDelegate
* GetInputMethodDelegate() override
;
120 ui::InputMethod
* GetHostInputMethod() override
;
121 void CenterWindow(const gfx::Size
& size
) override
;
122 void GetWindowPlacement(gfx::Rect
* bounds
,
123 ui::WindowShowState
* maximized
) const override
;
124 bool SetWindowTitle(const base::string16
& title
) override
;
125 void SetWindowIcons(const gfx::ImageSkia
& window_icon
,
126 const gfx::ImageSkia
& app_icon
) override
;
127 void InitModalType(ui::ModalType modal_type
) override
;
128 gfx::Rect
GetWindowBoundsInScreen() const override
;
129 gfx::Rect
GetClientAreaBoundsInScreen() const override
;
130 gfx::Rect
GetRestoredBounds() const override
;
131 void SetBounds(const gfx::Rect
& bounds
) override
;
132 void SetSize(const gfx::Size
& size
) override
;
133 void StackAbove(gfx::NativeView native_view
) override
;
134 void StackAtTop() override
;
135 void StackBelow(gfx::NativeView native_view
) override
;
136 void SetShape(gfx::NativeRegion shape
) override
;
137 void Close() override
;
138 void CloseNow() override
;
139 void Show() override
;
140 void Hide() override
;
141 void ShowMaximizedWithBounds(const gfx::Rect
& restored_bounds
) override
;
142 void ShowWithWindowState(ui::WindowShowState state
) override
;
143 bool IsVisible() const override
;
144 void Activate() override
;
145 void Deactivate() override
;
146 bool IsActive() const override
;
147 void SetAlwaysOnTop(bool always_on_top
) override
;
148 bool IsAlwaysOnTop() const override
;
149 void SetVisibleOnAllWorkspaces(bool always_visible
) override
;
150 void Maximize() override
;
151 void Minimize() override
;
152 bool IsMaximized() const override
;
153 bool IsMinimized() const override
;
154 void Restore() override
;
155 void SetFullscreen(bool fullscreen
) override
;
156 bool IsFullscreen() const override
;
157 void SetOpacity(unsigned char opacity
) override
;
158 void SetUseDragFrame(bool use_drag_frame
) override
;
159 void FlashFrame(bool flash_frame
) override
;
160 void RunShellDrag(View
* view
,
161 const ui::OSExchangeData
& data
,
162 const gfx::Point
& location
,
164 ui::DragDropTypes::DragEventSource source
) override
;
165 void SchedulePaintInRect(const gfx::Rect
& rect
) override
;
166 void SetCursor(gfx::NativeCursor cursor
) override
;
167 bool IsMouseEventsEnabled() const override
;
168 void ClearNativeFocus() override
;
169 gfx::Rect
GetWorkAreaBoundsInScreen() const override
;
170 Widget::MoveLoopResult
RunMoveLoop(
171 const gfx::Vector2d
& drag_offset
,
172 Widget::MoveLoopSource source
,
173 Widget::MoveLoopEscapeBehavior escape_behavior
) override
;
174 void EndMoveLoop() override
;
175 void SetVisibilityChangedAnimationsEnabled(bool value
) override
;
176 void SetVisibilityAnimationDuration(const base::TimeDelta
& duration
) override
;
177 void SetVisibilityAnimationTransition(
178 Widget::VisibilityTransition transition
) override
;
179 ui::NativeTheme
* GetNativeTheme() const override
;
180 void OnRootViewLayout() override
;
181 bool IsTranslucentWindowOpacitySupported() const override
;
182 void OnSizeConstraintsChanged() override
;
183 void RepostNativeEvent(gfx::NativeEvent native_event
) override
;
185 // Overridden from aura::WindowDelegate:
186 gfx::Size
GetMinimumSize() const override
;
187 gfx::Size
GetMaximumSize() const override
;
188 void OnBoundsChanged(const gfx::Rect
& old_bounds
,
189 const gfx::Rect
& new_bounds
) override
{}
190 ui::TextInputClient
* GetFocusedTextInputClient() override
;
191 gfx::NativeCursor
GetCursor(const gfx::Point
& point
) override
;
192 int GetNonClientComponent(const gfx::Point
& point
) const override
;
193 bool ShouldDescendIntoChildForEventHandling(
195 const gfx::Point
& location
) override
;
196 bool CanFocus() override
;
197 void OnCaptureLost() override
;
198 void OnPaint(const ui::PaintContext
& context
) override
;
199 void OnDeviceScaleFactorChanged(float device_scale_factor
) override
;
200 void OnWindowDestroying(aura::Window
* window
) override
;
201 void OnWindowDestroyed(aura::Window
* window
) override
;
202 void OnWindowTargetVisibilityChanged(bool visible
) override
;
203 bool HasHitTestMask() const override
;
204 void GetHitTestMask(gfx::Path
* mask
) const override
;
206 // Overridden from ui::EventHandler:
207 void OnKeyEvent(ui::KeyEvent
* event
) override
;
208 void OnMouseEvent(ui::MouseEvent
* event
) override
;
209 void OnScrollEvent(ui::ScrollEvent
* event
) override
;
210 void OnGestureEvent(ui::GestureEvent
* event
) override
;
212 // Overridden from aura::client::ActivationDelegate:
213 bool ShouldActivate() const override
;
215 // Overridden from aura::client::ActivationChangeObserver:
216 void OnWindowActivated(aura::Window
* gained_active
,
217 aura::Window
* lost_active
) override
;
219 // Overridden from aura::client::FocusChangeObserver:
220 void OnWindowFocused(aura::Window
* gained_focus
,
221 aura::Window
* lost_focus
) override
;
223 // Overridden from views::internal::InputMethodDelegate:
224 void DispatchKeyEventPostIME(const ui::KeyEvent
& key
) override
;
226 // Overridden from aura::client::DragDropDelegate:
227 void OnDragEntered(const ui::DropTargetEvent
& event
) override
;
228 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
;
229 void OnDragExited() override
;
230 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
;
232 // Overridden from aura::WindowTreeHostObserver:
233 void OnHostCloseRequested(const aura::WindowTreeHost
* host
) override
;
234 void OnHostResized(const aura::WindowTreeHost
* host
) override
;
235 void OnHostMoved(const aura::WindowTreeHost
* host
,
236 const gfx::Point
& new_origin
) override
;
239 friend class FocusManagerEventHandler
;
240 friend class RootWindowDestructionObserver
;
242 // Installs the input method filter.
243 void InstallInputMethodEventFilter();
245 // To save a clear on platforms where the window is never transparent, the
246 // window is only set as transparent when the glass frame is in use.
247 void UpdateWindowTransparency();
249 void RootWindowDestroyed();
251 scoped_ptr
<aura::WindowTreeHost
> host_
;
252 DesktopWindowTreeHost
* desktop_window_tree_host_
;
254 // See class documentation for Widget in widget.h for a note about ownership.
255 Widget::InitParams::Ownership ownership_
;
257 scoped_ptr
<DesktopCaptureClient
> capture_client_
;
259 // Child of the root, contains |content_window_|.
260 aura::Window
* content_window_container_
;
262 // Child of |content_window_container_|. This is the return value from
264 // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
265 aura::Window
* content_window_
;
267 internal::NativeWidgetDelegate
* native_widget_delegate_
;
269 scoped_ptr
<wm::FocusController
> focus_client_
;
270 scoped_ptr
<DesktopDispatcherClient
> dispatcher_client_
;
271 scoped_ptr
<aura::client::ScreenPositionClient
> position_client_
;
272 scoped_ptr
<aura::client::DragDropClient
> drag_drop_client_
;
273 scoped_ptr
<aura::client::WindowTreeClient
> window_tree_client_
;
274 scoped_ptr
<DesktopEventClient
> event_client_
;
275 scoped_ptr
<FocusManagerEventHandler
> focus_manager_event_handler_
;
277 // Toplevel event filter which dispatches to other event filters.
278 scoped_ptr
<wm::CompoundEventFilter
> root_window_event_filter_
;
280 scoped_ptr
<wm::InputMethodEventFilter
> input_method_event_filter_
;
282 scoped_ptr
<DropHelper
> drop_helper_
;
283 int last_drop_operation_
;
285 scoped_ptr
<corewm::TooltipController
> tooltip_controller_
;
286 scoped_ptr
<TooltipManagerAura
> tooltip_manager_
;
288 scoped_ptr
<wm::VisibilityController
> visibility_controller_
;
290 scoped_ptr
<wm::WindowModalityController
>
291 window_modality_controller_
;
293 bool restore_focus_on_activate_
;
295 gfx::NativeCursor cursor_
;
296 // We must manually reference count the number of users of |cursor_manager_|
297 // because the cursors created by |cursor_manager_| are shared among the
298 // DNWAs. We can't just stuff this in a LazyInstance because we need to
299 // destroy this as the last DNWA happens; we can't put it off until
300 // (potentially) after we tear down the X11 connection because that's a
302 static int cursor_reference_count_
;
303 static wm::CursorManager
* cursor_manager_
;
304 static views::DesktopNativeCursorManager
* native_cursor_manager_
;
306 scoped_ptr
<wm::ShadowController
> shadow_controller_
;
308 // Reorders child windows of |window_| associated with a view based on the
309 // order of the associated views in the widget's view hierarchy.
310 scoped_ptr
<WindowReorderer
> window_reorderer_
;
312 // See class documentation for Widget in widget.h for a note about type.
313 Widget::InitParams::Type widget_type_
;
315 // The following factory is used for calls to close the NativeWidgetAura
317 base::WeakPtrFactory
<DesktopNativeWidgetAura
> close_widget_factory_
;
319 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura
);
324 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_