| 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/chromeos/tray_display.h" | 5 #include "ash/system/chromeos/tray_display.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/tray/actionable_view.h" | 10 #include "ash/system/tray/actionable_view.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 private: | 319 private: |
| 320 user::LoginStatus login_status_; | 320 user::LoginStatus login_status_; |
| 321 | 321 |
| 322 DISALLOW_COPY_AND_ASSIGN(DisplayNotificationView); | 322 DISALLOW_COPY_AND_ASSIGN(DisplayNotificationView); |
| 323 }; | 323 }; |
| 324 | 324 |
| 325 TrayDisplay::TrayDisplay(SystemTray* system_tray) | 325 TrayDisplay::TrayDisplay(SystemTray* system_tray) |
| 326 : SystemTrayItem(system_tray), | 326 : SystemTrayItem(system_tray), |
| 327 default_(NULL) { | 327 default_(NULL) { |
| 328 Shell::GetInstance()->display_controller()->AddObserver(this); | 328 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 329 UpdateDisplayInfo(NULL); |
| 329 } | 330 } |
| 330 | 331 |
| 331 TrayDisplay::~TrayDisplay() { | 332 TrayDisplay::~TrayDisplay() { |
| 332 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 333 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool TrayDisplay::GetDisplayMessageForNotification(base::string16* message) { | 336 void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { |
| 337 if (old_info) |
| 338 old_info->swap(display_info_); |
| 339 display_info_.clear(); |
| 340 |
| 336 DisplayManager* display_manager = GetDisplayManager(); | 341 DisplayManager* display_manager = GetDisplayManager(); |
| 337 DisplayInfoMap old_info; | |
| 338 old_info.swap(display_info_); | |
| 339 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 342 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 340 int64 id = display_manager->GetDisplayAt(i).id(); | 343 int64 id = display_manager->GetDisplayAt(i).id(); |
| 341 display_info_[id] = display_manager->GetDisplayInfo(id); | 344 display_info_[id] = display_manager->GetDisplayInfo(id); |
| 342 } | 345 } |
| 346 } |
| 343 | 347 |
| 348 bool TrayDisplay::GetDisplayMessageForNotification( |
| 349 base::string16* message, |
| 350 const TrayDisplay::DisplayInfoMap& old_info) { |
| 344 // Display is added or removed. Use the same message as the one in | 351 // Display is added or removed. Use the same message as the one in |
| 345 // the system tray. | 352 // the system tray. |
| 346 if (display_info_.size() != old_info.size()) { | 353 if (display_info_.size() != old_info.size()) { |
| 347 *message = GetTrayDisplayMessage(); | 354 *message = GetTrayDisplayMessage(); |
| 348 return true; | 355 return true; |
| 349 } | 356 } |
| 350 | 357 |
| 351 for (DisplayInfoMap::const_iterator iter = display_info_.begin(); | 358 for (DisplayInfoMap::const_iterator iter = display_info_.begin(); |
| 352 iter != display_info_.end(); ++iter) { | 359 iter != display_info_.end(); ++iter) { |
| 353 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); | 360 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 DCHECK(default_ == NULL); | 405 DCHECK(default_ == NULL); |
| 399 default_ = new DisplayView(status); | 406 default_ = new DisplayView(status); |
| 400 return default_; | 407 return default_; |
| 401 } | 408 } |
| 402 | 409 |
| 403 void TrayDisplay::DestroyDefaultView() { | 410 void TrayDisplay::DestroyDefaultView() { |
| 404 default_ = NULL; | 411 default_ = NULL; |
| 405 } | 412 } |
| 406 | 413 |
| 407 void TrayDisplay::OnDisplayConfigurationChanged() { | 414 void TrayDisplay::OnDisplayConfigurationChanged() { |
| 415 DisplayInfoMap old_info; |
| 416 UpdateDisplayInfo(&old_info); |
| 417 |
| 408 if (!Shell::GetInstance()->system_tray_delegate()-> | 418 if (!Shell::GetInstance()->system_tray_delegate()-> |
| 409 ShouldShowDisplayNotification()) { | 419 ShouldShowDisplayNotification()) { |
| 410 return; | 420 return; |
| 411 } | 421 } |
| 412 | 422 |
| 413 base::string16 message; | 423 base::string16 message; |
| 414 if (GetDisplayMessageForNotification(&message)) | 424 if (GetDisplayMessageForNotification(&message, old_info)) |
| 415 UpdateDisplayNotification(message); | 425 UpdateDisplayNotification(message); |
| 416 } | 426 } |
| 417 | 427 |
| 418 base::string16 TrayDisplay::GetDefaultViewMessage() { | 428 base::string16 TrayDisplay::GetDefaultViewMessage() { |
| 419 if (!default_ || !default_->visible()) | 429 if (!default_ || !default_->visible()) |
| 420 return base::string16(); | 430 return base::string16(); |
| 421 | 431 |
| 422 return static_cast<DisplayView*>(default_)->label()->text(); | 432 return static_cast<DisplayView*>(default_)->label()->text(); |
| 423 } | 433 } |
| 424 | 434 |
| 425 base::string16 TrayDisplay::GetNotificationMessage() { | 435 base::string16 TrayDisplay::GetNotificationMessage() { |
| 426 message_center::NotificationList::Notifications notifications = | 436 message_center::NotificationList::Notifications notifications = |
| 427 message_center::MessageCenter::Get()->GetNotifications(); | 437 message_center::MessageCenter::Get()->GetNotifications(); |
| 428 for (message_center::NotificationList::Notifications::const_iterator iter = | 438 for (message_center::NotificationList::Notifications::const_iterator iter = |
| 429 notifications.begin(); iter != notifications.end(); ++iter) { | 439 notifications.begin(); iter != notifications.end(); ++iter) { |
| 430 if ((*iter)->id() == kDisplayNotificationId) | 440 if ((*iter)->id() == kDisplayNotificationId) |
| 431 return (*iter)->title(); | 441 return (*iter)->title(); |
| 432 } | 442 } |
| 433 | 443 |
| 434 return base::string16(); | 444 return base::string16(); |
| 435 } | 445 } |
| 436 | 446 |
| 437 void TrayDisplay::CloseNotificationForTest() { | 447 void TrayDisplay::CloseNotificationForTest() { |
| 438 message_center::MessageCenter::Get()->RemoveNotification( | 448 message_center::MessageCenter::Get()->RemoveNotification( |
| 439 kDisplayNotificationId, false); | 449 kDisplayNotificationId, false); |
| 440 } | 450 } |
| 441 | 451 |
| 442 } // namespace internal | 452 } // namespace internal |
| 443 } // namespace ash | 453 } // namespace ash |
| OLD | NEW |