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 using views::BoxLayout; |
| 37 using views::GridLayout; |
| 38 |
| 39 MediaGalleriesDialogViews::MediaGalleriesDialogViews( |
| 40 MediaGalleriesDialogController* controller) |
| 41 : controller_(controller), |
| 42 window_(NULL), |
| 43 contents_(new views::View()), |
| 44 accepted_(false) { |
| 45 InitChildViews(); |
| 46 |
| 47 window_ = new ConstrainedWindowViews(controller->tab_contents(), this); |
| 48 } |
| 49 |
| 50 void MediaGalleriesDialogViews::InitChildViews() { |
| 51 // Layout. |
| 52 GridLayout* layout = new GridLayout(contents_); |
| 53 layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin, |
| 54 0, views::kPanelHorizMargin); |
| 55 int column_set_id = 0; |
| 56 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); |
| 57 columns->AddColumn(GridLayout::LEADING, |
| 58 GridLayout::LEADING, |
| 59 1, |
| 60 GridLayout::FIXED, |
| 61 kContentWidth, |
| 62 0); |
| 63 contents_->SetLayoutManager(layout); |
| 64 |
| 65 // Header text. |
| 66 views::Label* header = new views::Label(controller_->GetHeader()); |
| 67 header->SetFont(header->font().DeriveFont(kHeadingFontSizeDelta, |
| 68 gfx::Font::BOLD)); |
| 69 header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 70 layout->StartRow(0, column_set_id); |
| 71 layout->AddView(header); |
| 72 |
| 73 // Message text. |
| 74 views::Label* subtext = new views::Label(controller_->GetSubtext()); |
| 75 subtext->SetMultiLine(true); |
| 76 subtext->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 77 layout->StartRowWithPadding(0, column_set_id, |
| 78 0, views::kRelatedControlVerticalSpacing); |
| 79 layout->AddView(subtext); |
| 80 |
| 81 // Checkboxes. |
| 82 checkbox_container_ = new views::View(); |
| 83 checkbox_container_->SetLayoutManager( |
| 84 new BoxLayout(BoxLayout::kVertical, |
| 85 views::kPanelHorizIndentation, |
| 86 0, |
| 87 views::kRelatedControlSmallVerticalSpacing)); |
| 88 layout->StartRowWithPadding(0, column_set_id, |
| 89 0, views::kRelatedControlVerticalSpacing); |
| 90 layout->AddView(checkbox_container_); |
| 91 |
| 92 const GalleryPermissions& permissions = controller_->permissions(); |
| 93 for (GalleryPermissions::const_iterator iter = permissions.begin(); |
| 94 iter != permissions.end(); iter++) { |
| 95 AddOrUpdateGallery(&iter->second.pref_info, iter->second.allowed); |
| 96 } |
| 97 |
| 98 // Add Gallery button. |
| 99 add_gallery_ = new views::NativeTextButton( |
| 100 this, l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); |
| 101 layout->StartRowWithPadding(0, column_set_id, |
| 102 0, views::kRelatedControlVerticalSpacing); |
| 103 layout->AddView(add_gallery_); |
| 104 } |
| 105 |
| 106 void MediaGalleriesDialogViews::UpdateGallery( |
| 107 const MediaGalleryPrefInfo* gallery, bool permitted) { |
| 108 // After adding a new checkbox, we have to update the size of the dialog. |
| 109 if (AddOrUpdateGallery(gallery, permitted)) |
| 110 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); |
| 111 } |
| 112 |
| 113 bool MediaGalleriesDialogViews::AddOrUpdateGallery( |
| 114 const MediaGalleryPrefInfo* gallery, bool permitted) { |
| 115 CheckboxMap::iterator iter = checkbox_map_.find(gallery); |
| 116 |
| 117 bool new_checkbox = false; |
| 118 views::Checkbox* checkbox = NULL; |
| 119 if (iter != checkbox_map_.end()) { |
| 120 checkbox = iter->second; |
| 121 } else { |
| 122 new_checkbox = true; |
| 123 checkbox = new views::Checkbox(gallery->display_name); |
| 124 checkbox->set_listener(this); |
| 125 checkbox->SetTooltipText(gallery->path.LossyDisplayName()); |
| 126 checkbox_container_->AddChildView(checkbox); |
| 127 checkbox_map_[gallery] = checkbox; |
| 128 } |
| 129 |
| 130 checkbox->SetChecked(permitted); |
| 131 return new_checkbox; |
| 132 } |
| 133 |
| 134 string16 MediaGalleriesDialogViews::GetDialogButtonLabel( |
| 135 ui::DialogButton button) const { |
| 136 if (button == ui::DIALOG_BUTTON_OK) |
| 137 return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CONFIRM); |
| 138 |
| 139 if (button == ui::DIALOG_BUTTON_CANCEL) |
| 140 return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CANCEL); |
| 141 |
| 142 return string16(); |
| 143 } |
| 144 |
| 145 bool MediaGalleriesDialogViews::Cancel() { |
| 146 return true; |
| 147 } |
| 148 |
| 149 bool MediaGalleriesDialogViews::Accept() { |
| 150 accepted_ = true; |
| 151 return true; |
| 152 } |
| 153 |
| 154 views::View* MediaGalleriesDialogViews::GetContentsView() { |
| 155 return contents_; |
| 156 } |
| 157 |
| 158 views::Widget* MediaGalleriesDialogViews::GetWidget() { |
| 159 return contents_->GetWidget(); |
| 160 } |
| 161 |
| 162 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { |
| 163 return contents_->GetWidget(); |
| 164 } |
| 165 |
| 166 void MediaGalleriesDialogViews::DeleteDelegate() { |
| 167 controller_->DialogFinished(accepted_); |
| 168 } |
| 169 |
| 170 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, |
| 171 const views::Event& event) { |
| 172 if (sender == add_gallery_) { |
| 173 controller_->OnAddFolderClicked(); |
| 174 return; |
| 175 } |
| 176 |
| 177 for (CheckboxMap::iterator iter = checkbox_map_.begin(); |
| 178 iter != checkbox_map_.end(); ++iter) { |
| 179 if (iter->second == sender) { |
| 180 controller_->GalleryToggled( |
| 181 iter->first, static_cast<views::Checkbox*>(sender)->checked()); |
| 182 return; |
| 183 } |
| 184 } |
| 185 |
| 186 NOTREACHED(); |
| 187 return; |
| 188 } |
| 189 |
| 190 // MediaGalleriesDialogViewsController ----------------------------------------- |
| 191 |
| 192 // static |
| 193 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 194 MediaGalleriesDialogController* controller) { |
| 195 return new MediaGalleriesDialogViews(controller); |
| 196 } |
| 197 |
| 198 } // namespace chrome |
OLD | NEW |