Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / extensions / media_galleries_dialog_cocoa.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_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #include "base/gtest_prod_util.h"
11 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
13
14 @class ConstrainedWindowAlert;
15 @class MediaGalleriesCocoaController;
16
17 class MediaGalleriesDialogBrowserTest;
18 class MediaGalleriesDialogTest;
19
20 namespace ui {
21 class MenuModel;
22 }
23
24 // This class displays an alert that can be used to grant permission for
25 // extensions to access a gallery (media folders).
26 class MediaGalleriesDialogCocoa : public ConstrainedWindowMacDelegate,
27                                   public MediaGalleriesDialog {
28  public:
29   MediaGalleriesDialogCocoa(
30       MediaGalleriesDialogController* controller,
31       MediaGalleriesCocoaController* delegate);
32   virtual ~MediaGalleriesDialogCocoa();
33
34   // Called when the user clicks the accept button.
35   void OnAcceptClicked();
36   // Called when the user clicks the cancel button.
37   void OnCancelClicked();
38   // Called when the user clicks the Add Gallery button.
39   void OnAddFolderClicked();
40   // Called when the user toggles a gallery checkbox.
41   void OnCheckboxToggled(NSButton* checkbox);
42
43   // MediaGalleriesDialog implementation:
44   virtual void UpdateGalleries() OVERRIDE;
45
46   // ConstrainedWindowMacDelegate implementation.
47   virtual void OnConstrainedWindowClosed(
48       ConstrainedWindowMac* window) OVERRIDE;
49
50   ui::MenuModel* GetContextMenu(MediaGalleryPrefId prefid);
51
52  private:
53   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogBrowserTest, Close);
54   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, InitializeCheckboxes);
55   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ToggleCheckboxes);
56   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, UpdateAdds);
57   FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ForgetDeletes);
58
59   void UpdateGalleryCheckbox(const MediaGalleryPrefInfo& gallery,
60                              bool permitted,
61                              CGFloat y_pos);
62
63   void InitDialogControls();
64   CGFloat CreateAddFolderButton();
65   CGFloat CreateAttachedCheckboxes(
66       CGFloat y_pos,
67       const MediaGalleriesDialogController::GalleryPermissionsVector&
68           permissions);
69   CGFloat CreateUnattachedCheckboxes(
70       CGFloat y_pos,
71       const MediaGalleriesDialogController::GalleryPermissionsVector&
72           permissions);
73   CGFloat CreateCheckboxSeparator(CGFloat y_pos);
74
75   MediaGalleriesDialogController* controller_;  // weak
76   scoped_ptr<ConstrainedWindowMac> window_;
77
78   // The alert that the dialog is being displayed as.
79   base::scoped_nsobject<ConstrainedWindowAlert> alert_;
80
81   // True if the user has pressed accept.
82   bool accepted_;
83
84   // List of checkboxes ordered from bottom to top.
85   base::scoped_nsobject<NSMutableArray> checkboxes_;
86
87   // Container view for checkboxes.
88   base::scoped_nsobject<NSView> checkbox_container_;
89
90   // Container view for the main dialog contents.
91   base::scoped_nsobject<NSBox> main_container_;
92
93   // An Objective-C class to route callbacks from Cocoa code.
94   base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller_;
95
96   DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogCocoa);
97 };
98
99 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_