Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_scan_result_dialog_ views.h" | 5 #include "chrome/browser/ui/views/extensions/media_galleries_scan_result_dialog_ views.h" | 
| 6 | 6 | 
| 7 #include "chrome/browser/ui/views/constrained_window_views.h" | 7 #include "chrome/browser/ui/views/constrained_window_views.h" | 
| 8 #include "components/web_modal/web_contents_modal_dialog_host.h" | 8 #include "components/web_modal/web_contents_modal_dialog_host.h" | 
| 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 9 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 
| 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" | 
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" | 
| 13 #include "grit/locale_settings.h" | 13 #include "grit/locale_settings.h" | 
| 14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" | 
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" | 
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" | 
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" | 
| 18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" | 
| 19 #include "ui/views/controls/button/checkbox.h" | 19 #include "ui/views/controls/button/checkbox.h" | 
| 20 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" | 
| 21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.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/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" | 
| 24 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" | 
| 25 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" | 
| 26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" | 
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" | 
| 28 #include "ui/views/window/dialog_client_view.h" | 29 #include "ui/views/window/dialog_client_view.h" | 
| 29 | 30 | 
| 30 typedef MediaGalleriesScanResultDialogController::OrderedScanResults | 31 typedef MediaGalleriesScanResultDialogController::OrderedScanResults | 
| 31 OrderedScanResults; | 32 OrderedScanResults; | 
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 checkbox->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE); | 177 checkbox->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE); | 
| 177 checkbox->SetTooltipText(tooltip_text); | 178 checkbox->SetTooltipText(tooltip_text); | 
| 178 // Replace the details string. | 179 // Replace the details string. | 
| 179 it->second.folder_viewer_button->SetVisible(is_attached); | 180 it->second.folder_viewer_button->SetVisible(is_attached); | 
| 180 it->second.secondary_text->SetText(details); | 181 it->second.secondary_text->SetText(details); | 
| 181 return false; | 182 return false; | 
| 182 } | 183 } | 
| 183 | 184 | 
| 184 views::Checkbox* checkbox = new views::Checkbox(label); | 185 views::Checkbox* checkbox = new views::Checkbox(label); | 
| 185 checkbox->set_listener(this); | 186 checkbox->set_listener(this); | 
| 187 checkbox->set_context_menu_controller(this); | |
| 186 checkbox->SetTooltipText(tooltip_text); | 188 checkbox->SetTooltipText(tooltip_text); | 
| 187 | 189 | 
| 188 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 190 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
| 189 views::ImageButton* folder_viewer_button = new views::ImageButton(this); | 191 views::ImageButton* folder_viewer_button = new views::ImageButton(this); | 
| 192 folder_viewer_button->set_context_menu_controller(this); | |
| 190 folder_viewer_button->SetImage(views::ImageButton::STATE_NORMAL, | 193 folder_viewer_button->SetImage(views::ImageButton::STATE_NORMAL, | 
| 191 rb.GetImageSkiaNamed(IDR_OAK)); | 194 rb.GetImageSkiaNamed(IDR_OAK)); | 
| 192 folder_viewer_button->SetAccessibleName(l10n_util::GetStringUTF16( | 195 folder_viewer_button->SetAccessibleName(l10n_util::GetStringUTF16( | 
| 193 IDS_MEDIA_GALLERIES_SCAN_RESULT_OPEN_FOLDER_VIEW_ACCESSIBILITY_NAME)); | 196 IDS_MEDIA_GALLERIES_SCAN_RESULT_OPEN_FOLDER_VIEW_ACCESSIBILITY_NAME)); | 
| 194 folder_viewer_button->SetFocusable(true); | 197 folder_viewer_button->SetFocusable(true); | 
| 195 folder_viewer_button->SetVisible(is_attached); | 198 folder_viewer_button->SetVisible(is_attached); | 
| 196 | 199 | 
| 197 views::Label* secondary_text = new views::Label(details); | 200 views::Label* secondary_text = new views::Label(details); | 
| 201 secondary_text->set_context_menu_controller(this); | |
| 198 secondary_text->SetTooltipText(tooltip_text); | 202 secondary_text->SetTooltipText(tooltip_text); | 
| 199 secondary_text->SetEnabledColor(kDeemphasizedTextColor); | 203 secondary_text->SetEnabledColor(kDeemphasizedTextColor); | 
| 200 secondary_text->SetTooltipText(tooltip_text); | 204 secondary_text->SetTooltipText(tooltip_text); | 
| 201 secondary_text->SetBorder(views::Border::CreateEmptyBorder( | 205 secondary_text->SetBorder(views::Border::CreateEmptyBorder( | 
| 202 0, | 206 0, | 
| 203 views::kRelatedControlSmallHorizontalSpacing, | 207 views::kRelatedControlSmallHorizontalSpacing, | 
| 204 0, | 208 0, | 
| 205 views::kRelatedControlSmallHorizontalSpacing)); | 209 views::kRelatedControlSmallHorizontalSpacing)); | 
| 206 | 210 | 
| 207 views::View* checkbox_view = new views::View(); | 211 views::View* checkbox_view = new views::View(); | 
| 208 checkbox_view->SetBorder(views::Border::CreateEmptyBorder( | 212 checkbox_view->SetBorder(views::Border::CreateEmptyBorder( | 
| 209 0, views::kPanelHorizMargin, trailing_vertical_space, 0)); | 213 0, views::kPanelHorizMargin, trailing_vertical_space, 0)); | 
| 214 checkbox_view->set_context_menu_controller(this); | |
| 210 checkbox_view->SetLayoutManager( | 215 checkbox_view->SetLayoutManager( | 
| 211 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 216 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 
| 212 checkbox_view->AddChildView(checkbox); | 217 checkbox_view->AddChildView(checkbox); | 
| 213 checkbox_view->AddChildView(folder_viewer_button); | 218 checkbox_view->AddChildView(folder_viewer_button); | 
| 214 checkbox_view->AddChildView(secondary_text); | 219 checkbox_view->AddChildView(secondary_text); | 
| 215 | 220 | 
| 216 container->AddChildView(checkbox_view); | 221 container->AddChildView(checkbox_view); | 
| 217 | 222 | 
| 218 checkbox->SetChecked(selected); | 223 checkbox->SetChecked(selected); | 
| 219 gallery_view_map_[gallery.pref_id].checkbox = checkbox; | 224 gallery_view_map_[gallery.pref_id].checkbox = checkbox; | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 it->second.checkbox->checked()); | 296 it->second.checkbox->checked()); | 
| 292 return; | 297 return; | 
| 293 } | 298 } | 
| 294 if (sender == it->second.folder_viewer_button) { | 299 if (sender == it->second.folder_viewer_button) { | 
| 295 controller_->DidClickOpenFolderViewer(it->first); | 300 controller_->DidClickOpenFolderViewer(it->first); | 
| 296 return; | 301 return; | 
| 297 } | 302 } | 
| 298 } | 303 } | 
| 299 } | 304 } | 
| 300 | 305 | 
| 306 void MediaGalleriesScanResultDialogViews::ShowContextMenuForView( | |
| 307 views::View* source, | |
| 308 const gfx::Point& point, | |
| 309 ui::MenuSourceType source_type) { | |
| 310 for (GalleryViewMap::const_iterator it = gallery_view_map_.begin(); | |
| 311 it != gallery_view_map_.end(); ++it) { | |
| 312 if (it->second.checkbox->parent()->Contains(source)) { | |
| 313 ShowContextMenu(point, source_type, it->first); | |
| 314 return; | |
| 315 } | |
| 316 } | |
| 317 } | |
| 
 
sky
2014/01/29 17:33:00
NOTREACHED()?
 
vandebo (ex-Chrome)
2014/01/29 17:42:38
Done.
 
 | |
| 318 | |
| 319 void MediaGalleriesScanResultDialogViews::ShowContextMenu( | |
| 320 const gfx::Point& point, | |
| 321 ui::MenuSourceType source_type, | |
| 322 MediaGalleryPrefId id) { | |
| 323 context_menu_runner_.reset(new views::MenuRunner( | |
| 324 controller_->GetContextMenu(id))); | |
| 325 | |
| 326 if (context_menu_runner_->RunMenuAt( | |
| 327 GetWidget(), NULL, gfx::Rect(point.x(), point.y(), 0, 0), | |
| 328 views::MenuItemView::TOPLEFT, source_type, | |
| 329 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | |
| 330 views::MenuRunner::MENU_DELETED) { | |
| 331 return; | |
| 332 } | |
| 333 } | |
| 334 | |
| 301 // MediaGalleriesScanResultDialogViewsController ------------------------------- | 335 // MediaGalleriesScanResultDialogViewsController ------------------------------- | 
| 302 | 336 | 
| 303 // static | 337 // static | 
| 304 MediaGalleriesScanResultDialog* MediaGalleriesScanResultDialog::Create( | 338 MediaGalleriesScanResultDialog* MediaGalleriesScanResultDialog::Create( | 
| 305 MediaGalleriesScanResultDialogController* controller) { | 339 MediaGalleriesScanResultDialogController* controller) { | 
| 306 return new MediaGalleriesScanResultDialogViews(controller); | 340 return new MediaGalleriesScanResultDialogViews(controller); | 
| 307 } | 341 } | 
| OLD | NEW |