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/activation_change_observer.h"
10 #include "ui/aura/client/activation_delegate.h"
11 #include "ui/aura/client/drag_drop_delegate.h"
12 #include "ui/aura/client/focus_change_observer.h"
13 #include "ui/aura/root_window_observer.h"
14 #include "ui/aura/window_delegate.h"
15 #include "ui/base/cursor/cursor.h"
16 #include "ui/views/ime/input_method_delegate.h"
17 #include "ui/views/widget/native_widget_private.h"
24 class ScreenPositionClient;
25 class WindowTreeClient;
32 class CompoundEventFilter;
34 class InputMethodEventFilter;
35 class ShadowController;
36 class TooltipController;
37 class VisibilityController;
38 class WindowModalityController;
41 class DesktopCaptureClient;
42 class DesktopDispatcherClient;
43 class DesktopRootWindowHost;
45 class FocusManagerEventHandler;
46 class TooltipManagerAura;
47 class WindowReorderer;
49 class VIEWS_EXPORT DesktopNativeWidgetAura
50 : public internal::NativeWidgetPrivate,
51 public aura::WindowDelegate,
52 public aura::client::ActivationDelegate,
53 public aura::client::ActivationChangeObserver,
54 public aura::client::FocusChangeObserver,
55 public views::internal::InputMethodDelegate,
56 public aura::client::DragDropDelegate,
57 public aura::RootWindowObserver {
59 explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate);
60 virtual ~DesktopNativeWidgetAura();
62 // Maps from window to DesktopNativeWidgetAura.
63 static DesktopNativeWidgetAura* ForWindow(aura::Window* window);
65 // Called by our DesktopRootWindowHost after it has deleted native resources;
66 // this is the signal that we should start our shutdown.
67 virtual void OnHostClosed();
69 // Called from ~DesktopRootWindowHost. This takes the RootWindow as by the
70 // time we get here |root_window_| is NULL.
71 virtual void OnDesktopRootWindowHostDestroyed(aura::RootWindow* root);
73 corewm::InputMethodEventFilter* input_method_event_filter() {
74 return input_method_event_filter_.get();
76 corewm::CompoundEventFilter* root_window_event_filter() {
77 return root_window_event_filter_;
80 // Overridden from NativeWidget:
81 virtual ui::EventHandler* GetEventHandler() OVERRIDE;
83 // Ensures that the correct window is activated/deactivated based on whether
84 // we are being activated/deactivated.
85 void HandleActivationChanged(bool active);
88 // Overridden from internal::NativeWidgetPrivate:
89 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
90 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
91 virtual bool ShouldUseNativeFrame() const OVERRIDE;
92 virtual void FrameTypeChanged() OVERRIDE;
93 virtual Widget* GetWidget() OVERRIDE;
94 virtual const Widget* GetWidget() const OVERRIDE;
95 virtual gfx::NativeView GetNativeView() const OVERRIDE;
96 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
97 virtual Widget* GetTopLevelWidget() OVERRIDE;
98 virtual const ui::Compositor* GetCompositor() const OVERRIDE;
99 virtual ui::Compositor* GetCompositor() OVERRIDE;
100 virtual ui::Layer* GetLayer() OVERRIDE;
101 virtual void ReorderNativeViews() OVERRIDE;
102 virtual void ViewRemoved(View* view) OVERRIDE;
103 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
104 virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
105 virtual TooltipManager* GetTooltipManager() const OVERRIDE;
106 virtual void SetCapture() OVERRIDE;
107 virtual void ReleaseCapture() OVERRIDE;
108 virtual bool HasCapture() const OVERRIDE;
109 virtual InputMethod* CreateInputMethod() OVERRIDE;
110 virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE;
111 virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
112 virtual void GetWindowPlacement(
114 ui::WindowShowState* maximized) const OVERRIDE;
115 virtual void SetWindowTitle(const string16& title) OVERRIDE;
116 virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
117 const gfx::ImageSkia& app_icon) OVERRIDE;
118 virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
119 virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
120 virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
121 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
122 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
123 virtual void SetSize(const gfx::Size& size) OVERRIDE;
124 virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
125 virtual void StackAtTop() OVERRIDE;
126 virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
127 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
128 virtual void Close() OVERRIDE;
129 virtual void CloseNow() OVERRIDE;
130 virtual void Show() OVERRIDE;
131 virtual void Hide() OVERRIDE;
132 virtual void ShowMaximizedWithBounds(
133 const gfx::Rect& restored_bounds) OVERRIDE;
134 virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE;
135 virtual bool IsVisible() const OVERRIDE;
136 virtual void Activate() OVERRIDE;
137 virtual void Deactivate() OVERRIDE;
138 virtual bool IsActive() const OVERRIDE;
139 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
140 virtual bool IsAlwaysOnTop() const OVERRIDE;
141 virtual void Maximize() OVERRIDE;
142 virtual void Minimize() OVERRIDE;
143 virtual bool IsMaximized() const OVERRIDE;
144 virtual bool IsMinimized() const OVERRIDE;
145 virtual void Restore() OVERRIDE;
146 virtual void SetFullscreen(bool fullscreen) OVERRIDE;
147 virtual bool IsFullscreen() const OVERRIDE;
148 virtual void SetOpacity(unsigned char opacity) OVERRIDE;
149 virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
150 virtual void FlashFrame(bool flash_frame) OVERRIDE;
151 virtual void RunShellDrag(View* view,
152 const ui::OSExchangeData& data,
153 const gfx::Point& location,
155 ui::DragDropTypes::DragEventSource source) OVERRIDE;
156 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
157 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
158 virtual bool IsMouseEventsEnabled() const OVERRIDE;
159 virtual void ClearNativeFocus() OVERRIDE;
160 virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
161 virtual Widget::MoveLoopResult RunMoveLoop(
162 const gfx::Vector2d& drag_offset,
163 Widget::MoveLoopSource source,
164 Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
165 virtual void EndMoveLoop() OVERRIDE;
166 virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
167 virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
168 virtual void OnRootViewLayout() const OVERRIDE;
170 // Overridden from aura::WindowDelegate:
171 virtual gfx::Size GetMinimumSize() const OVERRIDE;
172 virtual gfx::Size GetMaximumSize() const OVERRIDE;
173 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
174 const gfx::Rect& new_bounds) OVERRIDE {}
175 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
176 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
177 virtual bool ShouldDescendIntoChildForEventHandling(
179 const gfx::Point& location) OVERRIDE;
180 virtual bool CanFocus() OVERRIDE;
181 virtual void OnCaptureLost() OVERRIDE;
182 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
183 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
184 virtual void OnWindowDestroying() OVERRIDE;
185 virtual void OnWindowDestroyed() OVERRIDE;
186 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
187 virtual bool HasHitTestMask() const OVERRIDE;
188 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
189 virtual void DidRecreateLayer(ui::Layer* old_layer,
190 ui::Layer* new_layer) OVERRIDE;
192 // Overridden from ui::EventHandler:
193 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
194 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
195 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
196 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
197 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
199 // Overridden from aura::client::ActivationDelegate:
200 virtual bool ShouldActivate() const OVERRIDE;
202 // Overridden from aura::client::ActivationChangeObserver:
203 virtual void OnWindowActivated(aura::Window* gained_active,
204 aura::Window* lost_active) OVERRIDE;
206 // Overridden from aura::client::FocusChangeObserver:
207 virtual void OnWindowFocused(aura::Window* gained_focus,
208 aura::Window* lost_focus) OVERRIDE;
210 // Overridden from views::internal::InputMethodDelegate:
211 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
213 // Overridden from aura::client::DragDropDelegate:
214 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
215 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
216 virtual void OnDragExited() OVERRIDE;
217 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
219 // Overridden from aura::RootWindowObserver:
220 virtual void OnRootWindowHostCloseRequested(
221 const aura::RootWindow* root) OVERRIDE;
222 virtual void OnRootWindowHostResized(const aura::RootWindow* root) OVERRIDE;
223 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
224 const gfx::Point& new_origin) OVERRIDE;
227 friend class FocusManagerEventHandler;
229 // Installs the input method filter.
230 void InstallInputMethodEventFilter();
232 // To save a clear on platforms where the window is never transparent, the
233 // window is only set as transparent when the glass frame is in use.
234 void UpdateWindowTransparency();
236 // See class documentation for Widget in widget.h for a note about ownership.
237 Widget::InitParams::Ownership ownership_;
239 scoped_ptr<DesktopCaptureClient> capture_client_;
241 // The NativeWidget owns the RootWindow. Required because the RootWindow owns
242 // its RootWindowHost, so DesktopRootWindowHost can't own it.
243 scoped_ptr<aura::RootWindow> root_window_;
245 // The following factory is used for calls to close the NativeWidgetAura
247 base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_;
249 // Can we be made active?
252 // Ownership passed to RootWindow on Init.
253 DesktopRootWindowHost* desktop_root_window_host_;
255 // Child of the root, contains |content_window_|.
256 aura::Window* content_window_container_;
258 // Child of |content_window_container_|. This is the return value from
260 // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
261 aura::Window* content_window_;
263 internal::NativeWidgetDelegate* native_widget_delegate_;
265 scoped_ptr<aura::client::FocusClient> focus_client_;
266 scoped_ptr<DesktopDispatcherClient> dispatcher_client_;
267 scoped_ptr<views::corewm::CursorManager> cursor_client_;
268 scoped_ptr<aura::client::ScreenPositionClient> position_client_;
269 scoped_ptr<aura::client::DragDropClient> drag_drop_client_;
270 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
271 scoped_ptr<FocusManagerEventHandler> focus_manager_event_handler_;
273 // Toplevel event filter which dispatches to other event filters.
274 corewm::CompoundEventFilter* root_window_event_filter_;
276 scoped_ptr<corewm::InputMethodEventFilter> input_method_event_filter_;
278 scoped_ptr<DropHelper> drop_helper_;
279 int last_drop_operation_;
281 scoped_ptr<corewm::TooltipController> tooltip_controller_;
282 scoped_ptr<TooltipManagerAura> tooltip_manager_;
284 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
286 scoped_ptr<views::corewm::WindowModalityController>
287 window_modality_controller_;
289 // See comments in OnLostActive().
290 bool restore_focus_on_activate_;
292 gfx::NativeCursor cursor_;
294 scoped_ptr<corewm::ShadowController> shadow_controller_;
296 // Reorders child windows of |window_| associated with a view based on the
297 // order of the associated views in the widget's view hierarchy.
298 scoped_ptr<WindowReorderer> window_reorderer_;
300 // See class documentation for Widget in widget.h for a note about type.
301 Widget::InitParams::Type widget_type_;
303 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura);
308 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_