diff options
author | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 16:20:51 +0000 |
---|---|---|
committer | rhashimoto@chromium.org <rhashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 16:20:51 +0000 |
commit | feeb016d8e0c066e686c89385c21831d91e0f662 (patch) | |
tree | 72cb50e7eb5924f7291c66d74099d38275626ac4 | |
parent | efa5521a57c9765bc968d42ce22bb449ae40f3b3 (diff) | |
download | chromium_src-feeb016d8e0c066e686c89385c21831d91e0f662.zip chromium_src-feeb016d8e0c066e686c89385c21831d91e0f662.tar.gz chromium_src-feeb016d8e0c066e686c89385c21831d91e0f662.tar.bz2 |
Add views::MenuDelegate call for per-item fonts.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6969046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85274 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/controls/menu/menu_delegate.cc | 5 | ||||
-rw-r--r-- | views/controls/menu/menu_delegate.h | 9 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.h | 7 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_gtk.cc | 4 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_win.cc | 4 |
6 files changed, 36 insertions, 6 deletions
diff --git a/views/controls/menu/menu_delegate.cc b/views/controls/menu/menu_delegate.cc index e70fb17..8bd21bf 100644 --- a/views/controls/menu/menu_delegate.cc +++ b/views/controls/menu/menu_delegate.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "views/controls/menu/menu_config.h" #include "views/controls/menu/menu_delegate.h" namespace views { @@ -14,6 +15,10 @@ std::wstring MenuDelegate::GetLabel(int id) const { return std::wstring(); } +const gfx::Font& MenuDelegate::GetLabelFont(int id) const { + return MenuConfig::instance().font; +} + std::wstring MenuDelegate::GetTooltipText(int id, const gfx::Point& screen_loc) { return std::wstring(); diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index 6a5cc5b..578f679 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -17,6 +17,12 @@ using ui::OSExchangeData; +namespace gfx { + +class Font; + +} // namespace gfx + namespace views { class DropTargetEvent; @@ -53,6 +59,9 @@ class MenuDelegate { // added with an empty label. virtual std::wstring GetLabel(int id) const; + // The font for the menu item label. + virtual const gfx::Font& GetLabelFont(int id) const; + // The tooltip shown for the menu item. This is invoked when the user // hovers over the item, and no tooltip text has been set for that item. virtual std::wstring GetTooltipText(int id, const gfx::Point& screen_loc); diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index c2c266b8..bf2a768 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -462,7 +462,7 @@ void MenuItemView::Layout() { int MenuItemView::GetAcceleratorTextWidth() { string16 text = GetAcceleratorText(); - return text.empty() ? 0 : MenuConfig::instance().font.GetStringWidth(text); + return text.empty() ? 0 : GetFont().GetStringWidth(text); } MenuItemView::MenuItemView(MenuItemView* parent, @@ -590,6 +590,15 @@ int MenuItemView::GetDrawStringFlags() { return flags; } +const gfx::Font& MenuItemView::GetFont() { + // Check for item-specific font. + const MenuDelegate* delegate = GetDelegate(); + if (delegate) + return delegate->GetLabelFont(GetCommand()); + else + return MenuConfig::instance().font; +} + void MenuItemView::AddEmptyMenus() { DCHECK(HasSubmenu()); if (!submenu_->has_children()) { @@ -631,7 +640,7 @@ void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) { if (accel_text.empty()) return; - const gfx::Font& font = MenuConfig::instance().font; + const gfx::Font& font = GetFont(); int available_height = height() - GetTopMargin() - GetBottomMargin(); int max_accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 308c3e2..34cb391 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -21,6 +21,10 @@ #include "ui/gfx/native_theme.h" #endif +namespace gfx { +class Font; +} + namespace ui { class MenuModel; } @@ -316,6 +320,9 @@ class MenuItemView : public View { // Returns the flags passed to DrawStringInt. int GetDrawStringFlags(); + // Returns the font to use for menu text. + const gfx::Font& GetFont(); + // If this menu item has no children a child is added showing it has no // children. Otherwise AddEmtpyMenus is recursively invoked on child menu // items that have children. diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index 17604e4..aabe58b 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -25,7 +25,7 @@ static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); #endif gfx::Size MenuItemView::CalculatePreferredSize() { - const gfx::Font& font = MenuConfig::instance().font; + const gfx::Font& font = GetFont(); return gfx::Size( font.GetStringWidth(title_) + label_start_ + item_right_margin_ + GetChildPreferredWidth(), @@ -83,7 +83,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { SkColor fg_color = IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; #endif - const gfx::Font& font = MenuConfig::instance().font; + const gfx::Font& font = GetFont(); int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); int width = this->width() - item_right_margin_ - label_start_ - accel_width; gfx::Rect text_bounds(label_start_, top_margin + diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index e71f8c1..82f1c0d 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -18,7 +18,7 @@ using gfx::NativeTheme; namespace views { gfx::Size MenuItemView::CalculatePreferredSize() { - const gfx::Font& font = MenuConfig::instance().font; + const gfx::Font& font = GetFont(); return gfx::Size( font.GetStringWidth(title_) + label_start_ + item_right_margin_ + GetChildPreferredWidth(), @@ -82,7 +82,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { SkColor fg_color = gfx::NativeThemeWin::instance()->GetThemeColorWithDefault( gfx::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, default_sys_color); - const gfx::Font& font = MenuConfig::instance().font; + const gfx::Font& font = GetFont(); int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width(); int width = this->width() - item_right_margin_ - label_start_ - accel_width; gfx::Rect text_bounds(label_start_, top_margin, width, font.GetHeight()); |