Commit c44acc9a authored by stevenjb@google.com's avatar stevenjb@google.com

Add message to Ash message center for no notifications

Also hides tray before login.

BUG=137155
TBR=sky@chromium.org (for ash_strings.grd)

Review URL: https://chromiumcodereview.appspot.com/10834164

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150101 0039d316-1c4b-4281-b951-d872f2087c98
parent 3cc00b6e
...@@ -437,6 +437,9 @@ Press Search key to cancel. ...@@ -437,6 +437,9 @@ Press Search key to cancel.
<message name="IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL" desc="The button for clearing all notifications."> <message name="IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL" desc="The button for clearing all notifications.">
Clear All Clear All
</message> </message>
<message name="IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES" desc="The message displayed in the message center when there are no notifications.">
You have no notifications. Relax!
</message>
<message name="IDS_ASH_MAXIMIZE_WINDOW" desc="A help text to show that when the button gets clicked the window get maximized."> <message name="IDS_ASH_MAXIMIZE_WINDOW" desc="A help text to show that when the button gets clicked the window get maximized.">
Maximize Maximize
</message> </message>
......
...@@ -325,6 +325,7 @@ void StatusAreaWidget::AddSystemTray(SystemTray* system_tray, ...@@ -325,6 +325,7 @@ void StatusAreaWidget::AddSystemTray(SystemTray* system_tray,
system_tray_delegate_.reset(new DummySystemTrayDelegate()); system_tray_delegate_.reset(new DummySystemTrayDelegate());
system_tray->CreateItems(); // Called after delegate is created. system_tray->CreateItems(); // Called after delegate is created.
UpdateAfterLoginStatusChange(system_tray_delegate_->GetUserLoginStatus());
} }
void StatusAreaWidget::AddWebNotificationTray( void StatusAreaWidget::AddWebNotificationTray(
...@@ -367,6 +368,8 @@ bool StatusAreaWidget::ShouldShowNonSystemNotifications() { ...@@ -367,6 +368,8 @@ bool StatusAreaWidget::ShouldShowNonSystemNotifications() {
void StatusAreaWidget::UpdateAfterLoginStatusChange( void StatusAreaWidget::UpdateAfterLoginStatusChange(
user::LoginStatus login_status) { user::LoginStatus login_status) {
if (login_status_ == login_status)
return;
login_status_ = login_status; login_status_ = login_status;
if (system_tray_) if (system_tray_)
system_tray_->UpdateAfterLoginStatusChange(login_status); system_tray_->UpdateAfterLoginStatusChange(login_status);
......
...@@ -56,6 +56,8 @@ const int kUpdateDelayMs = 50; ...@@ -56,6 +56,8 @@ const int kUpdateDelayMs = 50;
// Limit the number of visible notifications. // Limit the number of visible notifications.
const int kMaxVisibleNotifications = 100; const int kMaxVisibleNotifications = 100;
const int kAutocloseDelaySeconds = 5; const int kAutocloseDelaySeconds = 5;
const SkColor kMessageCountColor = SkColorSetARGB(0xff, 0xff, 0xff, 0xff);
const SkColor kMessageCountDimmedColor = SkColorSetARGB(0x60, 0xff, 0xff, 0xff);
// Individual notifications constants // Individual notifications constants
const int kWebNotificationWidth = 320; const int kWebNotificationWidth = 320;
...@@ -437,8 +439,10 @@ class WebNotificationView : public views::View, ...@@ -437,8 +439,10 @@ class WebNotificationView : public views::View,
// Overridden from ButtonListener. // Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender, virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE { const views::Event& event) OVERRIDE {
if (sender == close_button_) if (sender == close_button_) {
tray_->RemoveNotification(notification_.id); tray_->RemoveNotification(notification_.id);
tray_->HideMessageCenterBubbleIfEmpty();
}
} }
// Overridden from MenuButtonListener. // Overridden from MenuButtonListener.
...@@ -504,11 +508,17 @@ class WebNotificationButtonView : public views::View, ...@@ -504,11 +508,17 @@ class WebNotificationButtonView : public views::View,
virtual ~WebNotificationButtonView() { virtual ~WebNotificationButtonView() {
} }
void SetCloseAllVisible(bool visible) {
close_all_button_->SetVisible(visible);
}
// Overridden from ButtonListener. // Overridden from ButtonListener.
virtual void ButtonPressed(views::Button* sender, virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE { const views::Event& event) OVERRIDE {
if (sender == close_all_button_) if (sender == close_all_button_) {
tray_->RemoveAllNotifications(); tray_->RemoveAllNotifications();
tray_->HideMessageCenterBubbleIfEmpty();
}
} }
private: private:
...@@ -545,16 +555,37 @@ class WebContentsView : public views::View { ...@@ -545,16 +555,37 @@ class WebContentsView : public views::View {
class MessageCenterContentsView : public WebContentsView { class MessageCenterContentsView : public WebContentsView {
public: public:
class ScrollContentView : public views::View {
public:
ScrollContentView() {
views::BoxLayout* layout =
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1);
layout->set_spread_blank_space(true);
SetLayoutManager(layout);
}
virtual ~ScrollContentView() {};
virtual gfx::Size GetPreferredSize() OVERRIDE {
if (!preferred_size_.IsEmpty())
return preferred_size_;
return views::View::GetPreferredSize();
}
void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; }
private:
gfx::Size preferred_size_;
DISALLOW_COPY_AND_ASSIGN(ScrollContentView);
};
explicit MessageCenterContentsView(WebNotificationTray* tray) explicit MessageCenterContentsView(WebNotificationTray* tray)
: WebContentsView(tray) { : WebContentsView(tray) {
SetLayoutManager( SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); set_background(views::Background::CreateSolidBackground(kBackgroundColor));
scroll_content_ = new views::View; scroll_content_ = new ScrollContentView;
scroll_content_->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
scroller_ = new internal::FixedSizedScrollView; scroller_ = new internal::FixedSizedScrollView;
scroller_->SetContentsView(scroll_content_); scroller_->SetContentsView(scroll_content_);
AddChildView(scroller_); AddChildView(scroller_);
...@@ -573,25 +604,40 @@ class MessageCenterContentsView : public WebContentsView { ...@@ -573,25 +604,40 @@ class MessageCenterContentsView : public WebContentsView {
if (++num_children >= kMaxVisibleNotifications) if (++num_children >= kMaxVisibleNotifications)
break; break;
} }
if (num_children == 0) {
views::Label* label = new views::Label(l10n_util::GetStringUTF16(
IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES));
label->SetFont(label->font().DeriveFont(2));
label->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
scroll_content_->AddChildView(label);
button_view_->SetCloseAllVisible(false);
} else {
button_view_->SetCloseAllVisible(true);
}
SizeScrollContent(); SizeScrollContent();
Layout();
GetWidget()->GetRootView()->SchedulePaint(); GetWidget()->GetRootView()->SchedulePaint();
} }
private: private:
void SizeScrollContent() { void SizeScrollContent() {
gfx::Size scroll_size = scroll_content_->GetPreferredSize(); gfx::Size scroll_size = scroll_content_->GetPreferredSize();
int button_height = button_view_->GetPreferredSize().height(); const int button_height = button_view_->GetPreferredSize().height();
int scroll_height = std::min( const int min_height = kWebNotificationBubbleMinHeight - button_height;
std::max(scroll_size.height(), const int max_height = kWebNotificationBubbleMaxHeight - button_height;
kWebNotificationBubbleMinHeight - button_height), int scroll_height = std::min(std::max(
kWebNotificationBubbleMaxHeight - button_height); scroll_size.height(), min_height), max_height);
scroll_size.set_height(scroll_height); scroll_size.set_height(scroll_height);
if (scroll_height == min_height)
scroll_content_->set_preferred_size(scroll_size);
else
scroll_content_->set_preferred_size(gfx::Size());
scroller_->SetFixedSize(scroll_size); scroller_->SetFixedSize(scroll_size);
scroller_->SizeToPreferredSize(); scroller_->SizeToPreferredSize();
} }
internal::FixedSizedScrollView* scroller_; internal::FixedSizedScrollView* scroller_;
views::View* scroll_content_; ScrollContentView* scroll_content_;
internal::WebNotificationButtonView* button_view_; internal::WebNotificationButtonView* button_view_;
DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView);
...@@ -731,10 +777,6 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host, ...@@ -731,10 +777,6 @@ class WebNotificationTray::Bubble : public TrayBubbleView::Host,
void UpdateBubbleView() { void UpdateBubbleView() {
const WebNotificationList::Notifications& notifications = const WebNotificationList::Notifications& notifications =
tray_->notification_list()->notifications(); tray_->notification_list()->notifications();
if (notifications.size() == 0) {
tray_->HideBubble(this); // deletes |this|!
return;
}
contents_view_->Update(notifications); contents_view_->Update(notifications);
bubble_view_->Show(); bubble_view_->Show();
bubble_view_->UpdateBubble(); bubble_view_->UpdateBubble();
...@@ -779,6 +821,7 @@ WebNotificationTray::WebNotificationTray( ...@@ -779,6 +821,7 @@ WebNotificationTray::WebNotificationTray(
gfx::Font font = count_label_->font(); gfx::Font font = count_label_->font();
count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD));
count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
count_label_->SetEnabledColor(kMessageCountDimmedColor);
tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight));
tray_container()->AddChildView(count_label_); tray_container()->AddChildView(count_label_);
...@@ -837,6 +880,7 @@ void WebNotificationTray::RemoveAllNotifications() { ...@@ -837,6 +880,7 @@ void WebNotificationTray::RemoveAllNotifications() {
} }
} }
notification_list_->RemoveAllNotifications(); notification_list_->RemoveAllNotifications();
HideMessageCenterBubble();
UpdateTrayAndBubble(); UpdateTrayAndBubble();
} }
...@@ -873,7 +917,7 @@ void WebNotificationTray::DisableByUrl(const std::string& id) { ...@@ -873,7 +917,7 @@ void WebNotificationTray::DisableByUrl(const std::string& id) {
void WebNotificationTray::ShowMessageCenterBubble() { void WebNotificationTray::ShowMessageCenterBubble() {
if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
return; return;
if (message_center_bubble() || GetNotificationCount() == 0) { if (message_center_bubble()) {
UpdateTray(); UpdateTray();
return; return;
} }
...@@ -886,12 +930,19 @@ void WebNotificationTray::ShowMessageCenterBubble() { ...@@ -886,12 +930,19 @@ void WebNotificationTray::ShowMessageCenterBubble() {
} }
void WebNotificationTray::HideMessageCenterBubble() { void WebNotificationTray::HideMessageCenterBubble() {
if (!message_center_bubble())
return;
message_center_bubble_.reset(); message_center_bubble_.reset();
show_message_center_on_unlock_ = false; show_message_center_on_unlock_ = false;
notification_list_->SetIsVisible(false); notification_list_->SetIsVisible(false);
status_area_widget()->SetHideSystemNotifications(false); status_area_widget()->SetHideSystemNotifications(false);
} }
void WebNotificationTray::HideMessageCenterBubbleIfEmpty() {
if (GetNotificationCount() == 0)
HideMessageCenterBubble();
}
void WebNotificationTray::ShowNotificationBubble() { void WebNotificationTray::ShowNotificationBubble() {
if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED)
return; return;
...@@ -966,21 +1017,27 @@ int WebNotificationTray::GetNotificationCount() const { ...@@ -966,21 +1017,27 @@ int WebNotificationTray::GetNotificationCount() const {
void WebNotificationTray::UpdateTray() { void WebNotificationTray::UpdateTray() {
count_label_->SetText(UTF8ToUTF16( count_label_->SetText(UTF8ToUTF16(
GetNotificationText(notification_list()->unread_count()))); GetNotificationText(notification_list()->unread_count())));
// Dim the message count text only if the message center is empty.
count_label_->SetEnabledColor(
(notification_list()->notifications().size() == 0) ?
kMessageCountDimmedColor : kMessageCountColor);
SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE));
Layout(); Layout();
SchedulePaint(); SchedulePaint();
} }
void WebNotificationTray::UpdateTrayAndBubble() { void WebNotificationTray::UpdateTrayAndBubble() {
UpdateTray(); UpdateTray();
if (GetNotificationCount() == 0) {
HideMessageCenterBubble();
HideNotificationBubble();
return;
}
if (message_center_bubble()) if (message_center_bubble())
message_center_bubble()->ScheduleUpdate(); message_center_bubble()->ScheduleUpdate();
if (notification_bubble())
if (notification_bubble()) {
if (GetNotificationCount() == 0)
HideNotificationBubble();
else
notification_bubble()->ScheduleUpdate(); notification_bubble()->ScheduleUpdate();
}
} }
void WebNotificationTray::HideBubble(Bubble* bubble) { void WebNotificationTray::HideBubble(Bubble* bubble) {
......
...@@ -110,6 +110,9 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView { ...@@ -110,6 +110,9 @@ class ASH_EXPORT WebNotificationTray : public internal::TrayBackgroundView {
// Hide the message center bubble. Should only be called by StatusAreaWidget. // Hide the message center bubble. Should only be called by StatusAreaWidget.
void HideMessageCenterBubble(); void HideMessageCenterBubble();
// Hide the message center bubble if there are no notifications.
void HideMessageCenterBubbleIfEmpty();
// Show a single notification bubble for the most recent notification. // Show a single notification bubble for the most recent notification.
void ShowNotificationBubble(); void ShowNotificationBubble();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment