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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4); | 54 const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4); |
55 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 55 const SkColor kBorderDarkColor = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
56 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); | 56 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); |
57 const SkColor kButtonTextHighlightColor = SkColorSetRGB(0x2a, 0x2a, 0x2a); | 57 const SkColor kButtonTextHighlightColor = SkColorSetRGB(0x2a, 0x2a, 0x2a); |
58 const SkColor kButtonTextHoverColor = SkColorSetRGB(0x2a, 0x2a, 0x2a); | 58 const SkColor kButtonTextHoverColor = SkColorSetRGB(0x2a, 0x2a, 0x2a); |
59 const int kAnimateClearingNextNotificationDelayMS = 40; | 59 const int kAnimateClearingNextNotificationDelayMS = 40; |
60 | 60 |
61 static const int kDefaultFrameRateHz = 60; | 61 static const int kDefaultFrameRateHz = 60; |
62 static const int kDefaultAnimationDurationMs = 120; | 62 static const int kDefaultAnimationDurationMs = 120; |
63 | 63 |
64 // PoorMessageCenterButtonBar ////////////////////////////////////////////////// | 64 } // namespace |
65 | |
66 // The view for the buttons at the bottom of the message center window used | |
67 // when kEnableRichNotifications is false (hence the "poor" in the name :-). | |
68 class PoorMessageCenterButtonBar : public MessageCenterButtonBar, | |
69 public views::ButtonListener { | |
70 public: | |
71 PoorMessageCenterButtonBar(MessageCenterView* message_center_view, | |
72 MessageCenter* message_center); | |
73 | |
74 // Overridden from views::ButtonListener: | |
75 virtual void ButtonPressed(views::Button* sender, | |
76 const ui::Event& event) OVERRIDE; | |
77 | |
78 private: | |
79 DISALLOW_COPY_AND_ASSIGN(PoorMessageCenterButtonBar); | |
80 }; | |
81 | |
82 PoorMessageCenterButtonBar::PoorMessageCenterButtonBar( | |
83 MessageCenterView* message_center_view, MessageCenter* message_center) | |
84 : MessageCenterButtonBar(message_center_view, message_center) { | |
85 set_background(views::Background::CreateBackgroundPainter( | |
86 true, | |
87 views::Painter::CreateVerticalGradient(kBackgroundLightColor, | |
88 kBackgroundDarkColor))); | |
89 set_border(views::Border::CreateSolidSidedBorder( | |
90 2, 0, 0, 0, kBorderDarkColor)); | |
91 | |
92 views::GridLayout* layout = new views::GridLayout(this); | |
93 SetLayoutManager(layout); | |
94 views::ColumnSet* columns = layout->AddColumnSet(0); | |
95 columns->AddPaddingColumn(100, 0); | |
96 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
97 0, /* resize percent */ | |
98 views::GridLayout::USE_PREF, 0, 0); | |
99 columns->AddPaddingColumn(0, 4); | |
100 | |
101 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); | |
102 views::LabelButton* close_all_button = new views::LabelButton( | |
103 this, resource_bundle.GetLocalizedString(IDS_MESSAGE_CENTER_CLEAR_ALL)); | |
104 close_all_button->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
105 close_all_button->set_request_focus_on_press(false); | |
106 close_all_button->SetTextColor(views::Button::STATE_NORMAL, kFooterTextColor); | |
107 close_all_button->SetTextColor(views::Button::STATE_HOVERED, | |
108 kButtonTextHoverColor); | |
109 | |
110 layout->AddPaddingRow(0, 4); | |
111 layout->StartRow(0, 0); | |
112 layout->AddView(close_all_button); | |
113 set_close_all_button(close_all_button); | |
114 } | |
115 | |
116 void PoorMessageCenterButtonBar::ButtonPressed(views::Button* sender, | |
117 const ui::Event& event) { | |
118 if (sender == close_all_button()) | |
119 message_center_view()->ClearAllNotifications(); | |
120 } | |
121 | 65 |
122 // NotificationCenterButton //////////////////////////////////////////////////// | 66 // NotificationCenterButton //////////////////////////////////////////////////// |
123 | 67 |
124 class NotificationCenterButton : public views::ToggleImageButton { | 68 class NotificationCenterButton : public views::ToggleImageButton { |
125 public: | 69 public: |
126 NotificationCenterButton(views::ButtonListener* listener, | 70 NotificationCenterButton(views::ButtonListener* listener, |
127 int normal_id, | 71 int normal_id, |
128 int hover_id, | 72 int hover_id, |
129 int pressed_id, | 73 int pressed_id, |
130 int text_id); | 74 int text_id); |
(...skipping 29 matching lines...) Expand all Loading... |
160 return gfx::Size(kButtonSize, kButtonSize); | 104 return gfx::Size(kButtonSize, kButtonSize); |
161 } | 105 } |
162 | 106 |
163 void NotificationCenterButton::OnPaintFocusBorder(gfx::Canvas* canvas) { | 107 void NotificationCenterButton::OnPaintFocusBorder(gfx::Canvas* canvas) { |
164 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { | 108 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) { |
165 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), | 109 canvas->DrawRect(gfx::Rect(2, 1, width() - 4, height() - 3), |
166 kFocusBorderColor); | 110 kFocusBorderColor); |
167 } | 111 } |
168 } | 112 } |
169 | 113 |
170 // RichMessageCenterButtonBar ////////////////////////////////////////////////// | 114 // MessageCenterButtonBar ////////////////////////////////////////////////// |
171 | 115 |
172 // TODO(mukai): Merge this into MessageCenterButtonBar and get rid of | 116 class MessageCenterButtonBar : public views::View, |
173 // PoorMessageCenterButtonBar when the kEnableRichNotifications flag disappears. | 117 public views::ButtonListener { |
174 class RichMessageCenterButtonBar : public MessageCenterButtonBar, | |
175 public views::ButtonListener { | |
176 public: | 118 public: |
177 RichMessageCenterButtonBar(MessageCenterView* message_center_view, | 119 MessageCenterButtonBar(MessageCenterView* message_center_view, |
178 MessageCenter* message_center); | 120 MessageCenter* message_center); |
| 121 virtual ~MessageCenterButtonBar(); |
| 122 |
| 123 virtual void SetAllButtonsEnabled(bool enabled); |
| 124 void SetCloseAllVisible(bool visible); |
179 | 125 |
180 private: | 126 private: |
181 // Overridden from MessageCenterButtonBar: | |
182 virtual void SetAllButtonsEnabled(bool enabled) OVERRIDE; | |
183 | |
184 // Overridden from views::View: | 127 // Overridden from views::View: |
185 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE; | 128 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE; |
186 | 129 |
187 // Overridden from views::ButtonListener: | 130 // Overridden from views::ButtonListener: |
188 virtual void ButtonPressed(views::Button* sender, | 131 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) |
189 const ui::Event& event) OVERRIDE; | 132 OVERRIDE; |
190 | 133 |
| 134 MessageCenterView* message_center_view() const { |
| 135 return message_center_view_; |
| 136 } |
| 137 MessageCenter* message_center() const { return message_center_; } |
| 138 MessageCenterTray* tray() const { return tray_; } |
| 139 views::Button* close_all_button() const { return close_all_button_; } |
| 140 void set_close_all_button(views::Button* button) { |
| 141 close_all_button_ = button; |
| 142 } |
| 143 |
| 144 MessageCenterView* message_center_view_; // Weak reference. |
| 145 MessageCenter* message_center_; // Weak reference. |
| 146 MessageCenterTray* tray_; // Weak reference. |
| 147 views::Button* close_all_button_; |
191 NotificationCenterButton* settings_button_; | 148 NotificationCenterButton* settings_button_; |
192 NotificationCenterButton* quiet_mode_button_; | 149 NotificationCenterButton* quiet_mode_button_; |
193 | 150 |
194 DISALLOW_COPY_AND_ASSIGN(RichMessageCenterButtonBar); | 151 DISALLOW_COPY_AND_ASSIGN(MessageCenterButtonBar); |
195 }; | 152 }; |
196 | 153 |
197 RichMessageCenterButtonBar::RichMessageCenterButtonBar( | 154 MessageCenterButtonBar::MessageCenterButtonBar( |
198 MessageCenterView* message_center_view, MessageCenter* message_center) | 155 MessageCenterView* message_center_view, |
199 : MessageCenterButtonBar(message_center_view, message_center) { | 156 MessageCenter* message_center) |
| 157 : message_center_view_(message_center_view), |
| 158 message_center_(message_center), |
| 159 close_all_button_(NULL) { |
200 if (get_use_acceleration_when_possible()) | 160 if (get_use_acceleration_when_possible()) |
201 SetPaintToLayer(true); | 161 SetPaintToLayer(true); |
202 set_background(views::Background::CreateSolidBackground( | 162 set_background(views::Background::CreateSolidBackground( |
203 kMessageCenterBackgroundColor)); | 163 kMessageCenterBackgroundColor)); |
204 | 164 |
205 views::Label* notification_label = new views::Label(l10n_util::GetStringUTF16( | 165 views::Label* notification_label = new views::Label(l10n_util::GetStringUTF16( |
206 IDS_MESSAGE_CENTER_FOOTER_TITLE)); | 166 IDS_MESSAGE_CENTER_FOOTER_TITLE)); |
207 notification_label->SetAutoColorReadabilityEnabled(false); | 167 notification_label->SetAutoColorReadabilityEnabled(false); |
208 notification_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 168 notification_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
209 notification_label->SetEnabledColor(kRegularTextColor); | 169 notification_label->SetEnabledColor(kRegularTextColor); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 views::ColumnSet* column = layout->AddColumnSet(0); | 218 views::ColumnSet* column = layout->AddColumnSet(0); |
259 column->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 219 column->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
260 1.0f, views::GridLayout::USE_PREF, 0, 0); | 220 1.0f, views::GridLayout::USE_PREF, 0, 0); |
261 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 221 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
262 0, views::GridLayout::USE_PREF, 0, 0); | 222 0, views::GridLayout::USE_PREF, 0, 0); |
263 layout->StartRow(0, 0); | 223 layout->StartRow(0, 0); |
264 layout->AddView(notification_label); | 224 layout->AddView(notification_label); |
265 layout->AddView(button_container); | 225 layout->AddView(button_container); |
266 } | 226 } |
267 | 227 |
268 // Overridden from MessageCenterButtonBar: | 228 MessageCenterButtonBar::~MessageCenterButtonBar() {} |
269 void RichMessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { | 229 |
270 MessageCenterButtonBar::SetAllButtonsEnabled(enabled); | 230 void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { |
| 231 if (close_all_button_) |
| 232 close_all_button_->SetEnabled(enabled); |
271 settings_button_->SetEnabled(enabled); | 233 settings_button_->SetEnabled(enabled); |
272 quiet_mode_button_->SetEnabled(enabled); | 234 quiet_mode_button_->SetEnabled(enabled); |
273 } | 235 } |
274 | 236 |
| 237 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { |
| 238 if (close_all_button_) |
| 239 close_all_button_->SetVisible(visible); |
| 240 } |
| 241 |
275 // Overridden from views::View: | 242 // Overridden from views::View: |
276 void RichMessageCenterButtonBar::ChildVisibilityChanged(views::View* child) { | 243 void MessageCenterButtonBar::ChildVisibilityChanged(views::View* child) { |
277 InvalidateLayout(); | 244 InvalidateLayout(); |
278 } | 245 } |
279 | 246 |
280 // Overridden from views::ButtonListener: | 247 // Overridden from views::ButtonListener: |
281 void RichMessageCenterButtonBar::ButtonPressed(views::Button* sender, | 248 void MessageCenterButtonBar::ButtonPressed(views::Button* sender, |
282 const ui::Event& event) { | 249 const ui::Event& event) { |
283 if (sender == close_all_button()) { | 250 if (sender == close_all_button()) { |
284 message_center_view()->ClearAllNotifications(); | 251 message_center_view()->ClearAllNotifications(); |
285 } else if (sender == settings_button_) { | 252 } else if (sender == settings_button_) { |
286 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); | 253 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); |
287 center_view->SetSettingsVisible(!center_view->settings_visible()); | 254 center_view->SetSettingsVisible(!center_view->settings_visible()); |
288 } else if (sender == quiet_mode_button_) { | 255 } else if (sender == quiet_mode_button_) { |
289 if (message_center()->IsQuietMode()) | 256 if (message_center()->IsQuietMode()) |
290 message_center()->SetQuietMode(false); | 257 message_center()->SetQuietMode(false); |
291 else | 258 else |
292 message_center()->EnterQuietModeWithExpire(base::TimeDelta::FromDays(1)); | 259 message_center()->EnterQuietModeWithExpire(base::TimeDelta::FromDays(1)); |
(...skipping 22 matching lines...) Expand all Loading... |
315 | 282 |
316 DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); | 283 DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); |
317 }; | 284 }; |
318 | 285 |
319 BoundedScrollView::BoundedScrollView(int min_height, int max_height) | 286 BoundedScrollView::BoundedScrollView(int min_height, int max_height) |
320 : min_height_(min_height), | 287 : min_height_(min_height), |
321 max_height_(max_height) { | 288 max_height_(max_height) { |
322 set_notify_enter_exit_on_child(true); | 289 set_notify_enter_exit_on_child(true); |
323 // Cancels the default dashed focus border. | 290 // Cancels the default dashed focus border. |
324 set_focus_border(NULL); | 291 set_focus_border(NULL); |
325 if (IsRichNotificationEnabled()) { | 292 set_background( |
326 set_background(views::Background::CreateSolidBackground( | 293 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); |
327 kMessageCenterBackgroundColor)); | 294 SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
328 SetVerticalScrollBar(new views::OverlayScrollBar(false)); | |
329 } | |
330 } | 295 } |
331 | 296 |
332 gfx::Size BoundedScrollView::GetPreferredSize() { | 297 gfx::Size BoundedScrollView::GetPreferredSize() { |
333 gfx::Size size = contents()->GetPreferredSize(); | 298 gfx::Size size = contents()->GetPreferredSize(); |
334 size.SetToMax(gfx::Size(size.width(), min_height_)); | 299 size.SetToMax(gfx::Size(size.width(), min_height_)); |
335 size.SetToMin(gfx::Size(size.width(), max_height_)); | 300 size.SetToMin(gfx::Size(size.width(), max_height_)); |
336 gfx::Insets insets = GetInsets(); | 301 gfx::Insets insets = GetInsets(); |
337 size.Enlarge(insets.width(), insets.height()); | 302 size.Enlarge(insets.width(), insets.height()); |
338 return size; | 303 return size; |
339 } | 304 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 int NoNotificationMessageView::GetHeightForWidth(int width) { | 361 int NoNotificationMessageView::GetHeightForWidth(int width) { |
397 return kMinScrollViewHeight; | 362 return kMinScrollViewHeight; |
398 } | 363 } |
399 | 364 |
400 void NoNotificationMessageView::Layout() { | 365 void NoNotificationMessageView::Layout() { |
401 int text_height = label_->GetHeightForWidth(width()); | 366 int text_height = label_->GetHeightForWidth(width()); |
402 int margin = (height() - text_height) / 2; | 367 int margin = (height() - text_height) / 2; |
403 label_->SetBounds(0, margin, width(), text_height); | 368 label_->SetBounds(0, margin, width(), text_height); |
404 } | 369 } |
405 | 370 |
406 } // namespace | |
407 | |
408 // MessageListView ///////////////////////////////////////////////////////////// | |
409 | |
410 // Displays a list of messages. | |
411 class MessageListView : public views::View { | |
412 public: | |
413 explicit MessageListView(MessageCenterView* message_center_view); | |
414 | |
415 // The interface for repositioning. | |
416 virtual void AddNotificationAt(views::View* view, int i); | |
417 virtual void RemoveNotificationAt(int i); | |
418 virtual void UpdateNotificationAt(views::View* view, int i); | |
419 virtual void SetRepositionTarget(const gfx::Rect& target_rect) {} | |
420 virtual void ResetRepositionSession() {} | |
421 virtual void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); | |
422 | |
423 protected: | |
424 MessageCenterView* message_center_view() const { | |
425 return message_center_view_; | |
426 } | |
427 | |
428 private: | |
429 MessageCenterView* message_center_view_; // Weak reference. | |
430 | |
431 DISALLOW_COPY_AND_ASSIGN(MessageListView); | |
432 }; | |
433 | |
434 MessageListView::MessageListView(MessageCenterView* message_center_view) | |
435 : message_center_view_(message_center_view) { | |
436 views::BoxLayout* layout = | |
437 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); | |
438 layout->set_spread_blank_space(true); | |
439 SetLayoutManager(layout); | |
440 } | |
441 | |
442 void MessageListView::AddNotificationAt(views::View* view, int i) { | |
443 AddChildViewAt(view, i); | |
444 } | |
445 | |
446 void MessageListView::RemoveNotificationAt(int i) { | |
447 delete child_at(i); | |
448 } | |
449 | |
450 void MessageListView::UpdateNotificationAt(views::View* view, int i) { | |
451 delete child_at(i); | |
452 AddChildViewAt(view, i); | |
453 } | |
454 | |
455 void MessageListView::ClearAllNotifications( | |
456 const gfx::Rect& visible_scroll_rect) { | |
457 message_center_view_->OnAllNotificationsCleared(); | |
458 } | |
459 | |
460 // Displays a list of messages for rich notifications. It also supports | 371 // Displays a list of messages for rich notifications. It also supports |
461 // repositioning. | 372 // repositioning. |
462 class RichMessageListView : public MessageListView, | 373 class MessageListView : public views::View, |
463 public views::BoundsAnimatorObserver { | 374 public views::BoundsAnimatorObserver { |
464 public: | 375 public: |
465 explicit RichMessageListView(MessageCenterView* message_center_view); | 376 explicit MessageListView(MessageCenterView* message_center_view); |
466 virtual ~RichMessageListView(); | 377 virtual ~MessageListView(); |
| 378 |
| 379 void AddNotificationAt(views::View* view, int i); |
| 380 void RemoveNotificationAt(int i); |
| 381 void UpdateNotificationAt(views::View* view, int i); |
| 382 void SetRepositionTarget(const gfx::Rect& target_rect); |
| 383 void ResetRepositionSession(); |
| 384 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); |
467 | 385 |
468 protected: | 386 protected: |
469 // Overridden from views::View. | 387 // Overridden from views::View. |
470 virtual void Layout() OVERRIDE; | 388 virtual void Layout() OVERRIDE; |
471 virtual gfx::Size GetPreferredSize() OVERRIDE; | 389 virtual gfx::Size GetPreferredSize() OVERRIDE; |
472 virtual int GetHeightForWidth(int width) OVERRIDE; | 390 virtual int GetHeightForWidth(int width) OVERRIDE; |
473 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 391 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
474 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; | 392 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; |
475 | 393 |
476 // Overridden from MessageListView. | |
477 virtual void AddNotificationAt(views::View* view, int i) OVERRIDE; | |
478 virtual void RemoveNotificationAt(int i) OVERRIDE; | |
479 virtual void UpdateNotificationAt(views::View* view, int i) OVERRIDE; | |
480 virtual void SetRepositionTarget(const gfx::Rect& target_rect) OVERRIDE; | |
481 virtual void ResetRepositionSession() OVERRIDE; | |
482 virtual void ClearAllNotifications( | |
483 const gfx::Rect& visible_scroll_rect) OVERRIDE; | |
484 | |
485 // Overridden from views::BoundsAnimatorObserver. | 394 // Overridden from views::BoundsAnimatorObserver. |
486 virtual void OnBoundsAnimatorProgressed( | 395 virtual void OnBoundsAnimatorProgressed( |
487 views::BoundsAnimator* animator) OVERRIDE; | 396 views::BoundsAnimator* animator) OVERRIDE; |
488 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE; | 397 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE; |
489 | 398 |
490 private: | 399 private: |
491 // Returns the actual index for child of |index|. | 400 // Returns the actual index for child of |index|. |
| 401 // MessageListView allows to slide down upper notifications, which means |
| 402 // that the upper ones should come above the lower ones. To achieve this, |
| 403 // inversed order is adopted. The top most notification is the last child, |
| 404 // and the bottom most notification is the first child. |
492 int GetActualIndex(int index); | 405 int GetActualIndex(int index); |
493 bool IsValidChild(views::View* child); | 406 bool IsValidChild(views::View* child); |
494 void DoUpdateIfPossible(); | 407 void DoUpdateIfPossible(); |
495 | 408 |
496 // Schedules animation for a child to the specified position. | 409 // Schedules animation for a child to the specified position. |
497 void AnimateChild(views::View* child, int top, int height); | 410 void AnimateChild(views::View* child, int top, int height); |
498 | 411 |
499 // Animate clearing one notification. | 412 // Animate clearing one notification. |
500 void AnimateClearingOneNotification(); | 413 void AnimateClearingOneNotification(); |
| 414 MessageCenterView* message_center_view() const { |
| 415 return message_center_view_; |
| 416 } |
501 | 417 |
| 418 MessageCenterView* message_center_view_; // Weak reference. |
502 // The top position of the reposition target rectangle. | 419 // The top position of the reposition target rectangle. |
503 int reposition_top_; | 420 int reposition_top_; |
504 | |
505 int fixed_height_; | 421 int fixed_height_; |
506 | |
507 bool has_deferred_task_; | 422 bool has_deferred_task_; |
508 bool clear_all_started_; | 423 bool clear_all_started_; |
509 std::set<views::View*> adding_views_; | 424 std::set<views::View*> adding_views_; |
510 std::set<views::View*> deleting_views_; | 425 std::set<views::View*> deleting_views_; |
511 std::set<views::View*> deleted_when_done_; | 426 std::set<views::View*> deleted_when_done_; |
512 std::list<views::View*> clearing_all_views_; | 427 std::list<views::View*> clearing_all_views_; |
513 scoped_ptr<views::BoundsAnimator> animator_; | 428 scoped_ptr<views::BoundsAnimator> animator_; |
514 base::WeakPtrFactory<RichMessageListView> weak_ptr_factory_; | 429 base::WeakPtrFactory<MessageListView> weak_ptr_factory_; |
515 | 430 |
516 DISALLOW_COPY_AND_ASSIGN(RichMessageListView); | 431 DISALLOW_COPY_AND_ASSIGN(MessageListView); |
517 }; | 432 }; |
518 | 433 |
519 RichMessageListView::RichMessageListView(MessageCenterView* message_center_view) | 434 MessageListView::MessageListView(MessageCenterView* message_center_view) |
520 : MessageListView(message_center_view), | 435 : message_center_view_(message_center_view), |
521 reposition_top_(-1), | 436 reposition_top_(-1), |
522 fixed_height_(0), | 437 fixed_height_(0), |
523 has_deferred_task_(false), | 438 has_deferred_task_(false), |
524 clear_all_started_(false), | 439 clear_all_started_(false), |
525 weak_ptr_factory_(this) { | 440 weak_ptr_factory_(this) { |
| 441 views::BoxLayout* layout = |
| 442 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); |
| 443 layout->set_spread_blank_space(true); |
| 444 SetLayoutManager(layout); |
| 445 |
526 // Set the margin to 0 for the layout. BoxLayout assumes the same margin | 446 // Set the margin to 0 for the layout. BoxLayout assumes the same margin |
527 // for top and bottom, but the bottom margin here should be smaller | 447 // for top and bottom, but the bottom margin here should be smaller |
528 // because of the shadow of message view. Use an empty border instead | 448 // because of the shadow of message view. Use an empty border instead |
529 // to provide this margin. | 449 // to provide this margin. |
530 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); | 450 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); |
531 set_background(views::Background::CreateSolidBackground( | 451 set_background(views::Background::CreateSolidBackground( |
532 kMessageCenterBackgroundColor)); | 452 kMessageCenterBackgroundColor)); |
533 set_border(views::Border::CreateEmptyBorder( | 453 set_border(views::Border::CreateEmptyBorder( |
534 kMarginBetweenItems - shadow_insets.top(), /* top */ | 454 kMarginBetweenItems - shadow_insets.top(), /* top */ |
535 kMarginBetweenItems - shadow_insets.left(), /* left */ | 455 kMarginBetweenItems - shadow_insets.left(), /* left */ |
536 kMarginBetweenItems - shadow_insets.bottom(), /* bottom */ | 456 kMarginBetweenItems - shadow_insets.bottom(), /* bottom */ |
537 kMarginBetweenItems - shadow_insets.right() /* right */ )); | 457 kMarginBetweenItems - shadow_insets.right() /* right */ )); |
538 } | 458 } |
539 | 459 |
540 RichMessageListView::~RichMessageListView() { | 460 MessageListView::~MessageListView() { |
541 if (animator_.get()) | 461 if (animator_.get()) |
542 animator_->RemoveObserver(this); | 462 animator_->RemoveObserver(this); |
543 } | 463 } |
544 | 464 |
545 void RichMessageListView::Layout() { | 465 void MessageListView::Layout() { |
546 if (animator_.get()) | 466 if (animator_.get()) |
547 return; | 467 return; |
548 | 468 |
549 gfx::Rect child_area = GetContentsBounds(); | 469 gfx::Rect child_area = GetContentsBounds(); |
550 int top = child_area.y(); | 470 int top = child_area.y(); |
551 int between_items = | 471 int between_items = |
552 kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); | 472 kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); |
553 | 473 |
554 for (int i = 0; i < child_count(); ++i) { | 474 for (int i = 0; i < child_count(); ++i) { |
555 views::View* child = child_at(i); | 475 views::View* child = child_at(i); |
556 if (!child->visible()) | 476 if (!child->visible()) |
557 continue; | 477 continue; |
558 int height = child->GetHeightForWidth(child_area.width()); | 478 int height = child->GetHeightForWidth(child_area.width()); |
559 child->SetBounds(child_area.x(), top, child_area.width(), height); | 479 child->SetBounds(child_area.x(), top, child_area.width(), height); |
560 top += height + between_items; | 480 top += height + between_items; |
561 } | 481 } |
562 } | 482 } |
563 | 483 |
564 void RichMessageListView::AddNotificationAt(views::View* view, int i) { | 484 void MessageListView::AddNotificationAt(views::View* view, int i) { |
565 AddChildViewAt(view, GetActualIndex(i)); | 485 AddChildViewAt(view, GetActualIndex(i)); |
566 if (GetContentsBounds().IsEmpty()) | 486 if (GetContentsBounds().IsEmpty()) |
567 return; | 487 return; |
568 | 488 |
569 adding_views_.insert(view); | 489 adding_views_.insert(view); |
570 DoUpdateIfPossible(); | 490 DoUpdateIfPossible(); |
571 } | 491 } |
572 | 492 |
573 void RichMessageListView::RemoveNotificationAt(int i) { | 493 void MessageListView::RemoveNotificationAt(int i) { |
574 views::View* child = child_at(GetActualIndex(i)); | 494 views::View* child = child_at(GetActualIndex(i)); |
575 if (GetContentsBounds().IsEmpty()) { | 495 if (GetContentsBounds().IsEmpty()) { |
576 delete child; | 496 delete child; |
577 } else { | 497 } else { |
578 if (child->layer()) { | 498 if (child->layer()) { |
579 deleting_views_.insert(child); | 499 deleting_views_.insert(child); |
580 } else { | 500 } else { |
581 if (animator_.get()) | 501 if (animator_.get()) |
582 animator_->StopAnimatingView(child); | 502 animator_->StopAnimatingView(child); |
583 delete child; | 503 delete child; |
584 } | 504 } |
585 DoUpdateIfPossible(); | 505 DoUpdateIfPossible(); |
586 } | 506 } |
587 } | 507 } |
588 | 508 |
589 void RichMessageListView::UpdateNotificationAt(views::View* view, int i) { | 509 void MessageListView::UpdateNotificationAt(views::View* view, int i) { |
590 int actual_index = GetActualIndex(i); | 510 int actual_index = GetActualIndex(i); |
591 views::View* child = child_at(actual_index); | 511 views::View* child = child_at(actual_index); |
592 if (animator_.get()) | 512 if (animator_.get()) |
593 animator_->StopAnimatingView(child); | 513 animator_->StopAnimatingView(child); |
594 gfx::Rect old_bounds = child->bounds(); | 514 gfx::Rect old_bounds = child->bounds(); |
595 if (deleting_views_.find(child) != deleting_views_.end()) | 515 if (deleting_views_.find(child) != deleting_views_.end()) |
596 deleting_views_.erase(child); | 516 deleting_views_.erase(child); |
597 if (deleted_when_done_.find(child) != deleted_when_done_.end()) | 517 if (deleted_when_done_.find(child) != deleted_when_done_.end()) |
598 deleted_when_done_.erase(child); | 518 deleted_when_done_.erase(child); |
599 delete child; | 519 delete child; |
600 AddChildViewAt(view, actual_index); | 520 AddChildViewAt(view, actual_index); |
601 view->SetBounds(old_bounds.x(), old_bounds.y(), old_bounds.width(), | 521 view->SetBounds(old_bounds.x(), old_bounds.y(), old_bounds.width(), |
602 view->GetHeightForWidth(old_bounds.width())); | 522 view->GetHeightForWidth(old_bounds.width())); |
603 DoUpdateIfPossible(); | 523 DoUpdateIfPossible(); |
604 } | 524 } |
605 | 525 |
606 gfx::Size RichMessageListView::GetPreferredSize() { | 526 gfx::Size MessageListView::GetPreferredSize() { |
607 int width = 0; | 527 int width = 0; |
608 for (int i = 0; i < child_count(); i++) { | 528 for (int i = 0; i < child_count(); i++) { |
609 views::View* child = child_at(i); | 529 views::View* child = child_at(i); |
610 if (IsValidChild(child)) | 530 if (IsValidChild(child)) |
611 width = std::max(width, child->GetPreferredSize().width()); | 531 width = std::max(width, child->GetPreferredSize().width()); |
612 } | 532 } |
613 | 533 |
614 return gfx::Size(width + GetInsets().width(), | 534 return gfx::Size(width + GetInsets().width(), |
615 GetHeightForWidth(width + GetInsets().width())); | 535 GetHeightForWidth(width + GetInsets().width())); |
616 } | 536 } |
617 | 537 |
618 int RichMessageListView::GetHeightForWidth(int width) { | 538 int MessageListView::GetHeightForWidth(int width) { |
619 if (fixed_height_ > 0) | 539 if (fixed_height_ > 0) |
620 return fixed_height_; | 540 return fixed_height_; |
621 | 541 |
622 width -= GetInsets().width(); | 542 width -= GetInsets().width(); |
623 int height = 0; | 543 int height = 0; |
624 int padding = 0; | 544 int padding = 0; |
625 for (int i = 0; i < child_count(); ++i) { | 545 for (int i = 0; i < child_count(); ++i) { |
626 views::View* child = child_at(i); | 546 views::View* child = child_at(i); |
627 if (!IsValidChild(child)) | 547 if (!IsValidChild(child)) |
628 continue; | 548 continue; |
629 height += child->GetHeightForWidth(width) + padding; | 549 height += child->GetHeightForWidth(width) + padding; |
630 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); | 550 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); |
631 } | 551 } |
632 | 552 |
633 return height + GetInsets().height(); | 553 return height + GetInsets().height(); |
634 } | 554 } |
635 | 555 |
636 void RichMessageListView::PaintChildren(gfx::Canvas* canvas) { | 556 void MessageListView::PaintChildren(gfx::Canvas* canvas) { |
637 // Paint in the inversed order. Otherwise upper notification may be | 557 // Paint in the inversed order. Otherwise upper notification may be |
638 // hidden by the lower one. | 558 // hidden by the lower one. |
639 for (int i = child_count() - 1; i >= 0; --i) { | 559 for (int i = child_count() - 1; i >= 0; --i) { |
640 if (!child_at(i)->layer()) | 560 if (!child_at(i)->layer()) |
641 child_at(i)->Paint(canvas); | 561 child_at(i)->Paint(canvas); |
642 } | 562 } |
643 } | 563 } |
644 | 564 |
645 void RichMessageListView::ReorderChildLayers(ui::Layer* parent_layer) { | 565 void MessageListView::ReorderChildLayers(ui::Layer* parent_layer) { |
646 // Reorder children to stack the last child layer at the top. Otherwise | 566 // Reorder children to stack the last child layer at the top. Otherwise |
647 // upper notification may be hidden by the lower one. | 567 // upper notification may be hidden by the lower one. |
648 for (int i = 0; i < child_count(); ++i) { | 568 for (int i = 0; i < child_count(); ++i) { |
649 if (child_at(i)->layer()) | 569 if (child_at(i)->layer()) |
650 parent_layer->StackAtBottom(child_at(i)->layer()); | 570 parent_layer->StackAtBottom(child_at(i)->layer()); |
651 } | 571 } |
652 } | 572 } |
653 | 573 |
654 void RichMessageListView::SetRepositionTarget(const gfx::Rect& target) { | 574 void MessageListView::SetRepositionTarget(const gfx::Rect& target) { |
655 reposition_top_ = target.y(); | 575 reposition_top_ = target.y(); |
656 fixed_height_ = GetHeightForWidth(width()); | 576 fixed_height_ = GetHeightForWidth(width()); |
657 } | 577 } |
658 | 578 |
659 void RichMessageListView::ResetRepositionSession() { | 579 void MessageListView::ResetRepositionSession() { |
660 // Don't call DoUpdateIfPossible(), but let Layout() do the task without | 580 // Don't call DoUpdateIfPossible(), but let Layout() do the task without |
661 // animation. Reset will cause the change of the bubble size itself, and | 581 // animation. Reset will cause the change of the bubble size itself, and |
662 // animation from the old location will look weird. | 582 // animation from the old location will look weird. |
663 if (reposition_top_ >= 0 && animator_.get()) { | 583 if (reposition_top_ >= 0 && animator_.get()) { |
664 has_deferred_task_ = false; | 584 has_deferred_task_ = false; |
665 // cancel cause OnBoundsAnimatorDone which deletes |deleted_when_done_|. | 585 // cancel cause OnBoundsAnimatorDone which deletes |deleted_when_done_|. |
666 animator_->Cancel(); | 586 animator_->Cancel(); |
667 STLDeleteContainerPointers(deleting_views_.begin(), deleting_views_.end()); | 587 STLDeleteContainerPointers(deleting_views_.begin(), deleting_views_.end()); |
668 deleting_views_.clear(); | 588 deleting_views_.clear(); |
669 adding_views_.clear(); | 589 adding_views_.clear(); |
670 animator_.reset(); | 590 animator_.reset(); |
671 } | 591 } |
672 | 592 |
673 reposition_top_ = -1; | 593 reposition_top_ = -1; |
674 fixed_height_ = 0; | 594 fixed_height_ = 0; |
675 } | 595 } |
676 | 596 |
677 void RichMessageListView::ClearAllNotifications( | 597 void MessageListView::ClearAllNotifications( |
678 const gfx::Rect& visible_scroll_rect) { | 598 const gfx::Rect& visible_scroll_rect) { |
679 for (int i = 0; i < child_count(); ++i) { | 599 for (int i = 0; i < child_count(); ++i) { |
680 views::View* child = child_at(i); | 600 views::View* child = child_at(i); |
681 if (!child->visible()) | 601 if (!child->visible()) |
682 continue; | 602 continue; |
683 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) | 603 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) |
684 continue; | 604 continue; |
685 clearing_all_views_.push_back(child); | 605 clearing_all_views_.push_back(child); |
686 } | 606 } |
687 DoUpdateIfPossible(); | 607 DoUpdateIfPossible(); |
688 } | 608 } |
689 | 609 |
690 void RichMessageListView::OnBoundsAnimatorProgressed( | 610 void MessageListView::OnBoundsAnimatorProgressed( |
691 views::BoundsAnimator* animator) { | 611 views::BoundsAnimator* animator) { |
692 DCHECK_EQ(animator_.get(), animator); | 612 DCHECK_EQ(animator_.get(), animator); |
693 for (std::set<views::View*>::iterator iter = deleted_when_done_.begin(); | 613 for (std::set<views::View*>::iterator iter = deleted_when_done_.begin(); |
694 iter != deleted_when_done_.end(); ++iter) { | 614 iter != deleted_when_done_.end(); ++iter) { |
695 const ui::SlideAnimation* animation = animator->GetAnimationForView(*iter); | 615 const ui::SlideAnimation* animation = animator->GetAnimationForView(*iter); |
696 if (animation) | 616 if (animation) |
697 (*iter)->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); | 617 (*iter)->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); |
698 } | 618 } |
699 } | 619 } |
700 | 620 |
701 void RichMessageListView::OnBoundsAnimatorDone( | 621 void MessageListView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
702 views::BoundsAnimator* animator) { | |
703 STLDeleteContainerPointers( | 622 STLDeleteContainerPointers( |
704 deleted_when_done_.begin(), deleted_when_done_.end()); | 623 deleted_when_done_.begin(), deleted_when_done_.end()); |
705 deleted_when_done_.clear(); | 624 deleted_when_done_.clear(); |
706 | 625 |
707 if (clear_all_started_) { | 626 if (clear_all_started_) { |
708 clear_all_started_ = false; | 627 clear_all_started_ = false; |
709 message_center_view()->OnAllNotificationsCleared(); | 628 message_center_view()->OnAllNotificationsCleared(); |
710 } | 629 } |
711 | 630 |
712 if (has_deferred_task_) { | 631 if (has_deferred_task_) { |
713 has_deferred_task_ = false; | 632 has_deferred_task_ = false; |
714 DoUpdateIfPossible(); | 633 DoUpdateIfPossible(); |
715 } | 634 } |
716 | 635 |
717 if (GetWidget()) | 636 if (GetWidget()) |
718 GetWidget()->SynthesizeMouseMoveEvent(); | 637 GetWidget()->SynthesizeMouseMoveEvent(); |
719 } | 638 } |
720 | 639 |
721 int RichMessageListView::GetActualIndex(int index) { | 640 int MessageListView::GetActualIndex(int index) { |
722 for (int i = 0; i < child_count() && i <= index; ++i) | 641 for (int i = 0; i < child_count() && i <= index; ++i) |
723 index += IsValidChild(child_at(i)) ? 0 : 1; | 642 index += IsValidChild(child_at(i)) ? 0 : 1; |
724 return std::min(index, child_count()); | 643 return std::min(index, child_count()); |
725 } | 644 } |
726 | 645 |
727 bool RichMessageListView::IsValidChild(views::View* child) { | 646 bool MessageListView::IsValidChild(views::View* child) { |
728 return child->visible() && | 647 return child->visible() && |
729 deleting_views_.find(child) == deleting_views_.end() && | 648 deleting_views_.find(child) == deleting_views_.end() && |
730 deleted_when_done_.find(child) == deleted_when_done_.end(); | 649 deleted_when_done_.find(child) == deleted_when_done_.end(); |
731 } | 650 } |
732 | 651 |
733 void RichMessageListView::DoUpdateIfPossible() { | 652 void MessageListView::DoUpdateIfPossible() { |
734 gfx::Rect child_area = GetContentsBounds(); | 653 gfx::Rect child_area = GetContentsBounds(); |
735 if (child_area.IsEmpty()) | 654 if (child_area.IsEmpty()) |
736 return; | 655 return; |
737 | 656 |
738 if (animator_.get() && animator_->IsAnimating()) { | 657 if (animator_.get() && animator_->IsAnimating()) { |
739 has_deferred_task_ = true; | 658 has_deferred_task_ = true; |
740 return; | 659 return; |
741 } | 660 } |
742 | 661 |
743 if (!animator_.get()) { | 662 if (!animator_.get()) { |
(...skipping 23 matching lines...) Expand all Loading... |
767 for (int i = last_index; i >= 0; --i) { | 686 for (int i = last_index; i >= 0; --i) { |
768 views::View* child = child_at(i); | 687 views::View* child = child_at(i); |
769 AnimateChild(child, bottom - child->height(), child->height()); | 688 AnimateChild(child, bottom - child->height(), child->height()); |
770 bottom -= child->height() + between_items; | 689 bottom -= child->height() + between_items; |
771 } | 690 } |
772 } | 691 } |
773 adding_views_.clear(); | 692 adding_views_.clear(); |
774 deleting_views_.clear(); | 693 deleting_views_.clear(); |
775 } | 694 } |
776 | 695 |
777 void RichMessageListView::AnimateChild(views::View* child, | 696 void MessageListView::AnimateChild(views::View* child, int top, int height) { |
778 int top, | |
779 int height) { | |
780 gfx::Rect child_area = GetContentsBounds(); | 697 gfx::Rect child_area = GetContentsBounds(); |
781 if (adding_views_.find(child) != adding_views_.end()) { | 698 if (adding_views_.find(child) != adding_views_.end()) { |
782 child->SetBounds(child_area.right(), top, child_area.width(), height); | 699 child->SetBounds(child_area.right(), top, child_area.width(), height); |
783 animator_->AnimateViewTo( | 700 animator_->AnimateViewTo( |
784 child, gfx::Rect(child_area.x(), top, child_area.width(), height)); | 701 child, gfx::Rect(child_area.x(), top, child_area.width(), height)); |
785 } else if (deleting_views_.find(child) != deleting_views_.end()) { | 702 } else if (deleting_views_.find(child) != deleting_views_.end()) { |
786 DCHECK(child->layer()); | 703 DCHECK(child->layer()); |
787 // No moves, but animate to fade-out. | 704 // No moves, but animate to fade-out. |
788 animator_->AnimateViewTo(child, child->bounds()); | 705 animator_->AnimateViewTo(child, child->bounds()); |
789 deleted_when_done_.insert(child); | 706 deleted_when_done_.insert(child); |
790 } else { | 707 } else { |
791 gfx::Rect target(child_area.x(), top, child_area.width(), height); | 708 gfx::Rect target(child_area.x(), top, child_area.width(), height); |
792 if (child->bounds().origin() != target.origin()) | 709 if (child->bounds().origin() != target.origin()) |
793 animator_->AnimateViewTo(child, target); | 710 animator_->AnimateViewTo(child, target); |
794 else | 711 else |
795 child->SetBoundsRect(target); | 712 child->SetBoundsRect(target); |
796 } | 713 } |
797 } | 714 } |
798 | 715 |
799 void RichMessageListView::AnimateClearingOneNotification() { | 716 void MessageListView::AnimateClearingOneNotification() { |
800 DCHECK(!clearing_all_views_.empty()); | 717 DCHECK(!clearing_all_views_.empty()); |
801 | 718 |
802 clear_all_started_ = true; | 719 clear_all_started_ = true; |
803 | 720 |
804 views::View* child = clearing_all_views_.front(); | 721 views::View* child = clearing_all_views_.front(); |
805 clearing_all_views_.pop_front(); | 722 clearing_all_views_.pop_front(); |
806 | 723 |
807 // Slide from left to right. | 724 // Slide from left to right. |
808 gfx::Rect new_bounds = child->bounds(); | 725 gfx::Rect new_bounds = child->bounds(); |
809 new_bounds.set_x(new_bounds.right() + kMarginBetweenItems); | 726 new_bounds.set_x(new_bounds.right() + kMarginBetweenItems); |
810 animator_->AnimateViewTo(child, new_bounds); | 727 animator_->AnimateViewTo(child, new_bounds); |
811 | 728 |
812 // Schedule to start sliding out next notification after a short delay. | 729 // Schedule to start sliding out next notification after a short delay. |
813 if (!clearing_all_views_.empty()) { | 730 if (!clearing_all_views_.empty()) { |
814 base::MessageLoop::current()->PostDelayedTask( | 731 base::MessageLoop::current()->PostDelayedTask( |
815 FROM_HERE, | 732 FROM_HERE, |
816 base::Bind(&RichMessageListView::AnimateClearingOneNotification, | 733 base::Bind(&MessageListView::AnimateClearingOneNotification, |
817 weak_ptr_factory_.GetWeakPtr()), | 734 weak_ptr_factory_.GetWeakPtr()), |
818 base::TimeDelta::FromMilliseconds( | 735 base::TimeDelta::FromMilliseconds( |
819 kAnimateClearingNextNotificationDelayMS)); | 736 kAnimateClearingNextNotificationDelayMS)); |
820 } | 737 } |
821 } | 738 } |
822 | 739 |
823 // MessageCenterButtonBar ////////////////////////////////////////////////////// | |
824 | |
825 MessageCenterButtonBar::MessageCenterButtonBar( | |
826 MessageCenterView* message_center_view, MessageCenter* message_center) | |
827 : message_center_view_(message_center_view), | |
828 message_center_(message_center), | |
829 close_all_button_(NULL) { | |
830 } | |
831 | |
832 MessageCenterButtonBar::~MessageCenterButtonBar() { | |
833 } | |
834 | |
835 void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { | |
836 if (close_all_button_) | |
837 close_all_button_->SetEnabled(enabled); | |
838 } | |
839 | |
840 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { | |
841 if (close_all_button_) | |
842 close_all_button_->SetVisible(visible); | |
843 } | |
844 | |
845 // MessageCenterView /////////////////////////////////////////////////////////// | 740 // MessageCenterView /////////////////////////////////////////////////////////// |
846 | 741 |
847 MessageCenterView::MessageCenterView(MessageCenter* message_center, | 742 MessageCenterView::MessageCenterView(MessageCenter* message_center, |
848 MessageCenterTray* tray, | 743 MessageCenterTray* tray, |
849 int max_height, | 744 int max_height, |
850 bool initially_settings_visible) | 745 bool initially_settings_visible) |
851 : message_center_(message_center), | 746 : message_center_(message_center), |
852 tray_(tray), | 747 tray_(tray), |
853 settings_visible_(initially_settings_visible) { | 748 settings_visible_(initially_settings_visible) { |
854 message_center_->AddObserver(this); | 749 message_center_->AddObserver(this); |
855 set_notify_enter_exit_on_child(true); | 750 set_notify_enter_exit_on_child(true); |
856 set_background(views::Background::CreateSolidBackground( | 751 set_background(views::Background::CreateSolidBackground( |
857 kMessageCenterBackgroundColor)); | 752 kMessageCenterBackgroundColor)); |
858 | 753 |
859 if (IsRichNotificationEnabled()) | 754 button_bar_ = new MessageCenterButtonBar(this, message_center); |
860 button_bar_ = new RichMessageCenterButtonBar(this, message_center); | |
861 else | |
862 button_bar_ = new PoorMessageCenterButtonBar(this, message_center); | |
863 | 755 |
864 const int button_height = button_bar_->GetPreferredSize().height(); | 756 const int button_height = button_bar_->GetPreferredSize().height(); |
865 scroller_ = new BoundedScrollView(kMinScrollViewHeight, | 757 scroller_ = new BoundedScrollView(kMinScrollViewHeight, |
866 max_height - button_height); | 758 max_height - button_height); |
867 | 759 |
868 if (get_use_acceleration_when_possible()) { | 760 if (get_use_acceleration_when_possible()) { |
869 scroller_->SetPaintToLayer(true); | 761 scroller_->SetPaintToLayer(true); |
870 scroller_->SetFillsBoundsOpaquely(false); | 762 scroller_->SetFillsBoundsOpaquely(false); |
871 scroller_->layer()->SetMasksToBounds(true); | 763 scroller_->layer()->SetMasksToBounds(true); |
872 } | 764 } |
873 | 765 |
874 message_list_view_ = IsRichNotificationEnabled() ? | 766 message_list_view_ = new MessageListView(this); |
875 new RichMessageListView(this) : new MessageListView(this); | |
876 no_notifications_message_view_ = new NoNotificationMessageView(); | 767 no_notifications_message_view_ = new NoNotificationMessageView(); |
877 // Set the default visibility to false, otherwise the notification has slide | 768 // Set the default visibility to false, otherwise the notification has slide |
878 // in animation when the center is shown. | 769 // in animation when the center is shown. |
879 no_notifications_message_view_->SetVisible(false); | 770 no_notifications_message_view_->SetVisible(false); |
880 message_list_view_->AddChildView(no_notifications_message_view_); | 771 message_list_view_->AddChildView(no_notifications_message_view_); |
881 scroller_->SetContents(message_list_view_); | 772 scroller_->SetContents(message_list_view_); |
882 | 773 |
883 settings_view_ = new NotifierSettingsView( | 774 settings_view_ = new NotifierSettingsView( |
884 message_center_->GetNotifierSettingsProvider()); | 775 message_center_->GetNotifierSettingsProvider()); |
885 | 776 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
966 scroller_->SetEnabled(true); | 857 scroller_->SetEnabled(true); |
967 button_bar_->SetAllButtonsEnabled(true); | 858 button_bar_->SetAllButtonsEnabled(true); |
968 message_center_->RemoveAllNotifications(true); // Action by user. | 859 message_center_->RemoveAllNotifications(true); // Action by user. |
969 } | 860 } |
970 | 861 |
971 size_t MessageCenterView::NumMessageViewsForTest() const { | 862 size_t MessageCenterView::NumMessageViewsForTest() const { |
972 return message_list_view_->child_count(); | 863 return message_list_view_->child_count(); |
973 } | 864 } |
974 | 865 |
975 void MessageCenterView::Layout() { | 866 void MessageCenterView::Layout() { |
976 int between_child = IsRichNotificationEnabled() ? 0 : 1; | |
977 int button_height = button_bar_->GetHeightForWidth(width()); | 867 int button_height = button_bar_->GetHeightForWidth(width()); |
978 // Skip unnecessary re-layout of contents during the resize animation. | 868 // Skip unnecessary re-layout of contents during the resize animation. |
979 if (settings_transition_animation_ && | 869 if (settings_transition_animation_ && |
980 settings_transition_animation_->is_animating() && | 870 settings_transition_animation_->is_animating() && |
981 settings_transition_animation_->current_part_index() == 0) { | 871 settings_transition_animation_->current_part_index() == 0) { |
982 button_bar_->SetBounds(0, height() - button_height, width(), button_height); | 872 button_bar_->SetBounds(0, height() - button_height, width(), button_height); |
983 return; | 873 return; |
984 } | 874 } |
985 | 875 |
986 scroller_->SetBounds(0, 0, width(), height() - button_height - between_child); | 876 scroller_->SetBounds(0, 0, width(), height() - button_height); |
987 settings_view_->SetBounds( | 877 settings_view_->SetBounds(0, 0, width(), height() - button_height); |
988 0, 0, width(), height() - button_height - between_child); | |
989 | 878 |
990 bool is_scrollable = false; | 879 bool is_scrollable = false; |
991 if (scroller_->visible()) | 880 if (scroller_->visible()) |
992 is_scrollable = scroller_->height() < message_list_view_->height(); | 881 is_scrollable = scroller_->height() < message_list_view_->height(); |
993 else | 882 else |
994 is_scrollable = settings_view_->IsScrollable(); | 883 is_scrollable = settings_view_->IsScrollable(); |
995 | 884 |
996 if (is_scrollable && !button_bar_->border()) { | 885 if (is_scrollable && !button_bar_->border()) { |
997 button_bar_->set_border(views::Border::CreateSolidSidedBorder( | 886 button_bar_->set_border(views::Border::CreateSolidSidedBorder( |
998 1, 0, 0, 0, kFooterDelimiterColor)); | 887 1, 0, 0, 0, kFooterDelimiterColor)); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 scroller_->InvalidateLayout(); | 1088 scroller_->InvalidateLayout(); |
1200 PreferredSizeChanged(); | 1089 PreferredSizeChanged(); |
1201 Layout(); | 1090 Layout(); |
1202 } | 1091 } |
1203 | 1092 |
1204 void MessageCenterView::SetNotificationViewForTest(views::View* view) { | 1093 void MessageCenterView::SetNotificationViewForTest(views::View* view) { |
1205 message_list_view_->AddNotificationAt(view, 0); | 1094 message_list_view_->AddNotificationAt(view, 0); |
1206 } | 1095 } |
1207 | 1096 |
1208 } // namespace message_center | 1097 } // namespace message_center |
OLD | NEW |