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