| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "ui/views/border.h" | 34 #include "ui/views/border.h" |
| 35 #include "ui/views/controls/button/button.h" | 35 #include "ui/views/controls/button/button.h" |
| 36 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/scroll_view.h" | 37 #include "ui/views/controls/scroll_view.h" |
| 38 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 38 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
| 39 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
| 40 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
| 41 | 41 |
| 42 namespace message_center { | 42 namespace message_center { |
| 43 | 43 |
| 44 // static | |
| 45 bool MessageCenterView::disable_animation_for_testing = false; | |
| 46 | |
| 47 namespace { | 44 namespace { |
| 48 | 45 |
| 49 const int kDefaultAnimationDurationMs = 120; | 46 const int kDefaultAnimationDurationMs = 120; |
| 50 const int kDefaultFrameRateHz = 60; | 47 const int kDefaultFrameRateHz = 60; |
| 51 | 48 |
| 52 void SetViewHierarchyEnabled(views::View* view, bool enabled) { | 49 void SetViewHierarchyEnabled(views::View* view, bool enabled) { |
| 53 for (int i = 0; i < view->child_count(); i++) | 50 for (int i = 0; i < view->child_count(); i++) |
| 54 SetViewHierarchyEnabled(view->child_at(i), enabled); | 51 SetViewHierarchyEnabled(view->child_at(i), enabled); |
| 55 view->SetEnabled(enabled); | 52 view->SetEnabled(enabled); |
| 56 } | 53 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 69 scroller_(NULL), | 66 scroller_(NULL), |
| 70 settings_view_(NULL), | 67 settings_view_(NULL), |
| 71 button_bar_(NULL), | 68 button_bar_(NULL), |
| 72 top_down_(top_down), | 69 top_down_(top_down), |
| 73 settings_visible_(initially_settings_visible), | 70 settings_visible_(initially_settings_visible), |
| 74 source_view_(NULL), | 71 source_view_(NULL), |
| 75 source_height_(0), | 72 source_height_(0), |
| 76 target_view_(NULL), | 73 target_view_(NULL), |
| 77 target_height_(0), | 74 target_height_(0), |
| 78 is_closing_(false), | 75 is_closing_(false), |
| 79 is_locked_(message_center_->IsLockedState()), | 76 mode_((!initially_settings_visible) ? Mode::BUTTONS_ONLY |
| 80 mode_((!initially_settings_visible || is_locked_) ? Mode::BUTTONS_ONLY | 77 : Mode::SETTINGS), |
| 81 : Mode::SETTINGS), | |
| 82 context_menu_controller_(new MessageViewContextMenuController(this)) { | 78 context_menu_controller_(new MessageViewContextMenuController(this)) { |
| 83 message_center_->AddObserver(this); | 79 message_center_->AddObserver(this); |
| 84 set_notify_enter_exit_on_child(true); | 80 set_notify_enter_exit_on_child(true); |
| 85 set_background(views::Background::CreateSolidBackground( | 81 set_background(views::Background::CreateSolidBackground( |
| 86 kMessageCenterBackgroundColor)); | 82 kMessageCenterBackgroundColor)); |
| 87 | 83 |
| 88 NotifierSettingsProvider* notifier_settings_provider = | 84 NotifierSettingsProvider* notifier_settings_provider = |
| 89 message_center_->GetNotifierSettingsProvider(); | 85 message_center_->GetNotifierSettingsProvider(); |
| 90 button_bar_ = new MessageCenterButtonBar( | 86 button_bar_ = new MessageCenterButtonBar( |
| 91 this, message_center, notifier_settings_provider, | 87 this, message_center, notifier_settings_provider, |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 int old_width = view->width(); | 395 int old_width = view->width(); |
| 400 int old_height = view->GetHeightForWidth(old_width); | 396 int old_height = view->GetHeightForWidth(old_width); |
| 401 message_list_view_->UpdateNotification(view, **iter); | 397 message_list_view_->UpdateNotification(view, **iter); |
| 402 if (view->GetHeightForWidth(old_width) != old_height) | 398 if (view->GetHeightForWidth(old_width) != old_height) |
| 403 Update(true /* animate */); | 399 Update(true /* animate */); |
| 404 break; | 400 break; |
| 405 } | 401 } |
| 406 } | 402 } |
| 407 } | 403 } |
| 408 | 404 |
| 409 void MessageCenterView::OnLockedStateChanged(bool locked) { | |
| 410 is_locked_ = locked; | |
| 411 UpdateButtonBarStatus(); | |
| 412 Update(true /* animate */); | |
| 413 } | |
| 414 | |
| 415 void MessageCenterView::ClickOnNotification( | 405 void MessageCenterView::ClickOnNotification( |
| 416 const std::string& notification_id) { | 406 const std::string& notification_id) { |
| 417 message_center_->ClickOnNotification(notification_id); | 407 message_center_->ClickOnNotification(notification_id); |
| 418 } | 408 } |
| 419 | 409 |
| 420 void MessageCenterView::RemoveNotification(const std::string& notification_id, | 410 void MessageCenterView::RemoveNotification(const std::string& notification_id, |
| 421 bool by_user) { | 411 bool by_user) { |
| 422 message_center_->RemoveNotification(notification_id, by_user); | 412 message_center_->RemoveNotification(notification_id, by_user); |
| 423 } | 413 } |
| 424 | 414 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 int index) { | 481 int index) { |
| 492 MessageView* view = | 482 MessageView* view = |
| 493 NotificationView::Create(this, notification, false); // Not top-level. | 483 NotificationView::Create(this, notification, false); // Not top-level. |
| 494 view->set_context_menu_controller(context_menu_controller_.get()); | 484 view->set_context_menu_controller(context_menu_controller_.get()); |
| 495 notification_views_[notification.id()] = view; | 485 notification_views_[notification.id()] = view; |
| 496 view->set_scroller(scroller_); | 486 view->set_scroller(scroller_); |
| 497 message_list_view_->AddNotificationAt(view, index); | 487 message_list_view_->AddNotificationAt(view, index); |
| 498 } | 488 } |
| 499 | 489 |
| 500 base::string16 MessageCenterView::GetButtonBarTitle() const { | 490 base::string16 MessageCenterView::GetButtonBarTitle() const { |
| 501 if (is_locked_) | 491 bool no_message_views = notification_views_.empty(); |
| 502 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_FOOTER_LOCKSCREEN); | 492 if (no_message_views && !settings_visible_) |
| 503 | |
| 504 if (mode_ == Mode::BUTTONS_ONLY) | |
| 505 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_NO_MESSAGES); | 493 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_NO_MESSAGES); |
| 506 | 494 |
| 507 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_FOOTER_TITLE); | 495 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_FOOTER_TITLE); |
| 508 } | 496 } |
| 509 | 497 |
| 510 void MessageCenterView::Update(bool animate) { | 498 void MessageCenterView::Update(bool animate) { |
| 511 bool no_message_views = notification_views_.empty(); | 499 bool no_message_views = notification_views_.empty(); |
| 512 | 500 |
| 513 // When the child view is removed from the hierarchy, its focus is cleared. | 501 // When the child view is removed from the hierarchy, its focus is cleared. |
| 514 // In this case we want to save which view has focus so that the user can | 502 // In this case we want to save which view has focus so that the user can |
| 515 // continue to interact with notifications in the order they were expecting. | 503 // continue to interact with notifications in the order they were expecting. |
| 516 views::FocusManager* focus_manager = scroller_->GetFocusManager(); | 504 views::FocusManager* focus_manager = scroller_->GetFocusManager(); |
| 517 View* focused_view = NULL; | 505 View* focused_view = NULL; |
| 518 // |focus_manager| can be NULL in tests. | 506 // |focus_manager| can be NULL in tests. |
| 519 if (focus_manager) | 507 if (focus_manager) |
| 520 focused_view = focus_manager->GetFocusedView(); | 508 focused_view = focus_manager->GetFocusedView(); |
| 521 | 509 |
| 522 if (is_locked_) | 510 if (settings_visible_) |
| 523 SetVisibilityMode(Mode::BUTTONS_ONLY, animate); | |
| 524 else if (settings_visible_) | |
| 525 SetVisibilityMode(Mode::SETTINGS, animate); | 511 SetVisibilityMode(Mode::SETTINGS, animate); |
| 526 else if (no_message_views) | 512 else if (no_message_views) |
| 527 SetVisibilityMode(Mode::BUTTONS_ONLY, animate); | 513 SetVisibilityMode(Mode::BUTTONS_ONLY, animate); |
| 528 else | 514 else |
| 529 SetVisibilityMode(Mode::NOTIFICATIONS, animate); | 515 SetVisibilityMode(Mode::NOTIFICATIONS, animate); |
| 530 | 516 |
| 531 if (no_message_views) { | 517 if (no_message_views) { |
| 532 scroller_->SetFocusBehavior(FocusBehavior::NEVER); | 518 scroller_->SetFocusBehavior(FocusBehavior::NEVER); |
| 533 } else { | 519 } else { |
| 534 #if defined(OS_MACOSX) | 520 #if defined(OS_MACOSX) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 else if (mode == Mode::SETTINGS) | 554 else if (mode == Mode::SETTINGS) |
| 569 target_view_ = settings_view_; | 555 target_view_ = settings_view_; |
| 570 else | 556 else |
| 571 target_view_ = NULL; | 557 target_view_ = NULL; |
| 572 | 558 |
| 573 mode_ = mode; | 559 mode_ = mode; |
| 574 | 560 |
| 575 source_height_ = source_view_ ? source_view_->GetHeightForWidth(width()) : 0; | 561 source_height_ = source_view_ ? source_view_->GetHeightForWidth(width()) : 0; |
| 576 target_height_ = target_view_ ? target_view_->GetHeightForWidth(width()) : 0; | 562 target_height_ = target_view_ ? target_view_->GetHeightForWidth(width()) : 0; |
| 577 | 563 |
| 578 if (!animate || disable_animation_for_testing) { | 564 if (!animate) { |
| 579 AnimationEnded(NULL); | 565 AnimationEnded(NULL); |
| 580 return; | 566 return; |
| 581 } | 567 } |
| 582 | 568 |
| 583 gfx::MultiAnimation::Parts parts; | 569 gfx::MultiAnimation::Parts parts; |
| 584 // First part: slide resize animation. | 570 // First part: slide resize animation. |
| 585 parts.push_back(gfx::MultiAnimation::Part( | 571 parts.push_back(gfx::MultiAnimation::Part( |
| 586 (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs, | 572 (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs, |
| 587 gfx::Tween::EASE_OUT)); | 573 gfx::Tween::EASE_OUT)); |
| 588 // Second part: fade-out the source_view. | 574 // Second part: fade-out the source_view. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 610 | 596 |
| 611 void MessageCenterView::UpdateButtonBarStatus() { | 597 void MessageCenterView::UpdateButtonBarStatus() { |
| 612 // Disables all buttons during animation of cleaning of all notifications. | 598 // Disables all buttons during animation of cleaning of all notifications. |
| 613 if (is_clearing_) { | 599 if (is_clearing_) { |
| 614 button_bar_->SetSettingsAndQuietModeButtonsEnabled(false); | 600 button_bar_->SetSettingsAndQuietModeButtonsEnabled(false); |
| 615 button_bar_->SetCloseAllButtonEnabled(false); | 601 button_bar_->SetCloseAllButtonEnabled(false); |
| 616 return; | 602 return; |
| 617 } | 603 } |
| 618 | 604 |
| 619 button_bar_->SetBackArrowVisible(mode_ == Mode::SETTINGS); | 605 button_bar_->SetBackArrowVisible(mode_ == Mode::SETTINGS); |
| 620 button_bar_->SetSettingsAndQuietModeButtonsEnabled(!is_locked_); | 606 button_bar_->SetSettingsAndQuietModeButtonsEnabled(true); |
| 621 button_bar_->SetTitle(GetButtonBarTitle()); | 607 button_bar_->SetTitle(GetButtonBarTitle()); |
| 622 | 608 |
| 623 if (mode_ == Mode::NOTIFICATIONS) { | 609 if (mode_ == Mode::NOTIFICATIONS) { |
| 624 bool no_closable_views = true; | 610 bool no_closable_views = true; |
| 625 for (const auto& view : notification_views_) { | 611 for (const auto& view : notification_views_) { |
| 626 if (!view.second->IsPinned()) { | 612 if (!view.second->IsPinned()) { |
| 627 no_closable_views = false; | 613 no_closable_views = false; |
| 628 break; | 614 break; |
| 629 } | 615 } |
| 630 } | 616 } |
| 631 button_bar_->SetCloseAllButtonEnabled(!no_closable_views); | 617 button_bar_->SetCloseAllButtonEnabled(!no_closable_views); |
| 632 } else { | 618 } else { |
| 633 // Disable the close-all button since no notification is visible. | 619 // Disable the close-all button since no notification is visible. |
| 634 button_bar_->SetCloseAllButtonEnabled(false); | 620 button_bar_->SetCloseAllButtonEnabled(false); |
| 635 } | 621 } |
| 636 } | 622 } |
| 637 | 623 |
| 638 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { | 624 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { |
| 639 message_list_view_->AddNotificationAt(view, 0); | 625 message_list_view_->AddNotificationAt(view, 0); |
| 640 } | 626 } |
| 641 | 627 |
| 642 } // namespace message_center | 628 } // namespace message_center |
| OLD | NEW |