Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / views / widget / 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_NATIVE_WIDGET_AURA_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_
7
8 #include "base/memory/scoped_vector.h"
9 #include "base/memory/weak_ptr.h"
10 #include "ui/aura/client/focus_change_observer.h"
11 #include "ui/aura/window_delegate.h"
12 #include "ui/base/cursor/cursor.h"
13 #include "ui/events/event_constants.h"
14 #include "ui/views/ime/input_method_delegate.h"
15 #include "ui/views/views_export.h"
16 #include "ui/views/widget/native_widget_private.h"
17 #include "ui/wm/public/activation_change_observer.h"
18 #include "ui/wm/public/activation_delegate.h"
19 #include "ui/wm/public/drag_drop_delegate.h"
20
21 namespace aura {
22 class Window;
23 }
24 namespace gfx {
25 class FontList;
26 }
27
28 namespace views {
29
30 class DropHelper;
31 class TooltipManagerAura;
32 class WindowReorderer;
33
34 class VIEWS_EXPORT NativeWidgetAura
35     : public internal::NativeWidgetPrivate,
36       public internal::InputMethodDelegate,
37       public aura::WindowDelegate,
38       public aura::client::ActivationDelegate,
39       public aura::client::ActivationChangeObserver,
40       public aura::client::FocusChangeObserver,
41       public aura::client::DragDropDelegate {
42  public:
43   explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate);
44
45   // Called internally by NativeWidgetAura and DesktopNativeWidgetAura to
46   // associate |native_widget| with |window|.
47   static void RegisterNativeWidgetForWindow(
48       internal::NativeWidgetPrivate* native_widget,
49       aura::Window* window);
50
51   // Overridden from internal::NativeWidgetPrivate:
52   virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
53   virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
54   virtual bool ShouldUseNativeFrame() const OVERRIDE;
55   virtual bool ShouldWindowContentsBeTransparent() const OVERRIDE;
56   virtual void FrameTypeChanged() OVERRIDE;
57   virtual Widget* GetWidget() OVERRIDE;
58   virtual const Widget* GetWidget() const OVERRIDE;
59   virtual gfx::NativeView GetNativeView() const OVERRIDE;
60   virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
61   virtual Widget* GetTopLevelWidget() OVERRIDE;
62   virtual const ui::Compositor* GetCompositor() const OVERRIDE;
63   virtual ui::Compositor* GetCompositor() OVERRIDE;
64   virtual ui::Layer* GetLayer() OVERRIDE;
65   virtual void ReorderNativeViews() OVERRIDE;
66   virtual void ViewRemoved(View* view) OVERRIDE;
67   virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
68   virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
69   virtual TooltipManager* GetTooltipManager() const OVERRIDE;
70   virtual void SetCapture() OVERRIDE;
71   virtual void ReleaseCapture() OVERRIDE;
72   virtual bool HasCapture() const OVERRIDE;
73   virtual InputMethod* CreateInputMethod() OVERRIDE;
74   virtual internal::InputMethodDelegate* GetInputMethodDelegate() OVERRIDE;
75   virtual ui::InputMethod* GetHostInputMethod() OVERRIDE;
76   virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
77   virtual void GetWindowPlacement(
78       gfx::Rect* bounds,
79       ui::WindowShowState* maximized) const OVERRIDE;
80   virtual bool SetWindowTitle(const base::string16& title) OVERRIDE;
81   virtual void SetWindowIcons(const gfx::ImageSkia& window_icon,
82                               const gfx::ImageSkia& app_icon) OVERRIDE;
83   virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
84   virtual gfx::Rect GetWindowBoundsInScreen() const OVERRIDE;
85   virtual gfx::Rect GetClientAreaBoundsInScreen() const OVERRIDE;
86   virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
87   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
88   virtual void SetSize(const gfx::Size& size) OVERRIDE;
89   virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
90   virtual void StackAtTop() OVERRIDE;
91   virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
92   virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
93   virtual void Close() OVERRIDE;
94   virtual void CloseNow() OVERRIDE;
95   virtual void Show() OVERRIDE;
96   virtual void Hide() OVERRIDE;
97   virtual void ShowMaximizedWithBounds(
98       const gfx::Rect& restored_bounds) OVERRIDE;
99   virtual void ShowWithWindowState(ui::WindowShowState state) OVERRIDE;
100   virtual bool IsVisible() const OVERRIDE;
101   virtual void Activate() OVERRIDE;
102   virtual void Deactivate() OVERRIDE;
103   virtual bool IsActive() const OVERRIDE;
104   virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
105   virtual bool IsAlwaysOnTop() const OVERRIDE;
106   virtual void SetVisibleOnAllWorkspaces(bool always_visible) OVERRIDE;
107   virtual void Maximize() OVERRIDE;
108   virtual void Minimize() OVERRIDE;
109   virtual bool IsMaximized() const OVERRIDE;
110   virtual bool IsMinimized() const OVERRIDE;
111   virtual void Restore() OVERRIDE;
112   virtual void SetFullscreen(bool fullscreen) OVERRIDE;
113   virtual bool IsFullscreen() const OVERRIDE;
114   virtual void SetOpacity(unsigned char opacity) OVERRIDE;
115   virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
116   virtual void FlashFrame(bool flash_frame) OVERRIDE;
117   virtual void RunShellDrag(View* view,
118                             const ui::OSExchangeData& data,
119                             const gfx::Point& location,
120                             int operation,
121                             ui::DragDropTypes::DragEventSource source) OVERRIDE;
122   virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
123   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
124   virtual bool IsMouseEventsEnabled() const OVERRIDE;
125   virtual void ClearNativeFocus() OVERRIDE;
126   virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
127   virtual Widget::MoveLoopResult RunMoveLoop(
128       const gfx::Vector2d& drag_offset,
129       Widget::MoveLoopSource source,
130       Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE;
131   virtual void EndMoveLoop() OVERRIDE;
132   virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
133   virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
134   virtual void OnRootViewLayout() const OVERRIDE;
135
136   // Overridden from views::InputMethodDelegate:
137   virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
138
139   // Overridden from aura::WindowDelegate:
140   virtual gfx::Size GetMinimumSize() const OVERRIDE;
141   virtual gfx::Size GetMaximumSize() const OVERRIDE;
142   virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
143                                const gfx::Rect& new_bounds) OVERRIDE;
144   virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
145   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
146   virtual bool ShouldDescendIntoChildForEventHandling(
147       aura::Window* child,
148       const gfx::Point& location) OVERRIDE;
149   virtual bool CanFocus() OVERRIDE;
150   virtual void OnCaptureLost() OVERRIDE;
151   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
152   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
153   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
154   virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
155   virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
156   virtual bool HasHitTestMask() const OVERRIDE;
157   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
158
159   // Overridden from ui::EventHandler:
160   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
161   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
162   virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
163   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
164
165   // Overridden from aura::client::ActivationDelegate:
166   virtual bool ShouldActivate() const OVERRIDE;
167
168   // Overridden from aura::client::ActivationChangeObserver:
169   virtual void OnWindowActivated(aura::Window* gained_active,
170                                  aura::Window* lost_active) OVERRIDE;
171
172   // Overridden from aura::client::FocusChangeObserver:
173   virtual void OnWindowFocused(aura::Window* gained_focus,
174                                aura::Window* lost_focus) OVERRIDE;
175
176   // Overridden from aura::client::DragDropDelegate:
177   virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
178   virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
179   virtual void OnDragExited() OVERRIDE;
180   virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
181
182   // Overridden from NativeWidget:
183   virtual ui::EventHandler* GetEventHandler() OVERRIDE;
184
185  protected:
186   virtual ~NativeWidgetAura();
187
188   internal::NativeWidgetDelegate* delegate() { return delegate_; }
189
190  private:
191   class ActiveWindowObserver;
192
193   void SetInitialFocus(ui::WindowShowState show_state);
194
195   internal::NativeWidgetDelegate* delegate_;
196
197   // WARNING: set to NULL when destroyed. As the Widget is not necessarily
198   // destroyed along with |window_| all usage of |window_| should first verify
199   // non-NULL.
200   aura::Window* window_;
201
202   // See class documentation for Widget in widget.h for a note about ownership.
203   Widget::InitParams::Ownership ownership_;
204
205   // The following factory is used for calls to close the NativeWidgetAura
206   // instance.
207   base::WeakPtrFactory<NativeWidgetAura> close_widget_factory_;
208
209   // Can we be made active?
210   bool can_activate_;
211
212   // Are we in the destructor?
213   bool destroying_;
214
215   gfx::NativeCursor cursor_;
216
217   // The saved window state for exiting full screen state.
218   ui::WindowShowState saved_window_state_;
219
220   scoped_ptr<TooltipManagerAura> tooltip_manager_;
221
222   // Reorders child windows of |window_| associated with a view based on the
223   // order of the associated views in the widget's view hierarchy.
224   scoped_ptr<WindowReorderer> window_reorderer_;
225
226   scoped_ptr<DropHelper> drop_helper_;
227   int last_drop_operation_;
228
229   DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura);
230 };
231
232 }  // namespace views
233
234 #endif  // UI_VIEWS_WIDGET_NATIVE_WIDGET_AURA_H_