Home | History | Annotate | Download | only in views
      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   virtual void NotifierEnabledChanged(const NotifierId& notifier_id,
     47                                       bool enabled) OVERRIDE;
     48 
     49   void set_provider(NotifierSettingsProvider* new_provider) {
     50     provider_ = new_provider;
     51   }
     52 
     53  private:
     54   FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestLearnMoreButton);
     55 
     56   class MESSAGE_CENTER_EXPORT NotifierButton : public views::CustomButton,
     57                          public views::ButtonListener {
     58    public:
     59     NotifierButton(NotifierSettingsProvider* provider,
     60                    Notifier* notifier,
     61                    views::ButtonListener* listener);
     62     virtual ~NotifierButton();
     63 
     64     void UpdateIconImage(const gfx::Image& icon);
     65     void SetChecked(bool checked);
     66     bool checked() const;
     67     bool has_learn_more() const;
     68     const Notifier& notifier() const;
     69 
     70     void SendLearnMorePressedForTest();
     71 
     72    private:
     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;
     77 
     78     bool ShouldHaveLearnMoreButton() const;
     79     // Helper function to reset the layout when the view has substantially
     80     // changed.
     81     void GridChanged(bool has_learn_more, bool has_icon_view);
     82 
     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_;
     91 
     92     DISALLOW_COPY_AND_ASSIGN(NotifierButton);
     93   };
     94 
     95   // Given a new list of notifiers, updates the view to reflect it.
     96   void UpdateContentsView(const std::vector<Notifier*>& notifiers);
     97 
     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;
    104 
    105   // Overridden from views::ButtonListener:
    106   virtual void ButtonPressed(views::Button* sender,
    107                              const ui::Event& event) OVERRIDE;
    108 
    109   // Overridden from views::MenuButtonListener:
    110   virtual void OnMenuButtonClicked(views::View* source,
    111                                    const gfx::Point& point) OVERRIDE;
    112 
    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_;
    121 
    122   DISALLOW_COPY_AND_ASSIGN(NotifierSettingsView);
    123 };
    124 
    125 }  // namespace message_center
    126 
    127 #endif  // UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
    128