Chromium Code Reviews| 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/constrained_window_views.h" | 8 #include "chrome/browser/ui/views/constrained_window_views.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 "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/locale_settings.h" | 15 #include "grit/locale_settings.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/models/simple_menu_model.h" | |
| 18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/native_theme/native_theme.h" | 20 #include "ui/native_theme/native_theme.h" |
| 20 #include "ui/views/controls/button/checkbox.h" | 21 #include "ui/views/controls/button/checkbox.h" |
| 21 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
| 22 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 24 #include "ui/views/controls/menu/menu_runner.h" | |
| 23 #include "ui/views/controls/scroll_view.h" | 25 #include "ui/views/controls/scroll_view.h" |
| 24 #include "ui/views/controls/separator.h" | 26 #include "ui/views/controls/separator.h" |
| 25 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
| 26 #include "ui/views/layout/grid_layout.h" | 28 #include "ui/views/layout/grid_layout.h" |
| 27 #include "ui/views/layout/layout_constants.h" | 29 #include "ui/views/layout/layout_constants.h" |
| 28 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
| 29 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/window/dialog_client_view.h" | 32 #include "ui/views/window/dialog_client_view.h" |
| 31 | 33 |
| 32 using web_modal::WebContentsModalDialogManager; | 34 using web_modal::WebContentsModalDialogManager; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 59 width = std::max(parent()->width(), width); | 61 width = std::max(parent()->width(), width); |
| 60 height = std::max(parent()->height(), height); | 62 height = std::max(parent()->height(), height); |
| 61 } | 63 } |
| 62 SetBounds(x(), y(), width, height); | 64 SetBounds(x(), y(), width, height); |
| 63 | 65 |
| 64 views::View::Layout(); | 66 views::View::Layout(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 } // namespace | 69 } // namespace |
| 68 | 70 |
| 71 class GalleryContextMenuModel : public ui::SimpleMenuModel::Delegate { | |
| 72 public: | |
| 73 explicit GalleryContextMenuModel(MediaGalleriesDialogViews* view) | |
| 74 : view_(view), id_(kInvalidMediaGalleryPrefId) {} | |
|
sky
2013/10/24 19:23:22
nit: when you wrap, each param gets its own line.
Greg Billock
2013/10/28 22:37:49
OK. Was trying too hard to conserve space in this
| |
| 75 virtual ~GalleryContextMenuModel() {} | |
| 76 | |
| 77 void set_media_gallery_pref_id(MediaGalleryPrefId id) { | |
| 78 id_ = id; | |
| 79 } | |
| 80 | |
| 81 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | |
|
sky
2013/10/24 19:23:22
nit: prefix with something like:
// ui::SimpleMenu
Greg Billock
2013/10/28 22:37:49
Done.
| |
| 82 return false; | |
| 83 } | |
| 84 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { | |
| 85 return true; | |
| 86 } | |
| 87 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE { | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 virtual bool GetAcceleratorForCommandId( | |
| 92 int command_id, ui::Accelerator* accelerator) OVERRIDE { | |
|
sky
2013/10/24 19:23:22
nit: again, when you wrap one param per line.
Greg Billock
2013/10/28 22:37:49
Done.
| |
| 93 return false; | |
| 94 } | |
| 95 | |
| 96 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE { | |
| 97 view_->DidForgetGallery(id_); | |
| 98 } | |
| 99 | |
| 100 private: | |
| 101 MediaGalleriesDialogViews* view_; | |
| 102 MediaGalleryPrefId id_; | |
| 103 }; | |
|
sky
2013/10/24 19:23:22
DISALLOW...
Greg Billock
2013/10/28 22:37:49
Done.
| |
| 104 | |
| 69 typedef MediaGalleriesDialogController::GalleryPermissionsVector | 105 typedef MediaGalleriesDialogController::GalleryPermissionsVector |
| 70 GalleryPermissionsVector; | 106 GalleryPermissionsVector; |
| 71 | 107 |
| 72 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | 108 MediaGalleriesDialogViews::MediaGalleriesDialogViews( |
| 73 MediaGalleriesDialogController* controller) | 109 MediaGalleriesDialogController* controller) |
| 74 : controller_(controller), | 110 : controller_(controller), |
| 75 window_(NULL), | 111 window_(NULL), |
| 76 contents_(new views::View()), | 112 contents_(new views::View()), |
| 77 add_gallery_button_(NULL), | 113 add_gallery_button_(NULL), |
| 78 confirm_available_(false), | 114 confirm_available_(false), |
| 79 accepted_(false) { | 115 accepted_(false) { |
| 80 InitChildViews(); | 116 InitChildViews(); |
| 81 | 117 |
| 118 gallery_menu_model_ = new GalleryContextMenuModel(this); | |
| 119 ui::SimpleMenuModel* menu_model = | |
| 120 new ui::SimpleMenuModel(gallery_menu_model_); | |
| 121 menu_model->AddItem(1, controller->GetDeleteMenuCommand()); | |
| 122 context_menu_model_.reset(menu_model); | |
| 123 | |
| 82 // Ownership of |contents_| is handed off by this call. |window_| will take | 124 // Ownership of |contents_| is handed off by this call. |window_| will take |
| 83 // care of deleting itself after calling DeleteDelegate(). | 125 // care of deleting itself after calling DeleteDelegate(). |
| 84 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 126 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 85 WebContentsModalDialogManager::FromWebContents( | 127 WebContentsModalDialogManager::FromWebContents( |
| 86 controller->web_contents()); | 128 controller->web_contents()); |
| 87 DCHECK(web_contents_modal_dialog_manager); | 129 DCHECK(web_contents_modal_dialog_manager); |
| 88 WebContentsModalDialogManagerDelegate* modal_delegate = | 130 WebContentsModalDialogManagerDelegate* modal_delegate = |
| 89 web_contents_modal_dialog_manager->delegate(); | 131 web_contents_modal_dialog_manager->delegate(); |
| 90 DCHECK(modal_delegate); | 132 DCHECK(modal_delegate); |
| 91 window_ = views::Widget::CreateWindowAsFramelessChild( | 133 window_ = views::Widget::CreateWindowAsFramelessChild( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 views::View* checkbox_view = checkbox->parent(); | 272 views::View* checkbox_view = checkbox->parent(); |
| 231 DCHECK_EQ(2, checkbox_view->child_count()); | 273 DCHECK_EQ(2, checkbox_view->child_count()); |
| 232 views::Label* secondary_text = | 274 views::Label* secondary_text = |
| 233 static_cast<views::Label*>(checkbox_view->child_at(1)); | 275 static_cast<views::Label*>(checkbox_view->child_at(1)); |
| 234 secondary_text->SetText(details); | 276 secondary_text->SetText(details); |
| 235 return false; | 277 return false; |
| 236 } | 278 } |
| 237 | 279 |
| 238 views::Checkbox* checkbox = new views::Checkbox(label); | 280 views::Checkbox* checkbox = new views::Checkbox(label); |
| 239 checkbox->set_listener(this); | 281 checkbox->set_listener(this); |
| 282 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
| 283 checkbox->set_context_menu_controller(this); | |
| 240 checkbox->SetTooltipText(tooltip_text); | 284 checkbox->SetTooltipText(tooltip_text); |
| 241 views::Label* secondary_text = new views::Label(details); | 285 views::Label* secondary_text = new views::Label(details); |
| 286 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
| 287 secondary_text->set_context_menu_controller(this); | |
| 242 secondary_text->SetTooltipText(tooltip_text); | 288 secondary_text->SetTooltipText(tooltip_text); |
| 243 secondary_text->SetEnabledColor(kDeemphasizedTextColor); | 289 secondary_text->SetEnabledColor(kDeemphasizedTextColor); |
| 244 secondary_text->SetTooltipText(tooltip_text); | 290 secondary_text->SetTooltipText(tooltip_text); |
| 245 secondary_text->set_border(views::Border::CreateEmptyBorder( | 291 secondary_text->set_border(views::Border::CreateEmptyBorder( |
| 246 0, | 292 0, |
| 247 views::kRelatedControlSmallHorizontalSpacing, | 293 views::kRelatedControlSmallHorizontalSpacing, |
| 248 0, | 294 0, |
| 249 views::kRelatedControlSmallHorizontalSpacing)); | 295 views::kRelatedControlSmallHorizontalSpacing)); |
| 250 | 296 |
| 251 views::View* checkbox_view = new views::View(); | 297 views::View* checkbox_view = new views::View(); |
| 298 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
| 299 checkbox_view->set_context_menu_controller(this); | |
| 252 checkbox_view->set_border(views::Border::CreateEmptyBorder( | 300 checkbox_view->set_border(views::Border::CreateEmptyBorder( |
| 253 0, | 301 0, |
| 254 views::kPanelHorizMargin, | 302 views::kPanelHorizMargin, |
| 255 trailing_vertical_space, | 303 trailing_vertical_space, |
| 256 0)); | 304 0)); |
| 257 checkbox_view->SetLayoutManager( | 305 checkbox_view->SetLayoutManager( |
| 258 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 306 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 259 checkbox_view->AddChildView(checkbox); | 307 checkbox_view->AddChildView(checkbox); |
| 260 checkbox_view->AddChildView(secondary_text); | 308 checkbox_view->AddChildView(secondary_text); |
| 261 | 309 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 408 } |
| 361 } | 409 } |
| 362 for (NewCheckboxMap::const_iterator iter = new_checkbox_map_.begin(); | 410 for (NewCheckboxMap::const_iterator iter = new_checkbox_map_.begin(); |
| 363 iter != new_checkbox_map_.end(); ++iter) { | 411 iter != new_checkbox_map_.end(); ++iter) { |
| 364 if (sender == iter->first) { | 412 if (sender == iter->first) { |
| 365 controller_->DidToggleNewGallery(iter->second, iter->first->checked()); | 413 controller_->DidToggleNewGallery(iter->second, iter->first->checked()); |
| 366 } | 414 } |
| 367 } | 415 } |
| 368 } | 416 } |
| 369 | 417 |
| 418 void MediaGalleriesDialogViews::ShowContextMenuForView( | |
| 419 views::View* source, | |
| 420 const gfx::Point& point, | |
| 421 ui::MenuSourceType source_type) { | |
| 422 views::Checkbox* checkbox = NULL; | |
| 423 if (source->GetClassName() == views::Checkbox::kViewClassName) { | |
|
sky
2013/10/24 19:23:22
The class name is best thought of as an internal i
Greg Billock
2013/10/28 22:37:49
OK. Found a much better plan for this.
| |
| 424 checkbox = static_cast<views::Checkbox*>(source); | |
| 425 } else { | |
| 426 views::View* checkbox_container_view = NULL; | |
| 427 if (source->child_count() == 2) { | |
| 428 checkbox_container_view = source; | |
| 429 } else { | |
| 430 checkbox_container_view = source->parent(); | |
| 431 } | |
| 432 if (!checkbox_container_view) | |
|
sky
2013/10/24 19:23:22
How can this ever be true?
Greg Billock
2013/10/28 22:37:49
line 299. (At least, I'm trying to set the context
sky
2013/10/29 01:19:50
The part I was confused on is you assign checkbox_
Greg Billock
2013/10/29 17:05:28
ok. I found a much better solution for this with C
| |
| 433 return; | |
| 434 checkbox = static_cast<views::Checkbox*>( | |
| 435 checkbox_container_view->child_at(0)); | |
|
sky
2013/10/24 19:23:22
This seems rather fragile. Could you instead add m
Greg Billock
2013/10/28 22:37:49
no longer used
| |
| 436 } | |
| 437 | |
| 438 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | |
| 439 iter != checkbox_map_.end(); ++iter) { | |
| 440 if (checkbox == iter->second) { | |
| 441 ShowContextMenu(point, source_type, iter->first); | |
|
sky
2013/10/24 19:23:22
return after this?
Greg Billock
2013/10/28 22:37:49
Done.
| |
| 442 } | |
| 443 } | |
| 444 } | |
| 445 | |
| 446 void MediaGalleriesDialogViews::ShowContextMenu(const gfx::Point& point, | |
| 447 ui::MenuSourceType source_type, | |
| 448 MediaGalleryPrefId id) { | |
| 449 gallery_menu_model_->set_media_gallery_pref_id(id); | |
| 450 | |
| 451 context_menu_runner_.reset(new views::MenuRunner(context_menu_model_.get())); | |
| 452 if (context_menu_runner_->RunMenuAt( | |
| 453 GetWidget(), NULL, gfx::Rect(point.x(), point.y(), 0, 0), | |
| 454 views::MenuItemView::TOPLEFT, source_type, | |
| 455 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | |
| 456 views::MenuRunner::MENU_DELETED) { | |
| 457 return; | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 void MediaGalleriesDialogViews::DidForgetGallery(MediaGalleryPrefId id) { | |
| 462 if (id == kInvalidMediaGalleryPrefId) | |
| 463 return; | |
| 464 | |
| 465 controller_->DidForgetGallery(id); | |
| 466 | |
| 467 gallery_menu_model_->set_media_gallery_pref_id(kInvalidMediaGalleryPrefId); | |
| 468 } | |
| 469 | |
| 370 // MediaGalleriesDialogViewsController ----------------------------------------- | 470 // MediaGalleriesDialogViewsController ----------------------------------------- |
| 371 | 471 |
| 372 // static | 472 // static |
| 373 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 473 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 374 MediaGalleriesDialogController* controller) { | 474 MediaGalleriesDialogController* controller) { |
| 375 return new MediaGalleriesDialogViews(controller); | 475 return new MediaGalleriesDialogViews(controller); |
| 376 } | 476 } |
| OLD | NEW |