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_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_ 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_ 7 8 #include <map> 9 10 #include "base/compiler_specific.h" 11 #include "base/gtest_prod_util.h" 12 #include "base/macros.h" 13 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" 14 #include "ui/views/context_menu_controller.h" 15 #include "ui/views/window/dialog_delegate.h" 16 17 namespace views { 18 class Checkbox; 19 class LabelButton; 20 class MenuRunner; 21 class Widget; 22 } 23 24 class MediaGalleryCheckboxView; 25 26 // The media galleries configuration view for Views. It will immediately show 27 // upon construction. 28 class MediaGalleriesDialogViews : public MediaGalleriesDialog, 29 public views::ContextMenuController, 30 public views::DialogDelegate { 31 public: 32 explicit MediaGalleriesDialogViews( 33 MediaGalleriesDialogController* controller); 34 ~MediaGalleriesDialogViews() override; 35 36 // MediaGalleriesDialog: 37 void UpdateGalleries() override; 38 39 // views::DialogDelegate: 40 void DeleteDelegate() override; 41 views::Widget* GetWidget() override; 42 const views::Widget* GetWidget() const override; 43 views::View* GetContentsView() override; 44 bool IsDialogButtonEnabled(ui::DialogButton button) const override; 45 ui::ModalType GetModalType() const override; 46 47 // views::ContextMenuController: 48 void ShowContextMenuForViewImpl(views::View* source, 49 const gfx::Point& point, 50 ui::MenuSourceType source_type) override; 51 52 private: 53 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, InitializeCheckboxes); 54 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ToggleCheckboxes); 55 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, UpdateAdds); 56 FRIEND_TEST_ALL_PREFIXES(MediaGalleriesDialogTest, ForgetDeletes); 57 58 using CheckboxMap = std::map<MediaGalleryPrefId, MediaGalleryCheckboxView*>; 59 60 // MediaGalleriesDialog: 61 void AcceptDialogForTesting() override; 62 63 void InitChildViews(); 64 65 // Adds a checkbox or updates an existing checkbox. Returns true if a new one 66 // was added. 67 bool AddOrUpdateGallery( 68 const MediaGalleriesDialogController::Entry& gallery, 69 views::View* container, 70 int trailing_vertical_space); 71 72 void ShowContextMenu(const gfx::Point& point, 73 ui::MenuSourceType source_type, 74 MediaGalleryPrefId id); 75 76 // Whether |controller_| has a valid WebContents or not. 77 // In unit tests, it may not. 78 bool ControllerHasWebContents() const; 79 80 // Called when a button is pressed; does common preamble, then runs the 81 // supplied closure to execute the specific details of the particular button. 82 void ButtonPressed(base::RepeatingClosure closure); 83 84 // Callback for MenuRunner. 85 void OnMenuClosed(); 86 87 MediaGalleriesDialogController* controller_; 88 89 // The contents of the dialog. Owned by the view hierarchy, except in tests. 90 views::View* contents_; 91 92 // A map from gallery ID to views::Checkbox view. 93 CheckboxMap checkbox_map_; 94 95 // Pointer to the controller specific auxiliary button, NULL otherwise. 96 // Owned by parent in the dialog views tree. 97 views::LabelButton* auxiliary_button_; 98 99 // This tracks whether the confirm button can be clicked. It starts as false 100 // if no checkboxes are ticked. After there is any interaction, or some 101 // checkboxes start checked, this will be true. 102 bool confirm_available_; 103 104 // True if the user has pressed accept. 105 bool accepted_; 106 107 std::unique_ptr<views::MenuRunner> context_menu_runner_; 108 109 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogViews); 110 }; 111 112 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_MEDIA_GALLERIES_DIALOG_VIEWS_H_ 113