diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 02:18:32 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-15 02:18:32 +0000 |
commit | 84e4f8c2fb5e47270fea69bdfe574ce646d64e59 (patch) | |
tree | cee34da8a0ec68e862bce9aeedf81c4169be0e64 /chrome | |
parent | 5a73ec6d0aa2362edfe5ee4a55ad98a806986621 (diff) | |
download | chromium_src-84e4f8c2fb5e47270fea69bdfe574ce646d64e59.zip chromium_src-84e4f8c2fb5e47270fea69bdfe574ce646d64e59.tar.gz chromium_src-84e4f8c2fb5e47270fea69bdfe574ce646d64e59.tar.bz2 |
Changes the wrench menu to calculate the width needed for the zoom
label from the strings that can be displayed. The old approach
resulted in too small a width and clipping.
BUG=chromium-os:4406
TEST=see bug
Review URL: http://codereview.chromium.org/2993005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/wrench_menu.cc | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/chrome/browser/views/wrench_menu.cc b/chrome/browser/views/wrench_menu.cc index d772122..29810ca 100644 --- a/chrome/browser/views/wrench_menu.cc +++ b/chrome/browser/views/wrench_menu.cc @@ -19,6 +19,7 @@ #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" #include "gfx/canvas.h" +#include "gfx/canvas_skia.h" #include "gfx/skia_util.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -367,9 +368,7 @@ class WrenchMenu::ZoomView : public ScheduleAllView, zoom_label_->set_border(new MenuButtonBorder()); zoom_label_->SetFont(MenuConfig::instance().font); AddChildView(zoom_label_); - // Get the preferred width given 100%, we'll use this in calculating our - // preferred size. - zoom_label_width_ = zoom_label_->GetPreferredSize().width(); + zoom_label_width_ = MaxWidthForZoomLabel(); decrement_button_ = CreateAndConfigureButton( this, this, IDS_ZOOM_MINUS2, MenuButtonBackground::RIGHT_BUTTON, @@ -456,7 +455,7 @@ class WrenchMenu::ZoomView : public ScheduleAllView, void UpdateZoomControls() { bool enable_increment, enable_decrement; int zoom_percent = - static_cast<int>(GetZoom(&enable_increment, &enable_decrement) * 100); + static_cast<int>(GetZoom(&enable_increment, &enable_decrement)); zoom_label_->SetText(l10n_util::GetStringF( IDS_ZOOM_PERCENT, IntToWString(zoom_percent))); increment_button_->SetEnabled(enable_increment); @@ -475,13 +474,33 @@ class WrenchMenu::ZoomView : public ScheduleAllView, return 1; int zoom_level = zoom_map->GetZoomLevel(selected_tab->GetURL()); - double value = static_cast<double>( - std::max(std::min(std::pow(1.2, zoom_level), 3.0), .5)); - *enable_decrement = (value != .5); - *enable_increment = (value != 3.0); + double value = ZoomPercentFromZoomLevel(zoom_level); + *enable_decrement = (value != 50); + *enable_increment = (value != 300); return value; } + double ZoomPercentFromZoomLevel(int level) { + return static_cast<double>( + std::max(std::min(std::pow(1.2, level), 3.0), .5)) * 100; + } + + // Calculates the max width the zoom string can be. + int MaxWidthForZoomLabel() { + gfx::Font font = zoom_label_->font(); + gfx::Insets insets; + if (zoom_label_->border()) + zoom_label_->border()->GetInsets(&insets); + int max_w = 0; + for (int i = -4; i <= 7; ++i) { + int zoom_percent = static_cast<int>(ZoomPercentFromZoomLevel(i)); + int w = font.GetStringWidth( + l10n_util::GetStringF(IDS_ZOOM_PERCENT, zoom_percent)); + max_w = std::max(w, max_w); + } + return max_w + insets.width(); + } + // Hosting WrenchMenu. WrenchMenu* menu_; |