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 52504eda4038fdd0656dde03ea3c0df3faf7e57f..991e9f1b2bba532bfb45f70cb83ad262f9d2b391 100644 |
--- a/ash/system/web_notification/web_notification_tray.cc |
+++ b/ash/system/web_notification/web_notification_tray.cc |
@@ -25,10 +25,12 @@ |
#include "base/i18n/rtl.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/thread_task_runner_handle.h" |
+#include "grit/ash_resources.h" |
#include "grit/ash_strings.h" |
#include "ui/aura/window.h" |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
#include "ui/display/screen.h" |
#include "ui/message_center/message_center_style.h" |
#include "ui/message_center/message_center_tray_delegate.h" |
@@ -118,9 +120,19 @@ class WebNotificationButton : public views::CustomButton { |
is_bubble_visible_(false), |
unread_count_(0) { |
SetLayoutManager(new views::FillLayout); |
- unread_label_ = new views::Label(); |
- SetupLabelForTray(unread_label_); |
- AddChildView(unread_label_); |
+ |
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
+ no_unread_icon_.reset(new views::ImageView()); |
+ no_unread_icon_->SetImage( |
+ rb.GetImageNamed(IDR_ASH_SHELF_NOTIFICATION_TRAY_EMPTY).ToImageSkia()); |
oshima
2016/05/11 02:46:30
do you really need an image view here? Doesn't emp
yoshiki
2016/05/11 05:42:51
Yes, the initial state is unread_count == 0, so we
oshima
2016/05/11 14:35:10
which one is bell icon? Or empty.png is just a pla
|
+ no_unread_icon_->SetImageSize(gfx::Size(18, 18)); |
+ no_unread_icon_->set_owned_by_client(); |
+ |
+ unread_label_.reset(new views::Label()); |
oshima
2016/05/11 02:46:30
you can just use view::Label unread_label_;
yoshiki
2016/05/11 05:42:51
Done.
|
+ unread_label_->set_owned_by_client(); |
+ SetupLabelForTray(unread_label_.get()); |
+ |
+ AddChildView(unread_label_.get()); |
} |
void SetBubbleVisible(bool visible) { |
@@ -135,11 +147,6 @@ class WebNotificationButton : public views::CustomButton { |
// base::FormatNumber doesn't convert to arabic numeric characters. |
// TODO(mukai): use ICU to support conversion for such locales. |
unread_count_ = unread_count; |
- // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to be |
- // in ash_strings. |
- unread_label_->SetText((unread_count > 9) ? |
- l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : |
- base::FormatNumber(unread_count)); |
UpdateIconVisibility(); |
} |
@@ -155,16 +162,36 @@ class WebNotificationButton : public views::CustomButton { |
private: |
void UpdateIconVisibility() { |
- unread_label_->SetEnabledColor( |
- (!is_bubble_visible_ && unread_count_ > 0) ? |
- kWebNotificationColorWithUnread : kWebNotificationColorNoUnread); |
+ if (unread_count_ == 0) { |
+ if (!Contains(no_unread_icon_.get())) { |
+ RemoveAllChildViews(false /* delete_children */); |
+ AddChildView(no_unread_icon_.get()); |
+ } |
+ } else { |
+ if (!Contains(unread_label_.get())) { |
+ RemoveAllChildViews(false /* delete_children */); |
+ AddChildView(unread_label_.get()); |
+ } |
+ |
+ // TODO(mukai): move NINE_PLUS message to ui_strings, it doesn't need to |
+ // be in ash_strings. |
+ unread_label_->SetText( |
+ (unread_count_ > 9) ? l10n_util::GetStringUTF16( |
+ IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) |
+ : base::FormatNumber(unread_count_)); |
+ unread_label_->SetEnabledColor((!is_bubble_visible_) |
+ ? kWebNotificationColorWithUnread |
+ : kWebNotificationColorNoUnread); |
+ } |
+ |
SchedulePaint(); |
} |
bool is_bubble_visible_; |
int unread_count_; |
- views::Label* unread_label_; |
+ std::unique_ptr<views::ImageView> no_unread_icon_; |
+ std::unique_ptr<views::Label> unread_label_; |
DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
}; |