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.
5 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
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"
26 namespace message_center
{
27 class NotifierGroupMenuModel
;
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
,
34 public views::ButtonListener
,
35 public views::MenuButtonListener
{
37 explicit NotifierSettingsView(NotifierSettingsProvider
* provider
);
38 virtual ~NotifierSettingsView();
42 // Overridden from NotifierSettingsDelegate:
43 virtual void UpdateIconImage(const NotifierId
& notifier_id
,
44 const gfx::Image
& icon
) OVERRIDE
;
45 virtual void NotifierGroupChanged() OVERRIDE
;
46 virtual void NotifierEnabledChanged(const NotifierId
& notifier_id
,
47 bool enabled
) OVERRIDE
;
49 void set_provider(NotifierSettingsProvider
* new_provider
) {
50 provider_
= new_provider
;
54 FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest
, TestLearnMoreButton
);
56 class MESSAGE_CENTER_EXPORT NotifierButton
: public views::CustomButton
,
57 public views::ButtonListener
{
59 NotifierButton(NotifierSettingsProvider
* provider
,
61 views::ButtonListener
* listener
);
62 virtual ~NotifierButton();
64 void UpdateIconImage(const gfx::Image
& icon
);
65 void SetChecked(bool checked
);
67 bool has_learn_more() const;
68 const Notifier
& notifier() const;
70 void SendLearnMorePressedForTest();
73 // Overridden from views::ButtonListener:
74 virtual void ButtonPressed(views::Button
* button
,
75 const ui::Event
& event
) OVERRIDE
;
76 virtual void GetAccessibleState(ui::AXViewState
* state
) OVERRIDE
;
78 bool ShouldHaveLearnMoreButton() const;
79 // Helper function to reset the layout when the view has substantially
81 void GridChanged(bool has_learn_more
, bool has_icon_view
);
83 NotifierSettingsProvider
* provider_
; // Weak.
84 const scoped_ptr
<Notifier
> notifier_
;
85 // |icon_view_| is owned by us because sometimes we don't leave it
86 // in the view hierarchy.
87 scoped_ptr
<views::ImageView
> icon_view_
;
88 views::Label
* name_view_
;
89 views::Checkbox
* checkbox_
;
90 views::ImageButton
* learn_more_
;
92 DISALLOW_COPY_AND_ASSIGN(NotifierButton
);
95 // Given a new list of notifiers, updates the view to reflect it.
96 void UpdateContentsView(const std::vector
<Notifier
*>& notifiers
);
98 // Overridden from views::View:
99 virtual void Layout() OVERRIDE
;
100 virtual gfx::Size
GetMinimumSize() const OVERRIDE
;
101 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
102 virtual bool OnKeyPressed(const ui::KeyEvent
& event
) OVERRIDE
;
103 virtual bool OnMouseWheel(const ui::MouseWheelEvent
& event
) OVERRIDE
;
105 // Overridden from views::ButtonListener:
106 virtual void ButtonPressed(views::Button
* sender
,
107 const ui::Event
& event
) OVERRIDE
;
109 // Overridden from views::MenuButtonListener:
110 virtual void OnMenuButtonClicked(views::View
* source
,
111 const gfx::Point
& point
) OVERRIDE
;
113 views::ImageButton
* title_arrow_
;
114 views::Label
* title_label_
;
115 views::MenuButton
* notifier_group_selector_
;
116 views::ScrollView
* scroller_
;
117 NotifierSettingsProvider
* provider_
;
118 std::set
<NotifierButton
*> buttons_
;
119 scoped_ptr
<NotifierGroupMenuModel
> notifier_group_menu_model_
;
120 scoped_ptr
<views::MenuRunner
> notifier_group_menu_runner_
;
122 DISALLOW_COPY_AND_ASSIGN(NotifierSettingsView
);
125 } // namespace message_center
127 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_