media_galleries_dialog_cocoa.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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
17class MediaGalleriesDialogBrowserTest;
18class MediaGalleriesDialogTest;
19
20namespace ui {
21class 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).
26class 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(GalleryDialogId gallery_id);
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(
60      const MediaGalleriesDialogController::GalleryPermission& gallery,
61      CGFloat y_pos);
62
63  void InitDialogControls();
64  CGFloat CreateAddFolderButton();
65  CGFloat CreateCheckboxes(
66      CGFloat y_pos,
67      const MediaGalleriesDialogController::GalleryPermissionsVector&
68          permissions);
69  CGFloat CreateCheckboxSeparator(CGFloat y_pos);
70
71  MediaGalleriesDialogController* controller_;  // weak
72  scoped_ptr<ConstrainedWindowMac> window_;
73
74  // The alert that the dialog is being displayed as.
75  base::scoped_nsobject<ConstrainedWindowAlert> alert_;
76
77  // True if the user has pressed accept.
78  bool accepted_;
79
80  // List of checkboxes ordered from bottom to top.
81  base::scoped_nsobject<NSMutableArray> checkboxes_;
82
83  // Container view for checkboxes.
84  base::scoped_nsobject<NSView> checkbox_container_;
85
86  // Container view for the main dialog contents.
87  base::scoped_nsobject<NSBox> main_container_;
88
89  // An Objective-C class to route callbacks from Cocoa code.
90  base::scoped_nsobject<MediaGalleriesCocoaController> cocoa_controller_;
91
92  DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogCocoa);
93};
94
95#endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_MEDIA_GALLERIES_DIALOG_COCOA_H_
96