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