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

Unified Diff: chrome/browser/ui/views/content_setting_bubble_contents.cc

Issue 12208010: Adding device selection menus to the content setting bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some more cleanup and ready for review. Created 7 years, 10 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
Index: chrome/browser/ui/views/content_setting_bubble_contents.cc
diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc
index 7a01e388149a61df764e1164a9ddb37189604b31..888f5370275634939cca5b46c9d25fda093da388 100644
--- a/chrome/browser/ui/views/content_setting_bubble_contents.cc
+++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/plugins/plugin_finder.h"
#include "chrome/browser/plugins/plugin_metadata.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
@@ -21,11 +22,15 @@
#include "content/public/browser/plugin_service.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
+#include "ui/views/controls/menu/menu.h"
+#include "ui/views/controls/menu/menu_model_adapter.h"
+#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
@@ -99,15 +104,18 @@ gfx::NativeCursor ContentSettingBubbleContents::Favicon::GetCursor(
ContentSettingBubbleContents::ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model,
+ Profile* profile,
WebContents* web_contents,
views::View* anchor_view,
views::BubbleBorder::ArrowLocation arrow_location)
: BubbleDelegateView(anchor_view, arrow_location),
content_setting_bubble_model_(content_setting_bubble_model),
+ profile_(profile),
web_contents_(web_contents),
custom_link_(NULL),
manage_link_(NULL),
close_button_(NULL) {
+ DCHECK(profile);
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
@@ -116,6 +124,11 @@ ContentSettingBubbleContents::ContentSettingBubbleContents(
}
ContentSettingBubbleContents::~ContentSettingBubbleContents() {
+ // Free any MediaMenuVoew objects left over.
markusheintz_ 2013/02/06 11:03:26 Typo s/MediaMenuVoew/MediaMenuView
no longer working on chromium 2013/02/06 13:31:52 Done.
+ for (MediaMenuViewMap::const_iterator it = media_menus_.begin();
+ it != media_menus_.end(); ++it) {
+ delete it->second;
+ }
}
gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
@@ -128,6 +141,20 @@ gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
return preferred_size;
}
+void ContentSettingBubbleContents::UpdateMenuLabel(
+ content::MediaStreamType type,
+ const std::string& label) {
+ MediaMenuViewMap::const_iterator it = media_menus_.begin();
+ for (; it != media_menus_.end(); ++it) {
+ if (it->second->type == type) {
+ it->first->SetText(UTF8ToUTF16(label));
+ DLOG(WARNING) << "TODO SET THE TITLE FOR THE MENU";
markusheintz_ 2013/02/06 11:03:26 Is this still an active TODO? Looks like some dbg
no longer working on chromium 2013/02/06 13:31:52 Removed.
+ break;
+ }
+ }
+ DCHECK(it != media_menus_.end());
+}
+
void ContentSettingBubbleContents::Init() {
using views::GridLayout;
@@ -225,6 +252,50 @@ void ContentSettingBubbleContents::Init() {
radio_group_[radio_group.default_item]->SetChecked(true);
}
+ // Layout code for the media device menus.
+ if (content_setting_bubble_model_->content_type() ==
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
+ const int kMediaMenuColumnSetId = 2;
+ views::ColumnSet* menu_column_set =
+ layout->AddColumnSet(kMediaMenuColumnSetId);
+ menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
+ GridLayout::USE_PREF, 0, 0);
+ menu_column_set->AddPaddingColumn(
+ 0, views::kRelatedControlHorizontalSpacing);
+ menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
+ GridLayout::USE_PREF, 0, 0);
+
+ for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i(
+ bubble_content.media_menus.begin());
+ i != bubble_content.media_menus.end(); ++i) {
+ if (!bubble_content_empty)
+ layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
+ layout->StartRow(0, kMediaMenuColumnSetId);
+
+ views::Label* menu_label = new views::Label(UTF8ToUTF16(i->second.label));
+ menu_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ layout->AddView(menu_label, 1, 1, GridLayout::FILL, GridLayout::LEADING);
+ views::MenuButton* menu_button =
+ new views::MenuButton(NULL, string16(), this, false);
+ menu_button->set_alignment(views::TextButton::ALIGN_CENTER);
+ menu_button->set_border(NULL);
+ //menu_button->SetBoundsRect(GetOptionsButtonBounds());
+
+ layout->AddView(menu_label);
+ layout->AddView(menu_button);
+ // Store the menu view to the map.
+ MediaMenuView* menu_view = new MediaMenuView();
+ menu_view->type = i->first;
+ menu_view->menu_model.reset(new ContentSettingMediaMenuModel(
+ profile_,
+ i->second.default_device.type,
+ content_setting_bubble_model_.get(),
+ this));
+ media_menus_[menu_button] = menu_view;
+ bubble_content_empty = false;
+ }
+ }
+
gfx::Font domain_font =
views::Label().font().DeriveFont(0, gfx::Font::BOLD);
for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i(
@@ -320,6 +391,27 @@ void ContentSettingBubbleContents::LinkClicked(views::Link* source,
content_setting_bubble_model_->OnPopupClicked(i->second);
}
+void ContentSettingBubbleContents::OnMenuButtonClicked(
+ views::View* source,
+ const gfx::Point& point) {
+ MediaMenuViewMap::iterator i(media_menus_.find(
+ static_cast<views::MenuButton*>(source)));
+ DCHECK(i != media_menus_.end());
+
+ views::MenuModelAdapter menu_model_adapter(i->second->menu_model.get());
+ menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu()));
+
+ gfx::Point screen_location;
+ views::View::ConvertPointToScreen(i->first, &screen_location);
+ if (menu_runner_->RunMenuAt(source->GetWidget(),
+ i->first,
+ gfx::Rect(screen_location, i->first->size()),
+ views::MenuItemView::TOPRIGHT,
+ views::MenuRunner::HAS_MNEMONICS) ==
+ views::MenuRunner::MENU_DELETED)
+ return;
+}
+
void ContentSettingBubbleContents::Observe(
int type,
const content::NotificationSource& source,
@@ -328,3 +420,7 @@ void ContentSettingBubbleContents::Observe(
DCHECK(source == content::Source<WebContents>(web_contents_));
web_contents_ = NULL;
}
+
+ContentSettingBubbleContents::MediaMenuView::MediaMenuView() {}
markusheintz_ 2013/02/06 11:03:26 |menu_model| initialized to NULL thanks to the sco
no longer working on chromium 2013/02/06 13:31:52 Done. I added the type as the input to the constru
+
+ContentSettingBubbleContents::MediaMenuView::~MediaMenuView() {}

Powered by Google App Engine
This is Rietveld 408576698