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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
// 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.
#include "ash/system/status_area_widget.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/network/network_observer.h"
#include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/web_notification/web_notification_tray.h"
#include "ash/volume_control_delegate.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/window_properties.h"
#include "base/i18n/time_formatting.h"
#include "base/utf_string_conversions.h"
#include "ui/aura/window.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace {
class DummyVolumeControlDelegate : public VolumeControlDelegate {
public:
DummyVolumeControlDelegate() {}
virtual ~DummyVolumeControlDelegate() {}
virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE {
return true;
}
virtual void SetVolumePercent(double percent) OVERRIDE {
}
virtual bool IsAudioMuted() const OVERRIDE {
return true;
}
virtual void SetAudioMuted(bool muted) OVERRIDE {
}
virtual float GetVolumeLevel() const OVERRIDE {
return 0.0;
}
virtual void SetVolumeLevel(float level) OVERRIDE {
}
private:
DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate);
};
class DummySystemTrayDelegate : public SystemTrayDelegate {
public:
DummySystemTrayDelegate()
: wifi_enabled_(true),
cellular_enabled_(true),
bluetooth_enabled_(true),
caps_lock_enabled_(false),
volume_control_delegate_(
ALLOW_THIS_IN_INITIALIZER_LIST(new DummyVolumeControlDelegate)) {
}
virtual ~DummySystemTrayDelegate() {}
private:
virtual bool GetTrayVisibilityOnStartup() OVERRIDE { return true; }
// Overridden from SystemTrayDelegate:
virtual const string16 GetUserDisplayName() const OVERRIDE {
return UTF8ToUTF16("Über tray Über tray Über tray Über tray");
}
virtual const std::string GetUserEmail() const OVERRIDE {
return "über@tray";
}
virtual const gfx::ImageSkia& GetUserImage() const OVERRIDE {
return null_image_;
}
virtual user::LoginStatus GetUserLoginStatus() const OVERRIDE {
return user::LOGGED_IN_USER;
}
virtual bool SystemShouldUpgrade() const OVERRIDE {
return true;
}
virtual base::HourClockType GetHourClockType() const OVERRIDE {
return base::k24HourClock;
}
virtual PowerSupplyStatus GetPowerSupplyStatus() const OVERRIDE {
return PowerSupplyStatus();
}
virtual void RequestStatusUpdate() const OVERRIDE {
}
virtual void ShowSettings() OVERRIDE {
}
virtual void ShowDateSettings() OVERRIDE {
}
virtual void ShowNetworkSettings() OVERRIDE {
}
virtual void ShowBluetoothSettings() OVERRIDE {
}
virtual void ShowDisplaySettings() OVERRIDE {
}
virtual void ShowDriveSettings() OVERRIDE {
}
virtual void ShowIMESettings() OVERRIDE {
}
virtual void ShowHelp() OVERRIDE {
}
virtual void ShutDown() OVERRIDE {
MessageLoop::current()->Quit();
}
virtual void SignOut() OVERRIDE {
MessageLoop::current()->Quit();
}
virtual void RequestLockScreen() OVERRIDE {}
virtual void RequestRestart() OVERRIDE {}
virtual void GetAvailableBluetoothDevices(
BluetoothDeviceList* list) OVERRIDE {
}
virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE {
}
virtual void GetCurrentIME(IMEInfo* info) OVERRIDE {
}
virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE {
}
virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list) OVERRIDE {
}
virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
}
virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
}
virtual void CancelDriveOperation(const FilePath&) OVERRIDE {
}
virtual void GetDriveOperationStatusList(
ash::DriveOperationStatusList*) OVERRIDE {
}
virtual void GetMostRelevantNetworkIcon(NetworkIconInfo* info,
bool large) OVERRIDE {
}
virtual void GetAvailableNetworks(
std::vector<NetworkIconInfo>* list) OVERRIDE {
}
virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE {
}
virtual void GetNetworkAddresses(std::string* ip_address,
std::string* ethernet_mac_address,
std::string* wifi_mac_address) OVERRIDE {
*ip_address = "127.0.0.1";
*ethernet_mac_address = "00:11:22:33:44:55";
*wifi_mac_address = "66:77:88:99:00:11";
}
virtual void RequestNetworkScan() OVERRIDE {
}
virtual void AddBluetoothDevice() OVERRIDE {
}
virtual void ToggleAirplaneMode() OVERRIDE {
}
virtual void ToggleWifi() OVERRIDE {
wifi_enabled_ = !wifi_enabled_;
ash::NetworkObserver* observer =
ash::Shell::GetInstance()->system_tray()->network_observer();
if (observer) {
ash::NetworkIconInfo info;
observer->OnNetworkRefresh(info);
}
}
virtual void ToggleMobile() OVERRIDE {
cellular_enabled_ = !cellular_enabled_;
ash::NetworkObserver* observer =
ash::Shell::GetInstance()->system_tray()->network_observer();
if (observer) {
ash::NetworkIconInfo info;
observer->OnNetworkRefresh(info);
}
}
virtual void ToggleBluetooth() OVERRIDE {
bluetooth_enabled_ = !bluetooth_enabled_;
ash::BluetoothObserver* observer =
ash::Shell::GetInstance()->system_tray()->bluetooth_observer();
if (observer)
observer->OnBluetoothRefresh();
}
virtual void ShowOtherWifi() OVERRIDE {
}
virtual void ShowOtherCellular() OVERRIDE {
}
virtual bool IsNetworkConnected() OVERRIDE {
return true;
}
virtual bool GetWifiAvailable() OVERRIDE {
return true;
}
virtual bool GetMobileAvailable() OVERRIDE {
return true;
}
virtual bool GetBluetoothAvailable() OVERRIDE {
return true;
}
virtual bool GetWifiEnabled() OVERRIDE {
return wifi_enabled_;
}
virtual bool GetMobileEnabled() OVERRIDE {
return cellular_enabled_;
}
virtual bool GetBluetoothEnabled() OVERRIDE {
return bluetooth_enabled_;
}
virtual bool GetMobileScanSupported() OVERRIDE {
return true;
}
virtual bool GetCellularCarrierInfo(std::string* carrier_id,
std::string* topup_url,
std::string* setup_url) OVERRIDE {
return false;
}
virtual void ShowCellularURL(const std::string& url) OVERRIDE {
}
virtual void ChangeProxySettings() OVERRIDE {
}
virtual VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE {
return volume_control_delegate_.get();
}
virtual void SetVolumeControlDelegate(
scoped_ptr<VolumeControlDelegate> delegate) OVERRIDE {
volume_control_delegate_.swap(delegate);
}
bool wifi_enabled_;
bool cellular_enabled_;
bool bluetooth_enabled_;
bool caps_lock_enabled_;
gfx::ImageSkia null_image_;
scoped_ptr<VolumeControlDelegate> volume_control_delegate_;
DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate);
};
} // namespace
namespace internal {
StatusAreaWidget::StatusAreaWidget()
: status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate),
system_tray_(NULL),
web_notification_tray_(NULL),
login_status_(user::LOGGED_IN_NONE) {
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.delegate = status_area_widget_delegate_;
params.parent =
Shell::GetPrimaryRootWindowController()->GetContainer(
ash::internal::kShellWindowId_StatusContainer);
params.transparent = true;
Init(params);
set_focus_on_creation(false);
SetContentsView(status_area_widget_delegate_);
GetNativeView()->SetName("StatusAreaWidget");
GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true);
}
StatusAreaWidget::~StatusAreaWidget() {
}
void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) {
AddSystemTray(shell_delegate);
AddWebNotificationTray();
// Initialize() must be called after all trays have been created.
if (system_tray_)
system_tray_->Initialize();
if (web_notification_tray_)
web_notification_tray_->Initialize();
UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus());
}
void StatusAreaWidget::Shutdown() {
// Destroy the trays early, causing them to be removed from the view
// hierarchy. Do not used scoped pointers since we don't want to destroy them
// in the destructor if Shutdown() is not called (e.g. in tests).
system_tray_delegate_.reset();
delete web_notification_tray_;
web_notification_tray_ = NULL;
delete system_tray_;
system_tray_ = NULL;
}
bool StatusAreaWidget::ShouldShowLauncher() const {
if ((system_tray_ && system_tray_->HasSystemBubble()) ||
(web_notification_tray_ &&
web_notification_tray_->IsMessageCenterBubbleVisible()))
return true;
if (!Shell::GetInstance()->shelf()->IsVisible())
return false;
// If the launcher is currently visible, don't hide the launcher if the mouse
// is in any of the notification bubbles.
return (system_tray_ && system_tray_->IsMouseInNotificationBubble()) ||
(web_notification_tray_ &&
web_notification_tray_->IsMouseInNotificationBubble());
}
void StatusAreaWidget::AddSystemTray(ShellDelegate* shell_delegate) {
system_tray_ = new SystemTray(this);
status_area_widget_delegate_->AddTray(system_tray_);
if (shell_delegate) {
system_tray_delegate_.reset(
shell_delegate->CreateSystemTrayDelegate(system_tray_));
}
if (!system_tray_delegate_.get())
system_tray_delegate_.reset(new DummySystemTrayDelegate());
}
void StatusAreaWidget::AddWebNotificationTray() {
web_notification_tray_ = new WebNotificationTray(this);
status_area_widget_delegate_->AddTray(web_notification_tray_);
}
void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
status_area_widget_delegate_->set_alignment(alignment);
if (system_tray_)
system_tray_->SetShelfAlignment(alignment);
if (web_notification_tray_)
web_notification_tray_->SetShelfAlignment(alignment);
status_area_widget_delegate_->UpdateLayout();
}
void StatusAreaWidget::SetPaintsBackground(
bool value,
internal::BackgroundAnimator::ChangeType change_type) {
if (system_tray_)
system_tray_->SetPaintsBackground(value, change_type);
if (web_notification_tray_)
web_notification_tray_->SetPaintsBackground(value, change_type);
}
void StatusAreaWidget::SetHideWebNotifications(bool hide) {
if (web_notification_tray_)
web_notification_tray_->SetHidePopupBubble(hide);
}
void StatusAreaWidget::SetHideSystemNotifications(bool hide) {
if (system_tray_)
system_tray_->SetHideNotifications(hide);
}
bool StatusAreaWidget::ShouldShowWebNotifications() {
return !(system_tray_ && system_tray_->IsAnyBubbleVisible());
}
void StatusAreaWidget::UpdateAfterLoginStatusChange(
user::LoginStatus login_status) {
if (login_status_ == login_status)
return;
login_status_ = login_status;
if (system_tray_)
system_tray_->UpdateAfterLoginStatusChange(login_status);
if (web_notification_tray_)
web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
}
} // namespace internal
} // namespace ash
|