| 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/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/system/status_area_widget.h" | 9 #include "ash/system/status_area_widget.h" |
| 10 #include "ash/system/tray/tray_bubble_wrapper.h" | 10 #include "ash/system/tray/tray_bubble_wrapper.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | 76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 } // namespace internal | 79 } // namespace internal |
| 80 | 80 |
| 81 WebNotificationTray::WebNotificationTray( | 81 WebNotificationTray::WebNotificationTray( |
| 82 internal::StatusAreaWidget* status_area_widget) | 82 internal::StatusAreaWidget* status_area_widget) |
| 83 : internal::TrayBackgroundView(status_area_widget), | 83 : internal::TrayBackgroundView(status_area_widget), |
| 84 button_(NULL), | 84 button_(NULL), |
| 85 show_message_center_on_unlock_(false) { | 85 show_message_center_on_unlock_(false) { |
| 86 message_center_.reset(new message_center::MessageCenter(this)); | 86 message_center_ = message_center::MessageCenter::GetInstance(); |
| 87 message_center_->AddObserver(this); |
| 87 button_ = new views::ImageButton(this); | 88 button_ = new views::ImageButton(this); |
| 88 button_->set_triggerable_event_flags( | 89 button_->set_triggerable_event_flags( |
| 89 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
| 90 tray_container()->AddChildView(button_); | 91 tray_container()->AddChildView(button_); |
| 91 UpdateTray(); | 92 UpdateTray(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 WebNotificationTray::~WebNotificationTray() { | 95 WebNotificationTray::~WebNotificationTray() { |
| 95 // message_center_ has a weak pointer to this; destroy it early. | 96 // Ensure the message center doesn't notify a destroyed object. |
| 96 message_center_.reset(); | 97 message_center_->RemoveObserver(this); |
| 97 // Release any child views that might have back pointers before ~View(). | 98 // Release any child views that might have back pointers before ~View(). |
| 98 message_center_bubble_.reset(); | 99 message_center_bubble_.reset(); |
| 99 popup_bubble_.reset(); | 100 popup_bubble_.reset(); |
| 100 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 101 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
| 101 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); | 102 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); |
| 102 quiet_mode_bubble_.reset(); | 103 quiet_mode_bubble_.reset(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void WebNotificationTray::ShowMessageCenterBubble() { | 106 void WebNotificationTray::ShowMessageCenterBubble() { |
| 106 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 107 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 107 return; | 108 return; |
| 108 if (quiet_mode_bubble()) | 109 if (quiet_mode_bubble()) |
| 109 quiet_mode_bubble_.reset(); | 110 quiet_mode_bubble_.reset(); |
| 110 if (message_center_bubble()) { | 111 if (message_center_bubble()) { |
| 111 UpdateTray(); | 112 UpdateTray(); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 // Indicate that the message center is visible. Clears the unread count. | 115 // Indicate that the message center is visible. Clears the unread count. |
| 115 message_center_->SetMessageCenterVisible(true); | 116 message_center_->SetMessageCenterVisible(true); |
| 116 UpdateTray(); | 117 UpdateTray(); |
| 117 HidePopupBubble(); | 118 HidePopupBubble(); |
| 118 message_center::MessageCenterBubble* bubble = | 119 message_center::MessageCenterBubble* bubble = |
| 119 new message_center::MessageCenterBubble(message_center_.get()); | 120 new message_center::MessageCenterBubble(message_center_); |
| 120 message_center_bubble_.reset( | 121 message_center_bubble_.reset( |
| 121 new internal::WebNotificationBubbleWrapper(this, bubble)); | 122 new internal::WebNotificationBubbleWrapper(this, bubble)); |
| 122 | 123 |
| 123 status_area_widget()->SetHideSystemNotifications(true); | 124 status_area_widget()->SetHideSystemNotifications(true); |
| 124 GetShelfLayoutManager()->UpdateAutoHideState(); | 125 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void WebNotificationTray::HideMessageCenterBubble() { | 128 void WebNotificationTray::HideMessageCenterBubble() { |
| 128 if (!message_center_bubble()) | 129 if (!message_center_bubble()) |
| 129 return; | 130 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 149 return; | 150 return; |
| 150 if (!status_area_widget()->ShouldShowWebNotifications()) | 151 if (!status_area_widget()->ShouldShowWebNotifications()) |
| 151 return; | 152 return; |
| 152 UpdateTray(); | 153 UpdateTray(); |
| 153 if (popup_bubble()) { | 154 if (popup_bubble()) { |
| 154 popup_bubble()->bubble()->ScheduleUpdate(); | 155 popup_bubble()->bubble()->ScheduleUpdate(); |
| 155 } else if (message_center_->HasPopupNotifications()) { | 156 } else if (message_center_->HasPopupNotifications()) { |
| 156 popup_bubble_.reset( | 157 popup_bubble_.reset( |
| 157 new internal::WebNotificationBubbleWrapper( | 158 new internal::WebNotificationBubbleWrapper( |
| 158 this, new message_center::MessagePopupBubble( | 159 this, new message_center::MessagePopupBubble( |
| 159 message_center_.get()))); | 160 message_center_))); |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 | 163 |
| 163 void WebNotificationTray::HidePopupBubble() { | 164 void WebNotificationTray::HidePopupBubble() { |
| 164 popup_bubble_.reset(); | 165 popup_bubble_.reset(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 168 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
| 168 // TODO(mukai): Add keyboard event handler. | 169 // TODO(mukai): Add keyboard event handler. |
| 169 if (!event.IsMouseEvent()) | 170 if (!event.IsMouseEvent()) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 288 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, |
| 288 AnchorType anchor_type, | 289 AnchorType anchor_type, |
| 289 AnchorAlignment anchor_alignment) { | 290 AnchorAlignment anchor_alignment) { |
| 290 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 291 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 294 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
| 294 HideBubbleWithView(bubble_view); | 295 HideBubbleWithView(bubble_view); |
| 295 } | 296 } |
| 296 | 297 |
| 297 void WebNotificationTray::MessageCenterChanged(bool new_notification) { | 298 void WebNotificationTray::OnMessageCenterChanged(bool new_notification) { |
| 298 if (message_center_bubble()) { | 299 if (message_center_bubble()) { |
| 299 if (message_center_->NotificationCount() == 0) | 300 if (message_center_->NotificationCount() == 0) |
| 300 HideMessageCenterBubble(); | 301 HideMessageCenterBubble(); |
| 301 else | 302 else |
| 302 message_center_bubble()->bubble()->ScheduleUpdate(); | 303 message_center_bubble()->bubble()->ScheduleUpdate(); |
| 303 } | 304 } |
| 304 if (popup_bubble()) { | 305 if (popup_bubble()) { |
| 305 if (message_center_->NotificationCount() == 0) | 306 if (message_center_->NotificationCount() == 0) |
| 306 HidePopupBubble(); | 307 HidePopupBubble(); |
| 307 else | 308 else |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 387 |
| 387 message_center::MessagePopupBubble* | 388 message_center::MessagePopupBubble* |
| 388 WebNotificationTray::GetPopupBubbleForTest() { | 389 WebNotificationTray::GetPopupBubbleForTest() { |
| 389 if (!popup_bubble_.get()) | 390 if (!popup_bubble_.get()) |
| 390 return NULL; | 391 return NULL; |
| 391 return static_cast<message_center::MessagePopupBubble*>( | 392 return static_cast<message_center::MessagePopupBubble*>( |
| 392 popup_bubble_->bubble()); | 393 popup_bubble_->bubble()); |
| 393 } | 394 } |
| 394 | 395 |
| 395 } // namespace ash | 396 } // namespace ash |
| OLD | NEW |