desktop_native_widget_aura.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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.
4
5#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_
6#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_
7
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/views/ime/input_method_delegate.h"
16#include "ui/views/widget/native_widget_private.h"
17
18namespace aura {
19class RootWindow;
20namespace client {
21class StackingClient;
22}
23}
24
25namespace views {
26
27namespace corewm {
28class CompoundEventFilter;
29class InputMethodEventFilter;
30class ShadowController;
31class TooltipController;
32class VisibilityController;
33class WindowModalityController;
34}
35
36class DesktopRootWindowHost;
37class DropHelper;
38class NativeWidgetAuraWindowObserver;
39class TooltipManagerAura;
40
41class VIEWS_EXPORT DesktopNativeWidgetAura
42    : public internal::NativeWidgetPrivate,
43      public aura::WindowDelegate,
44      public aura::client::ActivationDelegate,
45      public aura::client::ActivationChangeObserver,
46      public aura::client::FocusChangeObserver,
47      public views::internal::InputMethodDelegate,
48      public aura::client::DragDropDelegate,
49      public aura::RootWindowObserver {
50 public:
51  explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate);
52  virtual ~DesktopNativeWidgetAura();
53
54  // Maps from window to DesktopNativeWidgetAura.
55  static DesktopNativeWidgetAura* ForWindow(aura::Window* window);
56
57  // Called by our DesktopRootWindowHost after it has deleted native resources;
58  // this is the signal that we should start our shutdown.
59  void OnHostClosed();
60
61  // Installs the input method filter on |root|. This is intended to be invoked
62  // by the DesktopRootWindowHost implementation during Init().
63  void InstallInputMethodEventFilter(aura::RootWindow* root);
64  corewm::InputMethodEventFilter* input_method_event_filter() {
65    return input_method_event_filter_.get();
66  }
67  corewm::CompoundEventFilter* root_window_event_filter() {
68    return root_window_event_filter_;
69  }
70
71 protected:
72  // Overridden from internal::NativeWidgetPrivate:
73  virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
74  virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
75  virtual bool ShouldUseNativeFrame() const OVERRIDE;
76  virtual void FrameTypeChanged() OVERRIDE;
77  virtual Widget* GetWidget() OVERRIDE;
78  virtual const Widget* GetWidget() const OVERRIDE;
79  virtual gfx::NativeView GetNativeView() const OVERRIDE;
80  virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
81  virtual Widget* GetTopLevelWidget() OVERRIDE;
82  virtual const ui::Compositor* GetCompositor() const OVERRIDE;
83  virtual ui::Compositor* GetCompositor() OVERRIDE;
84  virtual ui::Layer* GetLayer() OVERRIDE;
85  virtual void ViewRemoved(View* view) OVERRIDE;
86  virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
87  virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
88  virtual TooltipManager* GetTooltipManager() const OVERRIDE;
89  virtual void SetCapture() OVERRIDE;
90  virtual void ReleaseCapture() OVERRIDE;
91  virtual bool HasCapture() const OVERRIDE;
92  virtual InputMethod* CreateInputMethod() OVERRIDE;
93  virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE;
94  virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
95  virtual void GetWindowPlacement(
96      gfx::Rect* bounds,
97      ui::WindowShowState* maximized) const OVERRIDE;
98  virtual void SetWindowTitle(const string16& title) OVERRIDE;
99  virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
100                              const gfx::ImageSkia& app_icon) OVERRIDE;
101  virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
102  virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
103  virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
104  virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
105  virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
106  virtual void SetSize(const gfx::Size& size) OVERRIDE;
107  virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
108  virtual void StackAtTop() OVERRIDE;
109  virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
110  virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
111  virtual void Close() OVERRIDE;
112  virtual void CloseNow() OVERRIDE;
113  virtual void Show() OVERRIDE;
114  virtual void Hide() OVERRIDE;
115  virtual void ShowMaximizedWithBounds(
116      const gfx::Rect& restored_bounds) OVERRIDE;
117  virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE;
118  virtual bool IsVisible() const OVERRIDE;
119  virtual void Activate() OVERRIDE;
120  virtual void Deactivate() OVERRIDE;
121  virtual bool IsActive() const OVERRIDE;
122  virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
123  virtual void Maximize() OVERRIDE;
124  virtual void Minimize() OVERRIDE;
125  virtual bool IsMaximized() const OVERRIDE;
126  virtual bool IsMinimized() const OVERRIDE;
127  virtual void Restore() OVERRIDE;
128  virtual void SetFullscreen(bool fullscreen) OVERRIDE;
129  virtual bool IsFullscreen() const OVERRIDE;
130  virtual void SetOpacity(unsigned char opacity) OVERRIDE;
131  virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
132  virtual void FlashFrame(bool flash_frame) OVERRIDE;
133  virtual void RunShellDrag(View* view,
134                            const ui::OSExchangeData& data,
135                            const gfx::Point& location,
136                            int operation,
137                            ui::DragDropTypes::DragEventSource source) OVERRIDE;
138  virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
139  virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
140  virtual void ClearNativeFocus() OVERRIDE;
141  virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
142  virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
143  virtual Widget::MoveLoopResult RunMoveLoop(
144      const gfx::Vector2d& drag_offset,
145      Widget::MoveLoopSource source) OVERRIDE;
146  virtual void EndMoveLoop() OVERRIDE;
147  virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
148  virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
149
150  // Overridden from aura::WindowDelegate:
151  virtual gfx::Size GetMinimumSize() const OVERRIDE;
152  virtual gfx::Size GetMaximumSize() const OVERRIDE;
153  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
154                               const gfx::Rect& new_bounds) OVERRIDE;
155  virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
156  virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
157  virtual bool ShouldDescendIntoChildForEventHandling(
158      aura::Window* child,
159      const gfx::Point& location) OVERRIDE;
160  virtual bool CanFocus() OVERRIDE;
161  virtual void OnCaptureLost() OVERRIDE;
162  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
163  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
164  virtual void OnWindowDestroying() OVERRIDE;
165  virtual void OnWindowDestroyed() OVERRIDE;
166  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
167  virtual bool HasHitTestMask() const OVERRIDE;
168  virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
169  virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE;
170
171  // Overridden from ui::EventHandler:
172  virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
173  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
174  virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
175  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
176  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
177
178  // Overridden from aura::client::ActivationDelegate:
179  virtual bool ShouldActivate() const OVERRIDE;
180
181  // Overridden from aura::client::ActivationChangeObserver:
182  virtual void OnWindowActivated(aura::Window* gained_active,
183                                 aura::Window* lost_active) OVERRIDE;
184
185  // Overridden from aura::client::FocusChangeObserver:
186  virtual void OnWindowFocused(aura::Window* gained_focus,
187                               aura::Window* lost_focus) OVERRIDE;
188
189  // Overridden from views::internal::InputMethodDelegate:
190  virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
191
192  // Overridden from aura::client::DragDropDelegate:
193  virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
194  virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
195  virtual void OnDragExited() OVERRIDE;
196  virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
197
198  // Overridden from aura::RootWindowObserver:
199  virtual void OnRootWindowHostCloseRequested(
200      const aura::RootWindow* root) OVERRIDE;
201
202 private:
203  // See class documentation for Widget in widget.h for a note about ownership.
204  Widget::InitParams::Ownership ownership_;
205
206  // The NativeWidget owns the RootWindow. Required because the RootWindow owns
207  // its RootWindowHost, so DesktopRootWindowHost can't own it.
208  scoped_ptr<aura::RootWindow> root_window_;
209
210  // The following factory is used for calls to close the NativeWidgetAura
211  // instance.
212  base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_;
213
214  scoped_ptr<NativeWidgetAuraWindowObserver> active_window_observer_;
215
216  // Can we be made active?
217  bool can_activate_;
218
219  // Ownership passed to RootWindow on Init.
220  DesktopRootWindowHost* desktop_root_window_host_;
221  aura::Window* window_;
222  internal::NativeWidgetDelegate* native_widget_delegate_;
223
224  scoped_ptr<aura::client::StackingClient> stacking_client_;
225
226  // Toplevel event filter which dispatches to other event filters.
227  corewm::CompoundEventFilter* root_window_event_filter_;
228
229  scoped_ptr<corewm::InputMethodEventFilter> input_method_event_filter_;
230
231  scoped_ptr<DropHelper> drop_helper_;
232  int last_drop_operation_;
233
234  scoped_ptr<corewm::TooltipController> tooltip_controller_;
235  scoped_ptr<TooltipManagerAura> tooltip_manager_;
236
237  scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
238
239  scoped_ptr<views::corewm::WindowModalityController>
240      window_modality_controller_;
241
242  // See comments in OnLostActive().
243  bool restore_focus_on_activate_;
244
245  scoped_ptr<corewm::ShadowController> shadow_controller_;
246
247  DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura);
248};
249
250}  // namespace views
251
252#endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_
253