Chromium Code Reviews| 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 05e6f6e7ba5aa7defaf5582d8afb58cc69795d9e..4637aadaf5de56b333e3ab289cf20ecaadc30daf 100644 |
| --- a/ash/system/web_notification/web_notification_tray.cc |
| +++ b/ash/system/web_notification/web_notification_tray.cc |
| @@ -4,38 +4,36 @@ |
| #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 { |
| +#if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_WIN) |
| +namespace chrome { |
| -// 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; |
| +ui::MessageCenterTrayDelegate* GetMessageCenterTray() { |
| + return ash::Shell::GetPrimaryRootWindowController()->status_area_widget()-> |
| + web_notification_tray(); |
| +} |
| + |
| +} // namespace chrome |
| +#endif |
| -} // namespace |
| namespace ash { |
| @@ -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,19 @@ 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_ = message_center::MessageCenter::GetInstance(); |
| - 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_ = make_scoped_ptr(new ui::MessageCenterTray(this)); |
| + OnMessageCenterTrayChanged(); |
| } |
| WebNotificationTray::~WebNotificationTray() { |
| - // Ensure the message center doesn't notify a destroyed object. |
| - message_center_->RemoveObserver(this); |
| // Release any child views that might have back pointers before ~View(). |
| message_center_bubble_.reset(); |
| popup_bubble_.reset(); |
| @@ -104,22 +102,16 @@ 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. |
| +bool WebNotificationTray::CanShowMessageCenter() { |
| + return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
| + status_area_widget()->ShouldShowWebNotifications(); |
| +} |
| + |
| +bool WebNotificationTray::ShowMessageCenter( |
| + message_center::MessageBubbleBase* message_center_bubble) { |
| + if (!CanShowMessageCenter()) |
| + return false; |
| + |
| // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
| // to set the height of the popup. |
| int max_height = 0; |
| @@ -132,51 +124,55 @@ 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(); |
| } |
| @@ -196,7 +192,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); |
| } |
| @@ -204,21 +202,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 { |
| @@ -231,31 +228,47 @@ bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| } |
| bool WebNotificationTray::IsMouseInNotificationBubble() const { |
| - if (!popup_bubble()) |
| - return false; |
| - return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| - Shell::GetScreen()->GetCursorScreenPoint()); |
| + // We only care about the mouse being in the popup view. |
| + if (popup_bubble()) { |
| + views::View* popup_bubble_view = popup_bubble_->bubble_view(); |
| + if (!popup_bubble_view) |
|
Pete Williamson
2013/01/17 19:07:45
While not harmful, this might not still be require
dewittj
2013/01/18 00:57:46
Done.
|
| + return false; |
|
Pete Williamson
2013/01/17 19:07:45
While not necessary, this might not still be requi
dewittj
2013/01/18 00:57:46
Done.
|
| + return popup_bubble_view->GetBoundsInScreen().Contains( |
| + Shell::GetScreen()->GetCursorScreenPoint()); |
| + } |
| + return false; |
| +} |
| + |
| +message_center::MessageCenter* WebNotificationTray::message_center() { |
| + return message_center_tray_->message_center(); |
| } |
| 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() { |
| - if (popup_bubble_.get()) { |
| - popup_bubble_->bubble_view()->UpdateBubble(); |
| - // Ensure that the notification buble is above the launcher/status area. |
| - popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| - UpdateBubbleViewArrow(popup_bubble_->bubble_view()); |
| + if (popup_bubble()) { |
| + views::TrayBubbleView* popup_bubble_view = popup_bubble_->bubble_view(); |
| + if (popup_bubble_view) { |
| + popup_bubble_view->UpdateBubble(); |
| + // Ensure that the notification buble is above the launcher/status area. |
| + popup_bubble_view->GetWidget()->StackAtTop(); |
| + UpdateBubbleViewArrow(popup_bubble_view); |
| + } |
| } |
| - if (message_center_bubble_.get()) { |
| - message_center_bubble_->bubble_view()->UpdateBubble(); |
| - UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); |
| + if (message_center_bubble()) { |
| + views::TrayBubbleView* message_center_bubble_view = |
| + message_center_bubble_->bubble_view(); |
| + if (message_center_bubble_view) { |
| + message_center_bubble_view->UpdateBubble(); |
| + UpdateBubbleViewArrow(message_center_bubble_view); |
| + } |
| } |
| // Quiet mode settings bubble has to be on top. |
| if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
| @@ -271,9 +284,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(); |
| } |
| } |
| @@ -283,10 +296,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(); |
| @@ -308,9 +328,10 @@ string16 WebNotificationTray::GetAccessibleNameForBubble() { |
| return GetAccessibleNameForTray(); |
| } |
| -gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, |
| - AnchorType anchor_type, |
| - AnchorAlignment anchor_alignment) { |
| +gfx::Rect WebNotificationTray::GetAnchorRect( |
|
Pete Williamson
2013/01/17 19:07:45
comment somewhere explaining what the anchor rect
dewittj
2013/01/18 00:57:46
BubbleDelegateView is where this originates, and i
|
| + views::Widget* anchor_widget, |
| + views::TrayBubbleView::AnchorType anchor_type, |
| + views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
| return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
| } |
| @@ -318,30 +339,13 @@ 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); |
| PerformAction(event); |
| } |
| + |
|
Pete Williamson
2013/01/17 19:07:45
remove extra blank line
|
| void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
| if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { |
| widget->RemoveObserver(this); |
| @@ -349,19 +353,12 @@ 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( |
| @@ -376,7 +373,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); |
| @@ -389,12 +386,16 @@ bool WebNotificationTray::ClickedOutsideBubble() { |
| if (!message_center_bubble() && !quiet_mode_bubble()) |
| return false; |
| quiet_mode_bubble_.reset(); |
| - HideMessageCenterBubble(); |
| + message_center_tray_->HideMessageCenterBubble(); |
| return true; |
| } |
| // Methods for testing |
| +bool WebNotificationTray::IsPopupVisible() const { |
| + return message_center_tray_->IsPopupVisible(); |
| +} |
| + |
| message_center::MessageCenterBubble* |
| WebNotificationTray::GetMessageCenterBubbleForTest() { |
| if (!message_center_bubble_.get()) |
| @@ -411,4 +412,5 @@ WebNotificationTray::GetPopupBubbleForTest() { |
| popup_bubble_->bubble()); |
| } |
| + |
| } // namespace ash |