diff options
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/views/message_popup_collection.cc | 46 | ||||
-rw-r--r-- | ui/message_center/views/message_popup_collection.h | 5 |
2 files changed, 28 insertions, 23 deletions
diff --git a/ui/message_center/views/message_popup_collection.cc b/ui/message_center/views/message_popup_collection.cc index bc2da0c..2039d49 100644 --- a/ui/message_center/views/message_popup_collection.cc +++ b/ui/message_center/views/message_popup_collection.cc @@ -65,6 +65,8 @@ MessagePopupCollection::MessagePopupCollection(gfx::NativeView parent, : parent_(parent), message_center_(message_center), tray_(tray), + display_id_(gfx::Display::kInvalidDisplayID), + screen_(NULL), defer_counter_(0), latest_toast_entered_(NULL), user_is_closing_toasts_by_clicking_(false), @@ -74,34 +76,13 @@ MessagePopupCollection::MessagePopupCollection(gfx::NativeView parent, DCHECK(message_center_); defer_timer_.reset(new base::OneShotTimer<MessagePopupCollection>); message_center_->AddObserver(this); - gfx::Screen* screen = NULL; - gfx::Display display; - if (!parent_) { - // On Win+Aura, we don't have a parent since the popups currently show up - // on the Windows desktop, not in the Aura/Ash desktop. This code will - // display the popups on the primary display. - screen = gfx::Screen::GetNativeScreen(); - display = screen->GetPrimaryDisplay(); - } else { - screen = gfx::Screen::GetScreenFor(parent_); - display = screen->GetDisplayNearestWindow(parent_); - } - screen->AddObserver(this); - - display_id_ = display.id(); - work_area_ = display.work_area(); - ComputePopupAlignment(work_area_, display.bounds()); - - // We should not update before work area and popup alignment are computed. - DoUpdateIfPossible(); } MessagePopupCollection::~MessagePopupCollection() { weak_factory_.InvalidateWeakPtrs(); - gfx::Screen* screen = parent_ ? - gfx::Screen::GetScreenFor(parent_) : gfx::Screen::GetNativeScreen(); - screen->RemoveObserver(this); + if (screen_) + screen_->RemoveObserver(this); message_center_->RemoveObserver(this); CloseAllWidgets(); @@ -525,6 +506,25 @@ void MessagePopupCollection::DecrementDeferCounter() { // deferred tasks are even able to run) // Then, see if there is vacant space for new toasts. void MessagePopupCollection::DoUpdateIfPossible() { + if (!screen_) { + gfx::Display display; + if (!parent_) { + // On Win+Aura, we don't have a parent since the popups currently show up + // on the Windows desktop, not in the Aura/Ash desktop. This code will + // display the popups on the primary display. + screen_ = gfx::Screen::GetNativeScreen(); + display = screen_->GetPrimaryDisplay(); + } else { + screen_ = gfx::Screen::GetScreenFor(parent_); + display = screen_->GetDisplayNearestWindow(parent_); + } + screen_->AddObserver(this); + + display_id_ = display.id(); + work_area_ = display.work_area(); + ComputePopupAlignment(work_area_, display.bounds()); + } + if (defer_counter_ > 0) return; diff --git a/ui/message_center/views/message_popup_collection.h b/ui/message_center/views/message_popup_collection.h index 6586b41..907274e 100644 --- a/ui/message_center/views/message_popup_collection.h +++ b/ui/message_center/views/message_popup_collection.h @@ -35,6 +35,10 @@ class WebNotificationTrayTest; FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications); } +namespace gfx { +class Screen; +} + namespace message_center { namespace test { class MessagePopupCollectionTest; @@ -184,6 +188,7 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection Toasts toasts_; gfx::Rect work_area_; int64 display_id_; + gfx::Screen* screen_; // Specifies which corner of the screen popups should show up. This should // ideally be the same corner the notification area (systray) is at. |