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.
5 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_
8 #import <Cocoa/Cocoa.h>
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"
14 @class ConstrainedWindowAlert;
15 @class MediaGalleriesCocoaController;
17 class MediaGalleriesDialogBrowserTest;
18 class MediaGalleriesDialogTest;
20 // This class displays an alert that can be used to grant permission for
21 // extensions to access a gallery (media folders).
22 class MediaGalleriesDialogCocoa : public ConstrainedWindowMacDelegate,
23 public MediaGalleriesDialog {
25 MediaGalleriesDialogCocoa(
26 MediaGalleriesDialogController* controller,
27 MediaGalleriesCocoaController* delegate);
28 virtual ~MediaGalleriesDialogCocoa();
30 // Called when the user clicks the accept button.
31 void OnAcceptClicked();
32 // Called when the user clicks the cancel button.
33 void OnCancelClicked();
34 // Called when the user clicks the Add Gallery button.
35 void OnAddFolderClicked();
36 // Called when the user toggles a gallery checkbox.
37 void OnCheckboxToggled(NSButton* checkbox);
39 // MediaGalleriesDialog implementation:
40 virtual void UpdateGalleries() OVERRIDE;
42 // ConstrainedWindowMacDelegate implementation.
43 virtual void OnConstrainedWindowClosed(
44 ConstrainedWindowMac* window) OVERRIDE;
47 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogBrowserTest, Close);
48 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, InitializeCheckboxes);
49 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ToggleCheckboxes);
50 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, UpdateAdds);
51 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ForgetDeletes);
53 void UpdateGalleryCheckbox(const MediaGalleryPrefInfo& gallery,
57 void InitDialogControls();
58 CGFloat CreateAddFolderButton();
59 CGFloat CreateAttachedCheckboxes(
61 const MediaGalleriesDialogController::GalleryPermissionsVector&
63 CGFloat CreateUnattachedCheckboxes(
65 const MediaGalleriesDialogController::GalleryPermissionsVector&
67 CGFloat CreateCheckboxSeparator(CGFloat y_pos);
69 MediaGalleriesDialogController* controller_; // weak
70 scoped_ptr<ConstrainedWindowMac> window_;
72 // The alert that the dialog is being displayed as.
73 base::scoped_nsobject<ConstrainedWindowAlert> alert_;
75 // True if the user has pressed accept.
78 // List of checkboxes ordered from bottom to top.
79 base::scoped_nsobject<NSMutableArray> checkboxes_;
81 // Container view for checkboxes.
82 base::scoped_nsobject<NSView> checkbox_container_;
84 // Container view for the main dialog contents.
85 base::scoped_nsobject<NSBox> accessory_;
87 // An Objective-C class to route callbacks from Cocoa code.
88 base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller_;
90 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogCocoa);
93 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_