notifier_settings_view.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include <set>
9bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
10bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "base/memory/scoped_ptr.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/message_center_export.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notifier_settings.h"
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/views/message_bubble_base.h"
140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ui/views/controls/button/checkbox.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/views/controls/button/image_button.h"
16bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/views/controls/button/menu_button_listener.h"
170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "ui/views/controls/image_view.h"
18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/views/view.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
20bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace views {
21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass Label;
22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass MenuButton;
23bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass MenuRunner;
24bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch}
25bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace message_center {
27bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochclass NotifierGroupMenuModel;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A class to show the list of notifier extensions / URL patterns and allow
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// users to customize the settings.
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MESSAGE_CENTER_EXPORT NotifierSettingsView
32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    : public NotifierSettingsObserver,
33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      public views::View,
34bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch      public views::ButtonListener,
35bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch      public views::MenuButtonListener {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explicit NotifierSettingsView(NotifierSettingsProvider* provider);
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual ~NotifierSettingsView();
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool IsScrollable();
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Overridden from NotifierSettingsDelegate:
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void UpdateIconImage(const NotifierId& notifier_id,
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                               const gfx::Image& icon) OVERRIDE;
45bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  virtual void NotifierGroupChanged() OVERRIDE;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
47eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void set_provider(NotifierSettingsProvider* new_provider) {
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    provider_ = new_provider;
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestLearnMoreButton);
530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  class MESSAGE_CENTER_EXPORT NotifierButton : public views::CustomButton,
550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                         public views::ButtonListener {
560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)   public:
570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    NotifierButton(NotifierSettingsProvider* provider,
580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                   Notifier* notifier,
590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                   views::ButtonListener* listener);
600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    virtual ~NotifierButton();
610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    void UpdateIconImage(const gfx::Image& icon);
630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    void SetChecked(bool checked);
640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    bool checked() const;
650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    bool has_learn_more() const;
660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    const Notifier& notifier() const;
670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    void SendLearnMorePressedForTest();
690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)   private:
710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Overridden from views::ButtonListener:
720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    virtual void ButtonPressed(views::Button* button,
730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                               const ui::Event& event) OVERRIDE;
74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    bool ShouldHaveLearnMoreButton() const;
770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Helper function to reset the layout when the view has substantially
780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // changed.
790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    void GridChanged(bool has_learn_more, bool has_icon_view);
800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    NotifierSettingsProvider* provider_;  // Weak.
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    const scoped_ptr<Notifier> notifier_;
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // |icon_view_| is owned by us because sometimes we don't leave it
840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // in the view hierarchy.
850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    scoped_ptr<views::ImageView> icon_view_;
860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    views::Label* name_view_;
870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    views::Checkbox* checkbox_;
880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    views::ImageButton* learn_more_;
890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(NotifierButton);
910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  };
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
93bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  // Given a new list of notifiers, updates the view to reflect it.
94bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  void UpdateContentsView(const std::vector<Notifier*>& notifiers);
95bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Overridden from views::View:
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void Layout() OVERRIDE;
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Size GetMinimumSize() OVERRIDE;
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Size GetPreferredSize() OVERRIDE;
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Overridden from views::ButtonListener:
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const ui::Event& event) OVERRIDE;
1060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Overridden from views::MenuButtonListener:
108bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  virtual void OnMenuButtonClicked(views::View* source,
109bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch                                   const gfx::Point& point) OVERRIDE;
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::ImageButton* title_arrow_;
112ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  views::Label* title_label_;
113ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  views::MenuButton* notifier_group_selector_;
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  views::ScrollView* scroller_;
115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  NotifierSettingsProvider* provider_;
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::set<NotifierButton*> buttons_;
117bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  scoped_ptr<NotifierGroupMenuModel> notifier_group_menu_model_;
118bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  scoped_ptr<views::MenuRunner> notifier_group_menu_runner_;
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NotifierSettingsView);
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace message_center
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // UI_MESSAGE_CENTER_VIEWS_NOTIFIER_SETTINGS_VIEW_H_
126