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

Side by Side Diff: ui/message_center/views/message_popup_bubble.cc

Issue 12326091: Made notification center notifications collapsed and expandable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, rebase, and rebase again! Created 7 years, 9 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_popup_bubble.h" 5 #include "ui/message_center/views/message_popup_bubble.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "ui/message_center/message_center_constants.h" 9 #include "ui/message_center/message_center_constants.h"
10 #include "ui/message_center/notification.h" 10 #include "ui/message_center/notification.h"
11 #include "ui/message_center/notification_change_observer.h"
11 #include "ui/message_center/notification_types.h" 12 #include "ui/message_center/notification_types.h"
12 #include "ui/message_center/views/message_view.h" 13 #include "ui/message_center/views/message_view.h"
13 #include "ui/message_center/views/notification_view.h" 14 #include "ui/message_center/views/notification_view.h"
14 #include "ui/views/bubble/tray_bubble_view.h" 15 #include "ui/views/bubble/tray_bubble_view.h"
15 #include "ui/views/layout/box_layout.h" 16 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/view.h" 17 #include "ui/views/view.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 namespace message_center { 20 namespace message_center {
20 21
21 // Popup notifications contents. 22 // Popup notifications contents.
22 class PopupBubbleContentsView : public views::View { 23 class PopupBubbleContentsView : public views::View {
23 public: 24 public:
24 explicit PopupBubbleContentsView(NotificationList::Delegate* list_delegate); 25 explicit PopupBubbleContentsView(NotificationChangeObserver* observer);
25 26
26 void Update(const NotificationList::PopupNotifications& popup_notifications); 27 void Update(const NotificationList::PopupNotifications& popup_notifications);
27 28
28 size_t NumMessageViews() const { 29 size_t NumMessageViews() const {
29 return content_->child_count(); 30 return content_->child_count();
30 } 31 }
31 32
32 private: 33 private:
33 NotificationList::Delegate* list_delegate_; 34 NotificationChangeObserver* observer_; // Weak reference.
34 views::View* content_; 35 views::View* content_;
35 36
36 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView); 37 DISALLOW_COPY_AND_ASSIGN(PopupBubbleContentsView);
37 }; 38 };
38 39
39 PopupBubbleContentsView::PopupBubbleContentsView( 40 PopupBubbleContentsView::PopupBubbleContentsView(
40 NotificationList::Delegate* list_delegate) 41 NotificationChangeObserver* observer)
41 : list_delegate_(list_delegate) { 42 : observer_(observer) {
42 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 43 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
43 44
44 content_ = new views::View; 45 content_ = new views::View;
45 content_->SetLayoutManager( 46 content_->SetLayoutManager(
46 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 47 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
47 AddChildView(content_); 48 AddChildView(content_);
48 49
49 if (get_use_acceleration_when_possible()) { 50 if (get_use_acceleration_when_possible()) {
50 content_->SetPaintToLayer(true); 51 content_->SetPaintToLayer(true);
51 content_->SetFillsBoundsOpaquely(false); 52 content_->SetFillsBoundsOpaquely(false);
52 content_->layer()->SetMasksToBounds(true); 53 content_->layer()->SetMasksToBounds(true);
53 } 54 }
54 } 55 }
55 56
56 void PopupBubbleContentsView::Update( 57 void PopupBubbleContentsView::Update(
57 const NotificationList::PopupNotifications& popup_notifications) { 58 const NotificationList::PopupNotifications& popup_notifications) {
58 content_->RemoveAllChildViews(true); 59 content_->RemoveAllChildViews(true);
59 for (NotificationList::PopupNotifications::const_iterator iter = 60 for (NotificationList::PopupNotifications::const_iterator iter =
60 popup_notifications.begin(); 61 popup_notifications.begin();
61 iter != popup_notifications.end(); ++iter) { 62 iter != popup_notifications.end(); ++iter) {
62 content_->AddChildView(NotificationView::Create(*(*iter), list_delegate_)); 63 // NotificationViews are expanded by default here because MessagePopupBubble
64 // hasn't been tested yet with changing subview sizes, and such changes
65 // could come if those subviews were initially collapsed and allowed to be
66 // expanded by users. TODO(dharcourt): Fix.
67 content_->AddChildView(NotificationView::Create(*(*iter), observer_, true));
63 } 68 }
64 content_->SizeToPreferredSize(); 69 content_->SizeToPreferredSize();
65 content_->InvalidateLayout(); 70 content_->InvalidateLayout();
66 Layout(); 71 Layout();
67 if (GetWidget()) 72 if (GetWidget())
68 GetWidget()->GetRootView()->SchedulePaint(); 73 GetWidget()->GetRootView()->SchedulePaint();
69 } 74 }
70 75
71 // The timer to call OnAutoClose for |notification|. 76 // The timer to call OnAutoClose for |notification|.
72 class MessagePopupBubble::AutocloseTimer { 77 class MessagePopupBubble::AutocloseTimer {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 base::Unretained(bubble_), id_)); 111 base::Unretained(bubble_), id_));
107 } 112 }
108 113
109 void MessagePopupBubble::AutocloseTimer::Suspend() { 114 void MessagePopupBubble::AutocloseTimer::Suspend() {
110 base::TimeDelta passed = base::Time::Now() - start_time_; 115 base::TimeDelta passed = base::Time::Now() - start_time_;
111 delay_ = std::max(base::TimeDelta(), delay_ - passed); 116 delay_ = std::max(base::TimeDelta(), delay_ - passed);
112 timer_.Reset(); 117 timer_.Reset();
113 } 118 }
114 119
115 // MessagePopupBubble 120 // MessagePopupBubble
116 MessagePopupBubble::MessagePopupBubble(NotificationList::Delegate* delegate) 121 MessagePopupBubble::MessagePopupBubble(MessageCenter* message_center)
117 : MessageBubbleBase(delegate), 122 : MessageBubbleBase(message_center),
118 contents_view_(NULL) { 123 contents_view_(NULL) {
119 } 124 }
120 125
121 MessagePopupBubble::~MessagePopupBubble() { 126 MessagePopupBubble::~MessagePopupBubble() {
122 STLDeleteContainerPairSecondPointers(autoclose_timers_.begin(), 127 STLDeleteContainerPairSecondPointers(autoclose_timers_.begin(),
123 autoclose_timers_.end()); 128 autoclose_timers_.end());
124 } 129 }
125 130
126 views::TrayBubbleView::InitParams MessagePopupBubble::GetInitParams( 131 views::TrayBubbleView::InitParams MessagePopupBubble::GetInitParams(
127 views::TrayBubbleView::AnchorAlignment anchor_alignment) { 132 views::TrayBubbleView::AnchorAlignment anchor_alignment) {
128 views::TrayBubbleView::InitParams init_params = 133 views::TrayBubbleView::InitParams init_params =
129 GetDefaultInitParams(anchor_alignment); 134 GetDefaultInitParams(anchor_alignment);
130 init_params.arrow_color = kBackgroundColor; 135 init_params.arrow_color = kBackgroundColor;
131 init_params.close_on_deactivate = false; 136 init_params.close_on_deactivate = false;
132 return init_params; 137 return init_params;
133 } 138 }
134 139
135 void MessagePopupBubble::InitializeContents( 140 void MessagePopupBubble::InitializeContents(
136 views::TrayBubbleView* new_bubble_view) { 141 views::TrayBubbleView* new_bubble_view) {
137 set_bubble_view(new_bubble_view); 142 set_bubble_view(new_bubble_view);
138 contents_view_ = new PopupBubbleContentsView(list_delegate()); 143 contents_view_ = new PopupBubbleContentsView(message_center());
139 bubble_view()->AddChildView(contents_view_); 144 bubble_view()->AddChildView(contents_view_);
140 UpdateBubbleView(); 145 UpdateBubbleView();
141 } 146 }
142 147
143 void MessagePopupBubble::OnBubbleViewDestroyed() { 148 void MessagePopupBubble::OnBubbleViewDestroyed() {
144 contents_view_ = NULL; 149 contents_view_ = NULL;
145 } 150 }
146 151
147 void MessagePopupBubble::UpdateBubbleView() { 152 void MessagePopupBubble::UpdateBubbleView() {
148 NotificationList::PopupNotifications popups = 153 NotificationList::PopupNotifications popups =
149 list_delegate()->GetNotificationList()->GetPopupNotifications(); 154 message_center()->notification_list()->GetPopupNotifications();
150 155
151 if (popups.size() == 0) { 156 if (popups.size() == 0) {
152 if (bubble_view()) 157 if (bubble_view())
153 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this| 158 bubble_view()->delegate()->HideBubble(bubble_view()); // deletes |this|
154 return; 159 return;
155 } 160 }
156 161
157 contents_view_->Update(popups); 162 contents_view_->Update(popups);
158 bubble_view()->Show(); 163 bubble_view()->Show();
159 bubble_view()->UpdateBubble(); 164 bubble_view()->UpdateBubble();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 198
194 void MessagePopupBubble::OnMouseExitedView() { 199 void MessagePopupBubble::OnMouseExitedView() {
195 for (std::map<std::string, AutocloseTimer*>::iterator iter = 200 for (std::map<std::string, AutocloseTimer*>::iterator iter =
196 autoclose_timers_.begin(); iter != autoclose_timers_.end(); ++iter) { 201 autoclose_timers_.begin(); iter != autoclose_timers_.end(); ++iter) {
197 iter->second->Start(); 202 iter->second->Start();
198 } 203 }
199 } 204 }
200 205
201 void MessagePopupBubble::OnAutoClose(const std::string& id) { 206 void MessagePopupBubble::OnAutoClose(const std::string& id) {
202 DeleteTimer(id); 207 DeleteTimer(id);
203 list_delegate()->GetNotificationList()->MarkSinglePopupAsShown(id, false); 208 message_center()->notification_list()->MarkSinglePopupAsShown(id, false);
204 UpdateBubbleView(); 209 UpdateBubbleView();
205 } 210 }
206 211
207 void MessagePopupBubble::DeleteTimer(const std::string& id) { 212 void MessagePopupBubble::DeleteTimer(const std::string& id) {
208 std::map<std::string, AutocloseTimer*>::iterator iter = 213 std::map<std::string, AutocloseTimer*>::iterator iter =
209 autoclose_timers_.find(id); 214 autoclose_timers_.find(id);
210 if (iter != autoclose_timers_.end()) { 215 if (iter != autoclose_timers_.end()) {
211 scoped_ptr<AutocloseTimer> release_timer(iter->second); 216 scoped_ptr<AutocloseTimer> release_timer(iter->second);
212 autoclose_timers_.erase(iter); 217 autoclose_timers_.erase(iter);
213 } 218 }
214 } 219 }
215 220
216 size_t MessagePopupBubble::NumMessageViewsForTest() const { 221 size_t MessagePopupBubble::NumMessageViewsForTest() const {
217 return contents_view_->NumMessageViews(); 222 return contents_view_->NumMessageViews();
218 } 223 }
219 224
220 } // namespace message_center 225 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_popup_bubble.h ('k') | ui/message_center/views/message_popup_collection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698