MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_native_widget_aura.h
blob6b8d93d8bacad9b00269687544998105b3e60d5f
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"
20 namespace aura {
21 class WindowEventDispatcher;
22 class WindowTreeHost;
23 namespace client {
24 class DragDropClient;
25 class FocusClient;
26 class ScreenPositionClient;
27 class WindowTreeClient;
31 namespace wm {
32 class CompoundEventFilter;
33 class CursorManager;
34 class FocusController;
35 class InputMethodEventFilter;
36 class ShadowController;
37 class VisibilityController;
38 class WindowModalityController;
41 namespace views {
42 namespace corewm {
43 class TooltipController;
45 class DesktopCaptureClient;
46 class DesktopDispatcherClient;
47 class DesktopEventClient;
48 class DesktopNativeCursorManager;
49 class DesktopWindowTreeHost;
50 class DropHelper;
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 {
64 public:
65 explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate);
66 virtual ~DesktopNativeWidgetAura();
68 // Maps from window to DesktopNativeWidgetAura. |window| must be a root
69 // window.
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() {
89 return host_.get();
92 // Ensures that the correct window is activated/deactivated based on whether
93 // we are being activated/deactivated.
94 void HandleActivationChanged(bool active);
96 protected:
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(
124 gfx::Rect* bounds,
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,
166 int operation,
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 OnSizeConstraintsChanged() override;
183 virtual void RepostNativeEvent(gfx::NativeEvent native_event) override;
185 // Overridden from aura::WindowDelegate:
186 virtual gfx::Size GetMinimumSize() const override;
187 virtual gfx::Size GetMaximumSize() const override;
188 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
189 const gfx::Rect& new_bounds) override {}
190 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) override;
191 virtual int GetNonClientComponent(const gfx::Point& point) const override;
192 virtual bool ShouldDescendIntoChildForEventHandling(
193 aura::Window* child,
194 const gfx::Point& location) override;
195 virtual bool CanFocus() override;
196 virtual void OnCaptureLost() override;
197 virtual void OnPaint(gfx::Canvas* canvas) override;
198 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) override;
199 virtual void OnWindowDestroying(aura::Window* window) override;
200 virtual void OnWindowDestroyed(aura::Window* window) override;
201 virtual void OnWindowTargetVisibilityChanged(bool visible) override;
202 virtual bool HasHitTestMask() const override;
203 virtual void GetHitTestMask(gfx::Path* mask) const override;
205 // Overridden from ui::EventHandler:
206 virtual void OnKeyEvent(ui::KeyEvent* event) override;
207 virtual void OnMouseEvent(ui::MouseEvent* event) override;
208 virtual void OnScrollEvent(ui::ScrollEvent* event) override;
209 virtual void OnGestureEvent(ui::GestureEvent* event) override;
211 // Overridden from aura::client::ActivationDelegate:
212 virtual bool ShouldActivate() const override;
214 // Overridden from aura::client::ActivationChangeObserver:
215 virtual void OnWindowActivated(aura::Window* gained_active,
216 aura::Window* lost_active) override;
218 // Overridden from aura::client::FocusChangeObserver:
219 virtual void OnWindowFocused(aura::Window* gained_focus,
220 aura::Window* lost_focus) override;
222 // Overridden from views::internal::InputMethodDelegate:
223 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
225 // Overridden from aura::client::DragDropDelegate:
226 virtual void OnDragEntered(const ui::DropTargetEvent& event) override;
227 virtual int OnDragUpdated(const ui::DropTargetEvent& event) override;
228 virtual void OnDragExited() override;
229 virtual int OnPerformDrop(const ui::DropTargetEvent& event) override;
231 // Overridden from aura::WindowTreeHostObserver:
232 virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) override;
233 virtual void OnHostResized(const aura::WindowTreeHost* host) override;
234 virtual void OnHostMoved(const aura::WindowTreeHost* host,
235 const gfx::Point& new_origin) override;
237 private:
238 friend class FocusManagerEventHandler;
239 friend class RootWindowDestructionObserver;
241 // Installs the input method filter.
242 void InstallInputMethodEventFilter();
244 // To save a clear on platforms where the window is never transparent, the
245 // window is only set as transparent when the glass frame is in use.
246 void UpdateWindowTransparency();
248 void RootWindowDestroyed();
250 scoped_ptr<aura::WindowTreeHost> host_;
251 DesktopWindowTreeHost* desktop_window_tree_host_;
253 // See class documentation for Widget in widget.h for a note about ownership.
254 Widget::InitParams::Ownership ownership_;
256 scoped_ptr<DesktopCaptureClient> capture_client_;
258 // Child of the root, contains |content_window_|.
259 aura::Window* content_window_container_;
261 // Child of |content_window_container_|. This is the return value from
262 // GetNativeView().
263 // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
264 aura::Window* content_window_;
266 internal::NativeWidgetDelegate* native_widget_delegate_;
268 scoped_ptr<wm::FocusController> focus_client_;
269 scoped_ptr<DesktopDispatcherClient> dispatcher_client_;
270 scoped_ptr<aura::client::ScreenPositionClient> position_client_;
271 scoped_ptr<aura::client::DragDropClient> drag_drop_client_;
272 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
273 scoped_ptr<DesktopEventClient> event_client_;
274 scoped_ptr<FocusManagerEventHandler> focus_manager_event_handler_;
276 // Toplevel event filter which dispatches to other event filters.
277 scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
279 scoped_ptr<wm::InputMethodEventFilter> input_method_event_filter_;
281 scoped_ptr<DropHelper> drop_helper_;
282 int last_drop_operation_;
284 scoped_ptr<corewm::TooltipController> tooltip_controller_;
285 scoped_ptr<TooltipManagerAura> tooltip_manager_;
287 scoped_ptr<wm::VisibilityController> visibility_controller_;
289 scoped_ptr<wm::WindowModalityController>
290 window_modality_controller_;
292 bool restore_focus_on_activate_;
294 gfx::NativeCursor cursor_;
295 // We must manually reference count the number of users of |cursor_manager_|
296 // because the cursors created by |cursor_manager_| are shared among the
297 // DNWAs. We can't just stuff this in a LazyInstance because we need to
298 // destroy this as the last DNWA happens; we can't put it off until
299 // (potentially) after we tear down the X11 connection because that's a
300 // crash.
301 static int cursor_reference_count_;
302 static wm::CursorManager* cursor_manager_;
303 static views::DesktopNativeCursorManager* native_cursor_manager_;
305 scoped_ptr<wm::ShadowController> shadow_controller_;
307 // Reorders child windows of |window_| associated with a view based on the
308 // order of the associated views in the widget's view hierarchy.
309 scoped_ptr<WindowReorderer> window_reorderer_;
311 // See class documentation for Widget in widget.h for a note about type.
312 Widget::InitParams::Type widget_type_;
314 // The following factory is used for calls to close the NativeWidgetAura
315 // instance.
316 base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_;
318 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura);
321 } // namespace views
323 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_