diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 16:28:01 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 16:28:01 +0000 |
commit | e2204921f8c6c651f6e8608793154da09c5c33fc (patch) | |
tree | 9004a84384cfa4c1e412a1e6652a3e237344ba56 /ui/message_center | |
parent | 15a86acd838be824320b0a4fb0227e46fa314699 (diff) | |
download | chromium_src-e2204921f8c6c651f6e8608793154da09c5c33fc.zip chromium_src-e2204921f8c6c651f6e8608793154da09c5c33fc.tar.gz chromium_src-e2204921f8c6c651f6e8608793154da09c5c33fc.tar.bz2 |
Marks the notification as read too if it's clicked on toast.
BUG=165576
Review URL: https://chromiumcodereview.appspot.com/11829066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r-- | ui/message_center/message_center.cc | 2 | ||||
-rw-r--r-- | ui/message_center/notification_list.cc | 10 | ||||
-rw-r--r-- | ui/message_center/notification_list.h | 6 | ||||
-rw-r--r-- | ui/message_center/notification_list_unittest.cc | 33 |
4 files changed, 34 insertions, 17 deletions
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc index 5486b22..394dab9 100644 --- a/ui/message_center/message_center.cc +++ b/ui/message_center/message_center.cc @@ -147,7 +147,7 @@ void MessageCenter::OnNotificationClicked(const std::string& id) { if (delegate_) delegate_->OnClicked(id); if (HasPopupNotifications()) { - notification_list_->MarkSinglePopupAsShown(id); + notification_list_->MarkSinglePopupAsShown(id, true); NotifyMessageCenterChanged(false); } } diff --git a/ui/message_center/notification_list.cc b/ui/message_center/notification_list.cc index 6cbaa70..ac447fc 100644 --- a/ui/message_center/notification_list.cc +++ b/ui/message_center/notification_list.cc @@ -261,7 +261,8 @@ void NotificationList::MarkPopupsAsShown(int priority) { iter->shown_as_popup = true; } -void NotificationList::MarkSinglePopupAsShown(const std::string& id) { +void NotificationList::MarkSinglePopupAsShown( + const std::string& id, bool mark_notification_as_read) { Notifications::iterator iter; if (!GetNotification(id, &iter)) return; @@ -269,9 +270,14 @@ void NotificationList::MarkSinglePopupAsShown(const std::string& id) { if (iter->shown_as_popup) return; - // Moves the item to the beginning of the already-shown items. + // Moves the item to the beginning of the already-shown items. Notification notification = *iter; notification.shown_as_popup = true; + if (mark_notification_as_read) { + --unread_count_; + notification.is_read = true; + } + notifications_[notification.priority].erase(iter); for (Notifications::iterator iter2 = notifications_[notification.priority].begin(); diff --git a/ui/message_center/notification_list.h b/ui/message_center/notification_list.h index 96368bb..83bc975 100644 --- a/ui/message_center/notification_list.h +++ b/ui/message_center/notification_list.h @@ -149,8 +149,10 @@ class MESSAGE_CENTER_EXPORT NotificationList { // Marks the popups for the |priority| as shown. void MarkPopupsAsShown(int priority); - // Marks a specific popup item as shown. - void MarkSinglePopupAsShown(const std::string& id); + // Marks a specific popup item as shown. Set |mark_notification_as_read| to + // true in case marking the notification as read too. + void MarkSinglePopupAsShown(const std::string& id, + bool mark_notification_as_read); bool quiet_mode() const { return quiet_mode_; } diff --git a/ui/message_center/notification_list_unittest.cc b/ui/message_center/notification_list_unittest.cc index 97f663a..72d6d8c 100644 --- a/ui/message_center/notification_list_unittest.cc +++ b/ui/message_center/notification_list_unittest.cc @@ -347,11 +347,16 @@ TEST_F(NotificationListTest, NotificationOrderAndPriority) { TEST_F(NotificationListTest, MarkSinglePopupAsShown) { std::string id1 = AddNotification(NULL); std::string id2 = AddNotification(NULL); - ASSERT_EQ(2u, notification_list()->NotificationCount()); - ASSERT_EQ(2u, GetPopupCounts()); + std::string id3 = AddNotification(NULL); + ASSERT_EQ(3u, notification_list()->NotificationCount()); + ASSERT_EQ(std::min(static_cast<size_t>(3u), + NotificationList::kMaxVisiblePopupNotifications), + GetPopupCounts()); - notification_list()->MarkSinglePopupAsShown(id2); - EXPECT_EQ(2u, notification_list()->NotificationCount()); + notification_list()->MarkSinglePopupAsShown(id2, true); + notification_list()->MarkSinglePopupAsShown(id3, false); + EXPECT_EQ(3u, notification_list()->NotificationCount()); + EXPECT_EQ(2u, notification_list()->unread_count()); EXPECT_EQ(1u, GetPopupCounts()); NotificationList::Notifications popups; notification_list()->GetPopupNotifications(&popups); @@ -365,33 +370,37 @@ TEST_F(NotificationListTest, MarkSinglePopupAsShown) { NotificationList::Notifications::const_iterator iter = notifications.begin(); EXPECT_EQ(id1, iter->id); iter++; + EXPECT_EQ(id3, iter->id); + iter++; EXPECT_EQ(id2, iter->id); // Trickier scenario. notification_list()->MarkPopupsAsShown(ui::notifications::DEFAULT_PRIORITY); - std::string id3 = AddNotification(NULL); std::string id4 = AddNotification(NULL); std::string id5 = AddNotification(NULL); - notification_list()->MarkSinglePopupAsShown(id4); + std::string id6 = AddNotification(NULL); + notification_list()->MarkSinglePopupAsShown(id5, true); popups.clear(); notifications.clear(); notification_list()->GetPopupNotifications(&popups); notification_list()->GetNotifications(¬ifications); EXPECT_EQ(2u, popups.size()); iter = popups.begin(); - EXPECT_EQ(id5, iter->id); + EXPECT_EQ(id6, iter->id); iter++; - EXPECT_EQ(id3, iter->id); - EXPECT_EQ(5u, notifications.size()); + EXPECT_EQ(id4, iter->id); + EXPECT_EQ(6u, notifications.size()); iter = notifications.begin(); - EXPECT_EQ(id5, iter->id); - iter++; - EXPECT_EQ(id3, iter->id); + EXPECT_EQ(id6, iter->id); iter++; EXPECT_EQ(id4, iter->id); iter++; + EXPECT_EQ(id5, iter->id); + iter++; EXPECT_EQ(id1, iter->id); iter++; + EXPECT_EQ(id3, iter->id); + iter++; EXPECT_EQ(id2, iter->id); } |