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