| 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/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 gfx::ImageSkia null_image_; | 269 gfx::ImageSkia null_image_; |
| 270 | 270 |
| 271 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); | 271 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 } // namespace | 274 } // namespace |
| 275 | 275 |
| 276 namespace internal { | 276 namespace internal { |
| 277 | 277 |
| 278 StatusAreaWidget::StatusAreaWidget() | 278 StatusAreaWidget::StatusAreaWidget() |
| 279 : widget_delegate_(new internal::StatusAreaWidgetDelegate), | 279 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), |
| 280 system_tray_(NULL), | 280 system_tray_(NULL), |
| 281 web_notification_tray_(NULL), | 281 web_notification_tray_(NULL), |
| 282 login_status_(user::LOGGED_IN_NONE) { | 282 login_status_(user::LOGGED_IN_NONE) { |
| 283 views::Widget::InitParams params( | 283 views::Widget::InitParams params( |
| 284 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 284 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 285 params.delegate = widget_delegate_; | 285 params.delegate = status_area_widget_delegate_; |
| 286 params.parent = | 286 params.parent = |
| 287 Shell::GetPrimaryRootWindowController()->GetContainer( | 287 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 288 ash::internal::kShellWindowId_StatusContainer); | 288 ash::internal::kShellWindowId_StatusContainer); |
| 289 params.transparent = true; | 289 params.transparent = true; |
| 290 Init(params); | 290 Init(params); |
| 291 set_focus_on_creation(false); | 291 set_focus_on_creation(false); |
| 292 SetContentsView(widget_delegate_); | 292 SetContentsView(status_area_widget_delegate_); |
| 293 GetNativeView()->SetName("StatusAreaWidget"); | 293 GetNativeView()->SetName("StatusAreaWidget"); |
| 294 } | 294 } |
| 295 | 295 |
| 296 StatusAreaWidget::~StatusAreaWidget() { | 296 StatusAreaWidget::~StatusAreaWidget() { |
| 297 } | 297 } |
| 298 | 298 |
| 299 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) { | 299 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) { |
| 300 AddWebNotificationTray(new WebNotificationTray(this)); | 300 AddWebNotificationTray(); |
| 301 AddSystemTray(new SystemTray(this), shell_delegate); | 301 AddSystemTray(shell_delegate); |
| 302 // SetBorder() must be called after all trays have been created. |
| 303 web_notification_tray_->SetBorder(); |
| 304 system_tray_->SetBorder(); |
| 302 } | 305 } |
| 303 | 306 |
| 304 void StatusAreaWidget::Shutdown() { | 307 void StatusAreaWidget::Shutdown() { |
| 305 // Destroy the trays early, causing them to be removed from the view | 308 // Destroy the trays early, causing them to be removed from the view |
| 306 // hierarchy. Do not used scoped pointers since we don't want to destroy them | 309 // hierarchy. Do not used scoped pointers since we don't want to destroy them |
| 307 // in the destructor if Shutdown() is not called (e.g. in tests). | 310 // in the destructor if Shutdown() is not called (e.g. in tests). |
| 308 system_tray_delegate_.reset(); | 311 system_tray_delegate_.reset(); |
| 309 delete system_tray_; | 312 delete system_tray_; |
| 310 system_tray_ = NULL; | 313 system_tray_ = NULL; |
| 311 delete web_notification_tray_; | 314 delete web_notification_tray_; |
| 312 web_notification_tray_ = NULL; | 315 web_notification_tray_ = NULL; |
| 313 } | 316 } |
| 314 | 317 |
| 315 void StatusAreaWidget::AddSystemTray(SystemTray* system_tray, | 318 void StatusAreaWidget::AddSystemTray(ShellDelegate* shell_delegate) { |
| 316 ShellDelegate* shell_delegate) { | 319 system_tray_ = new SystemTray(this); |
| 317 system_tray_ = system_tray; | 320 status_area_widget_delegate_->AddTray(system_tray_); |
| 318 widget_delegate_->AddTray(system_tray); | |
| 319 system_tray_->Initialize(); // Called after added to widget. | 321 system_tray_->Initialize(); // Called after added to widget. |
| 320 | 322 |
| 321 if (shell_delegate) { | 323 if (shell_delegate) { |
| 322 system_tray_delegate_.reset( | 324 system_tray_delegate_.reset( |
| 323 shell_delegate->CreateSystemTrayDelegate(system_tray)); | 325 shell_delegate->CreateSystemTrayDelegate(system_tray_)); |
| 324 } | 326 } |
| 325 if (!system_tray_delegate_.get()) | 327 if (!system_tray_delegate_.get()) |
| 326 system_tray_delegate_.reset(new DummySystemTrayDelegate()); | 328 system_tray_delegate_.reset(new DummySystemTrayDelegate()); |
| 327 | 329 |
| 328 system_tray->CreateItems(); // Called after delegate is created. | 330 system_tray_->CreateItems(); // Called after delegate is created. |
| 329 UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus()); | 331 UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus()); |
| 330 } | 332 } |
| 331 | 333 |
| 332 void StatusAreaWidget::AddWebNotificationTray( | 334 void StatusAreaWidget::AddWebNotificationTray() { |
| 333 WebNotificationTray* web_notification_tray) { | 335 web_notification_tray_ = new WebNotificationTray(this); |
| 334 web_notification_tray_ = web_notification_tray; | 336 status_area_widget_delegate_->AddTray(web_notification_tray_); |
| 335 widget_delegate_->AddTray(web_notification_tray); | |
| 336 } | 337 } |
| 337 | 338 |
| 338 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 339 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 339 widget_delegate_->set_alignment(alignment); | 340 status_area_widget_delegate_->set_alignment(alignment); |
| 340 if (system_tray_) | 341 if (system_tray_) |
| 341 system_tray_->SetShelfAlignment(alignment); | 342 system_tray_->SetShelfAlignment(alignment); |
| 342 if (web_notification_tray_) | 343 if (web_notification_tray_) |
| 343 web_notification_tray_->SetShelfAlignment(alignment); | 344 web_notification_tray_->SetShelfAlignment(alignment); |
| 344 widget_delegate_->UpdateLayout(); | 345 status_area_widget_delegate_->UpdateLayout(); |
| 345 } | 346 } |
| 346 | 347 |
| 347 void StatusAreaWidget::SetPaintsBackground( | 348 void StatusAreaWidget::SetPaintsBackground( |
| 348 bool value, | 349 bool value, |
| 349 internal::BackgroundAnimator::ChangeType change_type) { | 350 internal::BackgroundAnimator::ChangeType change_type) { |
| 350 if (system_tray_) | 351 if (system_tray_) |
| 351 system_tray_->SetPaintsBackground(value, change_type); | 352 system_tray_->SetPaintsBackground(value, change_type); |
| 352 if (web_notification_tray_) | 353 if (web_notification_tray_) |
| 353 web_notification_tray_->SetPaintsBackground(value, change_type); | 354 web_notification_tray_->SetPaintsBackground(value, change_type); |
| 354 } | 355 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 373 return; | 374 return; |
| 374 login_status_ = login_status; | 375 login_status_ = login_status; |
| 375 if (system_tray_) | 376 if (system_tray_) |
| 376 system_tray_->UpdateAfterLoginStatusChange(login_status); | 377 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 377 if (web_notification_tray_) | 378 if (web_notification_tray_) |
| 378 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 379 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 379 } | 380 } |
| 380 | 381 |
| 381 } // namespace internal | 382 } // namespace internal |
| 382 } // namespace ash | 383 } // namespace ash |
| OLD | NEW |