Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/views/constrained_window_views.h" | |
| 8 #include "grit/generated_resources.h" | |
| 9 #include "ui/base/l10n/l10n_util.h" | |
| 10 #include "ui/views/controls/button/checkbox.h" | |
| 11 #include "ui/views/controls/button/text_button.h" | |
| 12 #include "ui/views/controls/label.h" | |
| 13 #include "ui/views/layout/box_layout.h" | |
| 14 #include "ui/views/layout/grid_layout.h" | |
| 15 #include "ui/views/layout/layout_constants.h" | |
| 16 #include "ui/views/view.h" | |
| 17 | |
| 18 namespace chrome { | |
| 19 | |
| 20 typedef MediaGalleriesDialogController::KnownGalleryPermissions | |
| 21 GalleryPermissions; | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 // Heading font size correction. | |
| 26 #if defined(CROS_FONTS_USING_BCI) | |
| 27 const int kHeadingFontSizeDelta = 0; | |
| 28 #else | |
| 29 const int kHeadingFontSizeDelta = 1; | |
| 30 #endif | |
| 31 | |
| 32 const int kContentWidth = 450; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | |
| 37 MediaGalleriesDialogController* controller) | |
| 38 : controller_(controller), | |
| 39 window_(NULL), | |
| 40 contents_(new views::View()), | |
| 41 checkbox_container_(NULL), | |
| 42 add_gallery_(NULL), | |
| 43 confirm_available_(false), | |
| 44 accepted_(false) { | |
| 45 InitChildViews(); | |
| 46 | |
| 47 window_ = new ConstrainedWindowViews(controller->tab_contents(), this); | |
|
Peter Kasting
2012/08/14 18:44:01
Nit: Perhaps add "// After this call, |window_| an
| |
| 48 } | |
| 49 | |
| 50 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {} | |
| 51 | |
| 52 void MediaGalleriesDialogViews::InitChildViews() { | |
| 53 // Layout. | |
| 54 views::GridLayout* layout = new views::GridLayout(contents_); | |
| 55 layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin, | |
| 56 0, views::kPanelHorizMargin); | |
| 57 int column_set_id = 0; | |
| 58 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | |
| 59 columns->AddColumn(views::GridLayout::LEADING, | |
| 60 views::GridLayout::LEADING, | |
| 61 1, | |
| 62 views::GridLayout::FIXED, | |
| 63 kContentWidth, | |
| 64 0); | |
| 65 contents_->SetLayoutManager(layout); | |
| 66 | |
| 67 // Header text. | |
| 68 views::Label* header = new views::Label(controller_->GetHeader()); | |
| 69 header->SetFont(header->font().DeriveFont(kHeadingFontSizeDelta, | |
| 70 gfx::Font::BOLD)); | |
| 71 header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 72 layout->StartRow(0, column_set_id); | |
| 73 layout->AddView(header); | |
| 74 | |
| 75 // Message text. | |
| 76 views::Label* subtext = new views::Label(controller_->GetSubtext()); | |
| 77 subtext->SetMultiLine(true); | |
| 78 subtext->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
| 79 layout->StartRowWithPadding(0, column_set_id, | |
| 80 0, views::kRelatedControlVerticalSpacing); | |
| 81 layout->AddView(subtext); | |
| 82 | |
| 83 // Checkboxes. | |
| 84 checkbox_container_ = new views::View(); | |
| 85 checkbox_container_->SetLayoutManager( | |
| 86 new views::BoxLayout(views::BoxLayout::kVertical, | |
| 87 views::kPanelHorizIndentation, | |
| 88 0, | |
| 89 views::kRelatedControlSmallVerticalSpacing)); | |
| 90 layout->StartRowWithPadding(0, column_set_id, | |
| 91 0, views::kRelatedControlVerticalSpacing); | |
| 92 layout->AddView(checkbox_container_); | |
| 93 | |
| 94 const GalleryPermissions& permissions = controller_->permissions(); | |
| 95 for (GalleryPermissions::const_iterator iter = permissions.begin(); | |
| 96 iter != permissions.end(); ++iter) { | |
| 97 AddOrUpdateGallery(&iter->second.pref_info, iter->second.allowed); | |
| 98 if (iter->second.allowed) | |
| 99 confirm_available_ = true; | |
| 100 } | |
| 101 | |
| 102 // Add Gallery button. | |
| 103 add_gallery_ = new views::NativeTextButton( | |
| 104 this, l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); | |
| 105 layout->StartRowWithPadding(0, column_set_id, | |
| 106 0, views::kRelatedControlVerticalSpacing); | |
| 107 layout->AddView(add_gallery_); | |
| 108 } | |
| 109 | |
| 110 void MediaGalleriesDialogViews::UpdateGallery( | |
| 111 const MediaGalleryPrefInfo* gallery, | |
| 112 bool permitted) { | |
| 113 // After adding a new checkbox, we have to update the size of the dialog. | |
| 114 if (AddOrUpdateGallery(gallery, permitted)) | |
| 115 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); | |
| 116 } | |
| 117 | |
| 118 bool MediaGalleriesDialogViews::AddOrUpdateGallery( | |
| 119 const MediaGalleryPrefInfo* gallery, | |
| 120 bool permitted) { | |
| 121 CheckboxMap::iterator iter = checkbox_map_.find(gallery); | |
| 122 if (iter != checkbox_map_.end()) { | |
| 123 iter->second.SetChecked(permitted); | |
| 124 return false; | |
| 125 } | |
| 126 | |
| 127 views::Checkbox* checkbox = new views::Checkbox(gallery->display_name); | |
| 128 checkbox->set_listener(this); | |
| 129 checkbox->SetTooltipText(gallery->path.LossyDisplayName()); | |
| 130 checkbox_container_->AddChildView(checkbox); | |
| 131 checkbox->SetChecked(permitted); | |
| 132 checkbox_map_[gallery] = checkbox; | |
| 133 | |
| 134 return true; | |
| 135 } | |
| 136 | |
| 137 string16 MediaGalleriesDialogViews::GetDialogButtonLabel( | |
| 138 ui::DialogButton button) const { | |
| 139 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? | |
| 140 IDS_MEDIA_GALLERIES_DIALOG_CONFIRM : | |
| 141 IDS_MEDIA_GALLERIES_DIALOG_CANCEL); | |
| 142 } | |
| 143 | |
| 144 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( | |
| 145 ui::DialogButton button) const { | |
| 146 return button != ui::DIALOG_BUTTON_OK || confirm_available_; | |
| 147 } | |
| 148 | |
| 149 bool MediaGalleriesDialogViews::Cancel() { | |
| 150 return true; | |
| 151 } | |
| 152 | |
| 153 bool MediaGalleriesDialogViews::Accept() { | |
| 154 accepted_ = true; | |
| 155 return true; | |
| 156 } | |
| 157 | |
| 158 views::View* MediaGalleriesDialogViews::GetContentsView() { | |
| 159 return contents_; | |
| 160 } | |
| 161 | |
| 162 views::Widget* MediaGalleriesDialogViews::GetWidget() { | |
| 163 return contents_->GetWidget(); | |
| 164 } | |
| 165 | |
| 166 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { | |
| 167 return contents_->GetWidget(); | |
| 168 } | |
| 169 | |
| 170 void MediaGalleriesDialogViews::DeleteDelegate() { | |
| 171 controller_->DialogFinished(accepted_); | |
| 172 } | |
| 173 | |
| 174 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, | |
| 175 const ui::Event& event) { | |
| 176 confirm_available_ = true; | |
| 177 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); | |
| 178 | |
| 179 if (sender == add_gallery_) { | |
| 180 controller_->OnAddFolderClicked(); | |
| 181 return; | |
| 182 } | |
| 183 | |
| 184 for (CheckboxMap::iterator iter = checkbox_map_.begin(); | |
| 185 iter != checkbox_map_.end(); ++iter) { | |
| 186 if (sender == iter->second) { | |
| 187 controller_->GalleryToggled( | |
| 188 iter->first, static_cast<views::Checkbox*>(sender)->checked()); | |
| 189 return; | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 NOTREACHED(); | |
| 194 } | |
| 195 | |
| 196 // MediaGalleriesDialogViewsController ----------------------------------------- | |
| 197 | |
| 198 // static | |
| 199 MediaGalleriesDialog* MediaGalleriesDialog::Create( | |
| 200 MediaGalleriesDialogController* controller) { | |
| 201 return new MediaGalleriesDialogViews(controller); | |
| 202 } | |
| 203 | |
| 204 } // namespace chrome | |
| OLD | NEW |