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