media_galleries_dialog_views.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
1// Copyright (c) 2012 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 CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
6#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
7
8#include <map>
9
10#include "base/compiler_specific.h"
11#include "chrome/browser/media_galleries/media_galleries_dialog_controller.h"
12#include "ui/views/context_menu_controller.h"
13#include "ui/views/controls/button/button.h"
14#include "ui/views/window/dialog_delegate.h"
15
16namespace ui {
17class MenuModel;
18}
19
20namespace views {
21class Checkbox;
22class LabelButton;
23class MenuRunner;
24class Widget;
25}
26
27// The media galleries configuration view for Views. It will immediately show
28// upon construction.
29class MediaGalleriesDialogViews : public MediaGalleriesDialog,
30                                  public views::ButtonListener,
31                                  public views::ContextMenuController,
32                                  public views::DialogDelegate {
33 public:
34  explicit MediaGalleriesDialogViews(
35      MediaGalleriesDialogController* controller);
36  virtual ~MediaGalleriesDialogViews();
37
38  // MediaGalleriesDialog implementation:
39  virtual void UpdateGalleries() OVERRIDE;
40
41  // views::DialogDelegate implementation:
42  virtual string16 GetWindowTitle() const OVERRIDE;
43  virtual bool ShouldShowWindowTitle() const OVERRIDE;
44  virtual void DeleteDelegate() OVERRIDE;
45  virtual views::Widget* GetWidget() OVERRIDE;
46  virtual const views::Widget* GetWidget() const OVERRIDE;
47  virtual views::View* GetContentsView() OVERRIDE;
48  virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
49  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
50  virtual ui::ModalType GetModalType() const OVERRIDE;
51  virtual views::View* CreateExtraView() OVERRIDE;
52  virtual bool Cancel() OVERRIDE;
53  virtual bool Accept() OVERRIDE;
54  virtual views::NonClientFrameView* CreateNonClientFrameView(
55      views::Widget* widget) OVERRIDE;
56
57  // views::ButtonListener implementation:
58  virtual void ButtonPressed(views::Button* sender,
59                             const ui::Event& event) OVERRIDE;
60
61  // views::ContextMenuController implementation:
62  virtual void ShowContextMenuForView(views::View* source,
63                                      const gfx::Point& point,
64                                      ui::MenuSourceType source_type) OVERRIDE;
65
66 private:
67  typedef std::map<MediaGalleryPrefId, views::Checkbox*> CheckboxMap;
68  typedef std::map<views::Checkbox*, MediaGalleryPrefInfo> NewCheckboxMap;
69
70  void InitChildViews();
71
72  // Adds a checkbox or updates an existing checkbox. Returns true if a new one
73  // was added.
74  bool AddOrUpdateGallery(const MediaGalleryPrefInfo& gallery,
75                          bool permitted,
76                          views::View* container,
77                          int trailing_vertical_space);
78
79  void ShowContextMenu(const gfx::Point& point,
80                       ui::MenuSourceType source_type,
81                       MediaGalleryPrefId id);
82
83  MediaGalleriesDialogController* controller_;
84
85  // The containing window (a weak pointer).
86  views::Widget* window_;
87
88  // The contents of the dialog. Owned by |window_|'s RootView.
89  views::View* contents_;
90
91  // A map from media gallery ID to views::Checkbox view.
92  CheckboxMap checkbox_map_;
93
94  NewCheckboxMap new_checkbox_map_;
95
96  // Pointer to the button to add a new gallery. Owned by parent in
97  // the dialog views tree.
98  views::LabelButton* add_gallery_button_;
99
100  // This tracks whether the confirm button can be clicked. It starts as false
101  // if no checkboxes are ticked. After there is any interaction, or some
102  // checkboxes start checked, this will be true.
103  bool confirm_available_;
104
105  // True if the user has pressed accept.
106  bool accepted_;
107
108  scoped_ptr<views::MenuRunner> context_menu_runner_;
109
110  DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogViews);
111};
112
113#endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_
114