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