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