Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / desktop_aura / desktop_native_widget_aura.h
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/base/cursor/cursor.h"
16 #include "ui/views/ime/input_method_delegate.h"
17 #include "ui/views/widget/native_widget_private.h"
18
19 namespace aura {
20 class RootWindow;
21 namespace client {
22 class DragDropClient;
23 class FocusClient;
24 class ScreenPositionClient;
25 class WindowTreeClient;
26 }
27 }
28
29 namespace views {
30
31 namespace corewm {
32 class CompoundEventFilter;
33 class CursorManager;
34 class FocusController;
35 class InputMethodEventFilter;
36 class ShadowController;
37 class TooltipController;
38 class VisibilityController;
39 class WindowModalityController;
40 }
41
42 class DesktopCaptureClient;
43 class DesktopDispatcherClient;
44 class DesktopEventClient;
45 class DesktopNativeCursorManager;
46 class DesktopWindowTreeHost;
47 class DropHelper;
48 class FocusManagerEventHandler;
49 class TooltipManagerAura;
50 class WindowReorderer;
51
52 class VIEWS_EXPORT DesktopNativeWidgetAura
53     : public internal::NativeWidgetPrivate,
54       public aura::WindowDelegate,
55       public aura::client::ActivationDelegate,
56       public aura::client::ActivationChangeObserver,
57       public aura::client::FocusChangeObserver,
58       public views::internal::InputMethodDelegate,
59       public aura::client::DragDropDelegate,
60       public aura::RootWindowObserver {
61  public:
62   explicit DesktopNativeWidgetAura(internal::NativeWidgetDelegate* delegate);
63   virtual ~DesktopNativeWidgetAura();
64
65   // Maps from window to DesktopNativeWidgetAura. |window| must be a root
66   // window.
67   static DesktopNativeWidgetAura* ForWindow(aura::Window* window);
68
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();
72
73   // Called from ~DesktopWindowTreeHost. This takes the RootWindow as by the
74   // time we get here |root_window_| is NULL.
75   virtual void OnDesktopWindowTreeHostDestroyed(aura::RootWindow* root);
76
77   corewm::InputMethodEventFilter* input_method_event_filter() {
78     return input_method_event_filter_.get();
79   }
80   corewm::CompoundEventFilter* root_window_event_filter() {
81     return root_window_event_filter_;
82   }
83   aura::RootWindow* root_window() {
84     return root_window_.get();
85   }
86
87   // Overridden from NativeWidget:
88   virtual ui::EventHandler* GetEventHandler() OVERRIDE;
89
90   // Ensures that the correct window is activated/deactivated based on whether
91   // we are being activated/deactivated.
92   void HandleActivationChanged(bool active);
93
94  protected:
95   // Overridden from internal::NativeWidgetPrivate:
96   virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
97   virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
98   virtual bool ShouldUseNativeFrame() const OVERRIDE;
99   virtual bool ShouldWindowContentsBeTransparent() const OVERRIDE;
100   virtual void FrameTypeChanged() OVERRIDE;
101   virtual Widget* GetWidget() OVERRIDE;
102   virtual const Widget* GetWidget() const OVERRIDE;
103   virtual gfx::NativeView GetNativeView() const OVERRIDE;
104   virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
105   virtual Widget* GetTopLevelWidget() OVERRIDE;
106   virtual const ui::Compositor* GetCompositor() const OVERRIDE;
107   virtual ui::Compositor* GetCompositor() OVERRIDE;
108   virtual ui::Layer* GetLayer() OVERRIDE;
109   virtual void ReorderNativeViews() OVERRIDE;
110   virtual void ViewRemoved(View* view) OVERRIDE;
111   virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
112   virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
113   virtual TooltipManager* GetTooltipManager() const OVERRIDE;
114   virtual void SetCapture() OVERRIDE;
115   virtual void ReleaseCapture() OVERRIDE;
116   virtual bool HasCapture() const OVERRIDE;
117   virtual InputMethod* CreateInputMethod() OVERRIDE;
118   virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE;
119   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
120   virtual void GetWindowPlacement(
121       gfx::Rect* bounds,
122       ui::WindowShowState* maximized) const OVERRIDE;
123   virtual bool SetWindowTitle(const base::string16& title) OVERRIDE;
124   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
125                               const gfx::ImageSkia& app_icon) OVERRIDE;
126   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
127   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
128   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
129   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
130   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
131   virtual void SetSize(const gfx::Size& size) OVERRIDE;
132   virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
133   virtual void StackAtTop() OVERRIDE;
134   virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
135   virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
136   virtual void Close() OVERRIDE;
137   virtual void CloseNow() OVERRIDE;
138   virtual void Show() OVERRIDE;
139   virtual void Hide() OVERRIDE;
140   virtual void ShowMaximizedWithBounds(
141       const gfx::Rect& restored_bounds) OVERRIDE;
142   virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE;
143   virtual bool IsVisible() const OVERRIDE;
144   virtual void Activate() OVERRIDE;
145   virtual void Deactivate() OVERRIDE;
146   virtual bool IsActive() const OVERRIDE;
147   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
148   virtual bool IsAlwaysOnTop() const OVERRIDE;
149   virtual void Maximize() OVERRIDE;
150   virtual void Minimize() OVERRIDE;
151   virtual bool IsMaximized() const OVERRIDE;
152   virtual bool IsMinimized() const OVERRIDE;
153   virtual void Restore() OVERRIDE;
154   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
155   virtual bool IsFullscreen() const OVERRIDE;
156   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
157   virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
158   virtual void FlashFrame(bool flash_frame) OVERRIDE;
159   virtual void RunShellDrag(View* view,
160                             const ui::OSExchangeData& data,
161                             const gfx::Point& location,
162                             int operation,
163                             ui::DragDropTypes::DragEventSource source) OVERRIDE;
164   virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
165   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
166   virtual bool IsMouseEventsEnabled() const OVERRIDE;
167   virtual void ClearNativeFocus() OVERRIDE;
168   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
169   virtual Widget::MoveLoopResult RunMoveLoop(
170       const gfx::Vector2d& drag_offset,
171       Widget::MoveLoopSource source,
172       Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
173   virtual void EndMoveLoop() OVERRIDE;
174   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
175   virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
176   virtual void OnRootViewLayout() const OVERRIDE;
177
178   // Overridden from aura::WindowDelegate:
179   virtual gfx::Size GetMinimumSize() const OVERRIDE;
180   virtual gfx::Size GetMaximumSize() const OVERRIDE;
181   virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
182                                const gfx::Rect& new_bounds) OVERRIDE {}
183   virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
184   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
185   virtual bool ShouldDescendIntoChildForEventHandling(
186       aura::Window* child,
187       const gfx::Point& location) OVERRIDE;
188   virtual bool CanFocus() OVERRIDE;
189   virtual void OnCaptureLost() OVERRIDE;
190   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
191   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
192   virtual void OnWindowDestroying() OVERRIDE;
193   virtual void OnWindowDestroyed() OVERRIDE;
194   virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
195   virtual bool HasHitTestMask() const OVERRIDE;
196   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
197   virtual void DidRecreateLayer(ui::Layer* old_layer,
198                                 ui::Layer* new_layer) OVERRIDE;
199
200   // Overridden from ui::EventHandler:
201   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
202   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
203   virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
204   virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
205   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
206
207   // Overridden from aura::client::ActivationDelegate:
208   virtual bool ShouldActivate() const OVERRIDE;
209
210   // Overridden from aura::client::ActivationChangeObserver:
211   virtual void OnWindowActivated(aura::Window* gained_active,
212                                  aura::Window* lost_active) OVERRIDE;
213
214   // Overridden from aura::client::FocusChangeObserver:
215   virtual void OnWindowFocused(aura::Window* gained_focus,
216                                aura::Window* lost_focus) OVERRIDE;
217
218   // Overridden from views::internal::InputMethodDelegate:
219   virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
220
221   // Overridden from aura::client::DragDropDelegate:
222   virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
223   virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
224   virtual void OnDragExited() OVERRIDE;
225   virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
226
227   // Overridden from aura::RootWindowObserver:
228   virtual void OnWindowTreeHostCloseRequested(
229       const aura::RootWindow* root) OVERRIDE;
230   virtual void OnWindowTreeHostResized(const aura::RootWindow* root) OVERRIDE;
231   virtual void OnWindowTreeHostMoved(const aura::RootWindow* root,
232                                      const gfx::Point& new_origin) OVERRIDE;
233
234  private:
235   friend class FocusManagerEventHandler;
236
237   // Installs the input method filter.
238   void InstallInputMethodEventFilter();
239
240   // To save a clear on platforms where the window is never transparent, the
241   // window is only set as transparent when the glass frame is in use.
242   void UpdateWindowTransparency();
243
244   // See class documentation for Widget in widget.h for a note about ownership.
245   Widget::InitParams::Ownership ownership_;
246
247   scoped_ptr<DesktopCaptureClient> capture_client_;
248
249   // The NativeWidget owns the RootWindow. Required because the RootWindow owns
250   // its WindowTreeHost, so DesktopWindowTreeHost can't own it.
251   scoped_ptr<aura::RootWindow> root_window_;
252
253   // The following factory is used for calls to close the NativeWidgetAura
254   // instance.
255   base::WeakPtrFactory<DesktopNativeWidgetAura> close_widget_factory_;
256
257   // Can we be made active?
258   bool can_activate_;
259
260   // Ownership passed to RootWindow on Init.
261   DesktopWindowTreeHost* desktop_window_tree_host_;
262
263   // Child of the root, contains |content_window_|.
264   aura::Window* content_window_container_;
265
266   // Child of |content_window_container_|. This is the return value from
267   // GetNativeView().
268   // WARNING: this may be NULL, in particular during shutdown it becomes NULL.
269   aura::Window* content_window_;
270
271   internal::NativeWidgetDelegate* native_widget_delegate_;
272
273   scoped_ptr<corewm::FocusController> focus_client_;
274   scoped_ptr<DesktopDispatcherClient> dispatcher_client_;
275   scoped_ptr<aura::client::ScreenPositionClient> position_client_;
276   scoped_ptr<aura::client::DragDropClient> drag_drop_client_;
277   scoped_ptr<aura::client::WindowTreeClient> window_tree_client_;
278   scoped_ptr<DesktopEventClient> event_client_;
279   scoped_ptr<FocusManagerEventHandler> focus_manager_event_handler_;
280
281   // Toplevel event filter which dispatches to other event filters.
282   corewm::CompoundEventFilter* root_window_event_filter_;
283
284   scoped_ptr<corewm::InputMethodEventFilter> input_method_event_filter_;
285
286   scoped_ptr<DropHelper> drop_helper_;
287   int last_drop_operation_;
288
289   scoped_ptr<corewm::TooltipController> tooltip_controller_;
290   scoped_ptr<TooltipManagerAura> tooltip_manager_;
291
292   scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
293
294   scoped_ptr<views::corewm::WindowModalityController>
295       window_modality_controller_;
296
297   // See comments in OnLostActive().
298   bool restore_focus_on_activate_;
299
300   gfx::NativeCursor cursor_;
301   // We must manually reference count the number of users of |cursor_manager_|
302   // because the cursors created by |cursor_manager_| are shared among the
303   // DNWAs. We can't just stuff this in a LazyInstance because we need to
304   // destroy this as the last DNWA happens; we can't put it off until
305   // (potentially) after we tear down the X11 connection because that's a
306   // crash.
307   static int cursor_reference_count_;
308   static views::corewm::CursorManager* cursor_manager_;
309   static views::DesktopNativeCursorManager* native_cursor_manager_;
310
311   scoped_ptr<corewm::ShadowController> shadow_controller_;
312
313   // Reorders child windows of |window_| associated with a view based on the
314   // order of the associated views in the widget's view hierarchy.
315   scoped_ptr<WindowReorderer> window_reorderer_;
316
317   // See class documentation for Widget in widget.h for a note about type.
318   Widget::InitParams::Type widget_type_;
319
320   DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAura);
321 };
322
323 }  // namespace views
324
325 #endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_NATIVE_WIDGET_AURA_H_