Chromium Code Reviews| Index: ui/message_center/views/message_center_view.cc |
| diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc |
| index d54069488726a5fd10239c63399a24560a84410c..50e2e32f0f6fb92b63eef15af115344aa35dc84c 100644 |
| --- a/ui/message_center/views/message_center_view.cc |
| +++ b/ui/message_center/views/message_center_view.cc |
| @@ -663,13 +663,13 @@ void MessageCenterView::SetNotifications( |
| if (is_closing_) |
| return; |
| - message_views_.clear(); |
| + notification_views_.clear(); |
| int index = 0; |
| for (NotificationList::Notifications::const_iterator iter = |
| notifications.begin(); iter != notifications.end(); |
| ++iter, ++index) { |
| AddNotificationAt(*(*iter), index); |
| - if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| + if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| break; |
| } |
| NotificationsChanged(); |
| @@ -879,7 +879,7 @@ void MessageCenterView::OnNotificationAdded(const std::string& id) { |
| AddNotificationAt(*(*iter), index); |
| break; |
| } |
| - if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| + if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| break; |
| } |
| NotificationsChanged(); |
| @@ -887,49 +887,55 @@ void MessageCenterView::OnNotificationAdded(const std::string& id) { |
| void MessageCenterView::OnNotificationRemoved(const std::string& id, |
| bool by_user) { |
| - for (size_t i = 0; i < message_views_.size(); ++i) { |
| - if (message_views_[i]->notification_id() == id) { |
| - if (by_user) { |
| - message_list_view_->SetRepositionTarget(message_views_[i]->bounds()); |
| - // Moves the keyboard focus to the next notification if the removed |
| - // notification is focused so that the user can dismiss notifications |
| - // without re-focusing by tab key. |
| - if (message_views_.size() > 1) { |
| - views::View* focused_view = GetFocusManager()->GetFocusedView(); |
| - if (message_views_[i]->IsCloseButtonFocused() || |
| - focused_view == message_views_[i]) { |
| - size_t next_index = i + 1; |
| - if (next_index >= message_views_.size()) |
| - next_index = message_views_.size() - 2; |
| - if (focused_view == message_views_[i]) |
| - message_views_[next_index]->RequestFocus(); |
| - else |
| - message_views_[next_index]->RequestFocusOnCloseButton(); |
| - } |
| - } |
| + NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); |
| + if (view_iter == notification_views_.end()) |
| + return; |
| + NotificationView* view = view_iter->second; |
| + int index = message_list_view_->GetIndexOf(view); |
| + if (by_user) { |
| + message_list_view_->SetRepositionTarget(view->bounds()); |
| + // Moves the keyboard focus to the next notification if the removed |
| + // notification is focused so that the user can dismiss notifications |
| + // without re-focusing by tab key. |
| + if (view->IsCloseButtonFocused() || |
| + view == GetFocusManager()->GetFocusedView()) { |
| + views::View* next_focused_view = NULL; |
| + if (message_list_view_->child_count() > index + 1) |
| + next_focused_view = message_list_view_->child_at(index + 1); |
| + else if (index > 0) |
| + next_focused_view = message_list_view_->child_at(index - 1); |
| + |
| + if (next_focused_view) { |
| + if (view->IsCloseButtonFocused()) |
| + static_cast<MessageView*>( |
|
dewittj
2013/11/22 00:33:55
Can we document somewhere that this depends on all
Dmitry Titov
2013/11/22 01:13:51
I've changed the methods on MessageListView to acc
|
| + next_focused_view)->RequestFocusOnCloseButton(); |
| + else |
| + next_focused_view->RequestFocus(); |
| } |
| - message_list_view_->RemoveNotificationAt(i); |
| - message_views_.erase(message_views_.begin() + i); |
| - NotificationsChanged(); |
| - break; |
| } |
| } |
| + message_list_view_->RemoveNotificationAt(index); |
| + notification_views_.erase(view_iter); |
| + NotificationsChanged(); |
| } |
| void MessageCenterView::OnNotificationUpdated(const std::string& id) { |
| + NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); |
| + if (view_iter == notification_views_.end()) |
| + return; |
| + NotificationView* view = view_iter->second; |
| + size_t index = message_list_view_->GetIndexOf(view); |
| + DCHECK(index >= 0); |
| + // TODO(dimich): add MessageCenter::GetNotificationById(id) |
|
dewittj
2013/11/22 00:33:55
GetVisibleNotificationById?
Dmitry Titov
2013/11/22 01:13:51
Done.
|
| const NotificationList::Notifications& notifications = |
| message_center_->GetVisibleNotifications(); |
| - size_t index = 0; |
| for (NotificationList::Notifications::const_iterator iter = |
| - notifications.begin(); |
| - iter != notifications.end() && index < message_views_.size(); |
| - ++iter, ++index) { |
| - DCHECK((*iter)->id() == message_views_[index]->notification_id()); |
| + notifications.begin(); iter != notifications.end(); ++iter) { |
| if ((*iter)->id() == id) { |
| bool expanded = true; |
| if (IsExperimentalNotificationUIEnabled()) |
| expanded = (*iter)->is_expanded(); |
| - MessageView* view = |
| + NotificationView* view = |
| NotificationView::Create(*(*iter), |
| message_center_, |
| tray_, |
| @@ -938,7 +944,7 @@ void MessageCenterView::OnNotificationUpdated(const std::string& id) { |
| // notification. |
| view->set_scroller(scroller_); |
| message_list_view_->UpdateNotificationAt(view, index); |
| - message_views_[index] = view; |
| + notification_views_[id] = view; |
| NotificationsChanged(); |
| break; |
| } |
| @@ -992,7 +998,7 @@ void MessageCenterView::AddNotificationAt(const Notification& notification, |
| bool expanded = true; |
| if (IsExperimentalNotificationUIEnabled()) |
| expanded = notification.is_expanded(); |
| - MessageView* view = |
| + NotificationView* view = |
| NotificationView::Create(notification, |
| message_center_, |
| tray_, |
| @@ -1000,13 +1006,13 @@ void MessageCenterView::AddNotificationAt(const Notification& notification, |
| false); // Not creating a top-level |
| // notification. |
| view->set_scroller(scroller_); |
| - message_views_.insert(message_views_.begin() + index, view); |
| + notification_views_[notification.id()] = view; |
| message_list_view_->AddNotificationAt(view, index); |
| message_center_->DisplayedNotification(notification.id()); |
| } |
| void MessageCenterView::NotificationsChanged() { |
| - bool no_message_views = message_views_.empty(); |
| + bool no_message_views = notification_views_.empty(); |
| // All the children of this view are owned by |this|. |
| scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false); |
| scroller_->contents()->AddChildView( |