| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" | 5 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" | 8 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" |
| 9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 9 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
| 18 #include "ui/views/controls/button/checkbox.h" | 18 #include "ui/views/controls/button/checkbox.h" |
| 19 #include "ui/views/controls/button/image_button.h" |
| 19 #include "ui/views/controls/button/label_button.h" | 20 #include "ui/views/controls/button/label_button.h" |
| 20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/controls/menu/menu_runner.h" | 22 #include "ui/views/controls/menu/menu_runner.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 23 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/controls/separator.h" | 24 #include "ui/views/controls/separator.h" |
| 24 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/layout/grid_layout.h" | 26 #include "ui/views/layout/grid_layout.h" |
| 26 #include "ui/views/layout/layout_constants.h" | 27 #include "ui/views/layout/layout_constants.h" |
| 27 #include "ui/views/view.h" | 28 #include "ui/views/view.h" |
| 28 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 55 width = parent()->width(); | 56 width = parent()->width(); |
| 56 height = std::max(parent()->height(), height); | 57 height = std::max(parent()->height(), height); |
| 57 } | 58 } |
| 58 SetBounds(x(), y(), width, height); | 59 SetBounds(x(), y(), width, height); |
| 59 | 60 |
| 60 views::View::Layout(); | 61 views::View::Layout(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 typedef MediaGalleriesDialogController::GalleryPermissionsVector | |
| 66 GalleryPermissionsVector; | |
| 67 | |
| 68 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | 66 MediaGalleriesDialogViews::MediaGalleriesDialogViews( |
| 69 MediaGalleriesDialogController* controller) | 67 MediaGalleriesDialogController* controller) |
| 70 : controller_(controller), | 68 : controller_(controller), |
| 71 window_(NULL), | 69 window_(NULL), |
| 72 contents_(new views::View()), | 70 contents_(new views::View()), |
| 73 add_gallery_button_(NULL), | 71 auxilliary_button_(NULL), |
| 74 confirm_available_(false), | 72 confirm_available_(false), |
| 75 accepted_(false) { | 73 accepted_(false) { |
| 76 InitChildViews(); | 74 InitChildViews(); |
| 77 | 75 |
| 78 if (ControllerHasWebContents()) { | 76 if (ControllerHasWebContents()) { |
| 79 // Ownership of |contents_| is handed off by this call. |window_| will take | 77 // Ownership of |contents_| is handed off by this call. |window_| will take |
| 80 // care of deleting itself after calling DeleteDelegate(). | 78 // care of deleting itself after calling DeleteDelegate(). |
| 81 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 79 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 82 WebContentsModalDialogManager::FromWebContents( | 80 WebContentsModalDialogManager::FromWebContents( |
| 83 controller->web_contents()); | 81 controller->web_contents()); |
| 84 DCHECK(web_contents_modal_dialog_manager); | 82 DCHECK(web_contents_modal_dialog_manager); |
| 85 WebContentsModalDialogManagerDelegate* modal_delegate = | 83 WebContentsModalDialogManagerDelegate* modal_delegate = |
| 86 web_contents_modal_dialog_manager->delegate(); | 84 web_contents_modal_dialog_manager->delegate(); |
| 87 DCHECK(modal_delegate); | 85 DCHECK(modal_delegate); |
| 88 window_ = views::Widget::CreateWindowAsFramelessChild( | 86 window_ = views::Widget::CreateWindowAsFramelessChild( |
| 89 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 87 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
| 90 web_contents_modal_dialog_manager->ShowModalDialog( | 88 web_contents_modal_dialog_manager->ShowModalDialog( |
| 91 window_->GetNativeView()); | 89 window_->GetNativeView()); |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 | 92 |
| 95 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() { | 93 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() { |
| 96 if (!ControllerHasWebContents()) | 94 if (!ControllerHasWebContents()) |
| 97 delete contents_; | 95 delete contents_; |
| 98 } | 96 } |
| 99 | 97 |
| 100 void MediaGalleriesDialogViews::InitChildViews() { | 98 void MediaGalleriesDialogViews::InitChildViews() { |
| 101 // Outer dialog layout. | 99 // Outer dialog layout. |
| 102 contents_->RemoveAllChildViews(true); | 100 contents_->RemoveAllChildViews(true); |
| 101 checkbox_map_.clear(); |
| 102 |
| 103 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( | 103 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( |
| 104 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); | 104 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); |
| 105 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); | 105 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); |
| 106 contents_->SetLayoutManager(layout); | 106 contents_->SetLayoutManager(layout); |
| 107 | 107 |
| 108 int column_set_id = 0; | 108 int column_set_id = 0; |
| 109 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | 109 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); |
| 110 columns->AddColumn(views::GridLayout::LEADING, | 110 columns->AddColumn(views::GridLayout::LEADING, |
| 111 views::GridLayout::LEADING, | 111 views::GridLayout::LEADING, |
| 112 1, | 112 1, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 129 ScrollableView* scroll_container = new ScrollableView(); | 129 ScrollableView* scroll_container = new ScrollableView(); |
| 130 scroll_container->SetLayoutManager(new views::BoxLayout( | 130 scroll_container->SetLayoutManager(new views::BoxLayout( |
| 131 views::BoxLayout::kVertical, 0, 0, | 131 views::BoxLayout::kVertical, 0, 0, |
| 132 views::kRelatedControlSmallVerticalSpacing)); | 132 views::kRelatedControlSmallVerticalSpacing)); |
| 133 scroll_container->SetBorder( | 133 scroll_container->SetBorder( |
| 134 views::Border::CreateEmptyBorder(views::kRelatedControlVerticalSpacing, | 134 views::Border::CreateEmptyBorder(views::kRelatedControlVerticalSpacing, |
| 135 0, | 135 0, |
| 136 views::kRelatedControlVerticalSpacing, | 136 views::kRelatedControlVerticalSpacing, |
| 137 0)); | 137 0)); |
| 138 | 138 |
| 139 // Add attached galleries checkboxes. | 139 std::vector<base::string16> section_headers = |
| 140 checkbox_map_.clear(); | 140 controller_->GetSectionHeaders(); |
| 141 GalleryPermissionsVector permissions = controller_->AttachedPermissions(); | 141 for (size_t i = 0; i < section_headers.size(); i++) { |
| 142 for (GalleryPermissionsVector::const_iterator iter = permissions.begin(); | 142 MediaGalleriesDialogController::Entries entries = |
| 143 iter != permissions.end(); ++iter) { | 143 controller_->GetSectionEntries(i); |
| 144 int spacing = 0; | |
| 145 if (iter + 1 == permissions.end()) | |
| 146 spacing = views::kRelatedControlSmallVerticalSpacing; | |
| 147 AddOrUpdateGallery(*iter, scroll_container, spacing); | |
| 148 } | |
| 149 | 144 |
| 150 GalleryPermissionsVector unattached_permissions = | 145 // Header and separator line. |
| 151 controller_->UnattachedPermissions(); | 146 if (!section_headers[i].empty() && !entries.empty()) { |
| 147 views::Separator* separator = new views::Separator( |
| 148 views::Separator::HORIZONTAL); |
| 149 scroll_container->AddChildView(separator); |
| 152 | 150 |
| 153 if (!unattached_permissions.empty()) { | 151 views::Label* header = new views::Label(section_headers[i]); |
| 154 // Separator line. | 152 header->SetMultiLine(true); |
| 155 views::Separator* separator = new views::Separator( | 153 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 156 views::Separator::HORIZONTAL); | 154 header->SetBorder(views::Border::CreateEmptyBorder( |
| 157 scroll_container->AddChildView(separator); | 155 views::kRelatedControlVerticalSpacing, |
| 156 views::kPanelHorizMargin, |
| 157 views::kRelatedControlVerticalSpacing, |
| 158 0)); |
| 159 scroll_container->AddChildView(header); |
| 160 } |
| 158 | 161 |
| 159 // Unattached locations section. | 162 // Checkboxes. |
| 160 views::Label* unattached_text = new views::Label( | 163 MediaGalleriesDialogController::Entries::const_iterator iter; |
| 161 controller_->GetUnattachedLocationsHeader()); | 164 for (iter = entries.begin(); iter != entries.end(); ++iter) { |
| 162 unattached_text->SetMultiLine(true); | 165 int spacing = 0; |
| 163 unattached_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 166 if (iter + 1 == entries.end()) |
| 164 unattached_text->SetBorder( | 167 spacing = views::kRelatedControlSmallVerticalSpacing; |
| 165 views::Border::CreateEmptyBorder(views::kRelatedControlVerticalSpacing, | 168 AddOrUpdateGallery(*iter, scroll_container, spacing); |
| 166 views::kPanelHorizMargin, | |
| 167 views::kRelatedControlVerticalSpacing, | |
| 168 0)); | |
| 169 scroll_container->AddChildView(unattached_text); | |
| 170 | |
| 171 // Add unattached galleries checkboxes. | |
| 172 for (GalleryPermissionsVector::const_iterator iter = | |
| 173 unattached_permissions.begin(); | |
| 174 iter != unattached_permissions.end(); ++iter) { | |
| 175 AddOrUpdateGallery(*iter, scroll_container, 0); | |
| 176 } | 169 } |
| 177 } | 170 } |
| 178 | 171 |
| 179 confirm_available_ = controller_->IsAcceptAllowed(); | 172 confirm_available_ = controller_->IsAcceptAllowed(); |
| 180 | 173 |
| 181 // Add the scrollable area to the outer dialog view. It will squeeze against | 174 // Add the scrollable area to the outer dialog view. It will squeeze against |
| 182 // the title/subtitle and buttons to occupy all available space in the dialog. | 175 // the title/subtitle and buttons to occupy all available space in the dialog. |
| 183 views::ScrollView* scroll_view = | 176 views::ScrollView* scroll_view = |
| 184 views::ScrollView::CreateScrollViewWithBorder(); | 177 views::ScrollView::CreateScrollViewWithBorder(); |
| 185 scroll_view->SetContents(scroll_container); | 178 scroll_view->SetContents(scroll_container); |
| 186 layout->StartRowWithPadding(1, column_set_id, | 179 layout->StartRowWithPadding(1, column_set_id, |
| 187 0, views::kRelatedControlVerticalSpacing); | 180 0, views::kRelatedControlVerticalSpacing); |
| 188 layout->AddView(scroll_view, 1, 1, | 181 layout->AddView(scroll_view, 1, 1, |
| 189 views::GridLayout::FILL, views::GridLayout::FILL, | 182 views::GridLayout::FILL, views::GridLayout::FILL, |
| 190 dialog_content_width, kScrollAreaHeight); | 183 dialog_content_width, kScrollAreaHeight); |
| 191 } | 184 } |
| 192 | 185 |
| 193 void MediaGalleriesDialogViews::UpdateGalleries() { | 186 void MediaGalleriesDialogViews::UpdateGalleries() { |
| 194 InitChildViews(); | 187 InitChildViews(); |
| 195 contents_->Layout(); | 188 contents_->Layout(); |
| 196 } | 189 } |
| 197 | 190 |
| 198 bool MediaGalleriesDialogViews::AddOrUpdateGallery( | 191 bool MediaGalleriesDialogViews::AddOrUpdateGallery( |
| 199 const MediaGalleriesDialogController::GalleryPermission& gallery, | 192 const MediaGalleriesDialogController::Entry& gallery, |
| 200 views::View* container, | 193 views::View* container, |
| 201 int trailing_vertical_space) { | 194 int trailing_vertical_space) { |
| 202 base::string16 label = gallery.pref_info.GetGalleryDisplayName(); | 195 base::string16 label = gallery.pref_info.GetGalleryDisplayName(); |
| 203 base::string16 tooltip_text = gallery.pref_info.GetGalleryTooltip(); | 196 base::string16 tooltip_text = gallery.pref_info.GetGalleryTooltip(); |
| 204 base::string16 details = gallery.pref_info.GetGalleryAdditionalDetails(); | 197 base::string16 details = gallery.pref_info.GetGalleryAdditionalDetails(); |
| 198 bool show_folder_viewer = controller_->ShowFolderViewer(gallery); |
| 205 | 199 |
| 206 CheckboxMap::iterator iter = checkbox_map_.find(gallery.gallery_id); | 200 CheckboxMap::iterator iter = checkbox_map_.find(gallery.pref_info.pref_id); |
| 207 if (iter != checkbox_map_.end()) { | 201 if (iter != checkbox_map_.end()) { |
| 208 views::Checkbox* checkbox = iter->second->checkbox(); | 202 views::Checkbox* checkbox = iter->second->checkbox(); |
| 209 checkbox->SetChecked(gallery.allowed); | 203 checkbox->SetChecked(gallery.selected); |
| 210 checkbox->SetText(label); | 204 checkbox->SetText(label); |
| 211 checkbox->SetTooltipText(tooltip_text); | 205 checkbox->SetTooltipText(tooltip_text); |
| 212 iter->second->secondary_text()->SetText(details); | 206 iter->second->secondary_text()->SetText(details); |
| 213 iter->second->secondary_text()->SetVisible(details.length() > 0); | 207 iter->second->secondary_text()->SetVisible(details.length() > 0); |
| 208 iter->second->folder_viewer_button()->SetVisible(show_folder_viewer); |
| 214 return false; | 209 return false; |
| 215 } | 210 } |
| 216 | 211 |
| 217 MediaGalleryCheckboxView* gallery_view = | 212 MediaGalleryCheckboxView* gallery_view = |
| 218 new MediaGalleryCheckboxView(label, tooltip_text, details, false, | 213 new MediaGalleryCheckboxView(label, tooltip_text, details, |
| 219 trailing_vertical_space, this, this); | 214 show_folder_viewer, trailing_vertical_space, |
| 220 gallery_view->checkbox()->SetChecked(gallery.allowed); | 215 this, this); |
| 216 gallery_view->checkbox()->SetChecked(gallery.selected); |
| 221 container->AddChildView(gallery_view); | 217 container->AddChildView(gallery_view); |
| 222 checkbox_map_[gallery.gallery_id] = gallery_view; | 218 checkbox_map_[gallery.pref_info.pref_id] = gallery_view; |
| 223 | 219 |
| 224 return true; | 220 return true; |
| 225 } | 221 } |
| 226 | 222 |
| 227 base::string16 MediaGalleriesDialogViews::GetWindowTitle() const { | 223 base::string16 MediaGalleriesDialogViews::GetWindowTitle() const { |
| 228 return controller_->GetHeader(); | 224 return controller_->GetHeader(); |
| 229 } | 225 } |
| 230 | 226 |
| 231 void MediaGalleriesDialogViews::DeleteDelegate() { | 227 void MediaGalleriesDialogViews::DeleteDelegate() { |
| 232 controller_->DialogFinished(accepted_); | 228 controller_->DialogFinished(accepted_); |
| 233 } | 229 } |
| 234 | 230 |
| 235 views::Widget* MediaGalleriesDialogViews::GetWidget() { | 231 views::Widget* MediaGalleriesDialogViews::GetWidget() { |
| 236 return contents_->GetWidget(); | 232 return contents_->GetWidget(); |
| 237 } | 233 } |
| 238 | 234 |
| 239 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { | 235 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { |
| 240 return contents_->GetWidget(); | 236 return contents_->GetWidget(); |
| 241 } | 237 } |
| 242 | 238 |
| 243 views::View* MediaGalleriesDialogViews::GetContentsView() { | 239 views::View* MediaGalleriesDialogViews::GetContentsView() { |
| 244 return contents_; | 240 return contents_; |
| 245 } | 241 } |
| 246 | 242 |
| 247 base::string16 MediaGalleriesDialogViews::GetDialogButtonLabel( | 243 base::string16 MediaGalleriesDialogViews::GetDialogButtonLabel( |
| 248 ui::DialogButton button) const { | 244 ui::DialogButton button) const { |
| 249 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK ? | 245 if (button == ui::DIALOG_BUTTON_OK) |
| 250 IDS_MEDIA_GALLERIES_DIALOG_CONFIRM : | 246 return controller_->GetAcceptButtonText(); |
| 251 IDS_MEDIA_GALLERIES_DIALOG_CANCEL); | 247 return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CANCEL); |
| 252 } | 248 } |
| 253 | 249 |
| 254 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( | 250 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( |
| 255 ui::DialogButton button) const { | 251 ui::DialogButton button) const { |
| 256 return button != ui::DIALOG_BUTTON_OK || confirm_available_; | 252 return button != ui::DIALOG_BUTTON_OK || confirm_available_; |
| 257 } | 253 } |
| 258 | 254 |
| 259 ui::ModalType MediaGalleriesDialogViews::GetModalType() const { | 255 ui::ModalType MediaGalleriesDialogViews::GetModalType() const { |
| 260 #if defined(USE_ASH) | 256 #if defined(USE_ASH) |
| 261 return ui::MODAL_TYPE_CHILD; | 257 return ui::MODAL_TYPE_CHILD; |
| 262 #else | 258 #else |
| 263 return views::WidgetDelegate::GetModalType(); | 259 return views::WidgetDelegate::GetModalType(); |
| 264 #endif | 260 #endif |
| 265 } | 261 } |
| 266 | 262 |
| 267 views::View* MediaGalleriesDialogViews::CreateExtraView() { | 263 views::View* MediaGalleriesDialogViews::CreateExtraView() { |
| 268 DCHECK(!add_gallery_button_); | 264 DCHECK(!auxilliary_button_); |
| 269 add_gallery_button_ = new views::LabelButton(this, | 265 base::string16 button_label = controller_->GetAuxilliaryButtonText(); |
| 270 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); | 266 if (!button_label.empty()) { |
| 271 add_gallery_button_->SetStyle(views::Button::STYLE_BUTTON); | 267 auxilliary_button_ = new views::LabelButton(this, button_label); |
| 272 return add_gallery_button_; | 268 auxilliary_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 269 } |
| 270 return auxilliary_button_; |
| 273 } | 271 } |
| 274 | 272 |
| 275 bool MediaGalleriesDialogViews::Cancel() { | 273 bool MediaGalleriesDialogViews::Cancel() { |
| 276 return true; | 274 return true; |
| 277 } | 275 } |
| 278 | 276 |
| 279 bool MediaGalleriesDialogViews::Accept() { | 277 bool MediaGalleriesDialogViews::Accept() { |
| 280 accepted_ = true; | 278 accepted_ = true; |
| 281 | 279 |
| 282 return true; | 280 return true; |
| 283 } | 281 } |
| 284 | 282 |
| 285 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, | 283 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, |
| 286 const ui::Event& /* event */) { | 284 const ui::Event& /* event */) { |
| 287 confirm_available_ = true; | 285 confirm_available_ = true; |
| 288 | 286 |
| 289 if (ControllerHasWebContents()) | 287 if (ControllerHasWebContents()) |
| 290 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); | 288 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); |
| 291 | 289 |
| 292 if (sender == add_gallery_button_) { | 290 if (sender == auxilliary_button_) { |
| 293 controller_->OnAddFolderClicked(); | 291 controller_->OnAuxilliaryButtonClicked(); |
| 294 return; | 292 return; |
| 295 } | 293 } |
| 296 | 294 |
| 297 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | 295 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); |
| 298 iter != checkbox_map_.end(); ++iter) { | 296 iter != checkbox_map_.end(); ++iter) { |
| 299 if (sender == iter->second->checkbox()) { | 297 if (sender == iter->second->checkbox()) { |
| 300 controller_->DidToggleGallery(iter->first, | 298 controller_->DidToggleEntry(iter->first, |
| 301 iter->second->checkbox()->checked()); | 299 iter->second->checkbox()->checked()); |
| 300 return; |
| 301 } |
| 302 if (sender == iter->second->folder_viewer_button()) { |
| 303 controller_->DidClickOpenFolderViewer(iter->first); |
| 302 return; | 304 return; |
| 303 } | 305 } |
| 304 } | 306 } |
| 305 } | 307 } |
| 306 | 308 |
| 307 void MediaGalleriesDialogViews::ShowContextMenuForView( | 309 void MediaGalleriesDialogViews::ShowContextMenuForView( |
| 308 views::View* source, | 310 views::View* source, |
| 309 const gfx::Point& point, | 311 const gfx::Point& point, |
| 310 ui::MenuSourceType source_type) { | 312 ui::MenuSourceType source_type) { |
| 311 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | 313 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); |
| 312 iter != checkbox_map_.end(); ++iter) { | 314 iter != checkbox_map_.end(); ++iter) { |
| 313 if (iter->second->Contains(source)) { | 315 if (iter->second->Contains(source)) { |
| 314 ShowContextMenu(point, source_type, iter->first); | 316 ShowContextMenu(point, source_type, iter->first); |
| 315 return; | 317 return; |
| 316 } | 318 } |
| 317 } | 319 } |
| 318 } | 320 } |
| 319 | 321 |
| 320 void MediaGalleriesDialogViews::ShowContextMenu(const gfx::Point& point, | 322 void MediaGalleriesDialogViews::ShowContextMenu(const gfx::Point& point, |
| 321 ui::MenuSourceType source_type, | 323 ui::MenuSourceType source_type, |
| 322 GalleryDialogId id) { | 324 MediaGalleryPrefId id) { |
| 323 context_menu_runner_.reset(new views::MenuRunner( | 325 context_menu_runner_.reset(new views::MenuRunner( |
| 324 controller_->GetContextMenu(id))); | 326 controller_->GetContextMenu(id))); |
| 325 | 327 |
| 326 if (context_menu_runner_->RunMenuAt( | 328 if (context_menu_runner_->RunMenuAt( |
| 327 GetWidget(), | 329 GetWidget(), |
| 328 NULL, | 330 NULL, |
| 329 gfx::Rect(point.x(), point.y(), 0, 0), | 331 gfx::Rect(point.x(), point.y(), 0, 0), |
| 330 views::MENU_ANCHOR_TOPLEFT, | 332 views::MENU_ANCHOR_TOPLEFT, |
| 331 source_type, | 333 source_type, |
| 332 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | 334 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == |
| 333 views::MenuRunner::MENU_DELETED) { | 335 views::MenuRunner::MENU_DELETED) { |
| 334 return; | 336 return; |
| 335 } | 337 } |
| 336 } | 338 } |
| 337 | 339 |
| 338 bool MediaGalleriesDialogViews::ControllerHasWebContents() const { | 340 bool MediaGalleriesDialogViews::ControllerHasWebContents() const { |
| 339 return controller_->web_contents() != NULL; | 341 return controller_->web_contents() != NULL; |
| 340 } | 342 } |
| 341 | 343 |
| 342 // MediaGalleriesDialogViewsController ----------------------------------------- | 344 // MediaGalleriesDialogViewsController ----------------------------------------- |
| 343 | 345 |
| 344 // static | 346 // static |
| 345 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 347 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 346 MediaGalleriesDialogController* controller) { | 348 MediaGalleriesDialogController* controller) { |
| 347 return new MediaGalleriesDialogViews(controller); | 349 return new MediaGalleriesDialogViews(controller); |
| 348 } | 350 } |
| OLD | NEW |