| OLD | NEW |
| 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 | 835 |
| 836 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { | 836 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { |
| 837 if (close_all_button_) | 837 if (close_all_button_) |
| 838 close_all_button_->SetVisible(visible); | 838 close_all_button_->SetVisible(visible); |
| 839 } | 839 } |
| 840 | 840 |
| 841 // MessageCenterView /////////////////////////////////////////////////////////// | 841 // MessageCenterView /////////////////////////////////////////////////////////// |
| 842 | 842 |
| 843 MessageCenterView::MessageCenterView(MessageCenter* message_center, | 843 MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| 844 MessageCenterTray* tray, | 844 MessageCenterTray* tray, |
| 845 int max_height, | |
| 846 bool initially_settings_visible) | 845 bool initially_settings_visible) |
| 847 : message_center_(message_center), | 846 : message_center_(message_center), |
| 848 tray_(tray), | 847 tray_(tray), |
| 849 settings_visible_(initially_settings_visible) { | 848 settings_visible_(initially_settings_visible) { |
| 849 } |
| 850 |
| 851 MessageCenterView::~MessageCenterView() { |
| 852 message_center_->RemoveObserver(this); |
| 853 } |
| 854 |
| 855 void MessageCenterView::Init(int max_height) { |
| 850 message_center_->AddObserver(this); | 856 message_center_->AddObserver(this); |
| 851 set_notify_enter_exit_on_child(true); | 857 set_notify_enter_exit_on_child(true); |
| 852 set_background(views::Background::CreateSolidBackground( | 858 set_background(views::Background::CreateSolidBackground( |
| 853 kMessageCenterBackgroundColor)); | 859 kMessageCenterBackgroundColor)); |
| 854 | 860 |
| 855 if (IsRichNotificationEnabled()) | 861 if (IsRichNotificationEnabled()) |
| 856 button_bar_ = new RichMessageCenterButtonBar(this, message_center); | 862 button_bar_ = new RichMessageCenterButtonBar(this, message_center_); |
| 857 else | 863 else |
| 858 button_bar_ = new PoorMessageCenterButtonBar(this, message_center); | 864 button_bar_ = new PoorMessageCenterButtonBar(this, message_center_); |
| 859 | 865 |
| 860 const int button_height = button_bar_->GetPreferredSize().height(); | 866 const int button_height = button_bar_->GetPreferredSize().height(); |
| 861 scroller_ = new BoundedScrollView(kMinScrollViewHeight, | 867 scroller_ = new BoundedScrollView(kMinScrollViewHeight, |
| 862 max_height - button_height); | 868 max_height - button_height); |
| 863 | 869 |
| 864 if (get_use_acceleration_when_possible()) { | 870 if (get_use_acceleration_when_possible()) { |
| 865 scroller_->SetPaintToLayer(true); | 871 scroller_->SetPaintToLayer(true); |
| 866 scroller_->SetFillsBoundsOpaquely(false); | 872 scroller_->SetFillsBoundsOpaquely(false); |
| 867 scroller_->layer()->SetMasksToBounds(true); | 873 scroller_->layer()->SetMasksToBounds(true); |
| 868 } | 874 } |
| 869 | 875 |
| 870 message_list_view_ = IsRichNotificationEnabled() ? | 876 message_list_view_ = IsRichNotificationEnabled() ? |
| 871 new RichMessageListView(this) : new MessageListView(this); | 877 new RichMessageListView(this) : new MessageListView(this); |
| 872 no_notifications_message_view_ = new NoNotificationMessageView(); | 878 no_notifications_message_view_ = new NoNotificationMessageView(); |
| 873 // Set the default visibility to false, otherwise the notification has slide | 879 // Set the default visibility to false, otherwise the notification has slide |
| 874 // in animation when the center is shown. | 880 // in animation when the center is shown. |
| 875 no_notifications_message_view_->SetVisible(false); | 881 no_notifications_message_view_->SetVisible(false); |
| 876 message_list_view_->AddChildView(no_notifications_message_view_); | 882 message_list_view_->AddChildView(no_notifications_message_view_); |
| 877 scroller_->SetContents(message_list_view_); | 883 scroller_->SetContents(message_list_view_); |
| 878 | 884 |
| 879 settings_view_ = new NotifierSettingsView( | 885 settings_view_ = new NotifierSettingsView( |
| 880 message_center_->GetNotifierSettingsProvider()); | 886 message_center_->GetNotifierSettingsProvider()); |
| 881 | 887 |
| 882 if (initially_settings_visible) | 888 if (settings_visible_) |
| 883 scroller_->SetVisible(false); | 889 scroller_->SetVisible(false); |
| 884 else | 890 else |
| 885 settings_view_->SetVisible(false); | 891 settings_view_->SetVisible(false); |
| 886 | 892 |
| 887 AddChildView(scroller_); | 893 AddChildView(scroller_); |
| 888 AddChildView(settings_view_); | 894 AddChildView(settings_view_); |
| 889 AddChildView(button_bar_); | 895 AddChildView(button_bar_); |
| 890 } | 896 } |
| 891 | 897 |
| 892 MessageCenterView::~MessageCenterView() { | |
| 893 message_center_->RemoveObserver(this); | |
| 894 } | |
| 895 | |
| 896 void MessageCenterView::SetNotifications( | 898 void MessageCenterView::SetNotifications( |
| 897 const NotificationList::Notifications& notifications) { | 899 const NotificationList::Notifications& notifications) { |
| 898 message_views_.clear(); | 900 message_views_.clear(); |
| 899 int index = 0; | 901 int index = 0; |
| 900 for (NotificationList::Notifications::const_iterator iter = | 902 for (NotificationList::Notifications::const_iterator iter = |
| 901 notifications.begin(); iter != notifications.end(); | 903 notifications.begin(); iter != notifications.end(); |
| 902 ++iter, ++index) { | 904 ++iter, ++index) { |
| 903 AddNotificationAt(*(*iter), index); | 905 AddNotificationAt(*(*iter), index); |
| 904 if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) | 906 if (message_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| 905 break; | 907 break; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 view->set_scroller(scroller_); | 1126 view->set_scroller(scroller_); |
| 1125 message_list_view_->UpdateNotificationAt(view, index); | 1127 message_list_view_->UpdateNotificationAt(view, index); |
| 1126 message_views_[index] = view; | 1128 message_views_[index] = view; |
| 1127 NotificationsChanged(); | 1129 NotificationsChanged(); |
| 1128 break; | 1130 break; |
| 1129 } | 1131 } |
| 1130 } | 1132 } |
| 1131 } | 1133 } |
| 1132 | 1134 |
| 1133 void MessageCenterView::AnimationEnded(const ui::Animation* animation) { | 1135 void MessageCenterView::AnimationEnded(const ui::Animation* animation) { |
| 1134 DCHECK_EQ(animation, settings_transition_animation_.get()); | 1136 if (animation == settings_transition_animation_.get()) { |
| 1135 | 1137 source_view_->SetVisible(false); |
| 1136 source_view_->SetVisible(false); | 1138 target_view_->SetVisible(true); |
| 1137 target_view_->SetVisible(true); | 1139 if (source_view_->layer()) |
| 1138 if (source_view_->layer()) | 1140 source_view_->layer()->SetOpacity(1.0); |
| 1139 source_view_->layer()->SetOpacity(1.0); | 1141 if (target_view_->layer()) |
| 1140 if (target_view_->layer()) | 1142 target_view_->layer()->SetOpacity(1.0); |
| 1141 target_view_->layer()->SetOpacity(1.0); | 1143 settings_transition_animation_.reset(); |
| 1142 settings_transition_animation_.reset(); | 1144 PreferredSizeChanged(); |
| 1143 PreferredSizeChanged(); | 1145 Layout(); |
| 1144 Layout(); | 1146 } |
| 1145 } | 1147 } |
| 1146 | 1148 |
| 1147 void MessageCenterView::AnimationProgressed(const ui::Animation* animation) { | 1149 void MessageCenterView::AnimationProgressed(const ui::Animation* animation) { |
| 1148 DCHECK_EQ(animation, settings_transition_animation_.get()); | 1150 if (animation == settings_transition_animation_.get()) { |
| 1149 PreferredSizeChanged(); | 1151 PreferredSizeChanged(); |
| 1150 if (settings_transition_animation_->current_part_index() == 1 && | 1152 if (settings_transition_animation_->current_part_index() == 1 && |
| 1151 source_view_->layer()) { | 1153 source_view_->layer()) { |
| 1152 source_view_->layer()->SetOpacity( | 1154 source_view_->layer()->SetOpacity( |
| 1153 1.0 - settings_transition_animation_->GetCurrentValue()); | 1155 1.0 - settings_transition_animation_->GetCurrentValue()); |
| 1154 SchedulePaint(); | 1156 SchedulePaint(); |
| 1155 } else if (settings_transition_animation_->current_part_index() == 2 && | 1157 } else if (settings_transition_animation_->current_part_index() == 2 && |
| 1156 target_view_->layer()) { | 1158 target_view_->layer()) { |
| 1157 target_view_->layer()->SetOpacity( | 1159 target_view_->layer()->SetOpacity( |
| 1158 settings_transition_animation_->GetCurrentValue()); | 1160 settings_transition_animation_->GetCurrentValue()); |
| 1159 SchedulePaint(); | 1161 SchedulePaint(); |
| 1162 } |
| 1160 } | 1163 } |
| 1161 } | 1164 } |
| 1162 | 1165 |
| 1163 void MessageCenterView::AnimationCanceled(const ui::Animation* animation) { | 1166 void MessageCenterView::AnimationCanceled(const ui::Animation* animation) { |
| 1164 DCHECK_EQ(animation, settings_transition_animation_.get()); | 1167 DCHECK_EQ(animation, settings_transition_animation_.get()); |
| 1165 AnimationEnded(animation); | 1168 AnimationEnded(animation); |
| 1166 } | 1169 } |
| 1167 | 1170 |
| 1168 void MessageCenterView::AddNotificationAt(const Notification& notification, | 1171 void MessageCenterView::AddNotificationAt(const Notification& notification, |
| 1169 int index) { | 1172 int index) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1195 scroller_->InvalidateLayout(); | 1198 scroller_->InvalidateLayout(); |
| 1196 PreferredSizeChanged(); | 1199 PreferredSizeChanged(); |
| 1197 Layout(); | 1200 Layout(); |
| 1198 } | 1201 } |
| 1199 | 1202 |
| 1200 void MessageCenterView::SetNotificationViewForTest(views::View* view) { | 1203 void MessageCenterView::SetNotificationViewForTest(views::View* view) { |
| 1201 message_list_view_->AddNotificationAt(view, 0); | 1204 message_list_view_->AddNotificationAt(view, 0); |
| 1202 } | 1205 } |
| 1203 | 1206 |
| 1204 } // namespace message_center | 1207 } // namespace message_center |
| OLD | NEW |