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

Side by Side 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: remover types 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/message_center/views/message_center_view.h" 5 #include "ui/message_center/views/message_center_view.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 MessageCenterView::~MessageCenterView() { 656 MessageCenterView::~MessageCenterView() {
657 if (!is_closing_) 657 if (!is_closing_)
658 message_center_->RemoveObserver(this); 658 message_center_->RemoveObserver(this);
659 } 659 }
660 660
661 void MessageCenterView::SetNotifications( 661 void MessageCenterView::SetNotifications(
662 const NotificationList::Notifications& notifications) { 662 const NotificationList::Notifications& notifications) {
663 if (is_closing_) 663 if (is_closing_)
664 return; 664 return;
665 665
666 message_views_.clear(); 666 notification_views_.clear();
667 int index = 0; 667 int index = 0;
668 for (NotificationList::Notifications::const_iterator iter = 668 for (NotificationList::Notifications::const_iterator iter =
669 notifications.begin(); iter != notifications.end(); 669 notifications.begin(); iter != notifications.end();
670 ++iter, ++index) { 670 ++iter, ++index) {
671 AddNotificationAt(*(*iter), index); 671 AddNotificationAt(*(*iter), index);
672 if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) 672 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
673 break; 673 break;
674 } 674 }
675 NotificationsChanged(); 675 NotificationsChanged();
676 scroller_->RequestFocus(); 676 scroller_->RequestFocus();
677 } 677 }
678 678
679 void MessageCenterView::SetSettingsVisible(bool visible) { 679 void MessageCenterView::SetSettingsVisible(bool visible) {
680 if (is_closing_) 680 if (is_closing_)
681 return; 681 return;
682 682
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 int index = 0; 872 int index = 0;
873 const NotificationList::Notifications& notifications = 873 const NotificationList::Notifications& notifications =
874 message_center_->GetVisibleNotifications(); 874 message_center_->GetVisibleNotifications();
875 for (NotificationList::Notifications::const_iterator iter = 875 for (NotificationList::Notifications::const_iterator iter =
876 notifications.begin(); iter != notifications.end(); 876 notifications.begin(); iter != notifications.end();
877 ++iter, ++index) { 877 ++iter, ++index) {
878 if ((*iter)->id() == id) { 878 if ((*iter)->id() == id) {
879 AddNotificationAt(*(*iter), index); 879 AddNotificationAt(*(*iter), index);
880 break; 880 break;
881 } 881 }
882 if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) 882 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
883 break; 883 break;
884 } 884 }
885 NotificationsChanged(); 885 NotificationsChanged();
886 } 886 }
887 887
888 void MessageCenterView::OnNotificationRemoved(const std::string& id, 888 void MessageCenterView::OnNotificationRemoved(const std::string& id,
889 bool by_user) { 889 bool by_user) {
890 for (size_t i = 0; i < message_views_.size(); ++i) { 890 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
891 if (message_views_[i]->notification_id() == id) { 891 if (view_iter == notification_views_.end())
892 if (by_user) { 892 return;
893 message_list_view_->SetRepositionTarget(message_views_[i]->bounds()); 893 NotificationView* view = view_iter->second;
894 // Moves the keyboard focus to the next notification if the removed 894 int index = message_list_view_->GetIndexOf(view);
895 // notification is focused so that the user can dismiss notifications 895 if (by_user) {
896 // without re-focusing by tab key. 896 message_list_view_->SetRepositionTarget(view->bounds());
897 if (message_views_.size() > 1) { 897 // Moves the keyboard focus to the next notification if the removed
898 views::View* focused_view = GetFocusManager()->GetFocusedView(); 898 // notification is focused so that the user can dismiss notifications
899 if (message_views_[i]->IsCloseButtonFocused() || 899 // without re-focusing by tab key.
900 focused_view == message_views_[i]) { 900 if (view->IsCloseButtonFocused() ||
901 size_t next_index = i + 1; 901 view == GetFocusManager()->GetFocusedView()) {
902 if (next_index >= message_views_.size()) 902 views::View* next_focused_view = NULL;
903 next_index = message_views_.size() - 2; 903 if (message_list_view_->child_count() > index + 1)
904 if (focused_view == message_views_[i]) 904 next_focused_view = message_list_view_->child_at(index + 1);
905 message_views_[next_index]->RequestFocus(); 905 else if (index > 0)
906 else 906 next_focused_view = message_list_view_->child_at(index - 1);
907 message_views_[next_index]->RequestFocusOnCloseButton(); 907
908 } 908 if (next_focused_view) {
909 } 909 if (view->IsCloseButtonFocused())
910 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
911 next_focused_view)->RequestFocusOnCloseButton();
912 else
913 next_focused_view->RequestFocus();
910 } 914 }
911 message_list_view_->RemoveNotificationAt(i);
912 message_views_.erase(message_views_.begin() + i);
913 NotificationsChanged();
914 break;
915 } 915 }
916 } 916 }
917 message_list_view_->RemoveNotificationAt(index);
918 notification_views_.erase(view_iter);
919 NotificationsChanged();
917 } 920 }
918 921
919 void MessageCenterView::OnNotificationUpdated(const std::string& id) { 922 void MessageCenterView::OnNotificationUpdated(const std::string& id) {
923 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
924 if (view_iter == notification_views_.end())
925 return;
926 NotificationView* view = view_iter->second;
927 size_t index = message_list_view_->GetIndexOf(view);
928 DCHECK(index >= 0);
929 // TODO(dimich): add MessageCenter::GetNotificationById(id)
dewittj 2013/11/22 00:33:55 GetVisibleNotificationById?
Dmitry Titov 2013/11/22 01:13:51 Done.
920 const NotificationList::Notifications& notifications = 930 const NotificationList::Notifications& notifications =
921 message_center_->GetVisibleNotifications(); 931 message_center_->GetVisibleNotifications();
922 size_t index = 0;
923 for (NotificationList::Notifications::const_iterator iter = 932 for (NotificationList::Notifications::const_iterator iter =
924 notifications.begin(); 933 notifications.begin(); iter != notifications.end(); ++iter) {
925 iter != notifications.end() && index < message_views_.size();
926 ++iter, ++index) {
927 DCHECK((*iter)->id() == message_views_[index]->notification_id());
928 if ((*iter)->id() == id) { 934 if ((*iter)->id() == id) {
929 bool expanded = true; 935 bool expanded = true;
930 if (IsExperimentalNotificationUIEnabled()) 936 if (IsExperimentalNotificationUIEnabled())
931 expanded = (*iter)->is_expanded(); 937 expanded = (*iter)->is_expanded();
932 MessageView* view = 938 NotificationView* view =
933 NotificationView::Create(*(*iter), 939 NotificationView::Create(*(*iter),
934 message_center_, 940 message_center_,
935 tray_, 941 tray_,
936 expanded, 942 expanded,
937 false); // Not creating a top-level 943 false); // Not creating a top-level
938 // notification. 944 // notification.
939 view->set_scroller(scroller_); 945 view->set_scroller(scroller_);
940 message_list_view_->UpdateNotificationAt(view, index); 946 message_list_view_->UpdateNotificationAt(view, index);
941 message_views_[index] = view; 947 notification_views_[id] = view;
942 NotificationsChanged(); 948 NotificationsChanged();
943 break; 949 break;
944 } 950 }
945 } 951 }
946 } 952 }
947 953
948 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) { 954 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) {
949 DCHECK_EQ(animation, settings_transition_animation_.get()); 955 DCHECK_EQ(animation, settings_transition_animation_.get());
950 956
951 Visibility visibility = target_view_ == settings_view_ 957 Visibility visibility = target_view_ == settings_view_
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 AnimationEnded(animation); 991 AnimationEnded(animation);
986 } 992 }
987 993
988 void MessageCenterView::AddNotificationAt(const Notification& notification, 994 void MessageCenterView::AddNotificationAt(const Notification& notification,
989 int index) { 995 int index) {
990 // NotificationViews are expanded by default here until 996 // NotificationViews are expanded by default here until
991 // http://crbug.com/217902 is fixed. TODO(dharcourt): Fix. 997 // http://crbug.com/217902 is fixed. TODO(dharcourt): Fix.
992 bool expanded = true; 998 bool expanded = true;
993 if (IsExperimentalNotificationUIEnabled()) 999 if (IsExperimentalNotificationUIEnabled())
994 expanded = notification.is_expanded(); 1000 expanded = notification.is_expanded();
995 MessageView* view = 1001 NotificationView* view =
996 NotificationView::Create(notification, 1002 NotificationView::Create(notification,
997 message_center_, 1003 message_center_,
998 tray_, 1004 tray_,
999 expanded, 1005 expanded,
1000 false); // Not creating a top-level 1006 false); // Not creating a top-level
1001 // notification. 1007 // notification.
1002 view->set_scroller(scroller_); 1008 view->set_scroller(scroller_);
1003 message_views_.insert(message_views_.begin() + index, view); 1009 notification_views_[notification.id()] = view;
1004 message_list_view_->AddNotificationAt(view, index); 1010 message_list_view_->AddNotificationAt(view, index);
1005 message_center_->DisplayedNotification(notification.id()); 1011 message_center_->DisplayedNotification(notification.id());
1006 } 1012 }
1007 1013
1008 void MessageCenterView::NotificationsChanged() { 1014 void MessageCenterView::NotificationsChanged() {
1009 bool no_message_views = message_views_.empty(); 1015 bool no_message_views = notification_views_.empty();
1010 // All the children of this view are owned by |this|. 1016 // All the children of this view are owned by |this|.
1011 scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false); 1017 scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false);
1012 scroller_->contents()->AddChildView( 1018 scroller_->contents()->AddChildView(
1013 no_message_views ? empty_list_view_.get() : message_list_view_.get()); 1019 no_message_views ? empty_list_view_.get() : message_list_view_.get());
1014 1020
1015 button_bar_->SetCloseAllButtonEnabled(!no_message_views); 1021 button_bar_->SetCloseAllButtonEnabled(!no_message_views);
1016 scroller_->set_focusable(!no_message_views); 1022 scroller_->set_focusable(!no_message_views);
1017 1023
1018 scroller_->InvalidateLayout(); 1024 scroller_->InvalidateLayout();
1019 PreferredSizeChanged(); 1025 PreferredSizeChanged();
1020 Layout(); 1026 Layout();
1021 } 1027 }
1022 1028
1023 void MessageCenterView::SetNotificationViewForTest(views::View* view) { 1029 void MessageCenterView::SetNotificationViewForTest(views::View* view) {
1024 message_list_view_->AddNotificationAt(view, 0); 1030 message_list_view_->AddNotificationAt(view, 0);
1025 } 1031 }
1026 1032
1027 } // namespace message_center 1033 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698