Index: ash/system/web_notification/web_notification_tray.cc |
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc |
index b04b761d2d63aa2c83560f5432ddbc5aa03de800..851a81931ff117f3f6c5f324e6549b7745044194 100644 |
--- a/ash/system/web_notification/web_notification_tray.cc |
+++ b/ash/system/web_notification/web_notification_tray.cc |
@@ -4,36 +4,34 @@ |
#include "ash/system/web_notification/web_notification_tray.h" |
+#include "ash/root_window_controller.h" |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
#include "ash/system/status_area_widget.h" |
+#include "ash/system/tray/tray_background_view.h" |
#include "ash/system/tray/tray_bubble_wrapper.h" |
-#include "ash/system/tray/tray_constants.h" |
-#include "ash/system/tray/tray_views.h" |
#include "ash/wm/shelf_layout_manager.h" |
-#include "base/message_loop.h" |
-#include "base/stringprintf.h" |
#include "grit/ash_resources.h" |
#include "grit/ash_strings.h" |
#include "ui/aura/window.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/screen.h" |
+#include "ui/message_center/message_bubble_base.h" |
#include "ui/message_center/message_center_bubble.h" |
+#include "ui/message_center/message_center_tray.h" |
#include "ui/message_center/message_popup_bubble.h" |
#include "ui/message_center/quiet_mode_bubble.h" |
#include "ui/views/bubble/tray_bubble_view.h" |
#include "ui/views/widget/widget_observer.h" |
-namespace { |
+namespace ui { |
-// Tray constants |
-const int kTrayContainerVerticalPaddingBottomAlignment = 3; |
-const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
-const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
-const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; |
-const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; |
-const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; |
+// static |
+MessageCenterTrayDelegate* MessageCenterTrayDelegate::CreateForPlatform() { |
+ // On Ash, the status area widget creates the WebNotificationTray directly. |
+ return NULL; |
+} |
} // namespace |
@@ -70,6 +68,9 @@ class WebNotificationBubbleWrapper { |
// Convenience accessors. |
views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
+ views::Widget* bubble_widget() const { |
+ return bubble_wrapper_->bubble_widget(); |
+ } |
private: |
scoped_ptr<message_center::MessageBubbleBase> bubble_; |
@@ -80,22 +81,20 @@ class WebNotificationBubbleWrapper { |
WebNotificationTray::WebNotificationTray( |
internal::StatusAreaWidget* status_area_widget) |
- : internal::TrayBackgroundView(status_area_widget), |
+ : TrayBackgroundView(status_area_widget), |
button_(NULL), |
show_message_center_on_unlock_(false) { |
- message_center_ = ash::Shell::GetInstance()->message_center(); |
- message_center_->AddObserver(this); |
button_ = new views::ImageButton(this); |
button_->set_triggerable_event_flags( |
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
tray_container()->AddChildView(button_); |
SetVisible(false); |
- UpdateTray(); |
+ message_center_tray_.reset( |
+ new ui::MessageCenterTray(this, Shell::GetInstance()->message_center())); |
+ OnMessageCenterTrayChanged(); |
} |
WebNotificationTray::~WebNotificationTray() { |
- // Ensure the message center doesn't notify an object under destruction. |
- message_center_->RemoveObserver(this); |
// Release any child views that might have back pointers before ~View(). |
message_center_bubble_.reset(); |
popup_bubble_.reset(); |
@@ -104,22 +103,13 @@ WebNotificationTray::~WebNotificationTray() { |
quiet_mode_bubble_.reset(); |
} |
-void WebNotificationTray::ShowMessageCenterBubble() { |
- if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
- return; |
- if (quiet_mode_bubble()) |
- quiet_mode_bubble_.reset(); |
- if (message_center_bubble()) { |
- UpdateTray(); |
- return; |
- } |
- // Indicate that the message center is visible. Clears the unread count. |
- message_center_->SetMessageCenterVisible(true); |
- UpdateTray(); |
- HidePopupBubble(); |
- message_center::MessageCenterBubble* bubble = |
- new message_center::MessageCenterBubble(message_center_); |
- // Sets the maximum height of the bubble based on the screen. |
+// Public methods. |
+ |
+bool WebNotificationTray::ShowMessageCenter( |
+ message_center::MessageBubbleBase* message_center_bubble) { |
+ if (!ShouldShowMessageCenter()) |
+ return false; |
+ |
// TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
// to set the height of the popup. |
int max_height = 0; |
@@ -132,53 +122,63 @@ void WebNotificationTray::ShowMessageCenterBubble() { |
aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); |
max_height = status_area_window->GetBoundsInRootWindow().bottom(); |
} |
- bubble->SetMaxHeight(max_height); |
+ message_center_bubble->SetMaxHeight(max_height); |
message_center_bubble_.reset( |
- new internal::WebNotificationBubbleWrapper(this, bubble)); |
+ new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); |
status_area_widget()->SetHideSystemNotifications(true); |
GetShelfLayoutManager()->UpdateAutoHideState(); |
+ return true; |
+} |
+ |
+void WebNotificationTray::UpdateMessageCenter() { |
+ if (message_center_bubble()) |
+ message_center_bubble_->bubble()->ScheduleUpdate(); |
} |
-void WebNotificationTray::HideMessageCenterBubble() { |
+void WebNotificationTray::HideMessageCenter() { |
if (!message_center_bubble()) |
return; |
message_center_bubble_.reset(); |
show_message_center_on_unlock_ = false; |
- message_center_->SetMessageCenterVisible(false); |
- UpdateTray(); |
status_area_widget()->SetHideSystemNotifications(false); |
GetShelfLayoutManager()->UpdateAutoHideState(); |
} |
void WebNotificationTray::SetHidePopupBubble(bool hide) { |
if (hide) |
- HidePopupBubble(); |
+ message_center_tray_->HidePopupBubble(); |
else |
- ShowPopupBubble(); |
+ message_center_tray_->ShowPopupBubble(); |
} |
-void WebNotificationTray::ShowPopupBubble() { |
- if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
- return; |
- if (message_center_bubble()) |
- return; |
- if (!status_area_widget()->ShouldShowWebNotifications()) |
- return; |
- UpdateTray(); |
- if (popup_bubble()) { |
- popup_bubble()->bubble()->ScheduleUpdate(); |
- } else if (message_center_->HasPopupNotifications()) { |
- popup_bubble_.reset( |
- new internal::WebNotificationBubbleWrapper( |
- this, new message_center::MessagePopupBubble(message_center_))); |
- } |
+bool WebNotificationTray::ShowPopups( |
+ message_center::MessageBubbleBase* popup_bubble) { |
+ if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || |
+ message_center_bubble() || |
+ !status_area_widget()->ShouldShowWebNotifications()) |
+ return false; |
+ popup_bubble_.reset(new internal::WebNotificationBubbleWrapper( |
+ this, popup_bubble)); |
+ return true; |
} |
-void WebNotificationTray::HidePopupBubble() { |
+void WebNotificationTray::UpdatePopups() { |
+ if (popup_bubble()) |
+ popup_bubble_->bubble()->ScheduleUpdate(); |
+}; |
+ |
+void WebNotificationTray::HidePopups() { |
popup_bubble_.reset(); |
} |
+// Private methods. |
+ |
+bool WebNotificationTray::ShouldShowMessageCenter() { |
+ return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
+ status_area_widget()->ShouldShowWebNotifications(); |
+} |
+ |
bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
// TODO(mukai): Add keyboard event handler. |
if (!event.IsMouseEvent()) |
@@ -195,7 +195,9 @@ void WebNotificationTray::ShowQuietModeBubble() { |
Shell::GetPrimaryRootWindow(), |
internal::kShellWindowId_SettingBubbleContainer); |
quiet_mode_bubble_.reset(new message_center::QuietModeBubble( |
- button_, parent, message_center_->notification_list())); |
+ button_, |
+ parent, |
+ message_center_tray_->message_center()->notification_list())); |
quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); |
} |
@@ -203,21 +205,20 @@ void WebNotificationTray::ShowQuietModeBubble() { |
void WebNotificationTray::UpdateAfterLoginStatusChange( |
user::LoginStatus login_status) { |
if (login_status == user::LOGGED_IN_LOCKED) { |
- if (message_center_bubble()) { |
- message_center_bubble_.reset(); |
+ bool hidden = message_center_tray_->HideMessageCenterBubble(); |
+ if (hidden) |
show_message_center_on_unlock_ = true; |
- } |
- HidePopupBubble(); |
+ message_center_tray_->HidePopupBubble(); |
} else { |
if (show_message_center_on_unlock_) |
- ShowMessageCenterBubble(); |
+ message_center_tray_->ShowMessageCenterBubble(); |
show_message_center_on_unlock_ = false; |
} |
// The status icon should be always visible except for lock screen / login |
// screen, to allow quiet mode and settings. |
SetVisible((login_status != user::LOGGED_IN_NONE) && |
(login_status != user::LOGGED_IN_LOCKED)); |
- UpdateTray(); |
+ OnMessageCenterTrayChanged(); |
} |
bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { |
@@ -239,10 +240,10 @@ bool WebNotificationTray::IsMouseInNotificationBubble() const { |
void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
if (alignment == shelf_alignment()) |
return; |
- internal::TrayBackgroundView::SetShelfAlignment(alignment); |
+ SetShelfAlignment(alignment); |
// Destroy any existing bubble so that it will be rebuilt correctly. |
- HideMessageCenterBubble(); |
- HidePopupBubble(); |
+ message_center_tray_->HideMessageCenterBubble(); |
+ message_center_tray_->HidePopupBubble(); |
} |
void WebNotificationTray::AnchorUpdated() { |
@@ -270,9 +271,9 @@ void WebNotificationTray::HideBubbleWithView( |
const views::TrayBubbleView* bubble_view) { |
if (message_center_bubble() && |
bubble_view == message_center_bubble()->bubble_view()) { |
- HideMessageCenterBubble(); |
+ message_center_tray_->HideMessageCenterBubble(); |
} else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
- HidePopupBubble(); |
+ message_center_tray_->HidePopupBubble(); |
} |
} |
@@ -282,10 +283,17 @@ bool WebNotificationTray::PerformAction(const ui::Event& event) { |
return true; |
} |
quiet_mode_bubble_.reset(); |
- ToggleMessageCenterBubble(); |
+ if (message_center_bubble()) |
+ message_center_tray_->HideMessageCenterBubble(); |
+ else |
+ message_center_tray_->ShowMessageCenterBubble(); |
return true; |
} |
+void WebNotificationTray::ShowMessageCenter() { |
+ message_center_tray_->ShowMessageCenterBubble(); |
+} |
+ |
void WebNotificationTray::BubbleViewDestroyed() { |
if (message_center_bubble()) |
message_center_bubble()->bubble()->BubbleViewDestroyed(); |
@@ -307,9 +315,10 @@ string16 WebNotificationTray::GetAccessibleNameForBubble() { |
return GetAccessibleNameForTray(); |
} |
-gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, |
- AnchorType anchor_type, |
- AnchorAlignment anchor_alignment) { |
+gfx::Rect WebNotificationTray::GetAnchorRect( |
+ views::Widget* anchor_widget, |
+ views::TrayBubbleView::AnchorType anchor_type, |
+ views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
} |
@@ -317,24 +326,6 @@ void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
HideBubbleWithView(bubble_view); |
} |
-void WebNotificationTray::OnMessageCenterChanged(bool new_notification) { |
- if (message_center_bubble()) { |
- if (message_center_->NotificationCount() == 0) |
- HideMessageCenterBubble(); |
- else |
- message_center_bubble()->bubble()->ScheduleUpdate(); |
- } |
- if (popup_bubble()) { |
- if (message_center_->NotificationCount() == 0) |
- HidePopupBubble(); |
- else |
- popup_bubble()->bubble()->ScheduleUpdate(); |
- } |
- UpdateTray(); |
- if (new_notification) |
- ShowPopupBubble(); |
-} |
- |
void WebNotificationTray::ButtonPressed(views::Button* sender, |
const ui::Event& event) { |
DCHECK_EQ(button_, sender); |
@@ -348,19 +339,11 @@ void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
quiet_mode_bubble_.reset(); |
} |
-// Private methods |
- |
-void WebNotificationTray::ToggleMessageCenterBubble() { |
- if (message_center_bubble()) |
- HideMessageCenterBubble(); |
- else |
- ShowMessageCenterBubble(); |
- UpdateTray(); |
-} |
- |
-void WebNotificationTray::UpdateTray() { |
+void WebNotificationTray::OnMessageCenterTrayChanged() { |
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
- if (message_center_->UnreadNotificationCount() > 0) { |
+ message_center::MessageCenter* message_center = |
+ message_center_tray_->message_center(); |
+ if (message_center->UnreadNotificationCount() > 0) { |
button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); |
button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
@@ -375,7 +358,7 @@ void WebNotificationTray::UpdateTray() { |
button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); |
} |
- if (message_center_bubble()) |
+ if (IsMessageCenterBubbleVisible()) |
button_->SetState(views::CustomButton::STATE_PRESSED); |
else |
button_->SetState(views::CustomButton::STATE_NORMAL); |
@@ -388,12 +371,20 @@ bool WebNotificationTray::ClickedOutsideBubble() { |
if (!message_center_bubble() && !quiet_mode_bubble()) |
return false; |
quiet_mode_bubble_.reset(); |
- HideMessageCenterBubble(); |
+ message_center_tray_->HideMessageCenterBubble(); |
return true; |
} |
+message_center::MessageCenter* WebNotificationTray::message_center() { |
+ return message_center_tray_->message_center(); |
+} |
+ |
// Methods for testing |
+bool WebNotificationTray::IsPopupVisible() const { |
+ return message_center_tray_->popups_visible(); |
+} |
+ |
message_center::MessageCenterBubble* |
WebNotificationTray::GetMessageCenterBubbleForTest() { |
if (!message_center_bubble_.get()) |