#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/constrained_window_views.h"
-#include "components/web_modal/web_contents_modal_dialog_host.h"
-#include "components/web_modal/web_contents_modal_dialog_manager.h"
-#include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
+#include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h"
+#include "chrome/grit/generated_resources.h"
+#include "chrome/grit/locale_settings.h"
+#include "components/web_modal/popup_manager.h"
#include "content/public/browser/web_contents.h"
-#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
-#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/checkbox.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"
-using web_modal::WebContentsModalDialogManager;
-using web_modal::WebContentsModalDialogManagerDelegate;
-
namespace {
-// Equal to the #969696 color used in spec (note WebUI color is #999).
-const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159);
-
const int kScrollAreaHeight = 192;
// This container has the right Layout() impl to use within a ScrollView.
int width = pref.width();
int height = pref.height();
if (parent()) {
- width = std::max(parent()->width(), width);
+ width = parent()->width();
height = std::max(parent()->height(), height);
}
SetBounds(x(), y(), width, height);
} // namespace
-typedef MediaGalleriesDialogController::GalleryPermissionsVector
- GalleryPermissionsVector;
-
MediaGalleriesDialogViews::MediaGalleriesDialogViews(
MediaGalleriesDialogController* controller)
: controller_(controller),
- window_(NULL),
contents_(new views::View()),
- add_gallery_button_(NULL),
+ auxiliary_button_(NULL),
confirm_available_(false),
accepted_(false) {
InitChildViews();
+ if (ControllerHasWebContents())
+ ShowWebModalDialogViews(this, controller->WebContents());
+}
- // Ownership of |contents_| is handed off by this call. |window_| will take
- // care of deleting itself after calling DeleteDelegate().
- WebContentsModalDialogManager* web_contents_modal_dialog_manager =
- WebContentsModalDialogManager::FromWebContents(
- controller->web_contents());
- DCHECK(web_contents_modal_dialog_manager);
- WebContentsModalDialogManagerDelegate* modal_delegate =
- web_contents_modal_dialog_manager->delegate();
- DCHECK(modal_delegate);
- window_ = views::Widget::CreateWindowAsFramelessChild(
- this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
- web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView());
+MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {
+ if (!ControllerHasWebContents())
+ delete contents_;
}
-MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {}
+void MediaGalleriesDialogViews::AcceptDialogForTesting() {
+ accepted_ = true;
+
+ web_modal::PopupManager* popup_manager =
+ web_modal::PopupManager::FromWebContents(controller_->WebContents());
+ DCHECK(popup_manager);
+ popup_manager->CloseAllDialogsForTesting(controller_->WebContents());
+}
void MediaGalleriesDialogViews::InitChildViews() {
// Outer dialog layout.
contents_->RemoveAllChildViews(true);
+ checkbox_map_.clear();
+
int dialog_content_width = views::Widget::GetLocalizedContentsWidth(
IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS);
views::GridLayout* layout = views::GridLayout::CreatePanel(contents_);
views::kRelatedControlVerticalSpacing,
0));
- // Add attached galleries checkboxes.
- checkbox_map_.clear();
- new_checkbox_map_.clear();
- GalleryPermissionsVector permissions = controller_->AttachedPermissions();
- for (GalleryPermissionsVector::const_iterator iter = permissions.begin();
- iter != permissions.end(); ++iter) {
- int spacing = 0;
- if (iter + 1 == permissions.end())
- spacing = views::kRelatedControlSmallVerticalSpacing;
- AddOrUpdateGallery(iter->pref_info, iter->allowed, scroll_container,
- spacing);
- }
+ std::vector<base::string16> section_headers =
+ controller_->GetSectionHeaders();
+ for (size_t i = 0; i < section_headers.size(); i++) {
+ MediaGalleriesDialogController::Entries entries =
+ controller_->GetSectionEntries(i);
+
+ // Header and separator line.
+ if (!section_headers[i].empty() && !entries.empty()) {
+ views::Separator* separator = new views::Separator(
+ views::Separator::HORIZONTAL);
+ scroll_container->AddChildView(separator);
+
+ views::Label* header = new views::Label(section_headers[i]);
+ header->SetMultiLine(true);
+ header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ header->SetBorder(views::Border::CreateEmptyBorder(
+ views::kRelatedControlVerticalSpacing,
+ views::kPanelHorizMargin,
+ views::kRelatedControlVerticalSpacing,
+ 0));
+ scroll_container->AddChildView(header);
+ }
- GalleryPermissionsVector unattached_permissions =
- controller_->UnattachedPermissions();
-
- if (!unattached_permissions.empty()) {
- // Separator line.
- views::Separator* separator = new views::Separator(
- views::Separator::HORIZONTAL);
- scroll_container->AddChildView(separator);
-
- // Unattached locations section.
- views::Label* unattached_text = new views::Label(
- controller_->GetUnattachedLocationsHeader());
- unattached_text->SetMultiLine(true);
- unattached_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- unattached_text->SetBorder(
- views::Border::CreateEmptyBorder(views::kRelatedControlVerticalSpacing,
- views::kPanelHorizMargin,
- views::kRelatedControlVerticalSpacing,
- 0));
- scroll_container->AddChildView(unattached_text);
-
- // Add unattached galleries checkboxes.
- for (GalleryPermissionsVector::const_iterator iter =
- unattached_permissions.begin();
- iter != unattached_permissions.end(); ++iter) {
- AddOrUpdateGallery(iter->pref_info, iter->allowed, scroll_container, 0);
+ // Checkboxes.
+ MediaGalleriesDialogController::Entries::const_iterator iter;
+ for (iter = entries.begin(); iter != entries.end(); ++iter) {
+ int spacing = 0;
+ if (iter + 1 == entries.end())
+ spacing = views::kRelatedControlSmallVerticalSpacing;
+ AddOrUpdateGallery(*iter, scroll_container, spacing);
}
}
- confirm_available_ = controller_->HasPermittedGalleries();
+ confirm_available_ = controller_->IsAcceptAllowed();
// Add the scrollable area to the outer dialog view. It will squeeze against
// the title/subtitle and buttons to occupy all available space in the dialog.
void MediaGalleriesDialogViews::UpdateGalleries() {
InitChildViews();
contents_->Layout();
+
+ if (ControllerHasWebContents())
+ GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons();
}
bool MediaGalleriesDialogViews::AddOrUpdateGallery(
- const MediaGalleryPrefInfo& gallery,
- bool permitted,
+ const MediaGalleriesDialogController::Entry& gallery,
views::View* container,
int trailing_vertical_space) {
- base::string16 label = gallery.GetGalleryDisplayName();
- base::string16 tooltip_text = gallery.GetGalleryTooltip();
- base::string16 details = gallery.GetGalleryAdditionalDetails();
-
- CheckboxMap::iterator iter = checkbox_map_.find(gallery.pref_id);
- if (iter != checkbox_map_.end() &&
- gallery.pref_id != kInvalidMediaGalleryPrefId) {
- views::Checkbox* checkbox = iter->second;
- checkbox->SetChecked(permitted);
- checkbox->SetText(label);
- checkbox->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE);
- checkbox->SetTooltipText(tooltip_text);
- // Replace the details string.
- views::View* checkbox_view = checkbox->parent();
- DCHECK_EQ(2, checkbox_view->child_count());
- views::Label* secondary_text =
- static_cast<views::Label*>(checkbox_view->child_at(1));
- secondary_text->SetText(details);
+ bool show_folder_viewer = controller_->ShouldShowFolderViewer(gallery);
+
+ CheckboxMap::iterator iter = checkbox_map_.find(gallery.pref_info.pref_id);
+ if (iter != checkbox_map_.end()) {
+ views::Checkbox* checkbox = iter->second->checkbox();
+ checkbox->SetChecked(gallery.selected);
+ checkbox->SetText(gallery.pref_info.GetGalleryDisplayName());
+ checkbox->SetTooltipText(gallery.pref_info.GetGalleryTooltip());
+ base::string16 details = gallery.pref_info.GetGalleryAdditionalDetails();
+ iter->second->secondary_text()->SetText(details);
+ iter->second->secondary_text()->SetVisible(details.length() > 0);
+ iter->second->folder_viewer_button()->SetVisible(show_folder_viewer);
return false;
}
- views::Checkbox* checkbox = new views::Checkbox(label);
- checkbox->set_listener(this);
- if (gallery.pref_id != kInvalidMediaGalleryPrefId)
- checkbox->set_context_menu_controller(this);
- checkbox->SetTooltipText(tooltip_text);
- views::Label* secondary_text = new views::Label(details);
- if (gallery.pref_id != kInvalidMediaGalleryPrefId)
- secondary_text->set_context_menu_controller(this);
- secondary_text->SetTooltipText(tooltip_text);
- secondary_text->SetEnabledColor(kDeemphasizedTextColor);
- secondary_text->SetTooltipText(tooltip_text);
- secondary_text->SetBorder(views::Border::CreateEmptyBorder(
- 0,
- views::kRelatedControlSmallHorizontalSpacing,
- 0,
- views::kRelatedControlSmallHorizontalSpacing));
-
- views::View* checkbox_view = new views::View();
- if (gallery.pref_id != kInvalidMediaGalleryPrefId)
- checkbox_view->set_context_menu_controller(this);
- checkbox_view->SetBorder(views::Border::CreateEmptyBorder(
- 0, views::kPanelHorizMargin, trailing_vertical_space, 0));
- checkbox_view->SetLayoutManager(
- new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
- checkbox_view->AddChildView(checkbox);
- checkbox_view->AddChildView(secondary_text);
-
- container->AddChildView(checkbox_view);
-
- checkbox->SetChecked(permitted);
- if (gallery.pref_id != kInvalidMediaGalleryPrefId)
- checkbox_map_[gallery.pref_id] = checkbox;
- else
- new_checkbox_map_[checkbox] = gallery;
+ MediaGalleryCheckboxView* gallery_view =
+ new MediaGalleryCheckboxView(gallery.pref_info, show_folder_viewer,
+ trailing_vertical_space, this, this);
+ gallery_view->checkbox()->SetChecked(gallery.selected);
+ container->AddChildView(gallery_view);
+ checkbox_map_[gallery.pref_info.pref_id] = gallery_view;
return true;
}
base::string16 MediaGalleriesDialogViews::GetDialogButtonLabel(
ui::DialogButton button) const {
- return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ?
- IDS_MEDIA_GALLERIES_DIALOG_CONFIRM :
- IDS_MEDIA_GALLERIES_DIALOG_CANCEL);
+ if (button == ui::DIALOG_BUTTON_OK)
+ return controller_->GetAcceptButtonText();
+ return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CANCEL);
}
bool MediaGalleriesDialogViews::IsDialogButtonEnabled(
}
ui::ModalType MediaGalleriesDialogViews::GetModalType() const {
-#if defined(USE_ASH)
return ui::MODAL_TYPE_CHILD;
-#else
- return views::WidgetDelegate::GetModalType();
-#endif
}
views::View* MediaGalleriesDialogViews::CreateExtraView() {
- DCHECK(!add_gallery_button_);
- add_gallery_button_ = new views::LabelButton(this,
- l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY));
- add_gallery_button_->SetStyle(views::Button::STYLE_BUTTON);
- return add_gallery_button_;
+ DCHECK(!auxiliary_button_);
+ base::string16 button_label = controller_->GetAuxiliaryButtonText();
+ if (!button_label.empty()) {
+ auxiliary_button_ = new views::LabelButton(this, button_label);
+ auxiliary_button_->SetStyle(views::Button::STYLE_BUTTON);
+ }
+ return auxiliary_button_;
}
bool MediaGalleriesDialogViews::Cancel() {
bool MediaGalleriesDialogViews::Accept() {
accepted_ = true;
-
return true;
}
-// TODO(wittman): Remove this override once we move to the new style frame view
-// on all dialogs.
-views::NonClientFrameView* MediaGalleriesDialogViews::CreateNonClientFrameView(
- views::Widget* widget) {
- return CreateConstrainedStyleNonClientFrameView(
- widget,
- controller_->web_contents()->GetBrowserContext());
-}
-
void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender,
- const ui::Event& event) {
+ const ui::Event& /* event */) {
confirm_available_ = true;
- GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons();
- if (sender == add_gallery_button_) {
- controller_->OnAddFolderClicked();
+ if (ControllerHasWebContents())
+ GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons();
+
+ if (sender == auxiliary_button_) {
+ controller_->DidClickAuxiliaryButton();
return;
}
for (CheckboxMap::const_iterator iter = checkbox_map_.begin();
iter != checkbox_map_.end(); ++iter) {
- if (sender == iter->second) {
- controller_->DidToggleGalleryId(iter->first,
- iter->second->checked());
+ if (sender == iter->second->checkbox()) {
+ controller_->DidToggleEntry(iter->first,
+ iter->second->checkbox()->checked());
return;
}
- }
- for (NewCheckboxMap::const_iterator iter = new_checkbox_map_.begin();
- iter != new_checkbox_map_.end(); ++iter) {
- if (sender == iter->first) {
- controller_->DidToggleNewGallery(iter->second, iter->first->checked());
+ if (sender == iter->second->folder_viewer_button()) {
+ controller_->DidClickOpenFolderViewer(iter->first);
+ return;
}
}
}
ui::MenuSourceType source_type) {
for (CheckboxMap::const_iterator iter = checkbox_map_.begin();
iter != checkbox_map_.end(); ++iter) {
- if (iter->second->parent()->Contains(source)) {
+ if (iter->second->Contains(source)) {
ShowContextMenu(point, source_type, iter->first);
return;
}
ui::MenuSourceType source_type,
MediaGalleryPrefId id) {
context_menu_runner_.reset(new views::MenuRunner(
- controller_->GetContextMenuModel(id)));
-
- if (context_menu_runner_->RunMenuAt(
- GetWidget(), NULL, gfx::Rect(point.x(), point.y(), 0, 0),
- views::MenuItemView::TOPLEFT, source_type,
- views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
+ controller_->GetContextMenu(id),
+ views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
+
+ if (context_menu_runner_->RunMenuAt(GetWidget(),
+ NULL,
+ gfx::Rect(point.x(), point.y(), 0, 0),
+ views::MENU_ANCHOR_TOPLEFT,
+ source_type) ==
views::MenuRunner::MENU_DELETED) {
return;
}
}
+bool MediaGalleriesDialogViews::ControllerHasWebContents() const {
+ return controller_->WebContents() != NULL;
+}
+
// MediaGalleriesDialogViewsController -----------------------------------------
// static