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

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

Issue 387313005: views: Make the menu size the same as the menubutton size in the media bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT; trybots are failing. Created 6 years, 5 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/content_setting_bubble_contents.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/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 f662be4e4fe4b892f8eda09e5e45528fc72e6999..8965da5361df7dd21261295c24ebe62544888c8a 100644
--- a/chrome/browser/ui/views/content_setting_bubble_contents.cc
+++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc
@@ -26,6 +26,7 @@
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font_list.h"
+#include "ui/gfx/text_utils.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/radio_button.h"
@@ -33,6 +34,7 @@
#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_config.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/grid_layout.h"
@@ -291,7 +293,6 @@ void ContentSettingBubbleContents::Init() {
menu_column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
- int menu_width = 0;
for (ContentSettingBubbleModel::MediaMenuMap::const_iterator i(
bubble_content.media_menus.begin());
i != bubble_content.media_menus.end(); ++i) {
@@ -331,29 +332,15 @@ void ContentSettingBubbleContents::Init() {
if (i->second.disabled)
menu_button->SetEnabled(false);
- // Use the longest width of the menus as the width of the menu buttons.
- menu_width = std::max(menu_width,
- GetPreferredMediaMenuWidth(
- menu_button, menu_view->menu_model.get()));
-
layout->AddView(label);
layout->AddView(menu_button);
bubble_content_empty = false;
}
-
- // Make sure the width is at least kMinMediaMenuButtonWidth. The
- // maximum width will be clamped by kMaxContentsWidth of the view.
- menu_width = std::max(kMinMediaMenuButtonWidth, menu_width);
-
- // Set all the menu buttons to the width we calculated above.
- for (MediaMenuPartsMap::const_iterator i = media_menus_.begin();
- i != media_menus_.end(); ++i) {
- i->first->set_min_size(gfx::Size(menu_width, 0));
- i->first->set_max_size(gfx::Size(menu_width, 0));
- }
}
+ UpdateMenuButtonSizes(GetNativeTheme());
+
const gfx::FontList& domain_font =
ui::ResourceBundle::GetSharedInstance().GetFontList(
ui::ResourceBundle::BoldFont);
@@ -424,6 +411,12 @@ void ContentSettingBubbleContents::DidNavigateMainFrame(
GetWidget()->Close();
}
+void ContentSettingBubbleContents::OnNativeThemeChanged(
+ const ui::NativeTheme* theme) {
+ views::BubbleDelegateView::OnNativeThemeChanged(theme);
+ UpdateMenuButtonSizes(theme);
+}
+
void ContentSettingBubbleContents::ButtonPressed(views::Button* sender,
const ui::Event& event) {
RadioGroup::const_iterator i(
@@ -481,18 +474,36 @@ void ContentSettingBubbleContents::OnMenuButtonClicked(
ui::MENU_SOURCE_NONE));
}
-int ContentSettingBubbleContents::GetPreferredMediaMenuWidth(
- views::MenuButton* button,
- ui::SimpleMenuModel* menu_model) {
- base::string16 title = button->GetText();
-
- int width = button->GetPreferredSize().width();
- for (int i = 0; i < menu_model->GetItemCount(); ++i) {
- button->SetText(menu_model->GetLabelAt(i));
- width = std::max(width, button->GetPreferredSize().width());
+void ContentSettingBubbleContents::UpdateMenuButtonSizes(
+ const ui::NativeTheme* theme) {
+ const views::MenuConfig config = views::MenuConfig(theme);
+ const int margins = config.item_left_margin + config.check_width +
+ config.label_to_arrow_padding + config.arrow_width +
+ config.arrow_to_edge_padding;
+
+ // The preferred media menu size sort of copies the logic in
+ // MenuItemView::CalculateDimensions(). When this was using TextButton, it
+ // completely coincidentally matched the logic in MenuItemView. We now need
+ // to redo this manually.
+ int menu_width = 0;
+ for (MediaMenuPartsMap::const_iterator i = media_menus_.begin();
+ i != media_menus_.end(); ++i) {
+ for (int j = 0; j < i->second->menu_model->GetItemCount(); ++j) {
+ int string_width = gfx::GetStringWidth(
+ i->second->menu_model->GetLabelAt(j),
+ config.font_list);
+
+ menu_width = std::max(menu_width, string_width);
+ }
}
- // Recover the title for the menu button.
- button->SetText(title);
- return width;
+ // Make sure the width is at least kMinMediaMenuButtonWidth. The
+ // maximum width will be clamped by kMaxContentsWidth of the view.
+ menu_width = std::max(kMinMediaMenuButtonWidth, menu_width + margins);
+
+ for (MediaMenuPartsMap::const_iterator i = media_menus_.begin();
+ i != media_menus_.end(); ++i) {
+ i->first->set_min_size(gfx::Size(menu_width, 0));
+ i->first->set_max_size(gfx::Size(menu_width, 0));
+ }
}
« no previous file with comments | « chrome/browser/ui/views/content_setting_bubble_contents.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698