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
|
// Copyright (c) 2011 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.
#include "views/desktop/desktop_window_view.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/transform.h"
#include "views/desktop/desktop_background.h"
#include "views/desktop/desktop_window_root_view.h"
#include "views/layer_property_setter.h"
#include "views/widget/native_widget_view.h"
#include "views/widget/native_widget_views.h"
#include "views/widget/widget.h"
#include "views/window/native_frame_view.h"
#if defined(OS_WIN)
#include "views/widget/native_widget_win.h"
#elif defined(TOOLKIT_USES_GTK)
#include "views/widget/native_widget_gtk.h"
#endif
namespace views {
namespace desktop {
// The Widget that hosts the DesktopWindowView. Subclasses Widget to override
// CreateRootView() so that the DesktopWindowRootView can be supplied instead
// for custom event filtering.
class DesktopWindow : public Widget {
public:
explicit DesktopWindow(DesktopWindowView* desktop_window_view)
: desktop_window_view_(desktop_window_view) {}
virtual ~DesktopWindow() {}
private:
// Overridden from Widget:
virtual internal::RootView* CreateRootView() OVERRIDE {
return new DesktopWindowRootView(desktop_window_view_, this);
}
virtual bool OnKeyEvent(const KeyEvent& event) OVERRIDE {
NativeWidgetViews* native_widget =
desktop_window_view_->active_native_widget();
return native_widget ? native_widget->OnKeyEvent(event) : false;
}
DesktopWindowView* desktop_window_view_;
DISALLOW_COPY_AND_ASSIGN(DesktopWindow);
};
class TestWindowContentView : public WidgetDelegateView {
public:
TestWindowContentView(const std::wstring& title, SkColor color)
: title_(title),
color_(color) {
}
virtual ~TestWindowContentView() {}
private:
// Overridden from View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->FillRectInt(color_, 0, 0, width(), height());
}
// Overridden from WindowDelegate:
virtual std::wstring GetWindowTitle() const OVERRIDE {
return title_;
}
virtual View* GetContentsView() {
return this;
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE {
Widget* widget = View::GetWidget();
if (widget->IsMinimized())
widget->Restore();
else
widget->Minimize();
return true;
}
std::wstring title_;
SkColor color_;
DISALLOW_COPY_AND_ASSIGN(TestWindowContentView);
};
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowView, public:
// static
DesktopWindowView* DesktopWindowView::desktop_window_view = NULL;
DesktopWindowView::DesktopWindowView(DesktopType type)
: active_native_widget_(NULL),
type_(type) {
switch (type_) {
case DESKTOP_DEFAULT:
case DESKTOP_NETBOOK:
set_background(new DesktopBackground);
break;
case DESKTOP_OTHER:
set_background(Background::CreateStandardPanelBackground());
break;
}
}
DesktopWindowView::~DesktopWindowView() {
}
// static
void DesktopWindowView::CreateDesktopWindow(DesktopType type) {
DCHECK(!desktop_window_view);
desktop_window_view = new DesktopWindowView(type);
views::Widget* window = new DesktopWindow(desktop_window_view);
desktop_window_view->widget_ = window;
views::Widget::InitParams params;
params.delegate = desktop_window_view;
// In this environment, CreateChromeWindow will default to creating a views-
// window, so we need to construct a NativeWidgetWin by hand.
// TODO(beng): Replace this with NativeWindow::CreateNativeRootWindow().
#if defined(OS_WIN)
params.native_widget = new views::NativeWidgetWin(window);
params.bounds = gfx::Rect(20, 20, 1920, 1200);
#elif defined(TOOLKIT_USES_GTK)
params.native_widget = new views::NativeWidgetGtk(window);
#endif
window->Init(params);
window->Show();
window->Maximize();
}
void DesktopWindowView::ActivateWidget(Widget* widget) {
if (widget && widget->IsActive())
return;
if (widget) {
if (!widget->HasObserver(this))
widget->AddObserver(this);
widget->Activate();
}
}
void DesktopWindowView::CreateTestWindow(const std::wstring& title,
SkColor color,
gfx::Rect initial_bounds,
bool rotate) {
views::Widget* window = views::Widget::CreateWindowWithBounds(
new TestWindowContentView(title, color),
initial_bounds);
window->Show();
if (rotate) {
ui::Transform transform;
transform.SetRotate(90.0f);
transform.SetTranslateX(window->GetWindowScreenBounds().width());
static_cast<NativeWidgetViews*>(window->native_widget())->GetView()->
SetTransform(transform);
}
static_cast<NativeWidgetViews*>(window->native_widget())->GetView()->
SetLayerPropertySetter(LayerPropertySetter::CreateAnimatingSetter());
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowView, View overrides:
void DesktopWindowView::Layout() {
}
void DesktopWindowView::ViewHierarchyChanged(
bool is_add, View* parent, View* child) {
if (!is_add &&
active_native_widget_ &&
active_native_widget_->GetView() == child) {
active_native_widget_ = NULL;
} else if (child->GetClassName() ==
internal::NativeWidgetView::kViewClassName) {
internal::NativeWidgetView* native_widget_view =
static_cast<internal::NativeWidgetView*>(child);
native_widget_view->GetAssociatedWidget()->AddObserver(this);
}
}
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowView, WidgetDelegate implementation:
Widget* DesktopWindowView::GetWidget() {
return widget_;
}
const Widget* DesktopWindowView::GetWidget() const {
return widget_;
}
bool DesktopWindowView::CanResize() const {
return true;
}
bool DesktopWindowView::CanMaximize() const {
return CanResize();
}
std::wstring DesktopWindowView::GetWindowTitle() const {
return L"Aura Desktop";
}
SkBitmap DesktopWindowView::GetWindowAppIcon() {
return SkBitmap();
}
SkBitmap DesktopWindowView::GetWindowIcon() {
return SkBitmap();
}
bool DesktopWindowView::ShouldShowWindowIcon() const {
return false;
}
void DesktopWindowView::WindowClosing() {
MessageLoopForUI::current()->Quit();
}
View* DesktopWindowView::GetContentsView() {
return this;
}
NonClientFrameView* DesktopWindowView::CreateNonClientFrameView() {
switch (type_) {
case DESKTOP_DEFAULT:
case DESKTOP_NETBOOK:
return NULL;
case DESKTOP_OTHER:
return new NativeFrameView(widget_);
}
return NULL;
}
void DesktopWindowView::OnWidgetClosing(Widget* widget) {
if (active_native_widget_ && static_cast<internal::NativeWidgetPrivate*>
(active_native_widget_)->GetWidget() == widget)
active_native_widget_ = NULL;
}
void DesktopWindowView::OnWidgetVisibilityChanged(Widget* widget,
bool visible) {
}
void DesktopWindowView::OnWidgetActivationChanged(Widget* widget,
bool active) {
if (active) {
if (active_native_widget_)
active_native_widget_->GetWidget()->Deactivate();
active_native_widget_ =
static_cast<NativeWidgetViews*>(widget->native_widget());
} else if (widget == active_native_widget_->GetWidget()) {
active_native_widget_ = NULL;
}
}
} // namespace desktop
} // namespace views
|