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 c83eae76150101dc076792657ea37334162030ae..334e52d1f4371f36c3bbc8643350ed2ee70f52ee 100644 |
--- a/ash/system/web_notification/web_notification_tray.cc |
+++ b/ash/system/web_notification/web_notification_tray.cc |
@@ -4,169 +4,89 @@ |
#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_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_center_bubble.h" |
-#include "ui/message_center/message_popup_bubble.h" |
+#include "ui/message_center/message_center_tray.h" |
+#include "ui/message_center/message_center_tray_host.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) |
Pete Williamson
2013/01/16 19:43:20
Should we check for not windows or that we do have
dewittj
2013/01/16 22:30:40
There is a windows version of this function, in ch
|
+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; |
- |
-} // namespace |
- |
-namespace ash { |
- |
-namespace internal { |
- |
-// Class to initialize and manage the WebNotificationBubble and |
-// TrayBubbleWrapper instances for a bubble. |
- |
-class WebNotificationBubbleWrapper { |
- public: |
- // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
- WebNotificationBubbleWrapper(WebNotificationTray* tray, |
- message_center::MessageBubbleBase* bubble) { |
- bubble_.reset(bubble); |
- views::TrayBubbleView::AnchorAlignment anchor_alignment = |
- tray->GetAnchorAlignment(); |
- views::TrayBubbleView::InitParams init_params = |
- bubble->GetInitParams(anchor_alignment); |
- views::View* anchor = tray->tray_container(); |
- if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
- gfx::Point bounds(anchor->width() / 2, 0); |
- views::View::ConvertPointToWidget(anchor, &bounds); |
- init_params.arrow_offset = bounds.x(); |
- } |
- views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
- tray->GetBubbleWindowContainer(), anchor, tray, &init_params); |
- bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
- bubble->InitializeContents(bubble_view); |
- } |
- |
- message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
+ui::MessageCenterTrayHost* GetMessageCenterTray() { |
+ return ash::Shell::GetPrimaryRootWindowController()->status_area_widget()-> |
+ web_notification_tray(); |
+} |
- // Convenience accessors. |
- views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
+} // namespace chrome |
+#endif |
- private: |
- scoped_ptr<message_center::MessageBubbleBase> bubble_; |
- scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
-}; |
-} // namespace internal |
+namespace ash { |
Pete Williamson
2013/01/16 19:43:20
Where did the WebNotificationBubbleWrapper functio
dewittj
2013/01/16 22:30:40
It was squashed partly into the MessageCenterTray
|
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); |
+ show_message_center_on_unlock_(false), |
+ message_center_visible_(false) { |
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(); |
- if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
- quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); |
- quiet_mode_bubble_.reset(); |
+WebNotificationTray::~WebNotificationTray() { } |
+ |
+bool WebNotificationTray::CanShowMessageCenter() { |
+ return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
+ status_area_widget()->ShouldShowWebNotifications(); |
} |
-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_); |
- message_center_bubble_.reset( |
- new internal::WebNotificationBubbleWrapper(this, bubble)); |
+message_center::MessageCenter* WebNotificationTray::message_center() { |
+ return message_center_tray_->message_center(); |
+} |
+ |
+void WebNotificationTray::OnShowMessageCenterBubble() { |
+ message_center_visible_ = true; |
status_area_widget()->SetHideSystemNotifications(true); |
GetShelfLayoutManager()->UpdateAutoHideState(); |
} |
-void WebNotificationTray::HideMessageCenterBubble() { |
- if (!message_center_bubble()) |
- return; |
- message_center_bubble_.reset(); |
+void WebNotificationTray::OnHideMessageCenterBubble() { |
+ message_center_visible_ = false; |
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::CanShowPopups() { |
+ return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
+ status_area_widget()->ShouldShowWebNotifications(); |
} |
-void WebNotificationTray::HidePopupBubble() { |
- popup_bubble_.reset(); |
-} |
-bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
+namespace { // XXX move this to top after merge |
+ |
+bool ShouldShowQuietModeBubble(const ui::Event& event) { |
// TODO(mukai): Add keyboard event handler. |
if (!event.IsMouseEvent()) |
return false; |
@@ -177,12 +97,16 @@ bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
return mouse_event->IsRightMouseButton(); |
} |
+} // namespace |
+ |
void WebNotificationTray::ShowQuietModeBubble() { |
aura::Window* parent = Shell::GetContainer( |
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); |
} |
@@ -190,36 +114,36 @@ 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 { |
- return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; |
+ return message_center_visible_ || quiet_mode_bubble_.get() != NULL; |
} |
bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
- return (message_center_bubble() && |
- message_center_bubble_->bubble()->IsVisible()); |
+ return message_center_visible_; |
} |
bool WebNotificationTray::IsMouseInNotificationBubble() const { |
- if (!popup_bubble()) |
+ // We only care about the mouse being in the popup view. |
+ views::View* popup_bubble_view = message_center_tray_->GetPopupBubbleView(); |
+ if (!popup_bubble_view) |
return false; |
- return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
+ return popup_bubble_view->GetBoundsInScreen().Contains( |
Shell::GetScreen()->GetCursorScreenPoint()); |
} |
@@ -228,23 +152,27 @@ void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
return; |
internal::TrayBackgroundView::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(); |
+ views::TrayBubbleView* popup_bubble_view = |
+ message_center_tray_->GetPopupBubbleView(); |
+ if (popup_bubble_view) { |
+ popup_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()); |
+ 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()); |
+ views::TrayBubbleView* message_center_bubble_view = |
+ message_center_tray_->GetMessageCenterBubbleView(); |
+ 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()) |
+ if (quiet_mode_bubble_.get() && quiet_mode_bubble_->GetBubbleWidget()) |
quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
} |
@@ -255,72 +183,33 @@ string16 WebNotificationTray::GetAccessibleNameForTray() { |
void WebNotificationTray::HideBubbleWithView( |
const views::TrayBubbleView* bubble_view) { |
- if (message_center_bubble() && |
- bubble_view == message_center_bubble()->bubble_view()) { |
- HideMessageCenterBubble(); |
- } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
- HidePopupBubble(); |
- } |
+ message_center_tray_->HideBubble(bubble_view); |
} |
bool WebNotificationTray::PerformAction(const ui::Event& event) { |
- if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { |
+ if (!quiet_mode_bubble_.get() && ShouldShowQuietModeBubble(event)) { |
+ //XXX Put these back in? |
Pete Williamson
2013/01/16 19:43:20
This should be resolved before checkin. Also, the
dewittj
2013/01/16 22:30:40
The XXX means I'm definitely not checking it in.
|
+ message_center_tray_->HideMessageCenterBubble(); |
+ message_center_tray_->HidePopupBubble(); |
ShowQuietModeBubble(); |
return true; |
} |
quiet_mode_bubble_.reset(); |
- ToggleMessageCenterBubble(); |
+ message_center_tray_->ToggleMessageCenterBubble(); |
return true; |
} |
Pete Williamson
2013/01/16 19:43:20
Where did BubbleViewDestroyed go?
dewittj
2013/01/16 22:30:40
It's back.
|
-void WebNotificationTray::BubbleViewDestroyed() { |
- if (message_center_bubble()) |
- message_center_bubble()->bubble()->BubbleViewDestroyed(); |
- if (popup_bubble()) |
- popup_bubble()->bubble()->BubbleViewDestroyed(); |
-} |
- |
-void WebNotificationTray::OnMouseEnteredView() { |
- if (popup_bubble()) |
- popup_bubble()->bubble()->OnMouseEnteredView(); |
-} |
- |
-void WebNotificationTray::OnMouseExitedView() { |
- if (popup_bubble()) |
- popup_bubble()->bubble()->OnMouseExitedView(); |
-} |
- |
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); |
} |
-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) { |
@@ -329,25 +218,40 @@ void WebNotificationTray::ButtonPressed(views::Button* sender, |
} |
void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
- if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { |
+ if (quiet_mode_bubble_.get() && |
+ quiet_mode_bubble_->GetBubbleWidget() == widget) { |
widget->RemoveObserver(this); |
} |
quiet_mode_bubble_.reset(); |
} |
-// Private methods |
+gfx::NativeView WebNotificationTray::GetBubbleWindowContainer() { |
+ return TrayBackgroundView::GetBubbleWindowContainer(); |
+} |
-void WebNotificationTray::ToggleMessageCenterBubble() { |
- if (message_center_bubble()) |
- HideMessageCenterBubble(); |
- else |
- ShowMessageCenterBubble(); |
- UpdateTray(); |
+views::View* WebNotificationTray::GetAnchorView() { |
+ return tray_container(); |
} |
-void WebNotificationTray::UpdateTray() { |
+views::TrayBubbleView::AnchorAlignment |
+WebNotificationTray::GetAnchorAlignment() { |
+ return TrayBackgroundView::GetAnchorAlignment(); |
+} |
+ |
+void WebNotificationTray::UpdateInitParams( |
+ views::TrayBubbleView::InitParams* init_params) { |
+ if (GetAnchorAlignment() == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
+ gfx::Point bounds(tray_container()->width() / 2, 0); |
+ views::View::ConvertPointToWidget(tray_container(), &bounds); |
+ init_params->arrow_offset = bounds.x(); |
+ } |
+} |
+ |
+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( |
@@ -362,7 +266,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 (message_center_visible_) |
button_->SetState(views::CustomButton::STATE_PRESSED); |
else |
button_->SetState(views::CustomButton::STATE_NORMAL); |
@@ -372,29 +276,19 @@ void WebNotificationTray::UpdateTray() { |
bool WebNotificationTray::ClickedOutsideBubble() { |
// Only hide the message center and quiet mode bubble. |
- if (!message_center_bubble() && !quiet_mode_bubble()) |
+ if (!message_center_visible_ && !quiet_mode_bubble_.get()) |
return false; |
quiet_mode_bubble_.reset(); |
- HideMessageCenterBubble(); |
+ message_center_tray_->HideMessageCenterBubble(); |
return true; |
} |
-// Methods for testing |
- |
-message_center::MessageCenterBubble* |
-WebNotificationTray::GetMessageCenterBubbleForTest() { |
- if (!message_center_bubble_.get()) |
- return NULL; |
- return static_cast<message_center::MessageCenterBubble*>( |
- message_center_bubble_->bubble()); |
+void WebNotificationTray::ShowMessageCenter() { |
+ message_center_tray_->ShowMessageCenterBubble(); |
Pete Williamson
2013/01/16 19:43:20
We removed some testing methods, does that mean we
dewittj
2013/01/16 22:30:40
They were a work in progress. The patch you read
|
} |
-message_center::MessagePopupBubble* |
-WebNotificationTray::GetPopupBubbleForTest() { |
- if (!popup_bubble_.get()) |
- return NULL; |
- return static_cast<message_center::MessagePopupBubble*>( |
- popup_bubble_->bubble()); |
+bool WebNotificationTray::IsPopupVisible() const { |
+ return message_center_tray_->IsPopupVisible(); |
} |
} // namespace ash |