Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: ui/message_center/views/message_center_view.cc

Issue 75133006: Move knowledge about MessageCenter out of MessageView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fix Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..248432294e401490008b87a70793ca9b1f79064c 100644
--- a/ui/message_center/views/message_center_view.cc
+++ b/ui/message_center/views/message_center_view.cc
@@ -159,7 +159,8 @@ void NoNotificationMessageView::Layout() {
label_->SetBounds(0, margin, width(), text_height);
}
-// Displays a list of messages for rich notifications. It also supports
+// Displays a list of messages for rich notifications. Functions as an array of
+// MessageViews and animates them on transitions. It also supports
// repositioning.
class MessageListView : public views::View,
public views::BoundsAnimatorObserver {
@@ -168,9 +169,9 @@ class MessageListView : public views::View,
bool top_down);
virtual ~MessageListView();
- void AddNotificationAt(views::View* view, int i);
+ void AddNotificationAt(MessageView* view, int i);
void RemoveNotificationAt(int i);
- void UpdateNotificationAt(views::View* view, int i);
+ void UpdateNotificationAt(MessageView* view, int i);
void SetRepositionTarget(const gfx::Rect& target_rect);
void ResetRepositionSession();
void ClearAllNotifications(const gfx::Rect& visible_scroll_rect);
@@ -285,7 +286,7 @@ void MessageListView::Layout() {
}
}
-void MessageListView::AddNotificationAt(views::View* view, int i) {
+void MessageListView::AddNotificationAt(MessageView* view, int i) {
AddChildViewAt(view, GetActualIndex(i));
if (GetContentsBounds().IsEmpty())
return;
@@ -310,7 +311,7 @@ void MessageListView::RemoveNotificationAt(int i) {
}
}
-void MessageListView::UpdateNotificationAt(views::View* view, int i) {
+void MessageListView::UpdateNotificationAt(MessageView* view, int i) {
int actual_index = GetActualIndex(i);
views::View* child = child_at(actual_index);
if (animator_.get())
@@ -663,13 +664,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 +880,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 +888,56 @@ 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::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())
+ // Safe cast since all views in MessageListView are MessageViews.
+ static_cast<MessageView*>(
+ 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::GetVisibleNotificationById(id)
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 +946,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 +1000,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 +1008,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(
@@ -1020,7 +1028,7 @@ void MessageCenterView::NotificationsChanged() {
Layout();
}
-void MessageCenterView::SetNotificationViewForTest(views::View* view) {
+void MessageCenterView::SetNotificationViewForTest(MessageView* view) {
message_list_view_->AddNotificationAt(view, 0);
}
« no previous file with comments | « ui/message_center/views/message_center_view.h ('k') | ui/message_center/views/message_center_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698