OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/status_area_widget.h" | 5 #include "ash/system/status_area_widget.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_delegate.h" |
8 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/bluetooth/bluetooth_observer.h" |
| 11 #include "ash/system/network/network_observer.h" |
9 #include "ash/system/status_area_widget_delegate.h" | 12 #include "ash/system/status_area_widget_delegate.h" |
| 13 #include "ash/system/tray/system_tray.h" |
| 14 #include "ash/system/tray/system_tray_delegate.h" |
| 15 #include "ash/system/web_notification/web_notification_tray.h" |
| 16 #include "base/i18n/time_formatting.h" |
| 17 #include "base/utf_string_conversions.h" |
10 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
11 | 19 |
12 namespace ash { | 20 namespace ash { |
| 21 |
| 22 namespace { |
| 23 |
| 24 class DummySystemTrayDelegate : public SystemTrayDelegate { |
| 25 public: |
| 26 DummySystemTrayDelegate() |
| 27 : muted_(false), |
| 28 wifi_enabled_(true), |
| 29 cellular_enabled_(true), |
| 30 bluetooth_enabled_(true), |
| 31 volume_(0.5), |
| 32 caps_lock_enabled_(false) { |
| 33 } |
| 34 |
| 35 virtual ~DummySystemTrayDelegate() {} |
| 36 |
| 37 private: |
| 38 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { return true; } |
| 39 |
| 40 // Overridden from SystemTrayDelegate: |
| 41 virtual const string16 GetUserDisplayName() const OVERRIDE { |
| 42 return UTF8ToUTF16("Über tray Über tray Über tray Über tray"); |
| 43 } |
| 44 |
| 45 virtual const std::string GetUserEmail() const OVERRIDE { |
| 46 return "über@tray"; |
| 47 } |
| 48 |
| 49 virtual const gfx::ImageSkia& GetUserImage() const OVERRIDE { |
| 50 return null_image_; |
| 51 } |
| 52 |
| 53 virtual user::LoginStatus GetUserLoginStatus() const OVERRIDE { |
| 54 return user::LOGGED_IN_USER; |
| 55 } |
| 56 |
| 57 virtual bool SystemShouldUpgrade() const OVERRIDE { |
| 58 return true; |
| 59 } |
| 60 |
| 61 virtual base::HourClockType GetHourClockType() const OVERRIDE { |
| 62 return base::k24HourClock; |
| 63 } |
| 64 |
| 65 virtual PowerSupplyStatus GetPowerSupplyStatus() const OVERRIDE { |
| 66 return PowerSupplyStatus(); |
| 67 } |
| 68 |
| 69 virtual void RequestStatusUpdate() const OVERRIDE { |
| 70 } |
| 71 |
| 72 virtual void ShowSettings() OVERRIDE { |
| 73 } |
| 74 |
| 75 virtual void ShowDateSettings() OVERRIDE { |
| 76 } |
| 77 |
| 78 virtual void ShowNetworkSettings() OVERRIDE { |
| 79 } |
| 80 |
| 81 virtual void ShowBluetoothSettings() OVERRIDE { |
| 82 } |
| 83 |
| 84 virtual void ShowDriveSettings() OVERRIDE { |
| 85 } |
| 86 |
| 87 virtual void ShowIMESettings() OVERRIDE { |
| 88 } |
| 89 |
| 90 virtual void ShowHelp() OVERRIDE { |
| 91 } |
| 92 |
| 93 virtual bool IsAudioMuted() const OVERRIDE { |
| 94 return muted_; |
| 95 } |
| 96 |
| 97 virtual void SetAudioMuted(bool muted) OVERRIDE { |
| 98 muted_ = muted; |
| 99 } |
| 100 |
| 101 virtual float GetVolumeLevel() const OVERRIDE { |
| 102 return volume_; |
| 103 } |
| 104 |
| 105 virtual void SetVolumeLevel(float volume) OVERRIDE { |
| 106 volume_ = volume; |
| 107 } |
| 108 |
| 109 virtual bool IsCapsLockOn() const OVERRIDE { |
| 110 return caps_lock_enabled_; |
| 111 } |
| 112 |
| 113 virtual void SetCapsLockEnabled(bool enabled) OVERRIDE { |
| 114 caps_lock_enabled_ = enabled; |
| 115 } |
| 116 |
| 117 virtual bool IsInAccessibilityMode() const OVERRIDE { |
| 118 return false; |
| 119 } |
| 120 |
| 121 virtual void SetEnableSpokenFeedback(bool enable) OVERRIDE {} |
| 122 |
| 123 virtual void ShutDown() OVERRIDE {} |
| 124 |
| 125 virtual void SignOut() OVERRIDE { |
| 126 MessageLoop::current()->Quit(); |
| 127 } |
| 128 |
| 129 virtual void RequestLockScreen() OVERRIDE {} |
| 130 |
| 131 virtual void RequestRestart() OVERRIDE {} |
| 132 |
| 133 virtual void GetAvailableBluetoothDevices( |
| 134 BluetoothDeviceList* list) OVERRIDE { |
| 135 } |
| 136 |
| 137 virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE { |
| 138 } |
| 139 |
| 140 virtual void GetCurrentIME(IMEInfo* info) OVERRIDE { |
| 141 } |
| 142 |
| 143 virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE { |
| 144 } |
| 145 |
| 146 virtual void GetCurrentIMEProperties(IMEPropertyInfoList* list) OVERRIDE { |
| 147 } |
| 148 |
| 149 virtual void SwitchIME(const std::string& ime_id) OVERRIDE { |
| 150 } |
| 151 |
| 152 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { |
| 153 } |
| 154 |
| 155 virtual void CancelDriveOperation(const FilePath&) OVERRIDE { |
| 156 } |
| 157 |
| 158 virtual void GetDriveOperationStatusList( |
| 159 ash::DriveOperationStatusList*) OVERRIDE { |
| 160 } |
| 161 |
| 162 virtual void GetMostRelevantNetworkIcon(NetworkIconInfo* info, |
| 163 bool large) OVERRIDE { |
| 164 } |
| 165 |
| 166 virtual void GetAvailableNetworks( |
| 167 std::vector<NetworkIconInfo>* list) OVERRIDE { |
| 168 } |
| 169 |
| 170 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { |
| 171 } |
| 172 |
| 173 virtual void GetNetworkAddresses(std::string* ip_address, |
| 174 std::string* ethernet_mac_address, |
| 175 std::string* wifi_mac_address) OVERRIDE { |
| 176 *ip_address = "127.0.0.1"; |
| 177 *ethernet_mac_address = "00:11:22:33:44:55"; |
| 178 *wifi_mac_address = "66:77:88:99:00:11"; |
| 179 } |
| 180 |
| 181 virtual void RequestNetworkScan() OVERRIDE { |
| 182 } |
| 183 |
| 184 virtual void AddBluetoothDevice() OVERRIDE { |
| 185 } |
| 186 |
| 187 virtual void ToggleAirplaneMode() OVERRIDE { |
| 188 } |
| 189 |
| 190 virtual void ToggleWifi() OVERRIDE { |
| 191 wifi_enabled_ = !wifi_enabled_; |
| 192 ash::NetworkObserver* observer = |
| 193 ash::Shell::GetInstance()->system_tray()->network_observer(); |
| 194 if (observer) { |
| 195 ash::NetworkIconInfo info; |
| 196 observer->OnNetworkRefresh(info); |
| 197 } |
| 198 } |
| 199 |
| 200 virtual void ToggleMobile() OVERRIDE { |
| 201 cellular_enabled_ = !cellular_enabled_; |
| 202 ash::NetworkObserver* observer = |
| 203 ash::Shell::GetInstance()->system_tray()->network_observer(); |
| 204 if (observer) { |
| 205 ash::NetworkIconInfo info; |
| 206 observer->OnNetworkRefresh(info); |
| 207 } |
| 208 } |
| 209 |
| 210 virtual void ToggleBluetooth() OVERRIDE { |
| 211 bluetooth_enabled_ = !bluetooth_enabled_; |
| 212 ash::BluetoothObserver* observer = |
| 213 ash::Shell::GetInstance()->system_tray()->bluetooth_observer(); |
| 214 if (observer) |
| 215 observer->OnBluetoothRefresh(); |
| 216 } |
| 217 |
| 218 virtual void ShowOtherWifi() OVERRIDE { |
| 219 } |
| 220 |
| 221 virtual void ShowOtherCellular() OVERRIDE { |
| 222 } |
| 223 |
| 224 virtual bool IsNetworkConnected() OVERRIDE { |
| 225 return true; |
| 226 } |
| 227 |
| 228 virtual bool GetWifiAvailable() OVERRIDE { |
| 229 return true; |
| 230 } |
| 231 |
| 232 virtual bool GetMobileAvailable() OVERRIDE { |
| 233 return true; |
| 234 } |
| 235 |
| 236 virtual bool GetBluetoothAvailable() OVERRIDE { |
| 237 return true; |
| 238 } |
| 239 |
| 240 virtual bool GetWifiEnabled() OVERRIDE { |
| 241 return wifi_enabled_; |
| 242 } |
| 243 |
| 244 virtual bool GetMobileEnabled() OVERRIDE { |
| 245 return cellular_enabled_; |
| 246 } |
| 247 |
| 248 virtual bool GetBluetoothEnabled() OVERRIDE { |
| 249 return bluetooth_enabled_; |
| 250 } |
| 251 |
| 252 virtual bool GetMobileScanSupported() OVERRIDE { |
| 253 return true; |
| 254 } |
| 255 |
| 256 virtual bool GetCellularCarrierInfo(std::string* carrier_id, |
| 257 std::string* topup_url, |
| 258 std::string* setup_url) OVERRIDE { |
| 259 return false; |
| 260 } |
| 261 |
| 262 virtual void ShowCellularURL(const std::string& url) OVERRIDE { |
| 263 } |
| 264 |
| 265 virtual void ChangeProxySettings() OVERRIDE { |
| 266 } |
| 267 |
| 268 bool muted_; |
| 269 bool wifi_enabled_; |
| 270 bool cellular_enabled_; |
| 271 bool bluetooth_enabled_; |
| 272 float volume_; |
| 273 bool caps_lock_enabled_; |
| 274 gfx::ImageSkia null_image_; |
| 275 |
| 276 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); |
| 277 }; |
| 278 |
| 279 } // namespace |
| 280 |
13 namespace internal { | 281 namespace internal { |
14 | 282 |
15 StatusAreaWidget::StatusAreaWidget() { | 283 StatusAreaWidget::StatusAreaWidget() |
16 widget_delegate_ = new internal::StatusAreaWidgetDelegate; | 284 : widget_delegate_(new internal::StatusAreaWidgetDelegate), |
17 | 285 system_tray_(NULL), |
| 286 web_notification_tray_(NULL) { |
18 views::Widget::InitParams params( | 287 views::Widget::InitParams params( |
19 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 288 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
20 params.delegate = widget_delegate_; | 289 params.delegate = widget_delegate_; |
21 params.parent = Shell::GetInstance()->GetContainer( | 290 params.parent = Shell::GetInstance()->GetContainer( |
22 ash::internal::kShellWindowId_StatusContainer); | 291 ash::internal::kShellWindowId_StatusContainer); |
23 params.transparent = true; | 292 params.transparent = true; |
24 Init(params); | 293 Init(params); |
25 set_focus_on_creation(false); | 294 set_focus_on_creation(false); |
26 SetContentsView(widget_delegate_); | 295 SetContentsView(widget_delegate_); |
27 GetNativeView()->SetName("StatusAreaWidget"); | 296 GetNativeView()->SetName("StatusAreaWidget"); |
28 } | 297 } |
29 | 298 |
30 StatusAreaWidget::~StatusAreaWidget() { | 299 StatusAreaWidget::~StatusAreaWidget() { |
31 } | 300 } |
32 | 301 |
33 void StatusAreaWidget::AddTray(views::View* tray) { | 302 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) { |
34 widget_delegate_->AddChildView(tray); | 303 AddWebNotificationTray(new WebNotificationTray(this)); |
35 widget_delegate_->Layout(); | 304 AddSystemTray(new SystemTray(), shell_delegate); |
| 305 } |
| 306 |
| 307 void StatusAreaWidget::Shutdown() { |
| 308 // Destroy the trays early. Do not used scoped pointers since we don't |
| 309 // want to destroy them in the destructor (e.g. in tests). |
| 310 delete system_tray_; |
| 311 delete web_notification_tray_; |
| 312 } |
| 313 |
| 314 void StatusAreaWidget::AddSystemTray(SystemTray* system_tray, |
| 315 ShellDelegate* shell_delegate) { |
| 316 system_tray_ = system_tray; |
| 317 widget_delegate_->AddTray(system_tray); |
| 318 system_tray_->Initialize(); // Called after added to widget. |
| 319 |
| 320 if (shell_delegate) { |
| 321 system_tray_delegate_.reset( |
| 322 shell_delegate->CreateSystemTrayDelegate(system_tray)); |
| 323 } |
| 324 if (!system_tray_delegate_.get()) |
| 325 system_tray_delegate_.reset(new DummySystemTrayDelegate()); |
| 326 |
| 327 system_tray->CreateItems(); // Called after delegate is created. |
| 328 } |
| 329 |
| 330 void StatusAreaWidget::AddWebNotificationTray( |
| 331 WebNotificationTray* web_notification_tray) { |
| 332 web_notification_tray_ = web_notification_tray; |
| 333 widget_delegate_->AddTray(web_notification_tray); |
36 } | 334 } |
37 | 335 |
38 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 336 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
39 if (alignment == SHELF_ALIGNMENT_BOTTOM) | 337 widget_delegate_->set_alignment(alignment); |
40 widget_delegate_->SetLayout(views::BoxLayout::kHorizontal); | 338 widget_delegate_->UpdateLayout(); |
41 else | 339 } |
42 widget_delegate_->SetLayout(views::BoxLayout::kVertical); | 340 |
| 341 void StatusAreaWidget::ShowWebNotificationBubble(UserAction user_action) { |
| 342 // Only show the web notification bubble if the system tray is not shown, |
| 343 // unless triggered by a user action. |
| 344 if (user_action == USER_ACTION && |
| 345 system_tray_ && system_tray_->IsBubbleVisible()) { |
| 346 LOG(ERROR) << "System tray bubble visible"; |
| 347 return; |
| 348 } |
| 349 DCHECK(web_notification_tray_); |
| 350 web_notification_tray_->ShowBubble(); |
| 351 // Disable showing system notifications while viewing web notifications. |
| 352 if (system_tray_) |
| 353 system_tray_->SetHideNotifications(true); |
| 354 } |
| 355 |
| 356 void StatusAreaWidget::HideWebNotificationBubble() { |
| 357 DCHECK(web_notification_tray_); |
| 358 web_notification_tray_->HideBubble(); |
| 359 // Show any hidden or suppressed system notifications. |
| 360 if (system_tray_) |
| 361 system_tray_->SetHideNotifications(false); |
43 } | 362 } |
44 | 363 |
45 } // namespace internal | 364 } // namespace internal |
46 } // namespace ash | 365 } // namespace ash |
OLD | NEW |