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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // repositioning. | 106 // repositioning. |
107 class MessageListView : public views::View, | 107 class MessageListView : public views::View, |
108 public views::BoundsAnimatorObserver { | 108 public views::BoundsAnimatorObserver { |
109 public: | 109 public: |
110 explicit MessageListView(MessageCenterView* message_center_view, | 110 explicit MessageListView(MessageCenterView* message_center_view, |
111 bool top_down); | 111 bool top_down); |
112 virtual ~MessageListView(); | 112 virtual ~MessageListView(); |
113 | 113 |
114 void AddNotificationAt(MessageView* view, int i); | 114 void AddNotificationAt(MessageView* view, int i); |
115 void RemoveNotification(MessageView* view); | 115 void RemoveNotification(MessageView* view); |
116 void UpdateNotification(MessageView* view, MessageView* new_view); | 116 void UpdateNotification(MessageView* view, const Notification& notification); |
117 void SetRepositionTarget(const gfx::Rect& target_rect); | 117 void SetRepositionTarget(const gfx::Rect& target_rect); |
118 void ResetRepositionSession(); | 118 void ResetRepositionSession(); |
119 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); | 119 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); |
120 | 120 |
121 protected: | 121 protected: |
122 // Overridden from views::View. | 122 // Overridden from views::View. |
123 virtual void Layout() OVERRIDE; | 123 virtual void Layout() OVERRIDE; |
124 virtual gfx::Size GetPreferredSize() OVERRIDE; | 124 virtual gfx::Size GetPreferredSize() OVERRIDE; |
125 virtual int GetHeightForWidth(int width) OVERRIDE; | 125 virtual int GetHeightForWidth(int width) OVERRIDE; |
126 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 126 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } else { | 254 } else { |
255 if (animator_.get()) | 255 if (animator_.get()) |
256 animator_->StopAnimatingView(view); | 256 animator_->StopAnimatingView(view); |
257 delete view; | 257 delete view; |
258 } | 258 } |
259 DoUpdateIfPossible(); | 259 DoUpdateIfPossible(); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 void MessageListView::UpdateNotification(MessageView* view, | 263 void MessageListView::UpdateNotification(MessageView* view, |
264 MessageView* new_view) { | 264 const Notification& notification) { |
265 int index = GetIndexOf(view); | 265 int index = GetIndexOf(view); |
266 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. | 266 DCHECK_LE(0, index); // GetIndexOf is negative if not a child. |
267 | 267 |
268 if (animator_.get()) | 268 if (animator_.get()) |
269 animator_->StopAnimatingView(view); | 269 animator_->StopAnimatingView(view); |
270 gfx::Rect old_bounds = view->bounds(); | |
271 if (deleting_views_.find(view) != deleting_views_.end()) | 270 if (deleting_views_.find(view) != deleting_views_.end()) |
272 deleting_views_.erase(view); | 271 deleting_views_.erase(view); |
273 if (deleted_when_done_.find(view) != deleted_when_done_.end()) | 272 if (deleted_when_done_.find(view) != deleted_when_done_.end()) |
274 deleted_when_done_.erase(view); | 273 deleted_when_done_.erase(view); |
275 delete view; | 274 view->UpdateWithNotification(notification); |
276 AddChildViewAt(new_view, index); | |
277 new_view->SetBounds(old_bounds.x(), | |
278 old_bounds.y(), | |
279 old_bounds.width(), | |
280 new_view->GetHeightForWidth(old_bounds.width())); | |
281 DoUpdateIfPossible(); | 275 DoUpdateIfPossible(); |
282 } | 276 } |
283 | 277 |
284 gfx::Size MessageListView::GetPreferredSize() { | 278 gfx::Size MessageListView::GetPreferredSize() { |
285 int width = 0; | 279 int width = 0; |
286 for (int i = 0; i < child_count(); i++) { | 280 for (int i = 0; i < child_count(); i++) { |
287 views::View* child = child_at(i); | 281 views::View* child = child_at(i); |
288 if (IsValidChild(child)) | 282 if (IsValidChild(child)) |
289 width = std::max(width, child->GetPreferredSize().width()); | 283 width = std::max(width, child->GetPreferredSize().width()); |
290 } | 284 } |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); | 873 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); |
880 if (view_iter == notification_views_.end()) | 874 if (view_iter == notification_views_.end()) |
881 return; | 875 return; |
882 NotificationView* view = view_iter->second; | 876 NotificationView* view = view_iter->second; |
883 // TODO(dimich): add MessageCenter::GetVisibleNotificationById(id) | 877 // TODO(dimich): add MessageCenter::GetVisibleNotificationById(id) |
884 const NotificationList::Notifications& notifications = | 878 const NotificationList::Notifications& notifications = |
885 message_center_->GetVisibleNotifications(); | 879 message_center_->GetVisibleNotifications(); |
886 for (NotificationList::Notifications::const_iterator iter = | 880 for (NotificationList::Notifications::const_iterator iter = |
887 notifications.begin(); iter != notifications.end(); ++iter) { | 881 notifications.begin(); iter != notifications.end(); ++iter) { |
888 if ((*iter)->id() == id) { | 882 if ((*iter)->id() == id) { |
889 NotificationView* new_view = | 883 int old_width = view->width(); |
890 NotificationView::Create(this, | 884 int old_height = view->GetHeightForWidth(old_width); |
891 *(*iter), | 885 message_list_view_->UpdateNotification(view, **iter); |
892 false); // Not creating a top-level | 886 if (view->GetHeightForWidth(old_width) != old_height) |
893 // notification. | 887 NotificationsChanged(); |
894 new_view->set_context_menu_controller(context_menu_controller_.get()); | |
895 new_view->set_scroller(scroller_); | |
896 message_list_view_->UpdateNotification(view, new_view); | |
897 notification_views_[id] = new_view; | |
898 NotificationsChanged(); | |
899 break; | 888 break; |
900 } | 889 } |
901 } | 890 } |
902 } | 891 } |
903 | 892 |
904 void MessageCenterView::ClickOnNotification( | 893 void MessageCenterView::ClickOnNotification( |
905 const std::string& notification_id) { | 894 const std::string& notification_id) { |
906 message_center_->ClickOnNotification(notification_id); | 895 message_center_->ClickOnNotification(notification_id); |
907 } | 896 } |
908 | 897 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 scroller_->InvalidateLayout(); | 992 scroller_->InvalidateLayout(); |
1004 PreferredSizeChanged(); | 993 PreferredSizeChanged(); |
1005 Layout(); | 994 Layout(); |
1006 } | 995 } |
1007 | 996 |
1008 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { | 997 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { |
1009 message_list_view_->AddNotificationAt(view, 0); | 998 message_list_view_->AddNotificationAt(view, 0); |
1010 } | 999 } |
1011 | 1000 |
1012 } // namespace message_center | 1001 } // namespace message_center |
OLD | NEW |