notification_counter_view.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_
  5. #define ASH_SYSTEM_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/tray/tray_item_view.h"
  8. #include "base/scoped_observation.h"
  9. namespace session_manager {
  10. enum class SessionState;
  11. } // namespace session_manager
  12. namespace views {
  13. class Separator;
  14. } // namespace views
  15. namespace ash {
  16. class NotificationIconsController;
  17. // Maximum count of notification shown by a number label. "+" icon is shown
  18. // instead if it exceeds this limit.
  19. constexpr size_t kTrayNotificationMaxCount = 9;
  20. // A notification counter view in UnifiedSystemTray button.
  21. class ASH_EXPORT NotificationCounterView : public TrayItemView {
  22. public:
  23. NotificationCounterView(Shelf* shelf,
  24. NotificationIconsController* controller);
  25. ~NotificationCounterView() override;
  26. NotificationCounterView(const NotificationCounterView&) = delete;
  27. NotificationCounterView& operator=(const NotificationCounterView&) = delete;
  28. void Update();
  29. // Returns a string describing the current state for accessibility.
  30. std::u16string GetAccessibleNameString() const;
  31. // TrayItemView:
  32. void HandleLocaleChange() override;
  33. void OnThemeChanged() override;
  34. // views::TrayItemView:
  35. const char* GetClassName() const override;
  36. int count_for_display_for_testing() const { return count_for_display_; }
  37. private:
  38. // The type / number of the icon that is currently set to the image view.
  39. // 0 indicates no icon is drawn yet.
  40. // 1 through |kTrayNotificationMaxCount| indicates each number icons.
  41. // |kTrayNotificationMaxCount| + 1 indicates the plus icon.
  42. int count_for_display_ = 0;
  43. NotificationIconsController* const controller_;
  44. };
  45. // A do-not-distrub icon view in UnifiedSystemTray button.
  46. class QuietModeView : public TrayItemView {
  47. public:
  48. explicit QuietModeView(Shelf* shelf);
  49. ~QuietModeView() override;
  50. QuietModeView(const QuietModeView&) = delete;
  51. QuietModeView& operator=(const QuietModeView&) = delete;
  52. void Update();
  53. // TrayItemView:
  54. void HandleLocaleChange() override;
  55. void OnThemeChanged() override;
  56. // views::TrayItemView:
  57. const char* GetClassName() const override;
  58. };
  59. // Separator view in UnifiedSystemTray button.
  60. class SeparatorTrayItemView : public TrayItemView {
  61. public:
  62. explicit SeparatorTrayItemView(Shelf* shelf);
  63. ~SeparatorTrayItemView() override;
  64. SeparatorTrayItemView(const SeparatorTrayItemView&) = delete;
  65. SeparatorTrayItemView& operator=(const SeparatorTrayItemView&) = delete;
  66. // TrayItemView:
  67. void HandleLocaleChange() override;
  68. const char* GetClassName() const override;
  69. // Update the color of separator depending on the given state.
  70. void UpdateColor(session_manager::SessionState state);
  71. private:
  72. views::Separator* separator_ = nullptr;
  73. };
  74. } // namespace ash
  75. #endif // ASH_SYSTEM_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_