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

Side by Side Diff: chrome/browser/ui/views/content_setting_bubble_contents.cc

Issue 12457016: Added "None available" title and grey out the media menu when there is no device. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed the comments. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/ui/gtk/content_setting_bubble_gtk.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 namespace { 46 namespace {
47 47
48 // If we don't clamp the maximum width, then very long URLs and titles can make 48 // If we don't clamp the maximum width, then very long URLs and titles can make
49 // the bubble arbitrarily wide. 49 // the bubble arbitrarily wide.
50 const int kMaxContentsWidth = 500; 50 const int kMaxContentsWidth = 500;
51 51
52 // When we have multiline labels, we should set a minimum width lest we get very 52 // When we have multiline labels, we should set a minimum width lest we get very
53 // narrow bubbles with lots of line-wrapping. 53 // narrow bubbles with lots of line-wrapping.
54 const int kMinMultiLineContentsWidth = 250; 54 const int kMinMultiLineContentsWidth = 250;
55 55
56 // The minimum and maximum width of the media menu buttons. 56 // The minimum width of the media menu buttons.
57 const int kMinMediaMenuButtonWidth = 100; 57 const int kMinMediaMenuButtonWidth = 100;
58 const int kMaxMediaMenuButtonWidth = 600;
59 58
60 } 59 }
61 60
62 using content::PluginService; 61 using content::PluginService;
63 using content::WebContents; 62 using content::WebContents;
64 63
65 64
66 // ContentSettingBubbleContents::Favicon -------------------------------------- 65 // ContentSettingBubbleContents::Favicon --------------------------------------
67 66
68 class ContentSettingBubbleContents::Favicon : public views::ImageView { 67 class ContentSettingBubbleContents::Favicon : public views::ImageView {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 bubble_content.media_menus.begin()); 299 bubble_content.media_menus.begin());
301 i != bubble_content.media_menus.end(); ++i) { 300 i != bubble_content.media_menus.end(); ++i) {
302 if (!bubble_content_empty) 301 if (!bubble_content_empty)
303 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 302 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
304 layout->StartRow(0, kMediaMenuColumnSetId); 303 layout->StartRow(0, kMediaMenuColumnSetId);
305 304
306 views::Label* label = new views::Label(UTF8ToUTF16(i->second.label)); 305 views::Label* label = new views::Label(UTF8ToUTF16(i->second.label));
307 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 306 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
308 307
309 views::MenuButton* menu_button = new views::MenuButton( 308 views::MenuButton* menu_button = new views::MenuButton(
310 NULL, UTF8ToUTF16((i->second.selected_device.name)), this, false); 309 NULL, UTF8ToUTF16((i->second.selected_device.name)), this, true);
311 menu_button->set_alignment(views::TextButton::ALIGN_LEFT); 310 menu_button->set_alignment(views::TextButton::ALIGN_LEFT);
312 menu_button->set_border( 311 menu_button->set_border(
313 new views::TextButtonNativeThemeBorder(menu_button)); 312 new views::TextButtonNativeThemeBorder(menu_button));
314 menu_button->set_animate_on_state_change(false); 313 menu_button->set_animate_on_state_change(false);
315 314
316 MediaMenuParts* menu_view = new MediaMenuParts(i->first); 315 MediaMenuParts* menu_view = new MediaMenuParts(i->first);
317 menu_view->menu_model.reset(new ContentSettingMediaMenuModel( 316 menu_view->menu_model.reset(new ContentSettingMediaMenuModel(
318 i->first, 317 i->first,
319 content_setting_bubble_model_.get(), 318 content_setting_bubble_model_.get(),
320 base::Bind(&ContentSettingBubbleContents::UpdateMenuLabel, 319 base::Bind(&ContentSettingBubbleContents::UpdateMenuLabel,
321 base::Unretained(this)))); 320 base::Unretained(this))));
322 media_menus_[menu_button] = menu_view; 321 media_menus_[menu_button] = menu_view;
323 322
323 if (!menu_view->menu_model->GetItemCount()) {
324 // Show a "None available" title and grey out the menu when there is no
325 // available device.
326 menu_button->SetText(
327 l10n_util::GetStringUTF16(IDS_MEDIA_MENU_NO_DEVICE_TITLE));
328 menu_button->SetEnabled(false);
329 }
330
324 // Use the longest width of the menus as the width of the menu buttons. 331 // Use the longest width of the menus as the width of the menu buttons.
325 menu_width = std::max(menu_width, 332 menu_width = std::max(menu_width,
326 GetPreferredMediaMenuWidth( 333 GetPreferredMediaMenuWidth(
327 menu_button, menu_view->menu_model.get())); 334 menu_button, menu_view->menu_model.get()));
328 335
329 layout->AddView(label); 336 layout->AddView(label);
330 layout->AddView(menu_button); 337 layout->AddView(menu_button);
331 338
332 bubble_content_empty = false; 339 bubble_content_empty = false;
333 } 340 }
334 341
335 // Make sure the width is within [kMinMediaMenuButtonWidth, 342 // Make sure the width is at least kMinMediaMenuButtonWidth. The
336 // kMaxMediaMenuButtonWidth]. 343 // maximum width will be clamped by kMaxContentsWidth of the view.
337 menu_width = std::max(kMinMediaMenuButtonWidth, menu_width); 344 menu_width = std::max(kMinMediaMenuButtonWidth, menu_width);
338 menu_width = std::min(kMaxMediaMenuButtonWidth, menu_width);
339 345
340 // Set all the menu buttons to the width we calculated above. 346 // Set all the menu buttons to the width we calculated above.
341 for (MediaMenuPartsMap::const_iterator i = media_menus_.begin(); 347 for (MediaMenuPartsMap::const_iterator i = media_menus_.begin();
342 i != media_menus_.end(); ++i) { 348 i != media_menus_.end(); ++i) {
343 i->first->set_min_width(menu_width); 349 i->first->set_min_width(menu_width);
344 i->first->set_max_width(menu_width); 350 i->first->set_max_width(menu_width);
345 } 351 }
346 } 352 }
347 353
348 gfx::Font domain_font = 354 gfx::Font domain_font =
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 int width = button->GetPreferredSize().width(); 483 int width = button->GetPreferredSize().width();
478 for (int i = 0; i < menu_model->GetItemCount(); ++i) { 484 for (int i = 0; i < menu_model->GetItemCount(); ++i) {
479 button->SetText(menu_model->GetLabelAt(i)); 485 button->SetText(menu_model->GetLabelAt(i));
480 width = std::max(width, button->GetPreferredSize().width()); 486 width = std::max(width, button->GetPreferredSize().width());
481 } 487 }
482 488
483 // Recover the title for the menu button. 489 // Recover the title for the menu button.
484 button->SetText(title); 490 button->SetText(title);
485 return width; 491 return width;
486 } 492 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/content_setting_bubble_gtk.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698