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 5 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_ 6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_ 7 8 #include <set> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "ui/message_center/message_center_export.h" 12 #include "ui/message_center/notifier_settings.h" 13 #include "ui/message_center/views/message_bubble_base.h" 14 #include "ui/views/controls/button/checkbox.h" 15 #include "ui/views/controls/button/image_button.h" 16 #include "ui/views/controls/button/menu_button_listener.h" 17 #include "ui/views/controls/image_view.h" 18 #include "ui/views/view.h" 19 20 namespace views { 21 class Label; 22 class MenuButton; 23 class MenuRunner; 24 } 25 26 namespace message_center { 27 class NotifierGroupMenuModel; 28 29 // A class to show the list of notifier extensions / URL patterns and allow 30 // users to customize the settings. 31 class MESSAGE_CENTER_EXPORT NotifierSettingsView 32 : public NotifierSettingsObserver, 33 public views::View, 34 public views::ButtonListener, 35 public views::MenuButtonListener { 36 public: 37 explicit NotifierSettingsView(NotifierSettingsProvider* provider); 38 virtual ~NotifierSettingsView(); 39 40 bool IsScrollable(); 41 42 // Overridden from NotifierSettingsDelegate: 43 virtual void UpdateIconImage(const NotifierId& notifier_id, 44 const gfx::Image& icon) OVERRIDE; 45 virtual void NotifierGroupChanged() OVERRIDE; 46 47 void set_provider(NotifierSettingsProvider* new_provider) { 48 provider_ = new_provider; 49 } 50 51 private: 52 FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestLearnMoreButton); 53 54 class MESSAGE_CENTER_EXPORT NotifierButton : public views::CustomButton, 55 public views::ButtonListener { 56 public: 57 NotifierButton(NotifierSettingsProvider* provider, 58 Notifier* notifier, 59 views::ButtonListener* listener); 60 virtual ~NotifierButton(); 61 62 void UpdateIconImage(const gfx::Image& icon); 63 void SetChecked(bool checked); 64 bool checked() const; 65 bool has_learn_more() const; 66 const Notifier& notifier() const; 67 68 void SendLearnMorePressedForTest(); 69 70 private: 71 // Overridden from views::ButtonListener: 72 virtual void ButtonPressed(views::Button* button, 73 const ui::Event& event) OVERRIDE; 74 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 75 76 bool ShouldHaveLearnMoreButton() const; 77 // Helper function to reset the layout when the view has substantially 78 // changed. 79 void GridChanged(bool has_learn_more, bool has_icon_view); 80 81 NotifierSettingsProvider* provider_; // Weak. 82 const scoped_ptr<Notifier> notifier_; 83 // |icon_view_| is owned by us because sometimes we don't leave it 84 // in the view hierarchy. 85 scoped_ptr<views::ImageView> icon_view_; 86 views::Label* name_view_; 87 views::Checkbox* checkbox_; 88 views::ImageButton* learn_more_; 89 90 DISALLOW_COPY_AND_ASSIGN(NotifierButton); 91 }; 92 93 // Given a new list of notifiers, updates the view to reflect it. 94 void UpdateContentsView(const std::vector<Notifier*>& notifiers); 95 96 // Overridden from views::View: 97 virtual void Layout() OVERRIDE; 98 virtual gfx::Size GetMinimumSize() OVERRIDE; 99 virtual gfx::Size GetPreferredSize() OVERRIDE; 100 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 101 virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; 102 103 // Overridden from views::ButtonListener: 104 virtual void ButtonPressed(views::Button* sender, 105 const ui::Event& event) OVERRIDE; 106 107 // Overridden from views::MenuButtonListener: 108 virtual void OnMenuButtonClicked(views::View* source, 109 const gfx::Point& point) OVERRIDE; 110 111 views::ImageButton* title_arrow_; 112 views::Label* title_label_; 113 views::MenuButton* notifier_group_selector_; 114 views::ScrollView* scroller_; 115 NotifierSettingsProvider* provider_; 116 std::set<NotifierButton*> buttons_; 117 scoped_ptr<NotifierGroupMenuModel> notifier_group_menu_model_; 118 scoped_ptr<views::MenuRunner> notifier_group_menu_runner_; 119 120 DISALLOW_COPY_AND_ASSIGN(NotifierSettingsView); 121 }; 122 123 } // namespace message_center 124 125 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_ 126