OLD | NEW |
---|---|
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/message_center_bubble.h" | 5 #include "ui/message_center/message_center_bubble.h" |
6 | 6 |
7 #include <map> | |
8 | |
7 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
8 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
9 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/insets.h" | 14 #include "ui/gfx/insets.h" |
13 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
14 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
16 #include "ui/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 62 |
61 void set_close_all_button(views::Button* button) { | 63 void set_close_all_button(views::Button* button) { |
62 close_all_button_ = button; | 64 close_all_button_ = button; |
63 } | 65 } |
64 | 66 |
65 protected: | 67 protected: |
66 NotificationList::Delegate* list_delegate() { return list_delegate_; } | 68 NotificationList::Delegate* list_delegate() { return list_delegate_; } |
67 views::Button* close_all_button() { return close_all_button_; } | 69 views::Button* close_all_button() { return close_all_button_; } |
68 | 70 |
69 private: | 71 private: |
70 NotificationList::Delegate* list_delegate_; | 72 NotificationList::Delegate* list_delegate_; // Weak reference. |
71 views::Button* close_all_button_; | 73 views::Button* close_all_button_; |
72 | 74 |
73 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonViewBase); | 75 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonViewBase); |
74 }; | 76 }; |
75 | 77 |
76 // The view for the buttons at the bottom of the web notification tray. | 78 // The view for the buttons at the bottom of the web notification tray. |
77 class WebNotificationButtonView : public WebNotificationButtonViewBase, | 79 class WebNotificationButtonView : public WebNotificationButtonViewBase, |
78 public views::ButtonListener { | 80 public views::ButtonListener { |
79 public: | 81 public: |
80 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) | 82 explicit WebNotificationButtonView(NotificationList::Delegate* list_delegate) |
(...skipping 23 matching lines...) Expand all Loading... | |
104 close_all_button->set_request_focus_on_press(false); | 106 close_all_button->set_request_focus_on_press(false); |
105 | 107 |
106 layout->AddPaddingRow(0, 4); | 108 layout->AddPaddingRow(0, 4); |
107 layout->StartRow(0, 0); | 109 layout->StartRow(0, 0); |
108 layout->AddView(close_all_button); | 110 layout->AddView(close_all_button); |
109 set_close_all_button(close_all_button); | 111 set_close_all_button(close_all_button); |
110 } | 112 } |
111 | 113 |
112 virtual ~WebNotificationButtonView() {} | 114 virtual ~WebNotificationButtonView() {} |
113 | 115 |
114 // Overridden from ButtonListener. | 116 // Overridden from views::ButtonListener: |
115 virtual void ButtonPressed(views::Button* sender, | 117 virtual void ButtonPressed(views::Button* sender, |
116 const ui::Event& event) OVERRIDE { | 118 const ui::Event& event) OVERRIDE { |
117 if (sender == close_all_button()) | 119 if (sender == close_all_button()) |
118 list_delegate()->SendRemoveAllNotifications(true); // Action by user. | 120 list_delegate()->SendRemoveAllNotifications(true); // Action by user. |
119 } | 121 } |
120 | 122 |
121 private: | 123 private: |
122 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 124 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
123 }; | 125 }; |
124 | 126 |
125 class WebNotificationButton : public views::TextButton { | 127 class WebNotificationButton : public views::TextButton { |
126 public: | 128 public: |
127 WebNotificationButton(views::ButtonListener* listener, const string16& text) | 129 WebNotificationButton(views::ButtonListener* listener, const string16& text) |
128 : views::TextButton(listener, text) { | 130 : views::TextButton(listener, text) { |
129 set_border(views::Border::CreateEmptyBorder(0, 16, 0, 16)); | 131 set_border(views::Border::CreateEmptyBorder(0, 16, 0, 16)); |
130 set_min_height(kFooterHeight); | 132 set_min_height(kFooterHeight); |
131 SetEnabledColor(kFooterTextColor); | 133 SetEnabledColor(kFooterTextColor); |
132 SetHighlightColor(kButtonTextHighlightColor); | 134 SetHighlightColor(kButtonTextHighlightColor); |
133 SetHoverColor(kButtonTextHoverColor); | 135 SetHoverColor(kButtonTextHoverColor); |
134 } | 136 } |
135 | 137 |
136 protected: | 138 protected: |
137 // views::View overrides: | 139 // Overridden from views::View: |
dharcourt
2013/03/01 10:17:31
I took this opportunity to make the override comme
| |
138 virtual gfx::Size GetPreferredSize() OVERRIDE { | 140 virtual gfx::Size GetPreferredSize() OVERRIDE { |
139 // Returns an empty size when invisible, to trim its space in the parent's | 141 // Returns an empty size when invisible, to trim its space in the parent's |
140 // GridLayout. | 142 // GridLayout. |
141 if (!visible()) | 143 if (!visible()) |
142 return gfx::Size(); | 144 return gfx::Size(); |
143 return views::TextButton::GetPreferredSize(); | 145 return views::TextButton::GetPreferredSize(); |
144 } | 146 } |
145 | 147 |
146 virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE { | 148 virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE { |
147 // Just paint the left border. | 149 // Just paint the left border. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 201 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
200 0, views::GridLayout::USE_PREF, 0, 0); | 202 0, views::GridLayout::USE_PREF, 0, 0); |
201 layout->StartRow(0, 0); | 203 layout->StartRow(0, 0); |
202 layout->AddView(notification_label_); | 204 layout->AddView(notification_label_); |
203 layout->AddView(settings_button_); | 205 layout->AddView(settings_button_); |
204 layout->AddView(close_all_button); | 206 layout->AddView(close_all_button); |
205 set_close_all_button(close_all_button); | 207 set_close_all_button(close_all_button); |
206 } | 208 } |
207 | 209 |
208 private: | 210 private: |
209 // views::ButtonListener overrides: | 211 // Overridden from views::ButtonListener: |
210 virtual void ButtonPressed(views::Button* sender, | 212 virtual void ButtonPressed(views::Button* sender, |
211 const ui::Event& event) OVERRIDE { | 213 const ui::Event& event) OVERRIDE { |
212 if (sender == close_all_button()) | 214 if (sender == close_all_button()) |
213 list_delegate()->SendRemoveAllNotifications(true); // Action by user. | 215 list_delegate()->SendRemoveAllNotifications(true); // Action by user. |
214 else if (sender == settings_button_) | 216 else if (sender == settings_button_) |
215 list_delegate()->ShowNotificationSettingsDialog( | 217 list_delegate()->ShowNotificationSettingsDialog( |
216 GetWidget()->GetNativeView()); | 218 GetWidget()->GetNativeView()); |
217 else | 219 else |
218 NOTREACHED(); | 220 NOTREACHED(); |
219 } | 221 } |
220 | 222 |
221 views::Label* notification_label_; | 223 views::Label* notification_label_; |
222 views::Button* settings_button_; | 224 views::Button* settings_button_; |
223 | 225 |
224 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView2); | 226 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView2); |
225 }; | 227 }; |
226 | 228 |
227 // A custom scroll-view that has a specified size. | 229 // A custom scroll view whose height has a minimum and maximum value and whose |
228 class FixedSizedScrollView : public views::ScrollView { | 230 // scroll bar disappears when not needed. |
231 class BoundedScrollView : public views::ScrollView { | |
229 public: | 232 public: |
230 FixedSizedScrollView() { | 233 BoundedScrollView(int min_height, int max_height) |
234 : min_height_(min_height), | |
235 max_height_(max_height) { | |
231 set_focusable(true); | 236 set_focusable(true); |
232 set_notify_enter_exit_on_child(true); | 237 set_notify_enter_exit_on_child(true); |
233 if (IsRichNotificationEnabled()) { | 238 if (IsRichNotificationEnabled()) { |
234 set_background(views::Background::CreateSolidBackground( | 239 set_background(views::Background::CreateSolidBackground( |
235 kMessageCenterBackgroundColor)); | 240 kMessageCenterBackgroundColor)); |
236 } | 241 } |
237 } | 242 } |
238 | 243 |
239 virtual ~FixedSizedScrollView() {} | 244 virtual ~BoundedScrollView() {} |
240 | 245 |
241 void SetFixedSize(const gfx::Size& size) { | 246 // Overridden from views::View: |
242 if (fixed_size_ == size) | |
243 return; | |
244 fixed_size_ = size; | |
245 PreferredSizeChanged(); | |
246 } | |
247 | |
248 // views::View overrides. | |
249 virtual gfx::Size GetPreferredSize() OVERRIDE { | 247 virtual gfx::Size GetPreferredSize() OVERRIDE { |
250 gfx::Size size = fixed_size_.IsEmpty() ? | 248 gfx::Size size = contents()->GetPreferredSize(); |
251 contents()->GetPreferredSize() : fixed_size_; | 249 size.ClampToMin(gfx::Size(size.width(), min_height_)); |
250 size.ClampToMax(gfx::Size(size.width(), max_height_)); | |
252 gfx::Insets insets = GetInsets(); | 251 gfx::Insets insets = GetInsets(); |
253 size.Enlarge(insets.width(), insets.height()); | 252 size.Enlarge(insets.width(), insets.height()); |
254 return size; | 253 return size; |
255 } | 254 } |
256 | 255 |
257 virtual void Layout() OVERRIDE { | 256 virtual void Layout() OVERRIDE { |
258 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 257 // Lay out the view as if it will have a scroll bar. |
259 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 258 gfx::Rect content_bounds = gfx::Rect(contents()->GetPreferredSize()); |
260 contents()->SetBoundsRect(bounds); | 259 content_bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
260 contents()->SetBoundsRect(content_bounds); | |
261 views::ScrollView::Layout(); | |
261 | 262 |
262 views::ScrollView::Layout(); | 263 // But use the scroll bar space if no scroll bar is needed. |
263 if (!vertical_scroll_bar()->visible()) { | 264 if (!vertical_scroll_bar()->visible()) { |
264 gfx::Rect bounds = contents()->bounds(); | 265 content_bounds = contents()->bounds(); |
265 bounds.set_width(bounds.width() + GetScrollBarWidth()); | 266 content_bounds.set_width(content_bounds.width() + GetScrollBarWidth()); |
266 contents()->SetBoundsRect(bounds); | 267 contents()->SetBoundsRect(content_bounds); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { | 271 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE { |
271 gfx::Rect bounds = gfx::Rect(contents()->GetPreferredSize()); | 272 // Make sure any content resizing takes into account the scroll bar. |
272 bounds.set_width(std::max(0, width() - GetScrollBarWidth())); | 273 gfx::Rect content_bounds = gfx::Rect(contents()->GetPreferredSize()); |
273 contents()->SetBoundsRect(bounds); | 274 content_bounds.set_width(std::max(0, width() - GetScrollBarWidth())); |
275 contents()->SetBoundsRect(content_bounds); | |
274 } | 276 } |
275 | 277 |
276 private: | 278 private: |
277 gfx::Size fixed_size_; | 279 int min_height_; |
280 int max_height_; | |
278 | 281 |
279 DISALLOW_COPY_AND_ASSIGN(FixedSizedScrollView); | 282 DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); |
280 }; | 283 }; |
281 | 284 |
282 // Container for the messages. | 285 // Displays a list of messages. |
283 class ScrollContentView : public views::View { | 286 class MessageListView : public views::View { |
284 public: | 287 public: |
285 ScrollContentView() { | 288 MessageListView() { |
286 if (IsRichNotificationEnabled()) { | 289 if (IsRichNotificationEnabled()) { |
287 // Set the margin to 0 for the layout. BoxLayout assumes the same margin | 290 // Set the margin to 0 for the layout. BoxLayout assumes the same margin |
288 // for top and bottom, but the bottom margin here should be smaller | 291 // for top and bottom, but the bottom margin here should be smaller |
289 // because of the shadow of message view. Use an empty border instead | 292 // because of the shadow of message view. Use an empty border instead |
290 // to provide this margin. | 293 // to provide this margin. |
291 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); | 294 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); |
292 SetLayoutManager( | 295 SetLayoutManager( |
293 new views::BoxLayout(views::BoxLayout::kVertical, | 296 new views::BoxLayout(views::BoxLayout::kVertical, |
294 0, | 297 0, |
295 0, | 298 0, |
296 kMarginBetweenItems - shadow_insets.bottom())); | 299 kMarginBetweenItems - shadow_insets.bottom())); |
297 set_background(views::Background::CreateSolidBackground( | 300 set_background(views::Background::CreateSolidBackground( |
298 kMessageCenterBackgroundColor)); | 301 kMessageCenterBackgroundColor)); |
299 set_border(views::Border::CreateEmptyBorder( | 302 set_border(views::Border::CreateEmptyBorder( |
300 kMarginBetweenItems - shadow_insets.top(), /* top */ | 303 kMarginBetweenItems - shadow_insets.top(), /* top */ |
301 kMarginBetweenItems - shadow_insets.left(), /* left */ | 304 kMarginBetweenItems - shadow_insets.left(), /* left */ |
302 0, /* bottom */ | 305 0, /* bottom */ |
303 kMarginBetweenItems - shadow_insets.right() /* right */ )); | 306 kMarginBetweenItems - shadow_insets.right() /* right */ )); |
304 } else { | 307 } else { |
305 views::BoxLayout* layout = | 308 views::BoxLayout* layout = |
306 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); | 309 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); |
307 layout->set_spread_blank_space(true); | 310 layout->set_spread_blank_space(true); |
308 SetLayoutManager(layout); | 311 SetLayoutManager(layout); |
309 } | 312 } |
310 } | 313 } |
311 | 314 |
312 virtual ~ScrollContentView() { | 315 virtual ~MessageListView() { |
313 } | 316 } |
314 | 317 |
315 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
316 if (!preferred_size_.IsEmpty()) | |
317 return preferred_size_; | |
318 return views::View::GetPreferredSize(); | |
319 } | |
320 | |
321 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } | |
322 | |
323 private: | 318 private: |
324 gfx::Size preferred_size_; | 319 DISALLOW_COPY_AND_ASSIGN(MessageListView); |
325 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); | |
326 }; | 320 }; |
327 | 321 |
328 } // namespace | 322 } // namespace |
329 | 323 |
330 // Message Center contents. | 324 // View that displays the whole message center. |
331 class MessageCenterContentsView : public views::View { | 325 class MessageCenterView : public views::View { |
332 public: | 326 public: |
333 explicit MessageCenterContentsView(MessageCenterBubble* bubble, | 327 MessageCenterView(MessageCenterBubble* bubble) : bubble_(bubble) { |
334 NotificationList::Delegate* list_delegate) | |
335 : list_delegate_(list_delegate), | |
336 bubble_(bubble) { | |
337 int between_child = IsRichNotificationEnabled() ? 0 : 1; | 328 int between_child = IsRichNotificationEnabled() ? 0 : 1; |
338 SetLayoutManager( | 329 SetLayoutManager( |
339 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, between_child)); | 330 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, between_child)); |
340 | 331 |
341 scroll_content_ = new ScrollContentView; | 332 |
342 scroller_ = new FixedSizedScrollView; | 333 if (IsRichNotificationEnabled()) |
343 scroller_->SetContents(scroll_content_); | 334 button_view_ = new WebNotificationButtonView2(bubble_); |
344 AddChildView(scroller_); | 335 else |
336 button_view_ = new WebNotificationButtonView(bubble_); | |
337 | |
338 const int button_height = button_view_->GetPreferredSize().height(); | |
339 const int min_height = kMessageBubbleBaseMinHeight - button_height; | |
340 const int max_height = bubble_->max_height() - button_height; | |
341 scroller_ = new BoundedScrollView(min_height, max_height); | |
345 | 342 |
346 if (get_use_acceleration_when_possible()) { | 343 if (get_use_acceleration_when_possible()) { |
347 scroller_->SetPaintToLayer(true); | 344 scroller_->SetPaintToLayer(true); |
348 scroller_->SetFillsBoundsOpaquely(false); | 345 scroller_->SetFillsBoundsOpaquely(false); |
349 scroller_->layer()->SetMasksToBounds(true); | 346 scroller_->layer()->SetMasksToBounds(true); |
350 } | 347 } |
351 | 348 |
352 if (IsRichNotificationEnabled()) | 349 message_list_view_ = new MessageListView(); |
353 button_view_ = new WebNotificationButtonView2(list_delegate); | 350 scroller_->SetContents(message_list_view_); |
354 else | 351 |
355 button_view_ = new WebNotificationButtonView(list_delegate); | 352 AddChildView(scroller_); |
356 AddChildView(button_view_); | 353 AddChildView(button_view_); |
357 } | 354 } |
358 | 355 |
359 void FocusContents() { | 356 void FocusContents() { |
360 scroller_->RequestFocus(); | 357 scroller_->RequestFocus(); |
361 } | 358 } |
362 | 359 |
363 void Update(const NotificationList::Notifications& notifications) { | 360 void UpdateAllNotifications( |
364 scroll_content_->RemoveAllChildViews(true); | 361 const NotificationList::Notifications& notifications) { |
365 scroll_content_->set_preferred_size(gfx::Size()); | 362 RemoveAllNotifications(); |
366 size_t num_children = 0; | |
367 for (NotificationList::Notifications::const_iterator iter = | 363 for (NotificationList::Notifications::const_iterator iter = |
368 notifications.begin(); iter != notifications.end(); ++iter) { | 364 notifications.begin(); iter != notifications.end(); ++iter) { |
369 MessageView* view = NotificationView::Create(*(*iter), list_delegate_); | 365 AddNotification(*(*iter)); |
370 view->set_scroller(scroller_); | 366 if (message_views_.size() >= |
371 scroll_content_->AddChildView(view); | |
372 if (++num_children >= | |
373 NotificationList::kMaxVisibleMessageCenterNotifications) { | 367 NotificationList::kMaxVisibleMessageCenterNotifications) { |
374 break; | 368 break; |
375 } | 369 } |
376 } | 370 } |
377 if (num_children == 0) { | 371 if (message_views_.empty()) { |
378 views::Label* label = new views::Label(l10n_util::GetStringUTF16( | 372 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
379 IDS_MESSAGE_CENTER_NO_MESSAGES)); | 373 IDS_MESSAGE_CENTER_NO_MESSAGES)); |
380 label->SetFont(label->font().DeriveFont(1)); | 374 label->SetFont(label->font().DeriveFont(1)); |
381 label->SetEnabledColor(SK_ColorGRAY); | 375 label->SetEnabledColor(SK_ColorGRAY); |
382 // Set transparent background to ensure that subpixel rendering | 376 // Set transparent background to ensure that subpixel rendering |
383 // is disabled. See crbug.com/169056 | 377 // is disabled. See crbug.com/169056 |
384 label->SetBackgroundColor(kTransparentColor); | 378 label->SetBackgroundColor(kTransparentColor); |
385 scroll_content_->AddChildView(label); | 379 message_list_view_->AddChildView(label); |
386 button_view_->SetCloseAllVisible(false); | 380 button_view_->SetCloseAllVisible(false); |
387 scroller_->set_focusable(false); | 381 scroller_->set_focusable(false); |
388 } else { | 382 } else { |
389 button_view_->SetCloseAllVisible(true); | 383 button_view_->SetCloseAllVisible(true); |
390 scroller_->set_focusable(true); | 384 scroller_->set_focusable(true); |
391 } | 385 } |
392 SizeScrollContent(); | |
393 Layout(); | 386 Layout(); |
394 if (GetWidget()) | 387 } |
395 GetWidget()->GetRootView()->SchedulePaint(); | 388 |
389 void UpdateOneNotification(const Notification& notification) { | |
390 // Update the corresponding message view if there is one and explicitly | |
391 // update this view's layout as this is not automatic in spite of the | |
392 // updated view's likely size change because ScrollView's Viewport breaks | |
393 // the ChildPreferredSizeChange() chain. | |
394 MessageView* view = message_views_[notification.id()]; | |
395 if (view) { | |
396 view->Update(notification); | |
397 Layout(); | |
398 } | |
396 } | 399 } |
397 | 400 |
398 size_t NumMessageViews() const { | 401 size_t NumMessageViews() const { |
399 return scroll_content_->child_count(); | 402 return message_list_view_->child_count(); |
403 } | |
404 | |
405 protected: | |
406 // Overridden from views::View: | |
407 virtual void Layout() OVERRIDE { | |
408 scroller_->SizeToPreferredSize(); | |
409 views::View::Layout(); | |
410 if (GetWidget()) | |
411 GetWidget()->GetRootView()->SchedulePaint(); | |
412 bubble_->bubble_view()->UpdateBubble(); | |
400 } | 413 } |
401 | 414 |
402 private: | 415 private: |
403 void SizeScrollContent() { | 416 |
404 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); | 417 void RemoveAllNotifications() { |
405 const int button_height = button_view_->GetPreferredSize().height(); | 418 message_views_.clear(); |
406 const int min_height = kMessageBubbleBaseMinHeight - button_height; | 419 message_list_view_->RemoveAllChildViews(true); |
407 const int max_height = bubble_->max_height() - button_height; | |
408 int scroll_height = std::min(std::max( | |
409 scroll_size.height(), min_height), max_height); | |
410 scroll_size.set_height(scroll_height); | |
411 if (scroll_height == min_height) | |
412 scroll_content_->set_preferred_size(scroll_size); | |
413 else | |
414 scroll_content_->set_preferred_size(gfx::Size()); | |
415 scroller_->SetFixedSize(scroll_size); | |
416 scroller_->SizeToPreferredSize(); | |
417 scroll_content_->InvalidateLayout(); | |
418 } | 420 } |
419 | 421 |
420 NotificationList::Delegate* list_delegate_; | 422 void AddNotification(const Notification& notification) { |
421 FixedSizedScrollView* scroller_; | 423 // Always expand the first (topmost) notification. |
422 ScrollContentView* scroll_content_; | 424 bool expand = (notification.is_expanded() || message_views_.empty()); |
425 MessageView* view = NotificationView::Create(notification, bubble_, expand); | |
426 view->set_scroller(scroller_); | |
427 message_views_[notification.id()] = view; | |
428 message_list_view_->AddChildView(view); | |
429 } | |
430 | |
431 MessageCenterBubble* bubble_; // Weak reference. | |
432 std::map<std::string,MessageView*> message_views_; | |
433 BoundedScrollView* scroller_; | |
434 MessageListView* message_list_view_; | |
423 WebNotificationButtonViewBase* button_view_; | 435 WebNotificationButtonViewBase* button_view_; |
424 MessageCenterBubble* bubble_; | |
425 | 436 |
426 DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); | 437 DISALLOW_COPY_AND_ASSIGN(MessageCenterView); |
427 }; | 438 }; |
428 | 439 |
429 // Message Center Bubble. | 440 // Message Center Bubble. |
430 MessageCenterBubble::MessageCenterBubble(NotificationList::Delegate* delegate) | 441 MessageCenterBubble::MessageCenterBubble(MessageCenter* message_center) |
431 : MessageBubbleBase(delegate), | 442 : MessageBubbleBase(message_center), |
432 contents_view_(NULL) { | 443 contents_view_(NULL) { |
433 } | 444 } |
434 | 445 |
435 MessageCenterBubble::~MessageCenterBubble() {} | 446 MessageCenterBubble::~MessageCenterBubble() {} |
436 | 447 |
437 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( | 448 views::TrayBubbleView::InitParams MessageCenterBubble::GetInitParams( |
438 views::TrayBubbleView::AnchorAlignment anchor_alignment) { | 449 views::TrayBubbleView::AnchorAlignment anchor_alignment) { |
439 views::TrayBubbleView::InitParams init_params = | 450 views::TrayBubbleView::InitParams init_params = |
440 GetDefaultInitParams(anchor_alignment); | 451 GetDefaultInitParams(anchor_alignment); |
441 if (IsRichNotificationEnabled()) { | 452 if (IsRichNotificationEnabled()) { |
442 init_params.min_width += kMarginBetweenItems * 2; | 453 init_params.min_width += kMarginBetweenItems * 2; |
443 init_params.max_width += kMarginBetweenItems * 2; | 454 init_params.max_width += kMarginBetweenItems * 2; |
444 } | 455 } |
445 init_params.max_height = max_height(); | 456 init_params.max_height = max_height(); |
446 init_params.can_activate = true; | 457 init_params.can_activate = true; |
447 return init_params; | 458 return init_params; |
448 } | 459 } |
449 | 460 |
450 void MessageCenterBubble::InitializeContents( | 461 void MessageCenterBubble::InitializeContents( |
451 views::TrayBubbleView* new_bubble_view) { | 462 views::TrayBubbleView* new_bubble_view) { |
452 set_bubble_view(new_bubble_view); | 463 set_bubble_view(new_bubble_view); |
453 contents_view_ = new MessageCenterContentsView(this, list_delegate()); | 464 contents_view_ = new MessageCenterView(this); |
454 bubble_view()->AddChildView(contents_view_); | 465 bubble_view()->AddChildView(contents_view_); |
455 // Resize the content of the bubble view to the given bubble size. This is | 466 // Resize the content of the bubble view to the given bubble size. This is |
456 // necessary in case of the bubble border forcing a bigger size then the | 467 // necessary in case of the bubble border forcing a bigger size then the |
457 // |new_bubble_view| actually wants. See crbug.com/169390. | 468 // |new_bubble_view| actually wants. See crbug.com/169390. |
458 bubble_view()->Layout(); | 469 bubble_view()->Layout(); |
459 UpdateBubbleView(); | 470 UpdateBubbleView(); |
460 contents_view_->FocusContents(); | 471 contents_view_->FocusContents(); |
461 } | 472 } |
462 | 473 |
463 void MessageCenterBubble::OnBubbleViewDestroyed() { | 474 void MessageCenterBubble::OnBubbleViewDestroyed() { |
464 contents_view_ = NULL; | 475 contents_view_ = NULL; |
465 } | 476 } |
466 | 477 |
467 void MessageCenterBubble::UpdateBubbleView() { | 478 void MessageCenterBubble::UpdateBubbleView() { |
468 if (!bubble_view()) | 479 if (!bubble_view()) |
469 return; // Could get called after view is closed | 480 return; // Could get called after view is closed |
470 const NotificationList::Notifications& notifications = | 481 const NotificationList::Notifications& notifications = |
471 list_delegate()->GetNotificationList()->GetNotifications(); | 482 message_center()->notification_list()->GetNotifications(); |
472 contents_view_->Update(notifications); | 483 contents_view_->UpdateAllNotifications(notifications); |
473 bubble_view()->Show(); | 484 bubble_view()->Show(); |
474 bubble_view()->UpdateBubble(); | 485 bubble_view()->UpdateBubble(); |
475 } | 486 } |
476 | 487 |
477 void MessageCenterBubble::OnMouseEnteredView() { | 488 void MessageCenterBubble::OnMouseEnteredView() { |
478 } | 489 } |
479 | 490 |
480 void MessageCenterBubble::OnMouseExitedView() { | 491 void MessageCenterBubble::OnMouseExitedView() { |
481 } | 492 } |
482 | 493 |
494 void MessageCenterBubble::SendRemoveNotification(const std::string& id, | |
495 bool by_user) { | |
496 message_center()->SendRemoveNotification(id, by_user); | |
497 } | |
498 | |
499 void MessageCenterBubble::SendRemoveAllNotifications(bool by_user) { | |
500 message_center()->SendRemoveAllNotifications(by_user); | |
501 } | |
502 | |
503 void MessageCenterBubble::DisableNotificationByExtension( | |
504 const std::string& id) { | |
505 message_center()->DisableNotificationByExtension(id); | |
506 } | |
507 | |
508 void MessageCenterBubble::DisableNotificationByUrl(const std::string& id) { | |
509 message_center()->DisableNotificationByUrl(id); | |
510 } | |
511 | |
512 void MessageCenterBubble::ShowNotificationSettings(const std::string& id) { | |
513 message_center()->ShowNotificationSettings(id); | |
514 } | |
515 | |
516 void MessageCenterBubble::ShowNotificationSettingsDialog( | |
517 gfx::NativeView context) { | |
518 message_center()->ShowNotificationSettingsDialog(context); | |
519 } | |
520 | |
521 void MessageCenterBubble::OnNotificationClicked(const std::string& id) { | |
522 message_center()->OnNotificationClicked(id); | |
523 } | |
524 | |
525 void MessageCenterBubble::OnButtonClicked(const std::string& id, | |
526 int button_index) { | |
527 message_center()->OnButtonClicked(id, button_index); | |
528 } | |
529 | |
530 void MessageCenterBubble::OnExpand(const std::string& id) { | |
531 message_center()->OnExpand(id); | |
532 | |
533 // Update the view corresponding to this notification. | |
534 const NotificationList::Notifications& notifications = | |
535 message_center()->notification_list()->GetNotifications(); | |
536 for (NotificationList::Notifications::const_iterator iter = | |
537 notifications.begin(); iter != notifications.end(); ++iter) { | |
538 if ((*iter)->id() == id) { | |
539 contents_view_->UpdateOneNotification(*(*iter)); | |
540 break; | |
541 } | |
542 } | |
543 } | |
544 | |
545 void MessageCenterBubble::OnQuietModeChanged(bool quiet_mode) { | |
546 message_center()->OnQuietModeChanged(quiet_mode); | |
547 } | |
548 | |
dharcourt
2013/03/02 02:08:02
This isn't now only in NotificationList::Delegate
| |
483 size_t MessageCenterBubble::NumMessageViewsForTest() const { | 549 size_t MessageCenterBubble::NumMessageViewsForTest() const { |
484 return contents_view_->NumMessageViews(); | 550 return contents_view_->NumMessageViews(); |
485 } | 551 } |
486 | 552 |
487 } // namespace message_center | 553 } // namespace message_center |
OLD | NEW |