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