- add sources.
[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 // 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 {
24  public:
25   MediaGalleriesDialogCocoa(
26       MediaGalleriesDialogController* controller,
27       MediaGalleriesCocoaController* delegate);
28   virtual ~MediaGalleriesDialogCocoa();
29
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);
38
39   // MediaGalleriesDialog implementation:
40   virtual void UpdateGalleries() OVERRIDE;
41
42   // ConstrainedWindowMacDelegate implementation.
43   virtual void OnConstrainedWindowClosed(
44       ConstrainedWindowMac* window) OVERRIDE;
45
46  private:
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);
52
53   void UpdateGalleryCheckbox(const MediaGalleryPrefInfo& gallery,
54                              bool permitted,
55                              CGFloat y_pos);
56
57   void InitDialogControls();
58   CGFloat CreateAddFolderButton();
59   CGFloat CreateAttachedCheckboxes(
60       CGFloat y_pos,
61       const MediaGalleriesDialogController::GalleryPermissionsVector&
62           permissions);
63   CGFloat CreateUnattachedCheckboxes(
64       CGFloat y_pos,
65       const MediaGalleriesDialogController::GalleryPermissionsVector&
66           permissions);
67   CGFloat CreateCheckboxSeparator(CGFloat y_pos);
68
69   MediaGalleriesDialogController* controller_;  // weak
70   scoped_ptr<ConstrainedWindowMac> window_;
71
72   // The alert that the dialog is being displayed as.
73   base::scoped_nsobject<ConstrainedWindowAlert> alert_;
74
75   // True if the user has pressed accept.
76   bool accepted_;
77
78   // List of checkboxes ordered from bottom to top.
79   base::scoped_nsobject<NSMutableArray> checkboxes_;
80
81   // Container view for checkboxes.
82   base::scoped_nsobject<NSView> checkbox_container_;
83
84   // Container view for the main dialog contents.
85   base::scoped_nsobject<NSBox> accessory_;
86
87   // An Objective-C class to route callbacks from Cocoa code.
88   base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller_;
89
90   DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogCocoa);
91 };
92
93 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_