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