notifier_settings_view.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_SYSTEM_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_H_
  5. #define ASH_SYSTEM_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_H_
  6. #include <memory>
  7. #include <set>
  8. #include "ash/ash_export.h"
  9. #include "ash/public/cpp/notifier_settings_observer.h"
  10. #include "base/gtest_prod_util.h"
  11. #include "ui/message_center/public/cpp/notifier_id.h"
  12. #include "ui/views/controls/button/checkbox.h"
  13. #include "ui/views/controls/button/image_button.h"
  14. #include "ui/views/controls/image_view.h"
  15. #include "ui/views/view.h"
  16. namespace views {
  17. class Label;
  18. class ScrollBar;
  19. class ToggleButton;
  20. } // namespace views
  21. namespace ash {
  22. // A class to show the list of notifier extensions / URL patterns and allow
  23. // users to customize the settings.
  24. class ASH_EXPORT NotifierSettingsView : public views::View,
  25. public NotifierSettingsObserver {
  26. public:
  27. NotifierSettingsView();
  28. NotifierSettingsView(const NotifierSettingsView&) = delete;
  29. NotifierSettingsView& operator=(const NotifierSettingsView&) = delete;
  30. ~NotifierSettingsView() override;
  31. bool IsScrollable();
  32. void SetQuietModeState(bool is_quiet_mode);
  33. // NotifierSettingsObserver:
  34. void OnNotifiersUpdated(
  35. const std::vector<NotifierMetadata>& notifiers) override;
  36. void OnNotifierIconUpdated(const message_center::NotifierId& notifier_id,
  37. const gfx::ImageSkia& icon) override;
  38. // views::View:
  39. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  40. const char* GetClassName() const override;
  41. views::ScrollView* get_scroller_view_for_test() { return scroller_; }
  42. views::Label* get_notification_settings_lable_for_test() {
  43. return notification_settings_label_;
  44. }
  45. views::ImageView* get_quiet_mode_icon_view_for_test() {
  46. return quiet_mode_icon_;
  47. }
  48. views::ToggleButton* get_quiet_mode_toggle_for_test() {
  49. return quiet_mode_toggle_;
  50. }
  51. private:
  52. FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestLearnMoreButton);
  53. FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestEmptyNotifierView);
  54. class ASH_EXPORT NotifierButton : public views::Button {
  55. public:
  56. explicit NotifierButton(const NotifierMetadata& notifier);
  57. NotifierButton(const NotifierButton&) = delete;
  58. NotifierButton& operator=(const NotifierButton&) = delete;
  59. ~NotifierButton() override;
  60. void UpdateIconImage(const gfx::ImageSkia& icon);
  61. void SetChecked(bool checked);
  62. bool GetChecked() const;
  63. const message_center::NotifierId& notifier_id() const {
  64. return notifier_id_;
  65. }
  66. // views::Button:
  67. const char* GetClassName() const override;
  68. private:
  69. // views::Button:
  70. void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
  71. // Helper function to reset the layout when the view has substantially
  72. // changed.
  73. void GridChanged();
  74. message_center::NotifierId notifier_id_;
  75. views::ImageView* icon_view_ = nullptr;
  76. views::Label* name_view_ = nullptr;
  77. views::Checkbox* checkbox_ = nullptr;
  78. };
  79. // Overridden from views::View:
  80. void Layout() override;
  81. gfx::Size GetMinimumSize() const override;
  82. gfx::Size CalculatePreferredSize() const override;
  83. bool OnKeyPressed(const ui::KeyEvent& event) override;
  84. bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
  85. // Utility function that creates a row containing a toggle button, label,
  86. // and icon. All passed in views will be added to the returned row view.
  87. std::unique_ptr<views::View> CreateToggleButtonRow(
  88. std::unique_ptr<views::ImageView> icon,
  89. std::unique_ptr<views::Label> label,
  90. std::unique_ptr<views::ToggleButton> toggle_button);
  91. void AppBadgingTogglePressed();
  92. void QuietModeTogglePressed();
  93. void NotifierButtonPressed(NotifierButton* button);
  94. views::ToggleButton* app_badging_toggle_ = nullptr;
  95. views::ImageView* quiet_mode_icon_ = nullptr;
  96. views::ToggleButton* quiet_mode_toggle_ = nullptr;
  97. views::View* header_view_ = nullptr;
  98. views::Label* notification_settings_label_ = nullptr;
  99. views::Label* top_label_ = nullptr;
  100. views::ScrollBar* scroll_bar_ = nullptr;
  101. views::ScrollView* scroller_ = nullptr;
  102. views::View* no_notifiers_view_ = nullptr;
  103. // TODO(crbug/1194632): remove |buttons_| and all related views.
  104. std::set<NotifierButton*> buttons_;
  105. };
  106. } // namespace ash
  107. #endif // ASH_SYSTEM_MESSAGE_CENTER_NOTIFIER_SETTINGS_VIEW_H_