Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6750)

Unified Diff: chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc

Issue 37553002: [MediaGalleries] Add context menu for forgetting galleries. [views] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dlgfix
Patch Set: rename string Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/extensions/media_galleries_dialog_views.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc
diff --git a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc
index ac699d59fb5747d827580162ce65e4ee70a6b10d..a7cf3861667b9928c2442c54befc758126af7352 100644
--- a/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc
+++ b/chrome/browser/ui/views/extensions/media_galleries_dialog_views.cc
@@ -15,11 +15,13 @@
#include "grit/locale_settings.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
+#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
@@ -66,6 +68,40 @@ void ScrollableView::Layout() {
} // namespace
+class GalleryContextMenuModel : public ui::SimpleMenuModel::Delegate {
+ public:
+ explicit GalleryContextMenuModel(MediaGalleriesDialogViews* view)
+ : 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
+ virtual ~GalleryContextMenuModel() {}
+
+ void set_media_gallery_pref_id(MediaGalleryPrefId id) {
+ id_ = id;
+ }
+
+ 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.
+ return false;
+ }
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE {
+ return true;
+ }
+ virtual bool IsCommandIdVisible(int command_id) const OVERRIDE {
+ return true;
+ }
+
+ virtual bool GetAcceleratorForCommandId(
+ 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.
+ return false;
+ }
+
+ virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE {
+ view_->DidForgetGallery(id_);
+ }
+
+ private:
+ MediaGalleriesDialogViews* view_;
+ MediaGalleryPrefId id_;
+};
sky 2013/10/24 19:23:22 DISALLOW...
Greg Billock 2013/10/28 22:37:49 Done.
+
typedef MediaGalleriesDialogController::GalleryPermissionsVector
GalleryPermissionsVector;
@@ -79,6 +115,12 @@ MediaGalleriesDialogViews::MediaGalleriesDialogViews(
accepted_(false) {
InitChildViews();
+ gallery_menu_model_ = new GalleryContextMenuModel(this);
+ ui::SimpleMenuModel* menu_model =
+ new ui::SimpleMenuModel(gallery_menu_model_);
+ menu_model->AddItem(1, controller->GetDeleteMenuCommand());
+ context_menu_model_.reset(menu_model);
+
// Ownership of |contents_| is handed off by this call. |window_| will take
// care of deleting itself after calling DeleteDelegate().
WebContentsModalDialogManager* web_contents_modal_dialog_manager =
@@ -237,8 +279,12 @@ bool MediaGalleriesDialogViews::AddOrUpdateGallery(
views::Checkbox* checkbox = new views::Checkbox(label);
checkbox->set_listener(this);
+ if (gallery.pref_id != kInvalidMediaGalleryPrefId)
+ checkbox->set_context_menu_controller(this);
checkbox->SetTooltipText(tooltip_text);
views::Label* secondary_text = new views::Label(details);
+ if (gallery.pref_id != kInvalidMediaGalleryPrefId)
+ secondary_text->set_context_menu_controller(this);
secondary_text->SetTooltipText(tooltip_text);
secondary_text->SetEnabledColor(kDeemphasizedTextColor);
secondary_text->SetTooltipText(tooltip_text);
@@ -249,6 +295,8 @@ bool MediaGalleriesDialogViews::AddOrUpdateGallery(
views::kRelatedControlSmallHorizontalSpacing));
views::View* checkbox_view = new views::View();
+ if (gallery.pref_id != kInvalidMediaGalleryPrefId)
+ checkbox_view->set_context_menu_controller(this);
checkbox_view->set_border(views::Border::CreateEmptyBorder(
0,
views::kPanelHorizMargin,
@@ -367,6 +415,58 @@ void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender,
}
}
+void MediaGalleriesDialogViews::ShowContextMenuForView(
+ views::View* source,
+ const gfx::Point& point,
+ ui::MenuSourceType source_type) {
+ views::Checkbox* checkbox = NULL;
+ 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.
+ checkbox = static_cast<views::Checkbox*>(source);
+ } else {
+ views::View* checkbox_container_view = NULL;
+ if (source->child_count() == 2) {
+ checkbox_container_view = source;
+ } else {
+ checkbox_container_view = source->parent();
+ }
+ 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
+ return;
+ checkbox = static_cast<views::Checkbox*>(
+ 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
+ }
+
+ for (CheckboxMap::const_iterator iter = checkbox_map_.begin();
+ iter != checkbox_map_.end(); ++iter) {
+ if (checkbox == iter->second) {
+ 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.
+ }
+ }
+}
+
+void MediaGalleriesDialogViews::ShowContextMenu(const gfx::Point& point,
+ ui::MenuSourceType source_type,
+ MediaGalleryPrefId id) {
+ gallery_menu_model_->set_media_gallery_pref_id(id);
+
+ context_menu_runner_.reset(new views::MenuRunner(context_menu_model_.get()));
+ if (context_menu_runner_->RunMenuAt(
+ GetWidget(), NULL, gfx::Rect(point.x(), point.y(), 0, 0),
+ views::MenuItemView::TOPLEFT, source_type,
+ views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
+ views::MenuRunner::MENU_DELETED) {
+ return;
+ }
+}
+
+void MediaGalleriesDialogViews::DidForgetGallery(MediaGalleryPrefId id) {
+ if (id == kInvalidMediaGalleryPrefId)
+ return;
+
+ controller_->DidForgetGallery(id);
+
+ gallery_menu_model_->set_media_gallery_pref_id(kInvalidMediaGalleryPrefId);
+}
+
// MediaGalleriesDialogViewsController -----------------------------------------
// static
« no previous file with comments | « chrome/browser/ui/views/extensions/media_galleries_dialog_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698