Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_native_widget_aura.h
blobcb01adfd6b4108d490b766a70f0efbdcb4865f1c
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/widget/native_widget_private.h"
14 #include "ui/wm/core/compound_event_filter.h"
15 #include "ui/wm/public/activation_change_observer.h"
16 #include "ui/wm/public/activation_delegate.h"
17 #include "ui/wm/public/drag_drop_delegate.h"
19 namespace aura {
20 class WindowEventDispatcher;
21 class WindowTreeHost;
22 namespace client {
23 class DragDropClient;
24 class FocusClient;
25 class ScreenPositionClient;
26 class WindowTreeClient;
30 namespace wm {
31 class CompoundEventFilter;
32 class CursorManager;
33 class FocusController;
34 class ShadowController;
35 class VisibilityController;
36 class WindowModalityController;
39 namespace views {
40 namespace corewm {
41 class TooltipController;
43 class DesktopCaptureClient;
44 class DesktopDispatcherClient;
45 class DesktopEventClient;
46 class DesktopNativeCursorManager;
47 class DesktopWindowTreeHost;
48 class DropHelper;
49 class FocusManagerEventHandler;
50 class TooltipManagerAura;
51 class WindowReorderer;
53 class VIEWS_EXPORT DesktopNativeWidgetAura
54 : public internal::NativeWidgetPrivate,
55 public aura::WindowDelegate,
56 public aura::client::ActivationDelegate,
57 public aura::client::ActivationChangeObserver,
58 public aura::client::FocusChangeObserver,
59 public aura::client::DragDropDelegate,
60 public aura::WindowTreeHostObserver {
61 public:
62 explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate);
63 ~DesktopNativeWidgetAura() override;
65 // Maps from window to DesktopNativeWidgetAura. |window| must be a root
66 // window.
67 static DesktopNativeWidgetAura* ForWindow(aura::Window* window);
69 // Called by our DesktopWindowTreeHost after it has deleted native resources;
70 // this is the signal that we should start our shutdown.
71 virtual void OnHostClosed();
73 // TODO(beng): remove this method and replace with an implementation of
74 // WindowDestroying() that takes the window being destroyed.
75 // Called from ~DesktopWindowTreeHost. This takes the WindowEventDispatcher
76 // as by the time we get here |dispatcher_| is NULL.
77 virtual void OnDesktopWindowTreeHostDestroyed(aura::WindowTreeHost* host);
79 wm::CompoundEventFilter* root_window_event_filter() {
80 return root_window_event_filter_.get();
82 aura::WindowTreeHost* host() {
83 return host_.get();
86 // Ensures that the correct window is activated/deactivated based on whether
87 // we are being activated/deactivated.
88 void HandleActivationChanged(bool active);
90 protected:
91 // Overridden from internal::NativeWidgetPrivate:
92 void InitNativeWidget(const Widget::InitParams& params) override;
93 NonClientFrameView* CreateNonClientFrameView() override;
94 bool ShouldUseNativeFrame() const override;
95 bool ShouldWindowContentsBeTransparent() const override;
96 void FrameTypeChanged() override;
97 Widget* GetWidget() override;
98 const Widget* GetWidget() const override;
99 gfx::NativeView GetNativeView() const override;
100 gfx::NativeWindow GetNativeWindow() const override;
101 Widget* GetTopLevelWidget() override;
102 const ui::Compositor* GetCompositor() const override;
103 const ui::Layer* GetLayer() const override;
104 void ReorderNativeViews() override;
105 void ViewRemoved(View* view) override;
106 void SetNativeWindowProperty(const char* name, void* value) override;
107 void* GetNativeWindowProperty(const char* name) const override;
108 TooltipManager* GetTooltipManager() const override;
109 void SetCapture() override;
110 void ReleaseCapture() override;
111 bool HasCapture() const override;
112 ui::InputMethod* GetInputMethod() override;
113 void CenterWindow(const gfx::Size& size) override;
114 void GetWindowPlacement(gfx::Rect* bounds,
115 ui::WindowShowState* maximized) const override;
116 bool SetWindowTitle(const base::string16& title) override;
117 void SetWindowIcons(const gfx::ImageSkia& window_icon,
118 const gfx::ImageSkia& app_icon) override;
119 void InitModalType(ui::ModalType modal_type) override;
120 gfx::Rect GetWindowBoundsInScreen() const override;
121 gfx::Rect GetClientAreaBoundsInScreen() const override;
122 gfx::Rect GetRestoredBounds() const override;
123 void SetBounds(const gfx::Rect& bounds) override;
124 void SetSize(const gfx::Size& size) override;
125 void StackAbove(gfx::NativeView native_view) override;
126 void StackAtTop() override;
127 void StackBelow(gfx::NativeView native_view) override;
128 void SetShape(SkRegion* shape) override;
129 void Close() override;
130 void CloseNow() override;
131 void Show() override;
132 void Hide() override;
133 void ShowMaximizedWithBounds(const gfx::Rect& restored_bounds) override;
134 void ShowWithWindowState(ui::WindowShowState state) override;
135 bool IsVisible() const override;
136 void Activate() override;
137 void Deactivate() override;
138 bool IsActive() const override;
139 void SetAlwaysOnTop(bool always_on_top) override;
140 bool IsAlwaysOnTop() const override;
141 void SetVisibleOnAllWorkspaces(bool always_visible) override;
142 void Maximize() override;
143 void Minimize() override;
144 bool IsMaximized() const override;
145 bool IsMinimized() const override;
146 void Restore() override;
147 void SetFullscreen(bool fullscreen) override;
148 bool IsFullscreen() const override;
149 void SetOpacity(unsigned char opacity) override;
150 void SetUseDragFrame(bool use_drag_frame) override;
151 void FlashFrame(bool flash_frame) override;
152 void RunShellDrag(View* view,
153 const ui::OSExchangeData& data,
154 const gfx::Point& location,
155 int operation,
156 ui::DragDropTypes::DragEventSource source) override;
157 void SchedulePaintInRect(const gfx::Rect& rect) override;
158 void SetCursor(gfx::NativeCursor cursor) override;
159 bool IsMouseEventsEnabled() const override;
160 void ClearNativeFocus() override;
161 gfx::Rect GetWorkAreaBoundsInScreen() const override;
162 Widget::MoveLoopResult RunMoveLoop(
163 const gfx::Vector2d& drag_offset,
164 Widget::MoveLoopSource source,
165 Widget::MoveLoopEscapeBehavior escape_behavior) override;
166 void EndMoveLoop() override;
167 void SetVisibilityChangedAnimationsEnabled(bool value) override;
168 void SetVisibilityAnimationDuration(const base::TimeDelta& duration) override;
169 void SetVisibilityAnimationTransition(
170 Widget::VisibilityTransition transition) override;
171 ui::NativeTheme* GetNativeTheme() const override;
172 void OnRootViewLayout() override;
173 bool IsTranslucentWindowOpacitySupported() const override;
174 void OnSizeConstraintsChanged() override;
175 void RepostNativeEvent(gfx::NativeEvent native_event) override;
177 // Overridden from aura::WindowDelegate:
178 gfx::Size GetMinimumSize() const override;
179 gfx::Size GetMaximumSize() const override;
180 void OnBoundsChanged(const gfx::Rect& old_bounds,
181 const gfx::Rect& new_bounds) override {}
182 gfx::NativeCursor GetCursor(const gfx::Point& point) override;
183 int GetNonClientComponent(const gfx::Point& point) const override;
184 bool ShouldDescendIntoChildForEventHandling(
185 aura::Window* child,
186 const gfx::Point& location) override;
187 bool CanFocus() override;
188 void OnCaptureLost() override;
189 void OnPaint(const ui::PaintContext& context) override;
190 void OnDeviceScaleFactorChanged(float device_scale_factor) override;
191 void OnWindowDestroying(aura::Window* window) override;
192 void OnWindowDestroyed(aura::Window* window) override;
193 void OnWindowTargetVisibilityChanged(bool visible) override;
194 bool HasHitTestMask() const override;
195 void GetHitTestMask(gfx::Path* mask) const override;
197 // Overridden from ui::EventHandler:
198 void OnKeyEvent(ui::KeyEvent* event) override;
199 void OnMouseEvent(ui::MouseEvent* event) override;
200 void OnScrollEvent(ui::ScrollEvent* event) override;
201 void OnGestureEvent(ui::GestureEvent* event) override;
203 // Overridden from aura::client::ActivationDelegate:
204 bool ShouldActivate() const override;
206 // Overridden from aura::client::ActivationChangeObserver:
207 void OnWindowActivated(
208 aura::client::ActivationChangeObserver::ActivationReason reason,
209 aura::Window* gained_active,
210 aura::Window* lost_active) override;
212 // Overridden from aura::client::FocusChangeObserver:
213 void OnWindowFocused(aura::Window* gained_focus,
214 aura::Window* lost_focus) override;
216 // Overridden from aura::client::DragDropDelegate:
217 void OnDragEntered(const ui::DropTargetEvent& event) override;
218 int OnDragUpdated(const ui::DropTargetEvent& event) override;
219 void OnDragExited() override;
220 int OnPerformDrop(const ui::DropTargetEvent& event) override;
222 // Overridden from aura::WindowTreeHostObserver:
223 void OnHostCloseRequested(const aura::WindowTreeHost* host) override;
224 void OnHostResized(const aura::WindowTreeHost* host) override;
225 void OnHostMoved(const aura::WindowTreeHost* host,
226 const gfx::Point& new_origin) override;
228 private:
229 friend class FocusManagerEventHandler;
230 friend class RootWindowDestructionObserver;
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 void RootWindowDestroyed();
238 scoped_ptr<aura::WindowTreeHost> host_;
239 DesktopWindowTreeHost* desktop_window_tree_host_;
241 // See class documentation for Widget in widget.h for a note about ownership.
242 Widget::InitParams::Ownership ownership_;
244 scoped_ptr<DesktopCaptureClient> capture_client_;
246 // Child of the root, contains |content_window_|.
247 aura::Window* content_window_container_;
249 // Child of |content_window_container_|. This is the return value from
250 // GetNativeView().
251 // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
252 aura::Window* content_window_;
254 internal::NativeWidgetDelegate* native_widget_delegate_;
256 scoped_ptr<wm::FocusController> focus_client_;
257 scoped_ptr<DesktopDispatcherClient> dispatcher_client_;
258 scoped_ptr<aura::client::ScreenPositionClient> position_client_;
259 scoped_ptr<aura::client::DragDropClient> drag_drop_client_;
260 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
261 scoped_ptr<DesktopEventClient> event_client_;
262 scoped_ptr<FocusManagerEventHandler> focus_manager_event_handler_;
264 // Toplevel event filter which dispatches to other event filters.
265 scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
267 scoped_ptr<DropHelper> drop_helper_;
268 int last_drop_operation_;
270 scoped_ptr<corewm::TooltipController> tooltip_controller_;
271 scoped_ptr<TooltipManagerAura> tooltip_manager_;
273 scoped_ptr<wm::VisibilityController> visibility_controller_;
275 scoped_ptr<wm::WindowModalityController>
276 window_modality_controller_;
278 bool restore_focus_on_activate_;
280 gfx::NativeCursor cursor_;
281 // We must manually reference count the number of users of |cursor_manager_|
282 // because the cursors created by |cursor_manager_| are shared among the
283 // DNWAs. We can't just stuff this in a LazyInstance because we need to
284 // destroy this as the last DNWA happens; we can't put it off until
285 // (potentially) after we tear down the X11 connection because that's a
286 // crash.
287 static int cursor_reference_count_;
288 static wm::CursorManager* cursor_manager_;
289 static views::DesktopNativeCursorManager* native_cursor_manager_;
291 scoped_ptr<wm::ShadowController> shadow_controller_;
293 // Reorders child windows of |window_| associated with a view based on the
294 // order of the associated views in the widget's view hierarchy.
295 scoped_ptr<WindowReorderer> window_reorderer_;
297 // See class documentation for Widget in widget.h for a note about type.
298 Widget::InitParams::Type widget_type_;
300 // The following factory is used for calls to close the NativeWidgetAura
301 // instance.
302 base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_;
304 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura);
307 } // namespace views
309 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_