| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/system/status_area_widget.h" | 7 #include "ash/system/status_area_widget.h" |
| 8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
| 9 #include "ash/system/tray/tray_bubble_view.h" | 9 #include "ash/system/tray/tray_bubble_view.h" |
| 10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 // Web Notification Bubble constants | 50 // Web Notification Bubble constants |
| 51 const int kWebNotificationBubbleMinHeight = 80; | 51 const int kWebNotificationBubbleMinHeight = 80; |
| 52 const int kWebNotificationBubbleMaxHeight = 480; | 52 const int kWebNotificationBubbleMaxHeight = 480; |
| 53 // Delay laying out the Bubble until all notifications have been added and icons | 53 // Delay laying out the Bubble until all notifications have been added and icons |
| 54 // have had a chance to load. | 54 // have had a chance to load. |
| 55 const int kUpdateDelayMs = 50; | 55 const int kUpdateDelayMs = 50; |
| 56 // Limit the number of visible notifications. | 56 // Limit the number of visible notifications. |
| 57 const int kMaxVisibleNotifications = 100; | 57 const int kMaxVisibleNotifications = 100; |
| 58 const int kAutocloseDelaySeconds = 5; | 58 const int kAutocloseDelaySeconds = 5; |
| 59 const SkColor kMessageCountColor = SkColorSetARGB(0xff, 0xff, 0xff, 0xff); |
| 60 const SkColor kMessageCountDimmedColor = SkColorSetARGB(0x60, 0xff, 0xff, 0xff); |
| 59 | 61 |
| 60 // Individual notifications constants | 62 // Individual notifications constants |
| 61 const int kWebNotificationWidth = 320; | 63 const int kWebNotificationWidth = 320; |
| 62 const int kWebNotificationButtonWidth = 32; | 64 const int kWebNotificationButtonWidth = 32; |
| 63 const int kWebNotificationIconSize = 40; | 65 const int kWebNotificationIconSize = 40; |
| 64 | 66 |
| 65 // Menu constants | 67 // Menu constants |
| 66 const int kTogglePermissionCommand = 0; | 68 const int kTogglePermissionCommand = 0; |
| 67 const int kToggleExtensionCommand = 1; | 69 const int kToggleExtensionCommand = 1; |
| 68 const int kShowSettingsCommand = 2; | 70 const int kShowSettingsCommand = 2; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 const views::GestureEvent& event) OVERRIDE { | 432 const views::GestureEvent& event) OVERRIDE { |
| 431 if (event.type() != ui::ET_GESTURE_TAP) | 433 if (event.type() != ui::ET_GESTURE_TAP) |
| 432 return ui::GESTURE_STATUS_UNKNOWN; | 434 return ui::GESTURE_STATUS_UNKNOWN; |
| 433 tray_->OnClicked(notification_.id); | 435 tray_->OnClicked(notification_.id); |
| 434 return ui::GESTURE_STATUS_CONSUMED; | 436 return ui::GESTURE_STATUS_CONSUMED; |
| 435 } | 437 } |
| 436 | 438 |
| 437 // Overridden from ButtonListener. | 439 // Overridden from ButtonListener. |
| 438 virtual void ButtonPressed(views::Button* sender, | 440 virtual void ButtonPressed(views::Button* sender, |
| 439 const views::Event& event) OVERRIDE { | 441 const views::Event& event) OVERRIDE { |
| 440 if (sender == close_button_) | 442 if (sender == close_button_) { |
| 441 tray_->RemoveNotification(notification_.id); | 443 tray_->RemoveNotification(notification_.id); |
| 444 tray_->HideMessageCenterBubbleIfEmpty(); |
| 445 } |
| 442 } | 446 } |
| 443 | 447 |
| 444 // Overridden from MenuButtonListener. | 448 // Overridden from MenuButtonListener. |
| 445 virtual void OnMenuButtonClicked( | 449 virtual void OnMenuButtonClicked( |
| 446 View* source, const gfx::Point& point) OVERRIDE { | 450 View* source, const gfx::Point& point) OVERRIDE { |
| 447 if (source != menu_button_) | 451 if (source != menu_button_) |
| 448 return; | 452 return; |
| 449 WebNotificationMenuModel menu_model(tray_, notification_); | 453 WebNotificationMenuModel menu_model(tray_, notification_); |
| 450 views::MenuModelAdapter menu_model_adapter(&menu_model); | 454 views::MenuModelAdapter menu_model_adapter(&menu_model); |
| 451 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); | 455 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 close_all_button_ = new TrayPopupTextButton( | 501 close_all_button_ = new TrayPopupTextButton( |
| 498 this, rb.GetLocalizedString(IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL)); | 502 this, rb.GetLocalizedString(IDS_ASH_WEB_NOTFICATION_TRAY_CLEAR_ALL)); |
| 499 | 503 |
| 500 layout->StartRow(0, 0); | 504 layout->StartRow(0, 0); |
| 501 layout->AddView(close_all_button_); | 505 layout->AddView(close_all_button_); |
| 502 } | 506 } |
| 503 | 507 |
| 504 virtual ~WebNotificationButtonView() { | 508 virtual ~WebNotificationButtonView() { |
| 505 } | 509 } |
| 506 | 510 |
| 511 void SetCloseAllVisible(bool visible) { |
| 512 close_all_button_->SetVisible(visible); |
| 513 } |
| 514 |
| 507 // Overridden from ButtonListener. | 515 // Overridden from ButtonListener. |
| 508 virtual void ButtonPressed(views::Button* sender, | 516 virtual void ButtonPressed(views::Button* sender, |
| 509 const views::Event& event) OVERRIDE { | 517 const views::Event& event) OVERRIDE { |
| 510 if (sender == close_all_button_) | 518 if (sender == close_all_button_) { |
| 511 tray_->RemoveAllNotifications(); | 519 tray_->RemoveAllNotifications(); |
| 520 tray_->HideMessageCenterBubbleIfEmpty(); |
| 521 } |
| 512 } | 522 } |
| 513 | 523 |
| 514 private: | 524 private: |
| 515 WebNotificationTray* tray_; | 525 WebNotificationTray* tray_; |
| 516 TrayPopupTextButton* close_all_button_; | 526 TrayPopupTextButton* close_all_button_; |
| 517 | 527 |
| 518 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 528 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
| 519 }; | 529 }; |
| 520 | 530 |
| 521 class WebContentsView : public views::View { | 531 class WebContentsView : public views::View { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 538 | 548 |
| 539 protected: | 549 protected: |
| 540 WebNotificationTray* tray_; | 550 WebNotificationTray* tray_; |
| 541 | 551 |
| 542 private: | 552 private: |
| 543 DISALLOW_COPY_AND_ASSIGN(WebContentsView); | 553 DISALLOW_COPY_AND_ASSIGN(WebContentsView); |
| 544 }; | 554 }; |
| 545 | 555 |
| 546 class MessageCenterContentsView : public WebContentsView { | 556 class MessageCenterContentsView : public WebContentsView { |
| 547 public: | 557 public: |
| 558 class ScrollContentView : public views::View { |
| 559 public: |
| 560 ScrollContentView() { |
| 561 views::BoxLayout* layout = |
| 562 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1); |
| 563 layout->set_spread_blank_space(true); |
| 564 SetLayoutManager(layout); |
| 565 } |
| 566 |
| 567 virtual ~ScrollContentView() {}; |
| 568 |
| 569 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 570 if (!preferred_size_.IsEmpty()) |
| 571 return preferred_size_; |
| 572 return views::View::GetPreferredSize(); |
| 573 } |
| 574 |
| 575 void set_preferred_size(const gfx::Size& size) { preferred_size_ = size; } |
| 576 |
| 577 private: |
| 578 gfx::Size preferred_size_; |
| 579 DISALLOW_COPY_AND_ASSIGN(ScrollContentView); |
| 580 }; |
| 581 |
| 548 explicit MessageCenterContentsView(WebNotificationTray* tray) | 582 explicit MessageCenterContentsView(WebNotificationTray* tray) |
| 549 : WebContentsView(tray) { | 583 : WebContentsView(tray) { |
| 550 SetLayoutManager( | 584 SetLayoutManager( |
| 551 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 585 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 552 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 586 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 553 | 587 |
| 554 scroll_content_ = new views::View; | 588 scroll_content_ = new ScrollContentView; |
| 555 scroll_content_->SetLayoutManager( | |
| 556 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | |
| 557 | |
| 558 scroller_ = new internal::FixedSizedScrollView; | 589 scroller_ = new internal::FixedSizedScrollView; |
| 559 scroller_->SetContentsView(scroll_content_); | 590 scroller_->SetContentsView(scroll_content_); |
| 560 AddChildView(scroller_); | 591 AddChildView(scroller_); |
| 561 | 592 |
| 562 button_view_ = new internal::WebNotificationButtonView(tray); | 593 button_view_ = new internal::WebNotificationButtonView(tray); |
| 563 AddChildView(button_view_); | 594 AddChildView(button_view_); |
| 564 } | 595 } |
| 565 | 596 |
| 566 void Update(const WebNotificationList::Notifications& notifications) { | 597 void Update(const WebNotificationList::Notifications& notifications) { |
| 567 scroll_content_->RemoveAllChildViews(true); | 598 scroll_content_->RemoveAllChildViews(true); |
| 568 int num_children = 0; | 599 int num_children = 0; |
| 569 for (WebNotificationList::Notifications::const_iterator iter = | 600 for (WebNotificationList::Notifications::const_iterator iter = |
| 570 notifications.begin(); iter != notifications.end(); ++iter) { | 601 notifications.begin(); iter != notifications.end(); ++iter) { |
| 571 WebNotificationView* view = new WebNotificationView(tray_, *iter); | 602 WebNotificationView* view = new WebNotificationView(tray_, *iter); |
| 572 scroll_content_->AddChildView(view); | 603 scroll_content_->AddChildView(view); |
| 573 if (++num_children >= kMaxVisibleNotifications) | 604 if (++num_children >= kMaxVisibleNotifications) |
| 574 break; | 605 break; |
| 575 } | 606 } |
| 607 if (num_children == 0) { |
| 608 views::Label* label = new views::Label(l10n_util::GetStringUTF16( |
| 609 IDS_ASH_WEB_NOTFICATION_TRAY_NO_MESSAGES)); |
| 610 label->SetFont(label->font().DeriveFont(2)); |
| 611 label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 612 scroll_content_->AddChildView(label); |
| 613 button_view_->SetCloseAllVisible(false); |
| 614 } else { |
| 615 button_view_->SetCloseAllVisible(true); |
| 616 } |
| 576 SizeScrollContent(); | 617 SizeScrollContent(); |
| 618 Layout(); |
| 577 GetWidget()->GetRootView()->SchedulePaint(); | 619 GetWidget()->GetRootView()->SchedulePaint(); |
| 578 } | 620 } |
| 579 | 621 |
| 580 private: | 622 private: |
| 581 void SizeScrollContent() { | 623 void SizeScrollContent() { |
| 582 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); | 624 gfx::Size scroll_size = scroll_content_->GetPreferredSize(); |
| 583 int button_height = button_view_->GetPreferredSize().height(); | 625 const int button_height = button_view_->GetPreferredSize().height(); |
| 584 int scroll_height = std::min( | 626 const int min_height = kWebNotificationBubbleMinHeight - button_height; |
| 585 std::max(scroll_size.height(), | 627 const int max_height = kWebNotificationBubbleMaxHeight - button_height; |
| 586 kWebNotificationBubbleMinHeight - button_height), | 628 int scroll_height = std::min(std::max( |
| 587 kWebNotificationBubbleMaxHeight - button_height); | 629 scroll_size.height(), min_height), max_height); |
| 588 scroll_size.set_height(scroll_height); | 630 scroll_size.set_height(scroll_height); |
| 631 if (scroll_height == min_height) |
| 632 scroll_content_->set_preferred_size(scroll_size); |
| 633 else |
| 634 scroll_content_->set_preferred_size(gfx::Size()); |
| 589 scroller_->SetFixedSize(scroll_size); | 635 scroller_->SetFixedSize(scroll_size); |
| 590 scroller_->SizeToPreferredSize(); | 636 scroller_->SizeToPreferredSize(); |
| 591 } | 637 } |
| 592 | 638 |
| 593 internal::FixedSizedScrollView* scroller_; | 639 internal::FixedSizedScrollView* scroller_; |
| 594 views::View* scroll_content_; | 640 ScrollContentView* scroll_content_; |
| 595 internal::WebNotificationButtonView* button_view_; | 641 internal::WebNotificationButtonView* button_view_; |
| 596 | 642 |
| 597 DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); | 643 DISALLOW_COPY_AND_ASSIGN(MessageCenterContentsView); |
| 598 }; | 644 }; |
| 599 | 645 |
| 600 class WebNotificationContentsView : public WebContentsView { | 646 class WebNotificationContentsView : public WebContentsView { |
| 601 public: | 647 public: |
| 602 explicit WebNotificationContentsView(WebNotificationTray* tray) | 648 explicit WebNotificationContentsView(WebNotificationTray* tray) |
| 603 : WebContentsView(tray) { | 649 : WebContentsView(tray) { |
| 604 SetLayoutManager( | 650 SetLayoutManager( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 770 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
| 725 CHECK_EQ(bubble_widget_, widget); | 771 CHECK_EQ(bubble_widget_, widget); |
| 726 bubble_widget_ = NULL; | 772 bubble_widget_ = NULL; |
| 727 tray_->HideBubble(this); // Will destroy |this|. | 773 tray_->HideBubble(this); // Will destroy |this|. |
| 728 } | 774 } |
| 729 | 775 |
| 730 private: | 776 private: |
| 731 void UpdateBubbleView() { | 777 void UpdateBubbleView() { |
| 732 const WebNotificationList::Notifications& notifications = | 778 const WebNotificationList::Notifications& notifications = |
| 733 tray_->notification_list()->notifications(); | 779 tray_->notification_list()->notifications(); |
| 734 if (notifications.size() == 0) { | |
| 735 tray_->HideBubble(this); // deletes |this|! | |
| 736 return; | |
| 737 } | |
| 738 contents_view_->Update(notifications); | 780 contents_view_->Update(notifications); |
| 739 bubble_view_->Show(); | 781 bubble_view_->Show(); |
| 740 bubble_view_->UpdateBubble(); | 782 bubble_view_->UpdateBubble(); |
| 741 } | 783 } |
| 742 | 784 |
| 743 void StartAutoCloseTimer() { | 785 void StartAutoCloseTimer() { |
| 744 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION) | 786 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION) |
| 745 return; | 787 return; |
| 746 autoclose_.Start(FROM_HERE, | 788 autoclose_.Start(FROM_HERE, |
| 747 base::TimeDelta::FromSeconds(kAutocloseDelaySeconds), | 789 base::TimeDelta::FromSeconds(kAutocloseDelaySeconds), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 772 : internal::TrayBackgroundView(status_area_widget), | 814 : internal::TrayBackgroundView(status_area_widget), |
| 773 notification_list_(new WebNotificationList()), | 815 notification_list_(new WebNotificationList()), |
| 774 count_label_(NULL), | 816 count_label_(NULL), |
| 775 delegate_(NULL), | 817 delegate_(NULL), |
| 776 show_message_center_on_unlock_(false) { | 818 show_message_center_on_unlock_(false) { |
| 777 count_label_ = new views::Label(UTF8ToUTF16("0")); | 819 count_label_ = new views::Label(UTF8ToUTF16("0")); |
| 778 internal::SetupLabelForTray(count_label_); | 820 internal::SetupLabelForTray(count_label_); |
| 779 gfx::Font font = count_label_->font(); | 821 gfx::Font font = count_label_->font(); |
| 780 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); | 822 count_label_->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); |
| 781 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); | 823 count_label_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 824 count_label_->SetEnabledColor(kMessageCountDimmedColor); |
| 782 | 825 |
| 783 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); | 826 tray_container()->set_size(gfx::Size(kTrayWidth, kTrayHeight)); |
| 784 tray_container()->AddChildView(count_label_); | 827 tray_container()->AddChildView(count_label_); |
| 785 | 828 |
| 786 UpdateTray(); | 829 UpdateTray(); |
| 787 } | 830 } |
| 788 | 831 |
| 789 WebNotificationTray::~WebNotificationTray() { | 832 WebNotificationTray::~WebNotificationTray() { |
| 790 } | 833 } |
| 791 | 834 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 for (WebNotificationList::Notifications::const_iterator loopiter = | 873 for (WebNotificationList::Notifications::const_iterator loopiter = |
| 831 notifications.begin(); | 874 notifications.begin(); |
| 832 loopiter != notifications.end(); ) { | 875 loopiter != notifications.end(); ) { |
| 833 WebNotificationList::Notifications::const_iterator curiter = loopiter++; | 876 WebNotificationList::Notifications::const_iterator curiter = loopiter++; |
| 834 std::string notification_id = curiter->id; | 877 std::string notification_id = curiter->id; |
| 835 // May call RemoveNotification and erase curiter. | 878 // May call RemoveNotification and erase curiter. |
| 836 delegate_->NotificationRemoved(notification_id); | 879 delegate_->NotificationRemoved(notification_id); |
| 837 } | 880 } |
| 838 } | 881 } |
| 839 notification_list_->RemoveAllNotifications(); | 882 notification_list_->RemoveAllNotifications(); |
| 883 HideMessageCenterBubble(); |
| 840 UpdateTrayAndBubble(); | 884 UpdateTrayAndBubble(); |
| 841 } | 885 } |
| 842 | 886 |
| 843 void WebNotificationTray::SetNotificationImage(const std::string& id, | 887 void WebNotificationTray::SetNotificationImage(const std::string& id, |
| 844 const gfx::ImageSkia& image) { | 888 const gfx::ImageSkia& image) { |
| 845 if (!notification_list_->SetNotificationImage(id, image)) | 889 if (!notification_list_->SetNotificationImage(id, image)) |
| 846 return; | 890 return; |
| 847 UpdateTrayAndBubble(); | 891 UpdateTrayAndBubble(); |
| 848 if (notification_bubble() && id == notification_list_->GetFirstId()) | 892 if (notification_bubble() && id == notification_list_->GetFirstId()) |
| 849 ShowNotificationBubble(); | 893 ShowNotificationBubble(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 866 HideNotificationBubble(); | 910 HideNotificationBubble(); |
| 867 notification_list_->RemoveNotificationsBySource(id); | 911 notification_list_->RemoveNotificationsBySource(id); |
| 868 UpdateTrayAndBubble(); | 912 UpdateTrayAndBubble(); |
| 869 if (delegate_) | 913 if (delegate_) |
| 870 delegate_->DisableNotificationsFromSource(id); | 914 delegate_->DisableNotificationsFromSource(id); |
| 871 } | 915 } |
| 872 | 916 |
| 873 void WebNotificationTray::ShowMessageCenterBubble() { | 917 void WebNotificationTray::ShowMessageCenterBubble() { |
| 874 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 918 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 875 return; | 919 return; |
| 876 if (message_center_bubble() || GetNotificationCount() == 0) { | 920 if (message_center_bubble()) { |
| 877 UpdateTray(); | 921 UpdateTray(); |
| 878 return; | 922 return; |
| 879 } | 923 } |
| 880 notification_list_->SetIsVisible(true); // clears notification count | 924 notification_list_->SetIsVisible(true); // clears notification count |
| 881 UpdateTray(); | 925 UpdateTray(); |
| 882 HideNotificationBubble(); | 926 HideNotificationBubble(); |
| 883 message_center_bubble_.reset( | 927 message_center_bubble_.reset( |
| 884 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); | 928 new Bubble(this, Bubble::BUBBLE_TYPE_MESAGE_CENTER)); |
| 885 status_area_widget()->SetHideSystemNotifications(true); | 929 status_area_widget()->SetHideSystemNotifications(true); |
| 886 } | 930 } |
| 887 | 931 |
| 888 void WebNotificationTray::HideMessageCenterBubble() { | 932 void WebNotificationTray::HideMessageCenterBubble() { |
| 933 if (!message_center_bubble()) |
| 934 return; |
| 889 message_center_bubble_.reset(); | 935 message_center_bubble_.reset(); |
| 890 show_message_center_on_unlock_ = false; | 936 show_message_center_on_unlock_ = false; |
| 891 notification_list_->SetIsVisible(false); | 937 notification_list_->SetIsVisible(false); |
| 892 status_area_widget()->SetHideSystemNotifications(false); | 938 status_area_widget()->SetHideSystemNotifications(false); |
| 893 } | 939 } |
| 894 | 940 |
| 941 void WebNotificationTray::HideMessageCenterBubbleIfEmpty() { |
| 942 if (GetNotificationCount() == 0) |
| 943 HideMessageCenterBubble(); |
| 944 } |
| 945 |
| 895 void WebNotificationTray::ShowNotificationBubble() { | 946 void WebNotificationTray::ShowNotificationBubble() { |
| 896 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 947 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
| 897 return; | 948 return; |
| 898 if (message_center_bubble()) | 949 if (message_center_bubble()) |
| 899 return; | 950 return; |
| 900 if (!status_area_widget()->ShouldShowNonSystemNotifications()) | 951 if (!status_area_widget()->ShouldShowNonSystemNotifications()) |
| 901 return; | 952 return; |
| 902 UpdateTray(); | 953 UpdateTray(); |
| 903 if (notification_bubble()) { | 954 if (notification_bubble()) { |
| 904 notification_bubble()->ScheduleUpdate(); | 955 notification_bubble()->ScheduleUpdate(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 return true; | 1010 return true; |
| 960 } | 1011 } |
| 961 | 1012 |
| 962 int WebNotificationTray::GetNotificationCount() const { | 1013 int WebNotificationTray::GetNotificationCount() const { |
| 963 return notification_list()->notifications().size(); | 1014 return notification_list()->notifications().size(); |
| 964 } | 1015 } |
| 965 | 1016 |
| 966 void WebNotificationTray::UpdateTray() { | 1017 void WebNotificationTray::UpdateTray() { |
| 967 count_label_->SetText(UTF8ToUTF16( | 1018 count_label_->SetText(UTF8ToUTF16( |
| 968 GetNotificationText(notification_list()->unread_count()))); | 1019 GetNotificationText(notification_list()->unread_count()))); |
| 1020 // Dim the message count text only if the message center is empty. |
| 1021 count_label_->SetEnabledColor( |
| 1022 (notification_list()->notifications().size() == 0) ? |
| 1023 kMessageCountDimmedColor : kMessageCountColor); |
| 1024 SetVisible((status_area_widget()->login_status() != user::LOGGED_IN_NONE)); |
| 969 Layout(); | 1025 Layout(); |
| 970 SchedulePaint(); | 1026 SchedulePaint(); |
| 971 } | 1027 } |
| 972 | 1028 |
| 973 void WebNotificationTray::UpdateTrayAndBubble() { | 1029 void WebNotificationTray::UpdateTrayAndBubble() { |
| 974 UpdateTray(); | 1030 UpdateTray(); |
| 975 if (GetNotificationCount() == 0) { | 1031 |
| 976 HideMessageCenterBubble(); | |
| 977 HideNotificationBubble(); | |
| 978 return; | |
| 979 } | |
| 980 if (message_center_bubble()) | 1032 if (message_center_bubble()) |
| 981 message_center_bubble()->ScheduleUpdate(); | 1033 message_center_bubble()->ScheduleUpdate(); |
| 982 if (notification_bubble()) | 1034 |
| 983 notification_bubble()->ScheduleUpdate(); | 1035 if (notification_bubble()) { |
| 1036 if (GetNotificationCount() == 0) |
| 1037 HideNotificationBubble(); |
| 1038 else |
| 1039 notification_bubble()->ScheduleUpdate(); |
| 1040 } |
| 984 } | 1041 } |
| 985 | 1042 |
| 986 void WebNotificationTray::HideBubble(Bubble* bubble) { | 1043 void WebNotificationTray::HideBubble(Bubble* bubble) { |
| 987 if (bubble == message_center_bubble()) { | 1044 if (bubble == message_center_bubble()) { |
| 988 HideMessageCenterBubble(); | 1045 HideMessageCenterBubble(); |
| 989 } else if (bubble == notification_bubble()) { | 1046 } else if (bubble == notification_bubble()) { |
| 990 HideNotificationBubble(); | 1047 HideNotificationBubble(); |
| 991 } | 1048 } |
| 992 } | 1049 } |
| 993 | 1050 |
| 994 } // namespace ash | 1051 } // namespace ash |
| OLD | NEW |