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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/content_setting_bubble_contents.h" 5 #include "chrome/browser/ui/views/content_setting_bubble_contents.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
14 #include "chrome/browser/plugins/plugin_finder.h" 14 #include "chrome/browser/plugins/plugin_finder.h"
15 #include "chrome/browser/plugins/plugin_metadata.h" 15 #include "chrome/browser/plugins/plugin_metadata.h"
16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/chrome_style.h" 17 #include "chrome/browser/ui/chrome_style.h"
17 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 18 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
18 #include "chrome/browser/ui/views/browser_dialogs.h" 19 #include "chrome/browser/ui/views/browser_dialogs.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/plugin_service.h" 22 #include "content/public/browser/plugin_service.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/views/controls/button/menu_button.h"
24 #include "ui/views/controls/button/radio_button.h" 26 #include "ui/views/controls/button/radio_button.h"
25 #include "ui/views/controls/button/text_button.h" 27 #include "ui/views/controls/button/text_button.h"
26 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
27 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/link.h" 30 #include "ui/views/controls/link.h"
31 #include "ui/views/controls/menu/menu.h"
32 #include "ui/views/controls/menu/menu_model_adapter.h"
33 #include "ui/views/controls/menu/menu_runner.h"
29 #include "ui/views/controls/separator.h" 34 #include "ui/views/controls/separator.h"
30 #include "ui/views/layout/grid_layout.h" 35 #include "ui/views/layout/grid_layout.h"
31 #include "ui/views/layout/layout_constants.h" 36 #include "ui/views/layout/layout_constants.h"
32 37
33 #if defined(USE_AURA) 38 #if defined(USE_AURA)
34 #include "ui/base/cursor/cursor.h" 39 #include "ui/base/cursor/cursor.h"
35 #endif 40 #endif
36 41
37 // If we don't clamp the maximum width, then very long URLs and titles can make 42 // If we don't clamp the maximum width, then very long URLs and titles can make
38 // the bubble arbitrarily wide. 43 // the bubble arbitrarily wide.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #if defined(USE_AURA) 97 #if defined(USE_AURA)
93 return ui::kCursorHand; 98 return ui::kCursorHand;
94 #elif defined(OS_WIN) 99 #elif defined(OS_WIN)
95 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); 100 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND);
96 return g_hand_cursor; 101 return g_hand_cursor;
97 #endif 102 #endif
98 } 103 }
99 104
100 ContentSettingBubbleContents::ContentSettingBubbleContents( 105 ContentSettingBubbleContents::ContentSettingBubbleContents(
101 ContentSettingBubbleModel* content_setting_bubble_model, 106 ContentSettingBubbleModel* content_setting_bubble_model,
107 Profile* profile,
102 WebContents* web_contents, 108 WebContents* web_contents,
103 views::View* anchor_view, 109 views::View* anchor_view,
104 views::BubbleBorder::ArrowLocation arrow_location) 110 views::BubbleBorder::ArrowLocation arrow_location)
105 : BubbleDelegateView(anchor_view, arrow_location), 111 : BubbleDelegateView(anchor_view, arrow_location),
106 content_setting_bubble_model_(content_setting_bubble_model), 112 content_setting_bubble_model_(content_setting_bubble_model),
113 profile_(profile),
107 web_contents_(web_contents), 114 web_contents_(web_contents),
108 custom_link_(NULL), 115 custom_link_(NULL),
109 manage_link_(NULL), 116 manage_link_(NULL),
110 close_button_(NULL) { 117 close_button_(NULL) {
118 DCHECK(profile);
111 // Compensate for built-in vertical padding in the anchor view's image. 119 // Compensate for built-in vertical padding in the anchor view's image.
112 set_anchor_insets(gfx::Insets(5, 0, 5, 0)); 120 set_anchor_insets(gfx::Insets(5, 0, 5, 0));
113 121
114 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 122 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
115 content::Source<WebContents>(web_contents)); 123 content::Source<WebContents>(web_contents));
116 } 124 }
117 125
118 ContentSettingBubbleContents::~ContentSettingBubbleContents() { 126 ContentSettingBubbleContents::~ContentSettingBubbleContents() {
127 // 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.
128 for (MediaMenuViewMap::const_iterator it = media_menus_.begin();
129 it != media_menus_.end(); ++it) {
130 delete it->second;
131 }
119 } 132 }
120 133
121 gfx::Size ContentSettingBubbleContents::GetPreferredSize() { 134 gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
122 gfx::Size preferred_size(views::View::GetPreferredSize()); 135 gfx::Size preferred_size(views::View::GetPreferredSize());
123 int preferred_width = 136 int preferred_width =
124 (!content_setting_bubble_model_->bubble_content().domain_lists.empty() && 137 (!content_setting_bubble_model_->bubble_content().domain_lists.empty() &&
125 (kMinMultiLineContentsWidth > preferred_size.width())) ? 138 (kMinMultiLineContentsWidth > preferred_size.width())) ?
126 kMinMultiLineContentsWidth : preferred_size.width(); 139 kMinMultiLineContentsWidth : preferred_size.width();
127 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); 140 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth));
128 return preferred_size; 141 return preferred_size;
129 } 142 }
130 143
144 void ContentSettingBubbleContents::UpdateMenuLabel(
145 content::MediaStreamType type,
146 const std::string& label) {
147 MediaMenuViewMap::const_iterator it = media_menus_.begin();
148 for (; it != media_menus_.end(); ++it) {
149 if (it->second->type == type) {
150 it->first->SetText(UTF8ToUTF16(label));
151 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.
152 break;
153 }
154 }
155 DCHECK(it != media_menus_.end());
156 }
157
131 void ContentSettingBubbleContents::Init() { 158 void ContentSettingBubbleContents::Init() {
132 using views::GridLayout; 159 using views::GridLayout;
133 160
134 GridLayout* layout = new views::GridLayout(this); 161 GridLayout* layout = new views::GridLayout(this);
135 SetLayoutManager(layout); 162 SetLayoutManager(layout);
136 163
137 const int kSingleColumnSetId = 0; 164 const int kSingleColumnSetId = 0;
138 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); 165 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
139 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 166 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
140 GridLayout::USE_PREF, 0, 0); 167 GridLayout::USE_PREF, 0, 0);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 layout->StartRow(0, indented_kSingleColumnSetId); 245 layout->StartRow(0, indented_kSingleColumnSetId);
219 layout->AddView(radio); 246 layout->AddView(radio);
220 bubble_content_empty = false; 247 bubble_content_empty = false;
221 } 248 }
222 DCHECK(!radio_group_.empty()); 249 DCHECK(!radio_group_.empty());
223 // Now that the buttons have been added to the view hierarchy, it's safe 250 // Now that the buttons have been added to the view hierarchy, it's safe
224 // to call SetChecked() on them. 251 // to call SetChecked() on them.
225 radio_group_[radio_group.default_item]->SetChecked(true); 252 radio_group_[radio_group.default_item]->SetChecked(true);
226 } 253 }
227 254
255 // Layout code for the media device menus.
256 if (content_setting_bubble_model_->content_type() ==
257 CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
258 const int kMediaMenuColumnSetId = 2;
259 views::ColumnSet* menu_column_set =
260 layout->AddColumnSet(kMediaMenuColumnSetId);
261 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
262 GridLayout::USE_PREF, 0, 0);
263 menu_column_set->AddPaddingColumn(
264 0, views::kRelatedControlHorizontalSpacing);
265 menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
266 GridLayout::USE_PREF, 0, 0);
267
268 for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i(
269 bubble_content.media_menus.begin());
270 i != bubble_content.media_menus.end(); ++i) {
271 if (!bubble_content_empty)
272 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
273 layout->StartRow(0, kMediaMenuColumnSetId);
274
275 views::Label* menu_label = new views::Label(UTF8ToUTF16(i->second.label));
276 menu_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
277 layout->AddView(menu_label, 1, 1, GridLayout::FILL, GridLayout::LEADING);
278 views::MenuButton* menu_button =
279 new views::MenuButton(NULL, string16(), this, false);
280 menu_button->set_alignment(views::TextButton::ALIGN_CENTER);
281 menu_button->set_border(NULL);
282 //menu_button->SetBoundsRect(GetOptionsButtonBounds());
283
284 layout->AddView(menu_label);
285 layout->AddView(menu_button);
286 // Store the menu view to the map.
287 MediaMenuView* menu_view = new MediaMenuView();
288 menu_view->type = i->first;
289 menu_view->menu_model.reset(new ContentSettingMediaMenuModel(
290 profile_,
291 i->second.default_device.type,
292 content_setting_bubble_model_.get(),
293 this));
294 media_menus_[menu_button] = menu_view;
295 bubble_content_empty = false;
296 }
297 }
298
228 gfx::Font domain_font = 299 gfx::Font domain_font =
229 views::Label().font().DeriveFont(0, gfx::Font::BOLD); 300 views::Label().font().DeriveFont(0, gfx::Font::BOLD);
230 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i( 301 for (std::vector<ContentSettingBubbleModel::DomainList>::const_iterator i(
231 bubble_content.domain_lists.begin()); 302 bubble_content.domain_lists.begin());
232 i != bubble_content.domain_lists.end(); ++i) { 303 i != bubble_content.domain_lists.end(); ++i) {
233 layout->StartRow(0, kSingleColumnSetId); 304 layout->StartRow(0, kSingleColumnSetId);
234 views::Label* section_title = new views::Label(UTF8ToUTF16(i->title)); 305 views::Label* section_title = new views::Label(UTF8ToUTF16(i->title));
235 section_title->SetMultiLine(true); 306 section_title->SetMultiLine(true);
236 section_title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 307 section_title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
237 layout->AddView(section_title, 1, 1, GridLayout::FILL, GridLayout::LEADING); 308 layout->AddView(section_title, 1, 1, GridLayout::FILL, GridLayout::LEADING);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // CAREFUL: Showing the settings window activates it, which deactivates the 384 // CAREFUL: Showing the settings window activates it, which deactivates the
314 // info bubble, which causes it to close, which deletes us. 385 // info bubble, which causes it to close, which deletes us.
315 return; 386 return;
316 } 387 }
317 388
318 PopupLinks::const_iterator i(popup_links_.find(source)); 389 PopupLinks::const_iterator i(popup_links_.find(source));
319 DCHECK(i != popup_links_.end()); 390 DCHECK(i != popup_links_.end());
320 content_setting_bubble_model_->OnPopupClicked(i->second); 391 content_setting_bubble_model_->OnPopupClicked(i->second);
321 } 392 }
322 393
394 void ContentSettingBubbleContents::OnMenuButtonClicked(
395 views::View* source,
396 const gfx::Point& point) {
397 MediaMenuViewMap::iterator i(media_menus_.find(
398 static_cast<views::MenuButton*>(source)));
399 DCHECK(i != media_menus_.end());
400
401 views::MenuModelAdapter menu_model_adapter(i->second->menu_model.get());
402 menu_runner_.reset(new views::MenuRunner(menu_model_adapter.CreateMenu()));
403
404 gfx::Point screen_location;
405 views::View::ConvertPointToScreen(i->first, &screen_location);
406 if (menu_runner_->RunMenuAt(source->GetWidget(),
407 i->first,
408 gfx::Rect(screen_location, i->first->size()),
409 views::MenuItemView::TOPRIGHT,
410 views::MenuRunner::HAS_MNEMONICS) ==
411 views::MenuRunner::MENU_DELETED)
412 return;
413 }
414
323 void ContentSettingBubbleContents::Observe( 415 void ContentSettingBubbleContents::Observe(
324 int type, 416 int type,
325 const content::NotificationSource& source, 417 const content::NotificationSource& source,
326 const content::NotificationDetails& details) { 418 const content::NotificationDetails& details) {
327 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type); 419 DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
328 DCHECK(source == content::Source<WebContents>(web_contents_)); 420 DCHECK(source == content::Source<WebContents>(web_contents_));
329 web_contents_ = NULL; 421 web_contents_ = NULL;
330 } 422 }
423
424 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
425
426 ContentSettingBubbleContents::MediaMenuView::~MediaMenuView() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698