Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / extensions / media_galleries_dialog_views.h
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
16 namespace views {
17 class Checkbox;
18 class LabelButton;
19 class MenuRunner;
20 class Widget;
21 }
22
23 class MediaGalleryCheckboxView;
24
25 // The media galleries configuration view for Views. It will immediately show
26 // upon construction.
27 class MediaGalleriesDialogViews : public MediaGalleriesDialog,
28                                   public views::ButtonListener,
29                                   public views::ContextMenuController,
30                                   public views::DialogDelegate {
31  public:
32   explicit MediaGalleriesDialogViews(
33       MediaGalleriesDialogController* controller);
34   ~MediaGalleriesDialogViews() override;
35
36   // MediaGalleriesDialog implementation:
37   void UpdateGalleries() override;
38
39   // views::DialogDelegate implementation:
40   base::string16 GetWindowTitle() const override;
41   void DeleteDelegate() override;
42   views::Widget* GetWidget() override;
43   const views::Widget* GetWidget() const override;
44   views::View* GetContentsView() override;
45   base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
46   bool IsDialogButtonEnabled(ui::DialogButton button) const override;
47   ui::ModalType GetModalType() const override;
48   views::View* CreateExtraView() override;
49   bool Cancel() override;
50   bool Accept() override;
51
52   // views::ButtonListener implementation:
53   void ButtonPressed(views::Button* sender, const ui::Event& event) override;
54
55   // views::ContextMenuController implementation:
56   void ShowContextMenuForView(views::View* source,
57                               const gfx::Point& point,
58                               ui::MenuSourceType source_type) override;
59
60  private:
61   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, InitializeCheckboxes);
62   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ToggleCheckboxes);
63   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, UpdateAdds);
64   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ForgetDeletes);
65
66   typedef std::map<MediaGalleryPrefId, MediaGalleryCheckboxView*> CheckboxMap;
67
68   // MediaGalleriesDialog implementation:
69   void AcceptDialogForTesting() override;
70
71   void InitChildViews();
72
73   // Adds a checkbox or updates an existing checkbox. Returns true if a new one
74   // was added.
75   bool AddOrUpdateGallery(
76       const MediaGalleriesDialogController::Entry& gallery,
77       views::View* container,
78       int trailing_vertical_space);
79
80   void ShowContextMenu(const gfx::Point& point,
81                        ui::MenuSourceType source_type,
82                        MediaGalleryPrefId id);
83
84   // Whether |controller_| has a valid WebContents or not.
85   // In unit tests, it may not.
86   bool ControllerHasWebContents() const;
87
88   MediaGalleriesDialogController* controller_;
89
90   // The contents of the dialog. Owned by the view hierarchy, except in tests.
91   views::View* contents_;
92
93   // A map from gallery ID to views::Checkbox view.
94   CheckboxMap checkbox_map_;
95
96   // Pointer to the controller specific auxiliary button, NULL otherwise.
97   // Owned by parent in the dialog views tree.
98   views::LabelButton* auxiliary_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_