| 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 MessageCenterButtonBar::MessageCenterButtonBar( |
| 173 // PoorMessageCenterButtonBar when the kEnableRichNotifications flag disappears. | 117 MessageCenterView* message_center_view, |
| 174 class RichMessageCenterButtonBar : public MessageCenterButtonBar, | 118 MessageCenter* message_center) |
| 175 public views::ButtonListener { | 119 : message_center_view_(message_center_view), |
| 176 public: | 120 message_center_(message_center), |
| 177 RichMessageCenterButtonBar(MessageCenterView* message_center_view, | 121 close_all_button_(NULL) { |
| 178 MessageCenter* message_center); | |
| 179 | |
| 180 private: | |
| 181 // Overridden from MessageCenterButtonBar: | |
| 182 virtual void SetAllButtonsEnabled(bool enabled) OVERRIDE; | |
| 183 | |
| 184 // Overridden from views::View: | |
| 185 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE; | |
| 186 | |
| 187 // Overridden from views::ButtonListener: | |
| 188 virtual void ButtonPressed(views::Button* sender, | |
| 189 const ui::Event& event) OVERRIDE; | |
| 190 | |
| 191 NotificationCenterButton* settings_button_; | |
| 192 NotificationCenterButton* quiet_mode_button_; | |
| 193 | |
| 194 DISALLOW_COPY_AND_ASSIGN(RichMessageCenterButtonBar); | |
| 195 }; | |
| 196 | |
| 197 RichMessageCenterButtonBar::RichMessageCenterButtonBar( | |
| 198 MessageCenterView* message_center_view, MessageCenter* message_center) | |
| 199 : MessageCenterButtonBar(message_center_view, message_center) { | |
| 200 if (get_use_acceleration_when_possible()) | 122 if (get_use_acceleration_when_possible()) |
| 201 SetPaintToLayer(true); | 123 SetPaintToLayer(true); |
| 202 set_background(views::Background::CreateSolidBackground( | 124 set_background(views::Background::CreateSolidBackground( |
| 203 kMessageCenterBackgroundColor)); | 125 kMessageCenterBackgroundColor)); |
| 204 | 126 |
| 205 views::Label* notification_label = new views::Label(l10n_util::GetStringUTF16( | 127 views::Label* notification_label = new views::Label(l10n_util::GetStringUTF16( |
| 206 IDS_MESSAGE_CENTER_FOOTER_TITLE)); | 128 IDS_MESSAGE_CENTER_FOOTER_TITLE)); |
| 207 notification_label->SetAutoColorReadabilityEnabled(false); | 129 notification_label->SetAutoColorReadabilityEnabled(false); |
| 208 notification_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 130 notification_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 209 notification_label->SetEnabledColor(kRegularTextColor); | 131 notification_label->SetEnabledColor(kRegularTextColor); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 views::ColumnSet* column = layout->AddColumnSet(0); | 180 views::ColumnSet* column = layout->AddColumnSet(0); |
| 259 column->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 181 column->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 260 1.0f, views::GridLayout::USE_PREF, 0, 0); | 182 1.0f, views::GridLayout::USE_PREF, 0, 0); |
| 261 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 183 column->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
| 262 0, views::GridLayout::USE_PREF, 0, 0); | 184 0, views::GridLayout::USE_PREF, 0, 0); |
| 263 layout->StartRow(0, 0); | 185 layout->StartRow(0, 0); |
| 264 layout->AddView(notification_label); | 186 layout->AddView(notification_label); |
| 265 layout->AddView(button_container); | 187 layout->AddView(button_container); |
| 266 } | 188 } |
| 267 | 189 |
| 268 // Overridden from MessageCenterButtonBar: | 190 MessageCenterButtonBar::~MessageCenterButtonBar() {} |
| 269 void RichMessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { | 191 |
| 270 MessageCenterButtonBar::SetAllButtonsEnabled(enabled); | 192 void MessageCenterButtonBar::SetAllButtonsEnabled(bool enabled) { |
| 193 if (close_all_button_) |
| 194 close_all_button_->SetEnabled(enabled); |
| 271 settings_button_->SetEnabled(enabled); | 195 settings_button_->SetEnabled(enabled); |
| 272 quiet_mode_button_->SetEnabled(enabled); | 196 quiet_mode_button_->SetEnabled(enabled); |
| 273 } | 197 } |
| 274 | 198 |
| 199 void MessageCenterButtonBar::SetCloseAllVisible(bool visible) { |
| 200 if (close_all_button_) |
| 201 close_all_button_->SetVisible(visible); |
| 202 } |
| 203 |
| 275 // Overridden from views::View: | 204 // Overridden from views::View: |
| 276 void RichMessageCenterButtonBar::ChildVisibilityChanged(views::View* child) { | 205 void MessageCenterButtonBar::ChildVisibilityChanged(views::View* child) { |
| 277 InvalidateLayout(); | 206 InvalidateLayout(); |
| 278 } | 207 } |
| 279 | 208 |
| 280 // Overridden from views::ButtonListener: | 209 // Overridden from views::ButtonListener: |
| 281 void RichMessageCenterButtonBar::ButtonPressed(views::Button* sender, | 210 void MessageCenterButtonBar::ButtonPressed(views::Button* sender, |
| 282 const ui::Event& event) { | 211 const ui::Event& event) { |
| 283 if (sender == close_all_button()) { | 212 if (sender == close_all_button()) { |
| 284 message_center_view()->ClearAllNotifications(); | 213 message_center_view()->ClearAllNotifications(); |
| 285 } else if (sender == settings_button_) { | 214 } else if (sender == settings_button_) { |
| 286 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); | 215 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); |
| 287 center_view->SetSettingsVisible(!center_view->settings_visible()); | 216 center_view->SetSettingsVisible(!center_view->settings_visible()); |
| 288 } else if (sender == quiet_mode_button_) { | 217 } else if (sender == quiet_mode_button_) { |
| 289 if (message_center()->IsQuietMode()) | 218 if (message_center()->IsQuietMode()) |
| 290 message_center()->SetQuietMode(false); | 219 message_center()->SetQuietMode(false); |
| 291 else | 220 else |
| 292 message_center()->EnterQuietModeWithExpire(base::TimeDelta::FromDays(1)); | 221 message_center()->EnterQuietModeWithExpire(base::TimeDelta::FromDays(1)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 315 | 244 |
| 316 DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); | 245 DISALLOW_COPY_AND_ASSIGN(BoundedScrollView); |
| 317 }; | 246 }; |
| 318 | 247 |
| 319 BoundedScrollView::BoundedScrollView(int min_height, int max_height) | 248 BoundedScrollView::BoundedScrollView(int min_height, int max_height) |
| 320 : min_height_(min_height), | 249 : min_height_(min_height), |
| 321 max_height_(max_height) { | 250 max_height_(max_height) { |
| 322 set_notify_enter_exit_on_child(true); | 251 set_notify_enter_exit_on_child(true); |
| 323 // Cancels the default dashed focus border. | 252 // Cancels the default dashed focus border. |
| 324 set_focus_border(NULL); | 253 set_focus_border(NULL); |
| 325 if (IsRichNotificationEnabled()) { | 254 set_background( |
| 326 set_background(views::Background::CreateSolidBackground( | 255 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); |
| 327 kMessageCenterBackgroundColor)); | 256 SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
| 328 SetVerticalScrollBar(new views::OverlayScrollBar(false)); | |
| 329 } | |
| 330 } | 257 } |
| 331 | 258 |
| 332 gfx::Size BoundedScrollView::GetPreferredSize() { | 259 gfx::Size BoundedScrollView::GetPreferredSize() { |
| 333 gfx::Size size = contents()->GetPreferredSize(); | 260 gfx::Size size = contents()->GetPreferredSize(); |
| 334 size.SetToMax(gfx::Size(size.width(), min_height_)); | 261 size.SetToMax(gfx::Size(size.width(), min_height_)); |
| 335 size.SetToMin(gfx::Size(size.width(), max_height_)); | 262 size.SetToMin(gfx::Size(size.width(), max_height_)); |
| 336 gfx::Insets insets = GetInsets(); | 263 gfx::Insets insets = GetInsets(); |
| 337 size.Enlarge(insets.width(), insets.height()); | 264 size.Enlarge(insets.width(), insets.height()); |
| 338 return size; | 265 return size; |
| 339 } | 266 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 int NoNotificationMessageView::GetHeightForWidth(int width) { | 323 int NoNotificationMessageView::GetHeightForWidth(int width) { |
| 397 return kMinScrollViewHeight; | 324 return kMinScrollViewHeight; |
| 398 } | 325 } |
| 399 | 326 |
| 400 void NoNotificationMessageView::Layout() { | 327 void NoNotificationMessageView::Layout() { |
| 401 int text_height = label_->GetHeightForWidth(width()); | 328 int text_height = label_->GetHeightForWidth(width()); |
| 402 int margin = (height() - text_height) / 2; | 329 int margin = (height() - text_height) / 2; |
| 403 label_->SetBounds(0, margin, width(), text_height); | 330 label_->SetBounds(0, margin, width(), text_height); |
| 404 } | 331 } |
| 405 | 332 |
| 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 | 333 // Displays a list of messages for rich notifications. It also supports |
| 461 // repositioning. | 334 // repositioning. |
| 462 class RichMessageListView : public MessageListView, | 335 class MessageListView : public views::View, |
| 463 public views::BoundsAnimatorObserver { | 336 public views::BoundsAnimatorObserver { |
| 464 public: | 337 public: |
| 465 explicit RichMessageListView(MessageCenterView* message_center_view); | 338 explicit MessageListView(MessageCenterView* message_center_view); |
| 466 virtual ~RichMessageListView(); | 339 virtual ~MessageListView(); |
| 340 |
| 341 void AddNotificationAt(views::View* view, int i); |
| 342 void RemoveNotificationAt(int i); |
| 343 void UpdateNotificationAt(views::View* view, int i); |
| 344 void SetRepositionTarget(const gfx::Rect& target_rect); |
| 345 void ResetRepositionSession(); |
| 346 void ClearAllNotifications(const gfx::Rect& visible_scroll_rect); |
| 467 | 347 |
| 468 protected: | 348 protected: |
| 469 // Overridden from views::View. | 349 // Overridden from views::View. |
| 470 virtual void Layout() OVERRIDE; | 350 virtual void Layout() OVERRIDE; |
| 471 virtual gfx::Size GetPreferredSize() OVERRIDE; | 351 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 472 virtual int GetHeightForWidth(int width) OVERRIDE; | 352 virtual int GetHeightForWidth(int width) OVERRIDE; |
| 473 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 353 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
| 474 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; | 354 virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; |
| 475 | 355 |
| 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. | 356 // Overridden from views::BoundsAnimatorObserver. |
| 486 virtual void OnBoundsAnimatorProgressed( | 357 virtual void OnBoundsAnimatorProgressed( |
| 487 views::BoundsAnimator* animator) OVERRIDE; | 358 views::BoundsAnimator* animator) OVERRIDE; |
| 488 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE; | 359 virtual void OnBoundsAnimatorDone(views::BoundsAnimator* animator) OVERRIDE; |
| 489 | 360 |
| 490 private: | 361 private: |
| 491 // Returns the actual index for child of |index|. | 362 // Returns the actual index for child of |index|. |
| 363 // MessageListView allows to slide down upper notifications, which means |
| 364 // that the upper ones should come above the lower ones. To achieve this, |
| 365 // inversed order is adopted. The top most notification is the last child, |
| 366 // and the bottom most notification is the first child. |
| 492 int GetActualIndex(int index); | 367 int GetActualIndex(int index); |
| 493 bool IsValidChild(views::View* child); | 368 bool IsValidChild(views::View* child); |
| 494 void DoUpdateIfPossible(); | 369 void DoUpdateIfPossible(); |
| 495 | 370 |
| 496 // Schedules animation for a child to the specified position. | 371 // Schedules animation for a child to the specified position. |
| 497 void AnimateChild(views::View* child, int top, int height); | 372 void AnimateChild(views::View* child, int top, int height); |
| 498 | 373 |
| 499 // Animate clearing one notification. | 374 // Animate clearing one notification. |
| 500 void AnimateClearingOneNotification(); | 375 void AnimateClearingOneNotification(); |
| 376 MessageCenterView* message_center_view() const { |
| 377 return message_center_view_; |
| 378 } |
| 501 | 379 |
| 380 MessageCenterView* message_center_view_; // Weak reference. |
| 502 // The top position of the reposition target rectangle. | 381 // The top position of the reposition target rectangle. |
| 503 int reposition_top_; | 382 int reposition_top_; |
| 504 | |
| 505 int fixed_height_; | 383 int fixed_height_; |
| 506 | |
| 507 bool has_deferred_task_; | 384 bool has_deferred_task_; |
| 508 bool clear_all_started_; | 385 bool clear_all_started_; |
| 509 std::set<views::View*> adding_views_; | 386 std::set<views::View*> adding_views_; |
| 510 std::set<views::View*> deleting_views_; | 387 std::set<views::View*> deleting_views_; |
| 511 std::set<views::View*> deleted_when_done_; | 388 std::set<views::View*> deleted_when_done_; |
| 512 std::list<views::View*> clearing_all_views_; | 389 std::list<views::View*> clearing_all_views_; |
| 513 scoped_ptr<views::BoundsAnimator> animator_; | 390 scoped_ptr<views::BoundsAnimator> animator_; |
| 514 base::WeakPtrFactory<RichMessageListView> weak_ptr_factory_; | 391 base::WeakPtrFactory<MessageListView> weak_ptr_factory_; |
| 515 | 392 |
| 516 DISALLOW_COPY_AND_ASSIGN(RichMessageListView); | 393 DISALLOW_COPY_AND_ASSIGN(MessageListView); |
| 517 }; | 394 }; |
| 518 | 395 |
| 519 RichMessageListView::RichMessageListView(MessageCenterView* message_center_view) | 396 MessageListView::MessageListView(MessageCenterView* message_center_view) |
| 520 : MessageListView(message_center_view), | 397 : message_center_view_(message_center_view), |
| 521 reposition_top_(-1), | 398 reposition_top_(-1), |
| 522 fixed_height_(0), | 399 fixed_height_(0), |
| 523 has_deferred_task_(false), | 400 has_deferred_task_(false), |
| 524 clear_all_started_(false), | 401 clear_all_started_(false), |
| 525 weak_ptr_factory_(this) { | 402 weak_ptr_factory_(this) { |
| 403 views::BoxLayout* layout = |
| 404 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); |
| 405 layout->set_spread_blank_space(true); |
| 406 SetLayoutManager(layout); |
| 407 |
| 526 // Set the margin to 0 for the layout. BoxLayout assumes the same margin | 408 // 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 | 409 // 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 | 410 // because of the shadow of message view. Use an empty border instead |
| 529 // to provide this margin. | 411 // to provide this margin. |
| 530 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); | 412 gfx::Insets shadow_insets = MessageView::GetShadowInsets(); |
| 531 set_background(views::Background::CreateSolidBackground( | 413 set_background(views::Background::CreateSolidBackground( |
| 532 kMessageCenterBackgroundColor)); | 414 kMessageCenterBackgroundColor)); |
| 533 set_border(views::Border::CreateEmptyBorder( | 415 set_border(views::Border::CreateEmptyBorder( |
| 534 kMarginBetweenItems - shadow_insets.top(), /* top */ | 416 kMarginBetweenItems - shadow_insets.top(), /* top */ |
| 535 kMarginBetweenItems - shadow_insets.left(), /* left */ | 417 kMarginBetweenItems - shadow_insets.left(), /* left */ |
| 536 kMarginBetweenItems - shadow_insets.bottom(), /* bottom */ | 418 kMarginBetweenItems - shadow_insets.bottom(), /* bottom */ |
| 537 kMarginBetweenItems - shadow_insets.right() /* right */ )); | 419 kMarginBetweenItems - shadow_insets.right() /* right */ )); |
| 538 } | 420 } |
| 539 | 421 |
| 540 RichMessageListView::~RichMessageListView() { | 422 MessageListView::~MessageListView() { |
| 541 if (animator_.get()) | 423 if (animator_.get()) |
| 542 animator_->RemoveObserver(this); | 424 animator_->RemoveObserver(this); |
| 543 } | 425 } |
| 544 | 426 |
| 545 void RichMessageListView::Layout() { | 427 void MessageListView::Layout() { |
| 546 if (animator_.get()) | 428 if (animator_.get()) |
| 547 return; | 429 return; |
| 548 | 430 |
| 549 gfx::Rect child_area = GetContentsBounds(); | 431 gfx::Rect child_area = GetContentsBounds(); |
| 550 int top = child_area.y(); | 432 int top = child_area.y(); |
| 551 int between_items = | 433 int between_items = |
| 552 kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); | 434 kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); |
| 553 | 435 |
| 554 for (int i = 0; i < child_count(); ++i) { | 436 for (int i = 0; i < child_count(); ++i) { |
| 555 views::View* child = child_at(i); | 437 views::View* child = child_at(i); |
| 556 if (!child->visible()) | 438 if (!child->visible()) |
| 557 continue; | 439 continue; |
| 558 int height = child->GetHeightForWidth(child_area.width()); | 440 int height = child->GetHeightForWidth(child_area.width()); |
| 559 child->SetBounds(child_area.x(), top, child_area.width(), height); | 441 child->SetBounds(child_area.x(), top, child_area.width(), height); |
| 560 top += height + between_items; | 442 top += height + between_items; |
| 561 } | 443 } |
| 562 } | 444 } |
| 563 | 445 |
| 564 void RichMessageListView::AddNotificationAt(views::View* view, int i) { | 446 void MessageListView::AddNotificationAt(views::View* view, int i) { |
| 565 AddChildViewAt(view, GetActualIndex(i)); | 447 AddChildViewAt(view, GetActualIndex(i)); |
| 566 if (GetContentsBounds().IsEmpty()) | 448 if (GetContentsBounds().IsEmpty()) |
| 567 return; | 449 return; |
| 568 | 450 |
| 569 adding_views_.insert(view); | 451 adding_views_.insert(view); |
| 570 DoUpdateIfPossible(); | 452 DoUpdateIfPossible(); |
| 571 } | 453 } |
| 572 | 454 |
| 573 void RichMessageListView::RemoveNotificationAt(int i) { | 455 void MessageListView::RemoveNotificationAt(int i) { |
| 574 views::View* child = child_at(GetActualIndex(i)); | 456 views::View* child = child_at(GetActualIndex(i)); |
| 575 if (GetContentsBounds().IsEmpty()) { | 457 if (GetContentsBounds().IsEmpty()) { |
| 576 delete child; | 458 delete child; |
| 577 } else { | 459 } else { |
| 578 if (child->layer()) { | 460 if (child->layer()) { |
| 579 deleting_views_.insert(child); | 461 deleting_views_.insert(child); |
| 580 } else { | 462 } else { |
| 581 if (animator_.get()) | 463 if (animator_.get()) |
| 582 animator_->StopAnimatingView(child); | 464 animator_->StopAnimatingView(child); |
| 583 delete child; | 465 delete child; |
| 584 } | 466 } |
| 585 DoUpdateIfPossible(); | 467 DoUpdateIfPossible(); |
| 586 } | 468 } |
| 587 } | 469 } |
| 588 | 470 |
| 589 void RichMessageListView::UpdateNotificationAt(views::View* view, int i) { | 471 void MessageListView::UpdateNotificationAt(views::View* view, int i) { |
| 590 int actual_index = GetActualIndex(i); | 472 int actual_index = GetActualIndex(i); |
| 591 views::View* child = child_at(actual_index); | 473 views::View* child = child_at(actual_index); |
| 592 if (animator_.get()) | 474 if (animator_.get()) |
| 593 animator_->StopAnimatingView(child); | 475 animator_->StopAnimatingView(child); |
| 594 gfx::Rect old_bounds = child->bounds(); | 476 gfx::Rect old_bounds = child->bounds(); |
| 595 if (deleting_views_.find(child) != deleting_views_.end()) | 477 if (deleting_views_.find(child) != deleting_views_.end()) |
| 596 deleting_views_.erase(child); | 478 deleting_views_.erase(child); |
| 597 if (deleted_when_done_.find(child) != deleted_when_done_.end()) | 479 if (deleted_when_done_.find(child) != deleted_when_done_.end()) |
| 598 deleted_when_done_.erase(child); | 480 deleted_when_done_.erase(child); |
| 599 delete child; | 481 delete child; |
| 600 AddChildViewAt(view, actual_index); | 482 AddChildViewAt(view, actual_index); |
| 601 view->SetBounds(old_bounds.x(), old_bounds.y(), old_bounds.width(), | 483 view->SetBounds(old_bounds.x(), old_bounds.y(), old_bounds.width(), |
| 602 view->GetHeightForWidth(old_bounds.width())); | 484 view->GetHeightForWidth(old_bounds.width())); |
| 603 DoUpdateIfPossible(); | 485 DoUpdateIfPossible(); |
| 604 } | 486 } |
| 605 | 487 |
| 606 gfx::Size RichMessageListView::GetPreferredSize() { | 488 gfx::Size MessageListView::GetPreferredSize() { |
| 607 int width = 0; | 489 int width = 0; |
| 608 for (int i = 0; i < child_count(); i++) { | 490 for (int i = 0; i < child_count(); i++) { |
| 609 views::View* child = child_at(i); | 491 views::View* child = child_at(i); |
| 610 if (IsValidChild(child)) | 492 if (IsValidChild(child)) |
| 611 width = std::max(width, child->GetPreferredSize().width()); | 493 width = std::max(width, child->GetPreferredSize().width()); |
| 612 } | 494 } |
| 613 | 495 |
| 614 return gfx::Size(width + GetInsets().width(), | 496 return gfx::Size(width + GetInsets().width(), |
| 615 GetHeightForWidth(width + GetInsets().width())); | 497 GetHeightForWidth(width + GetInsets().width())); |
| 616 } | 498 } |
| 617 | 499 |
| 618 int RichMessageListView::GetHeightForWidth(int width) { | 500 int MessageListView::GetHeightForWidth(int width) { |
| 619 if (fixed_height_ > 0) | 501 if (fixed_height_ > 0) |
| 620 return fixed_height_; | 502 return fixed_height_; |
| 621 | 503 |
| 622 width -= GetInsets().width(); | 504 width -= GetInsets().width(); |
| 623 int height = 0; | 505 int height = 0; |
| 624 int padding = 0; | 506 int padding = 0; |
| 625 for (int i = 0; i < child_count(); ++i) { | 507 for (int i = 0; i < child_count(); ++i) { |
| 626 views::View* child = child_at(i); | 508 views::View* child = child_at(i); |
| 627 if (!IsValidChild(child)) | 509 if (!IsValidChild(child)) |
| 628 continue; | 510 continue; |
| 629 height += child->GetHeightForWidth(width) + padding; | 511 height += child->GetHeightForWidth(width) + padding; |
| 630 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); | 512 padding = kMarginBetweenItems - MessageView::GetShadowInsets().bottom(); |
| 631 } | 513 } |
| 632 | 514 |
| 633 return height + GetInsets().height(); | 515 return height + GetInsets().height(); |
| 634 } | 516 } |
| 635 | 517 |
| 636 void RichMessageListView::PaintChildren(gfx::Canvas* canvas) { | 518 void MessageListView::PaintChildren(gfx::Canvas* canvas) { |
| 637 // Paint in the inversed order. Otherwise upper notification may be | 519 // Paint in the inversed order. Otherwise upper notification may be |
| 638 // hidden by the lower one. | 520 // hidden by the lower one. |
| 639 for (int i = child_count() - 1; i >= 0; --i) { | 521 for (int i = child_count() - 1; i >= 0; --i) { |
| 640 if (!child_at(i)->layer()) | 522 if (!child_at(i)->layer()) |
| 641 child_at(i)->Paint(canvas); | 523 child_at(i)->Paint(canvas); |
| 642 } | 524 } |
| 643 } | 525 } |
| 644 | 526 |
| 645 void RichMessageListView::ReorderChildLayers(ui::Layer* parent_layer) { | 527 void MessageListView::ReorderChildLayers(ui::Layer* parent_layer) { |
| 646 // Reorder children to stack the last child layer at the top. Otherwise | 528 // Reorder children to stack the last child layer at the top. Otherwise |
| 647 // upper notification may be hidden by the lower one. | 529 // upper notification may be hidden by the lower one. |
| 648 for (int i = 0; i < child_count(); ++i) { | 530 for (int i = 0; i < child_count(); ++i) { |
| 649 if (child_at(i)->layer()) | 531 if (child_at(i)->layer()) |
| 650 parent_layer->StackAtBottom(child_at(i)->layer()); | 532 parent_layer->StackAtBottom(child_at(i)->layer()); |
| 651 } | 533 } |
| 652 } | 534 } |
| 653 | 535 |
| 654 void RichMessageListView::SetRepositionTarget(const gfx::Rect& target) { | 536 void MessageListView::SetRepositionTarget(const gfx::Rect& target) { |
| 655 reposition_top_ = target.y(); | 537 reposition_top_ = target.y(); |
| 656 fixed_height_ = GetHeightForWidth(width()); | 538 fixed_height_ = GetHeightForWidth(width()); |
| 657 } | 539 } |
| 658 | 540 |
| 659 void RichMessageListView::ResetRepositionSession() { | 541 void MessageListView::ResetRepositionSession() { |
| 660 // Don't call DoUpdateIfPossible(), but let Layout() do the task without | 542 // Don't call DoUpdateIfPossible(), but let Layout() do the task without |
| 661 // animation. Reset will cause the change of the bubble size itself, and | 543 // animation. Reset will cause the change of the bubble size itself, and |
| 662 // animation from the old location will look weird. | 544 // animation from the old location will look weird. |
| 663 if (reposition_top_ >= 0 && animator_.get()) { | 545 if (reposition_top_ >= 0 && animator_.get()) { |
| 664 has_deferred_task_ = false; | 546 has_deferred_task_ = false; |
| 665 // cancel cause OnBoundsAnimatorDone which deletes |deleted_when_done_|. | 547 // cancel cause OnBoundsAnimatorDone which deletes |deleted_when_done_|. |
| 666 animator_->Cancel(); | 548 animator_->Cancel(); |
| 667 STLDeleteContainerPointers(deleting_views_.begin(), deleting_views_.end()); | 549 STLDeleteContainerPointers(deleting_views_.begin(), deleting_views_.end()); |
| 668 deleting_views_.clear(); | 550 deleting_views_.clear(); |
| 669 adding_views_.clear(); | 551 adding_views_.clear(); |
| 670 animator_.reset(); | 552 animator_.reset(); |
| 671 } | 553 } |
| 672 | 554 |
| 673 reposition_top_ = -1; | 555 reposition_top_ = -1; |
| 674 fixed_height_ = 0; | 556 fixed_height_ = 0; |
| 675 } | 557 } |
| 676 | 558 |
| 677 void RichMessageListView::ClearAllNotifications( | 559 void MessageListView::ClearAllNotifications( |
| 678 const gfx::Rect& visible_scroll_rect) { | 560 const gfx::Rect& visible_scroll_rect) { |
| 679 for (int i = 0; i < child_count(); ++i) { | 561 for (int i = 0; i < child_count(); ++i) { |
| 680 views::View* child = child_at(i); | 562 views::View* child = child_at(i); |
| 681 if (!child->visible()) | 563 if (!child->visible()) |
| 682 continue; | 564 continue; |
| 683 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) | 565 if (gfx::IntersectRects(child->bounds(), visible_scroll_rect).IsEmpty()) |
| 684 continue; | 566 continue; |
| 685 clearing_all_views_.push_back(child); | 567 clearing_all_views_.push_back(child); |
| 686 } | 568 } |
| 687 DoUpdateIfPossible(); | 569 DoUpdateIfPossible(); |
| 688 } | 570 } |
| 689 | 571 |
| 690 void RichMessageListView::OnBoundsAnimatorProgressed( | 572 void MessageListView::OnBoundsAnimatorProgressed( |
| 691 views::BoundsAnimator* animator) { | 573 views::BoundsAnimator* animator) { |
| 692 DCHECK_EQ(animator_.get(), animator); | 574 DCHECK_EQ(animator_.get(), animator); |
| 693 for (std::set<views::View*>::iterator iter = deleted_when_done_.begin(); | 575 for (std::set<views::View*>::iterator iter = deleted_when_done_.begin(); |
| 694 iter != deleted_when_done_.end(); ++iter) { | 576 iter != deleted_when_done_.end(); ++iter) { |
| 695 const ui::SlideAnimation* animation = animator->GetAnimationForView(*iter); | 577 const ui::SlideAnimation* animation = animator->GetAnimationForView(*iter); |
| 696 if (animation) | 578 if (animation) |
| 697 (*iter)->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); | 579 (*iter)->layer()->SetOpacity(animation->CurrentValueBetween(1.0, 0.0)); |
| 698 } | 580 } |
| 699 } | 581 } |
| 700 | 582 |
| 701 void RichMessageListView::OnBoundsAnimatorDone( | 583 void MessageListView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
| 702 views::BoundsAnimator* animator) { | |
| 703 STLDeleteContainerPointers( | 584 STLDeleteContainerPointers( |
| 704 deleted_when_done_.begin(), deleted_when_done_.end()); | 585 deleted_when_done_.begin(), deleted_when_done_.end()); |
| 705 deleted_when_done_.clear(); | 586 deleted_when_done_.clear(); |
| 706 | 587 |
| 707 if (clear_all_started_) { | 588 if (clear_all_started_) { |
| 708 clear_all_started_ = false; | 589 clear_all_started_ = false; |
| 709 message_center_view()->OnAllNotificationsCleared(); | 590 message_center_view()->OnAllNotificationsCleared(); |
| 710 } | 591 } |
| 711 | 592 |
| 712 if (has_deferred_task_) { | 593 if (has_deferred_task_) { |
| 713 has_deferred_task_ = false; | 594 has_deferred_task_ = false; |
| 714 DoUpdateIfPossible(); | 595 DoUpdateIfPossible(); |
| 715 } | 596 } |
| 716 | 597 |
| 717 if (GetWidget()) | 598 if (GetWidget()) |
| 718 GetWidget()->SynthesizeMouseMoveEvent(); | 599 GetWidget()->SynthesizeMouseMoveEvent(); |
| 719 } | 600 } |
| 720 | 601 |
| 721 int RichMessageListView::GetActualIndex(int index) { | 602 int MessageListView::GetActualIndex(int index) { |
| 722 for (int i = 0; i < child_count() && i <= index; ++i) | 603 for (int i = 0; i < child_count() && i <= index; ++i) |
| 723 index += IsValidChild(child_at(i)) ? 0 : 1; | 604 index += IsValidChild(child_at(i)) ? 0 : 1; |
| 724 return std::min(index, child_count()); | 605 return std::min(index, child_count()); |
| 725 } | 606 } |
| 726 | 607 |
| 727 bool RichMessageListView::IsValidChild(views::View* child) { | 608 bool MessageListView::IsValidChild(views::View* child) { |
| 728 return child->visible() && | 609 return child->visible() && |
| 729 deleting_views_.find(child) == deleting_views_.end() && | 610 deleting_views_.find(child) == deleting_views_.end() && |
| 730 deleted_when_done_.find(child) == deleted_when_done_.end(); | 611 deleted_when_done_.find(child) == deleted_when_done_.end(); |
| 731 } | 612 } |
| 732 | 613 |
| 733 void RichMessageListView::DoUpdateIfPossible() { | 614 void MessageListView::DoUpdateIfPossible() { |
| 734 gfx::Rect child_area = GetContentsBounds(); | 615 gfx::Rect child_area = GetContentsBounds(); |
| 735 if (child_area.IsEmpty()) | 616 if (child_area.IsEmpty()) |
| 736 return; | 617 return; |
| 737 | 618 |
| 738 if (animator_.get() && animator_->IsAnimating()) { | 619 if (animator_.get() && animator_->IsAnimating()) { |
| 739 has_deferred_task_ = true; | 620 has_deferred_task_ = true; |
| 740 return; | 621 return; |
| 741 } | 622 } |
| 742 | 623 |
| 743 if (!animator_.get()) { | 624 if (!animator_.get()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 767 for (int i = last_index; i >= 0; --i) { | 648 for (int i = last_index; i >= 0; --i) { |
| 768 views::View* child = child_at(i); | 649 views::View* child = child_at(i); |
| 769 AnimateChild(child, bottom - child->height(), child->height()); | 650 AnimateChild(child, bottom - child->height(), child->height()); |
| 770 bottom -= child->height() + between_items; | 651 bottom -= child->height() + between_items; |
| 771 } | 652 } |
| 772 } | 653 } |
| 773 adding_views_.clear(); | 654 adding_views_.clear(); |
| 774 deleting_views_.clear(); | 655 deleting_views_.clear(); |
| 775 } | 656 } |
| 776 | 657 |
| 777 void RichMessageListView::AnimateChild(views::View* child, | 658 void MessageListView::AnimateChild(views::View* child, int top, int height) { |
| 778 int top, | |
| 779 int height) { | |
| 780 gfx::Rect child_area = GetContentsBounds(); | 659 gfx::Rect child_area = GetContentsBounds(); |
| 781 if (adding_views_.find(child) != adding_views_.end()) { | 660 if (adding_views_.find(child) != adding_views_.end()) { |
| 782 child->SetBounds(child_area.right(), top, child_area.width(), height); | 661 child->SetBounds(child_area.right(), top, child_area.width(), height); |
| 783 animator_->AnimateViewTo( | 662 animator_->AnimateViewTo( |
| 784 child, gfx::Rect(child_area.x(), top, child_area.width(), height)); | 663 child, gfx::Rect(child_area.x(), top, child_area.width(), height)); |
| 785 } else if (deleting_views_.find(child) != deleting_views_.end()) { | 664 } else if (deleting_views_.find(child) != deleting_views_.end()) { |
| 786 DCHECK(child->layer()); | 665 DCHECK(child->layer()); |
| 787 // No moves, but animate to fade-out. | 666 // No moves, but animate to fade-out. |
| 788 animator_->AnimateViewTo(child, child->bounds()); | 667 animator_->AnimateViewTo(child, child->bounds()); |
| 789 deleted_when_done_.insert(child); | 668 deleted_when_done_.insert(child); |
| 790 } else { | 669 } else { |
| 791 gfx::Rect target(child_area.x(), top, child_area.width(), height); | 670 gfx::Rect target(child_area.x(), top, child_area.width(), height); |
| 792 if (child->bounds().origin() != target.origin()) | 671 if (child->bounds().origin() != target.origin()) |
| 793 animator_->AnimateViewTo(child, target); | 672 animator_->AnimateViewTo(child, target); |
| 794 else | 673 else |
| 795 child->SetBoundsRect(target); | 674 child->SetBoundsRect(target); |
| 796 } | 675 } |
| 797 } | 676 } |
| 798 | 677 |
| 799 void RichMessageListView::AnimateClearingOneNotification() { | 678 void MessageListView::AnimateClearingOneNotification() { |
| 800 DCHECK(!clearing_all_views_.empty()); | 679 DCHECK(!clearing_all_views_.empty()); |
| 801 | 680 |
| 802 clear_all_started_ = true; | 681 clear_all_started_ = true; |
| 803 | 682 |
| 804 views::View* child = clearing_all_views_.front(); | 683 views::View* child = clearing_all_views_.front(); |
| 805 clearing_all_views_.pop_front(); | 684 clearing_all_views_.pop_front(); |
| 806 | 685 |
| 807 // Slide from left to right. | 686 // Slide from left to right. |
| 808 gfx::Rect new_bounds = child->bounds(); | 687 gfx::Rect new_bounds = child->bounds(); |
| 809 new_bounds.set_x(new_bounds.right() + kMarginBetweenItems); | 688 new_bounds.set_x(new_bounds.right() + kMarginBetweenItems); |
| 810 animator_->AnimateViewTo(child, new_bounds); | 689 animator_->AnimateViewTo(child, new_bounds); |
| 811 | 690 |
| 812 // Schedule to start sliding out next notification after a short delay. | 691 // Schedule to start sliding out next notification after a short delay. |
| 813 if (!clearing_all_views_.empty()) { | 692 if (!clearing_all_views_.empty()) { |
| 814 base::MessageLoop::current()->PostDelayedTask( | 693 base::MessageLoop::current()->PostDelayedTask( |
| 815 FROM_HERE, | 694 FROM_HERE, |
| 816 base::Bind(&RichMessageListView::AnimateClearingOneNotification, | 695 base::Bind(&MessageListView::AnimateClearingOneNotification, |
| 817 weak_ptr_factory_.GetWeakPtr()), | 696 weak_ptr_factory_.GetWeakPtr()), |
| 818 base::TimeDelta::FromMilliseconds( | 697 base::TimeDelta::FromMilliseconds( |
| 819 kAnimateClearingNextNotificationDelayMS)); | 698 kAnimateClearingNextNotificationDelayMS)); |
| 820 } | 699 } |
| 821 } | 700 } |
| 822 | 701 |
| 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 /////////////////////////////////////////////////////////// | 702 // MessageCenterView /////////////////////////////////////////////////////////// |
| 846 | 703 |
| 847 MessageCenterView::MessageCenterView(MessageCenter* message_center, | 704 MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| 848 MessageCenterTray* tray, | 705 MessageCenterTray* tray, |
| 849 int max_height, | 706 int max_height, |
| 850 bool initially_settings_visible) | 707 bool initially_settings_visible) |
| 851 : message_center_(message_center), | 708 : message_center_(message_center), |
| 852 tray_(tray), | 709 tray_(tray), |
| 853 settings_visible_(initially_settings_visible) { | 710 settings_visible_(initially_settings_visible) { |
| 854 message_center_->AddObserver(this); | 711 message_center_->AddObserver(this); |
| 855 set_notify_enter_exit_on_child(true); | 712 set_notify_enter_exit_on_child(true); |
| 856 set_background(views::Background::CreateSolidBackground( | 713 set_background(views::Background::CreateSolidBackground( |
| 857 kMessageCenterBackgroundColor)); | 714 kMessageCenterBackgroundColor)); |
| 858 | 715 |
| 859 if (IsRichNotificationEnabled()) | 716 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 | 717 |
| 864 const int button_height = button_bar_->GetPreferredSize().height(); | 718 const int button_height = button_bar_->GetPreferredSize().height(); |
| 865 scroller_ = new BoundedScrollView(kMinScrollViewHeight, | 719 scroller_ = new BoundedScrollView(kMinScrollViewHeight, |
| 866 max_height - button_height); | 720 max_height - button_height); |
| 867 | 721 |
| 868 if (get_use_acceleration_when_possible()) { | 722 if (get_use_acceleration_when_possible()) { |
| 869 scroller_->SetPaintToLayer(true); | 723 scroller_->SetPaintToLayer(true); |
| 870 scroller_->SetFillsBoundsOpaquely(false); | 724 scroller_->SetFillsBoundsOpaquely(false); |
| 871 scroller_->layer()->SetMasksToBounds(true); | 725 scroller_->layer()->SetMasksToBounds(true); |
| 872 } | 726 } |
| 873 | 727 |
| 874 message_list_view_ = IsRichNotificationEnabled() ? | 728 message_list_view_ = new MessageListView(this); |
| 875 new RichMessageListView(this) : new MessageListView(this); | |
| 876 no_notifications_message_view_ = new NoNotificationMessageView(); | 729 no_notifications_message_view_ = new NoNotificationMessageView(); |
| 877 // Set the default visibility to false, otherwise the notification has slide | 730 // Set the default visibility to false, otherwise the notification has slide |
| 878 // in animation when the center is shown. | 731 // in animation when the center is shown. |
| 879 no_notifications_message_view_->SetVisible(false); | 732 no_notifications_message_view_->SetVisible(false); |
| 880 message_list_view_->AddChildView(no_notifications_message_view_); | 733 message_list_view_->AddChildView(no_notifications_message_view_); |
| 881 scroller_->SetContents(message_list_view_); | 734 scroller_->SetContents(message_list_view_); |
| 882 | 735 |
| 883 settings_view_ = new NotifierSettingsView( | 736 settings_view_ = new NotifierSettingsView( |
| 884 message_center_->GetNotifierSettingsProvider()); | 737 message_center_->GetNotifierSettingsProvider()); |
| 885 | 738 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 scroller_->SetEnabled(true); | 819 scroller_->SetEnabled(true); |
| 967 button_bar_->SetAllButtonsEnabled(true); | 820 button_bar_->SetAllButtonsEnabled(true); |
| 968 message_center_->RemoveAllNotifications(true); // Action by user. | 821 message_center_->RemoveAllNotifications(true); // Action by user. |
| 969 } | 822 } |
| 970 | 823 |
| 971 size_t MessageCenterView::NumMessageViewsForTest() const { | 824 size_t MessageCenterView::NumMessageViewsForTest() const { |
| 972 return message_list_view_->child_count(); | 825 return message_list_view_->child_count(); |
| 973 } | 826 } |
| 974 | 827 |
| 975 void MessageCenterView::Layout() { | 828 void MessageCenterView::Layout() { |
| 976 int between_child = IsRichNotificationEnabled() ? 0 : 1; | |
| 977 int button_height = button_bar_->GetHeightForWidth(width()); | 829 int button_height = button_bar_->GetHeightForWidth(width()); |
| 978 // Skip unnecessary re-layout of contents during the resize animation. | 830 // Skip unnecessary re-layout of contents during the resize animation. |
| 979 if (settings_transition_animation_ && | 831 if (settings_transition_animation_ && |
| 980 settings_transition_animation_->is_animating() && | 832 settings_transition_animation_->is_animating() && |
| 981 settings_transition_animation_->current_part_index() == 0) { | 833 settings_transition_animation_->current_part_index() == 0) { |
| 982 button_bar_->SetBounds(0, height() - button_height, width(), button_height); | 834 button_bar_->SetBounds(0, height() - button_height, width(), button_height); |
| 983 return; | 835 return; |
| 984 } | 836 } |
| 985 | 837 |
| 986 scroller_->SetBounds(0, 0, width(), height() - button_height - between_child); | 838 scroller_->SetBounds(0, 0, width(), height() - button_height); |
| 987 settings_view_->SetBounds( | 839 settings_view_->SetBounds(0, 0, width(), height() - button_height); |
| 988 0, 0, width(), height() - button_height - between_child); | |
| 989 | 840 |
| 990 bool is_scrollable = false; | 841 bool is_scrollable = false; |
| 991 if (scroller_->visible()) | 842 if (scroller_->visible()) |
| 992 is_scrollable = scroller_->height() < message_list_view_->height(); | 843 is_scrollable = scroller_->height() < message_list_view_->height(); |
| 993 else | 844 else |
| 994 is_scrollable = settings_view_->IsScrollable(); | 845 is_scrollable = settings_view_->IsScrollable(); |
| 995 | 846 |
| 996 if (is_scrollable && !button_bar_->border()) { | 847 if (is_scrollable && !button_bar_->border()) { |
| 997 button_bar_->set_border(views::Border::CreateSolidSidedBorder( | 848 button_bar_->set_border(views::Border::CreateSolidSidedBorder( |
| 998 1, 0, 0, 0, kFooterDelimiterColor)); | 849 1, 0, 0, 0, kFooterDelimiterColor)); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 scroller_->InvalidateLayout(); | 1050 scroller_->InvalidateLayout(); |
| 1200 PreferredSizeChanged(); | 1051 PreferredSizeChanged(); |
| 1201 Layout(); | 1052 Layout(); |
| 1202 } | 1053 } |
| 1203 | 1054 |
| 1204 void MessageCenterView::SetNotificationViewForTest(views::View* view) { | 1055 void MessageCenterView::SetNotificationViewForTest(views::View* view) { |
| 1205 message_list_view_->AddNotificationAt(view, 0); | 1056 message_list_view_->AddNotificationAt(view, 0); |
| 1206 } | 1057 } |
| 1207 | 1058 |
| 1208 } // namespace message_center | 1059 } // namespace message_center |
| OLD | NEW |