diff options
author | yukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:48:48 +0000 |
---|---|---|
committer | yukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-14 13:48:48 +0000 |
commit | 1b9d460c4de34e226f7d67cc305014099fcd2693 (patch) | |
tree | c8b0d2ceb23c62a062496a4ad941344f0a776f23 | |
parent | 736315d37daa263e6ce11f0b2e6fcd646a96e2f2 (diff) | |
download | chromium_src-1b9d460c4de34e226f7d67cc305014099fcd2693.zip chromium_src-1b9d460c4de34e226f7d67cc305014099fcd2693.tar.gz chromium_src-1b9d460c4de34e226f7d67cc305014099fcd2693.tar.bz2 |
Refactor: Makes menus use gfx::FontList instead of gfx::Font.
As part of effort to support multiple fonts, this CL changes methods which are now taking gfx::Font so they will take gfx::FontList instead.
See https://docs.google.com/a/chromium.org/document/d/1D_25fp9B8b9aZJORfAjDIFq61NWvUquZ5xmKH-VcC4k/view
BUG=265485
TEST=Run unit_tests, ui_unittests, views_unittests
Review URL: https://codereview.chromium.org/117903006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244684 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 136 insertions, 134 deletions
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc index 4348c98..b387e25 100644 --- a/ash/shelf/shelf_view.cc +++ b/ash/shelf/shelf_view.cc @@ -128,7 +128,7 @@ class ShelfMenuModelAdapter : public views::MenuModelAdapter { explicit ShelfMenuModelAdapter(ShelfMenuModel* menu_model); // views::MenuModelAdapter: - virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; + virtual const gfx::FontList* GetLabelFontList(int command_id) const OVERRIDE; virtual bool IsCommandEnabled(int id) const OVERRIDE; virtual void GetHorizontalIconMargins(int id, int icon_size, @@ -154,12 +154,13 @@ ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model) menu_model_(menu_model) { } -const gfx::Font* ShelfMenuModelAdapter::GetLabelFont(int command_id) const { +const gfx::FontList* ShelfMenuModelAdapter::GetLabelFontList( + int command_id) const { if (command_id != kCommandIdOfMenuName) - return MenuModelAdapter::GetLabelFont(command_id); + return MenuModelAdapter::GetLabelFontList(command_id); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - return &rb.GetFont(ui::ResourceBundle::BoldFont); + return &rb.GetFontList(ui::ResourceBundle::BoldFont); } bool ShelfMenuModelAdapter::IsCommandEnabled(int id) const { diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc index 04d5c51..b6f2583 100644 --- a/chrome/browser/chromeos/status/network_menu.cc +++ b/chrome/browser/chromeos/status/network_menu.cc @@ -124,7 +124,7 @@ class NetworkMenuModel : public ui::MenuModel { virtual ui::MenuSeparatorType GetSeparatorTypeAt(int index) const OVERRIDE; virtual base::string16 GetLabelAt(int index) const OVERRIDE; virtual bool IsItemDynamicAt(int index) const OVERRIDE; - virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE; + virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE; virtual bool GetAcceleratorAt(int index, ui::Accelerator* accelerator) const OVERRIDE; virtual bool IsItemCheckedAt(int index) const OVERRIDE; @@ -244,15 +244,14 @@ bool NetworkMenuModel::IsItemDynamicAt(int index) const { return false; } -const gfx::Font* NetworkMenuModel::GetLabelFontAt(int index) const { - const gfx::Font* font = NULL; +const gfx::FontList* NetworkMenuModel::GetLabelFontListAt(int index) const { + const gfx::FontList* font_list = NULL; if (menu_items_[index].flags & FLAG_ASSOCIATED) { - ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); - font = &resource_bundle.GetFont( - browser_defaults::kAssociatedNetworkFontStyle); + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + font_list = &rb.GetFontList(browser_defaults::kAssociatedNetworkFontStyle); } - return font; + return font_list; } bool NetworkMenuModel::GetAcceleratorAt(int index, diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm index f7ffcac..2b56111 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm @@ -159,10 +159,11 @@ class ZoomLevelObserver { [[menuItem representedObject] pointerValue]); // The section headers in the recent tabs submenu should be bold and black if - // a font is specified for the items (bold is already applied in the - // |MenuController| as the font returned by |GetLabelFontAt| is bold). + // a font list is specified for the items (bold is already applied in the + // |MenuController| as the font list returned by |GetLabelFontListAt| is + // bold). if (model && model == [self recentTabsMenuModel]) { - if (model->GetLabelFontAt([item tag])) { + if (model->GetLabelFontListAt([item tag])) { DCHECK([menuItem attributedTitle]); base::scoped_nsobject<NSMutableAttributedString> title( [[NSMutableAttributedString alloc] diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc index 8d069f2..57f5898 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc @@ -172,8 +172,8 @@ RecentTabsSubMenuModel::RecentTabsSubMenuModel( browser_(browser), open_tabs_delegate_(open_tabs_delegate), last_local_model_index_(-1), - default_favicon_(ResourceBundle::GetSharedInstance(). - GetNativeImageNamed(IDR_DEFAULT_FAVICON)), + default_favicon_(ui::ResourceBundle::GetSharedInstance(). + GetNativeImageNamed(IDR_DEFAULT_FAVICON)), weak_ptr_factory_(this) { // Invoke asynchronous call to load tabs from local last session, which does // nothing if the tabs have already been loaded or they shouldn't be loaded. @@ -313,12 +313,13 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { } } -const gfx::Font* RecentTabsSubMenuModel::GetLabelFontAt(int index) const { +const gfx::FontList* RecentTabsSubMenuModel::GetLabelFontListAt( + int index) const { int command_id = GetCommandIdAt(index); if (command_id == kRecentlyClosedHeaderCommandId || IsDeviceNameCommandId(command_id)) { - return &ResourceBundle::GetSharedInstance().GetFont( - ResourceBundle::BoldFont); + return &ui::ResourceBundle::GetSharedInstance().GetFontList( + ui::ResourceBundle::BoldFont); } return NULL; } @@ -385,7 +386,7 @@ void RecentTabsSubMenuModel::BuildLocalEntries() { InsertItemWithStringIdAt(++last_local_model_index_, kRecentlyClosedHeaderCommandId, IDS_NEW_TAB_RECENTLY_CLOSED); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); SetIcon(last_local_model_index_, rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); @@ -527,7 +528,7 @@ void RecentTabsSubMenuModel::BuildLocalWindowItem( IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_MULTIPLE, base::IntToString16(num_tabs))); } - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); SetIcon(curr_model_index, rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); local_window_items_.push_back(window_id); } @@ -575,7 +576,7 @@ void RecentTabsSubMenuModel::AddDeviceFavicon( break; }; - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); SetIcon(index_in_menu, rb.GetNativeImageNamed(favicon_id)); } diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h index b4c102c..fea3ba9 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h @@ -61,7 +61,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, int command_id, ui::Accelerator* accelerator) OVERRIDE; virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; - virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE; + virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE; int GetMaxWidthForItemAtIndex(int item_index) const; bool GetURLAndTitleForItemAtIndex(int index, diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc index af65a87..0ed6ffc 100644 --- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc +++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc @@ -208,9 +208,9 @@ TEST_F(RecentTabsSubMenuModelTest, NoTabs) { EXPECT_FALSE(model.IsEnabledAt(2)); EXPECT_EQ(0, model.enable_count()); - EXPECT_EQ(NULL, model.GetLabelFontAt(0)); - EXPECT_EQ(NULL, model.GetLabelFontAt(1)); - EXPECT_EQ(NULL, model.GetLabelFontAt(2)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); std::string url; base::string16 title; @@ -249,11 +249,11 @@ TEST_F(RecentTabsSubMenuModelTest, RecentlyClosedTabsFromCurrentSession) { EXPECT_EQ(2, model.enable_count()); EXPECT_EQ(2, model.execute_count()); - EXPECT_TRUE(model.GetLabelFontAt(0) != NULL); - EXPECT_EQ(NULL, model.GetLabelFontAt(1)); - EXPECT_EQ(NULL, model.GetLabelFontAt(2)); - EXPECT_EQ(NULL, model.GetLabelFontAt(3)); - EXPECT_EQ(NULL, model.GetLabelFontAt(4)); + EXPECT_TRUE(model.GetLabelFontListAt(0) != NULL); + EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); std::string url; base::string16 title; @@ -359,12 +359,12 @@ TEST_F(RecentTabsSubMenuModelTest, EXPECT_EQ(3, model.enable_count()); EXPECT_EQ(3, model.execute_count()); - EXPECT_TRUE(model.GetLabelFontAt(0) != NULL); - EXPECT_EQ(NULL, model.GetLabelFontAt(1)); - EXPECT_EQ(NULL, model.GetLabelFontAt(2)); - EXPECT_EQ(NULL, model.GetLabelFontAt(3)); - EXPECT_EQ(NULL, model.GetLabelFontAt(4)); - EXPECT_EQ(NULL, model.GetLabelFontAt(5)); + EXPECT_TRUE(model.GetLabelFontListAt(0) != NULL); + EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(2)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); std::string url; base::string16 title; @@ -443,19 +443,19 @@ TEST_F(RecentTabsSubMenuModelTest, OtherDevices) { EXPECT_EQ(7, model.enable_count()); EXPECT_EQ(7, model.execute_count()); - EXPECT_EQ(NULL, model.GetLabelFontAt(0)); - EXPECT_EQ(NULL, model.GetLabelFontAt(1)); - EXPECT_TRUE(model.GetLabelFontAt(2) != NULL); - EXPECT_EQ(NULL, model.GetLabelFontAt(3)); - EXPECT_EQ(NULL, model.GetLabelFontAt(4)); - EXPECT_EQ(NULL, model.GetLabelFontAt(5)); - EXPECT_EQ(NULL, model.GetLabelFontAt(6)); - EXPECT_TRUE(model.GetLabelFontAt(7) != NULL); - EXPECT_EQ(NULL, model.GetLabelFontAt(8)); - EXPECT_EQ(NULL, model.GetLabelFontAt(9)); - EXPECT_EQ(NULL, model.GetLabelFontAt(10)); - EXPECT_EQ(NULL, model.GetLabelFontAt(11)); - EXPECT_EQ(NULL, model.GetLabelFontAt(12)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(0)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(1)); + EXPECT_TRUE(model.GetLabelFontListAt(2) != NULL); + EXPECT_EQ(NULL, model.GetLabelFontListAt(3)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(4)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(5)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(6)); + EXPECT_TRUE(model.GetLabelFontListAt(7) != NULL); + EXPECT_EQ(NULL, model.GetLabelFontListAt(8)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(9)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(10)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(11)); + EXPECT_EQ(NULL, model.GetLabelFontListAt(12)); std::string url; base::string16 title; diff --git a/chrome/browser/ui/views/toolbar/wrench_menu.cc b/chrome/browser/ui/views/toolbar/wrench_menu.cc index 561cb63..cb85839 100644 --- a/chrome/browser/ui/views/toolbar/wrench_menu.cc +++ b/chrome/browser/ui/views/toolbar/wrench_menu.cc @@ -407,7 +407,7 @@ class WrenchMenuView : public views::View, button->set_border( new MenuButtonBorder(menu_config, menu_->use_new_menu())); button->SetHorizontalAlignment(gfx::ALIGN_CENTER); - button->SetFontList(gfx::FontList(menu_config.font)); + button->SetFontList(menu_config.font_list); ui::NativeTheme* native_theme = button->GetNativeTheme(); button->SetTextColor( views::Button::STATE_DISABLED, @@ -628,7 +628,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView { const MenuConfig& menu_config(menu->GetMenuConfig()); zoom_label_->set_border( new MenuButtonBorder(menu_config, menu->use_new_menu())); - zoom_label_->SetFontList(gfx::FontList(menu_config.font)); + zoom_label_->SetFontList(menu_config.font_list); AddChildView(zoom_label_); zoom_label_width_ = MaxWidthForZoomLabel(); @@ -850,15 +850,15 @@ class WrenchMenu::RecentTabsMenuModelDelegate : public ui::MenuModelDelegate { kMaxMenuItemWidth : -1; } - const gfx::Font* GetLabelFontAt(int index) const { - return model_->GetLabelFontAt(index); + const gfx::FontList* GetLabelFontListAt(int index) const { + return model_->GetLabelFontListAt(index); } bool GetForegroundColorAt(int index, bool is_hovered, SkColor* override_color) const { - // The items for which we get a font, should be shown in black. - if (GetLabelFontAt(index)) { + // The items for which we get a font list, should be shown in black. + if (GetLabelFontListAt(index)) { *override_color = SK_ColorBLACK; return true; } @@ -1001,9 +1001,9 @@ void WrenchMenu::RemoveObserver(WrenchMenuObserver* observer) { observer_list_.RemoveObserver(observer); } -const gfx::Font* WrenchMenu::GetLabelFont(int command_id) const { +const gfx::FontList* WrenchMenu::GetLabelFontList(int command_id) const { if (IsRecentTabsCommand(command_id)) { - return recent_tabs_menu_model_delegate_->GetLabelFontAt( + return recent_tabs_menu_model_delegate_->GetLabelFontListAt( ModelIndexFromCommandId(command_id)); } return NULL; diff --git a/chrome/browser/ui/views/toolbar/wrench_menu.h b/chrome/browser/ui/views/toolbar/wrench_menu.h index 839994e..32da47b 100644 --- a/chrome/browser/ui/views/toolbar/wrench_menu.h +++ b/chrome/browser/ui/views/toolbar/wrench_menu.h @@ -59,7 +59,7 @@ class WrenchMenu : public views::MenuDelegate, void RemoveObserver(WrenchMenuObserver* observer); // MenuDelegate overrides: - virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; + virtual const gfx::FontList* GetLabelFontList(int command_id) const OVERRIDE; virtual bool GetForegroundColor(int command_id, bool is_hovered, SkColor* override_color) const OVERRIDE; diff --git a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc index 5076cc4..d40fab6 100644 --- a/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc +++ b/chrome/browser/ui/webui/chromeos/login/network_dropdown.cc @@ -16,7 +16,7 @@ #include "content/public/browser/web_ui.h" #include "ui/base/models/menu_model.h" #include "ui/base/webui/web_ui_util.h" -#include "ui/gfx/font.h" +#include "ui/gfx/font_list.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" @@ -96,10 +96,9 @@ base::ListValue* NetworkMenuWebUI::ConvertMenuModel(ui::MenuModel* model) { } if (id >= 0) { item->SetBoolean("enabled", model->IsEnabledAt(i)); - const gfx::Font* font = model->GetLabelFontAt(i); - if (font) { - item->SetBoolean("bold", font->GetStyle() == gfx::Font::BOLD); - } + const gfx::FontList* font_list = model->GetLabelFontListAt(i); + if (font_list) + item->SetBoolean("bold", font_list->GetFontStyle() == gfx::Font::BOLD); } if (type == ui::MenuModel::TYPE_SUBMENU) item->Set("sub", ConvertMenuModel(model->GetSubmenuModelAt(i))); diff --git a/ui/base/cocoa/menu_controller.mm b/ui/base/cocoa/menu_controller.mm index 8f03d0f..ad3ada5 100644 --- a/ui/base/cocoa/menu_controller.mm +++ b/ui/base/cocoa/menu_controller.mm @@ -179,10 +179,11 @@ model->GetIconAt(modelIndex, &icon); [(id)item setImage:icon.IsEmpty() ? nil : icon.ToNSImage()]; } - const gfx::Font* font = model->GetLabelFontAt(modelIndex); - if (font) { + const gfx::FontList* font_list = model->GetLabelFontListAt(modelIndex); + if (font_list) { NSDictionary *attributes = - [NSDictionary dictionaryWithObject:font->GetNativeFont() + [NSDictionary dictionaryWithObject:font_list->GetPrimaryFont(). + GetNativeFont() forKey:NSFontAttributeName]; base::scoped_nsobject<NSAttributedString> title( [[NSAttributedString alloc] initWithString:[(id)item title] diff --git a/ui/base/cocoa/menu_controller_unittest.mm b/ui/base/cocoa/menu_controller_unittest.mm index 9e54ee8..119685d 100644 --- a/ui/base/cocoa/menu_controller_unittest.mm +++ b/ui/base/cocoa/menu_controller_unittest.mm @@ -110,22 +110,23 @@ class DynamicDelegate : public Delegate { gfx::Image icon_; }; -// Menu model that returns a gfx::Font object for one of the items in the menu. -class FontMenuModel : public SimpleMenuModel { +// Menu model that returns a gfx::FontList object for one of the items in the +// menu. +class FontListMenuModel : public SimpleMenuModel { public: - FontMenuModel(SimpleMenuModel::Delegate* delegate, - const gfx::Font* font, int index) + FontListMenuModel(SimpleMenuModel::Delegate* delegate, + const gfx::FontList* font_list, int index) : SimpleMenuModel(delegate), - font_(font), + font_list_(font_list), index_(index) { } - virtual ~FontMenuModel() {} - virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE { - return (index == index_) ? font_ : NULL; + virtual ~FontListMenuModel() {} + virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE { + return (index == index_) ? font_list_ : NULL; } private: - const gfx::Font* font_; + const gfx::FontList* font_list_; const int index_; }; @@ -272,10 +273,11 @@ TEST_F(MenuControllerTest, Validate) { } // Tests that items which have a font set actually use that font. -TEST_F(MenuControllerTest, LabelFont) { +TEST_F(MenuControllerTest, LabelFontList) { Delegate delegate; - gfx::Font bold = (gfx::Font()).DeriveFont(0, gfx::Font::BOLD); - FontMenuModel model(&delegate, &bold, 0); + const gfx::FontList& bold = ResourceBundle::GetSharedInstance().GetFontList( + ResourceBundle::BoldFont); + FontListMenuModel model(&delegate, &bold, 0); model.AddItem(1, ASCIIToUTF16("one")); model.AddItem(2, ASCIIToUTF16("two")); diff --git a/ui/base/models/menu_model.cc b/ui/base/models/menu_model.cc index e88742e..1b5f6ab 100644 --- a/ui/base/models/menu_model.cc +++ b/ui/base/models/menu_model.cc @@ -40,7 +40,7 @@ base::string16 MenuModel::GetMinorTextAt(int index) const { return base::string16(); } -const gfx::Font* MenuModel::GetLabelFontAt(int index) const { +const gfx::FontList* MenuModel::GetLabelFontListAt(int index) const { return NULL; } diff --git a/ui/base/models/menu_model.h b/ui/base/models/menu_model.h index af40f6b..d0d3100 100644 --- a/ui/base/models/menu_model.h +++ b/ui/base/models/menu_model.h @@ -13,7 +13,7 @@ #include "ui/gfx/native_widget_types.h" namespace gfx { -class Font; +class FontList; class Image; } @@ -71,9 +71,9 @@ class UI_BASE_EXPORT MenuModel { // updated each time the menu is shown. virtual bool IsItemDynamicAt(int index) const = 0; - // Returns the font used for the label at the specified index. - // If NULL, then the default font should be used. - virtual const gfx::Font* GetLabelFontAt(int index) const; + // Returns the font list used for the label at the specified index. + // If NULL, then the default font list should be used. + virtual const gfx::FontList* GetLabelFontListAt(int index) const; // Gets the acclerator information for the specified index, returning true if // there is a shortcut accelerator for the item, false otherwise. diff --git a/ui/views/controls/menu/menu_config.h b/ui/views/controls/menu/menu_config.h index 96eb21a..fac60e8 100644 --- a/ui/views/controls/menu/menu_config.h +++ b/ui/views/controls/menu/menu_config.h @@ -6,7 +6,7 @@ #define UI_VIEWS_CONTROLS_MENU_MENU_CONFIG_H_ #include "third_party/skia/include/core/SkColor.h" -#include "ui/gfx/font.h" +#include "ui/gfx/font_list.h" #include "ui/views/views_export.h" namespace ui { @@ -23,8 +23,8 @@ struct VIEWS_EXPORT MenuConfig { static const MenuConfig& instance(const ui::NativeTheme* theme); - // Font used by menus. - gfx::Font font; + // Font list used by menus. + gfx::FontList font_list; // Normal text color. SkColor text_color; diff --git a/ui/views/controls/menu/menu_config_views.cc b/ui/views/controls/menu/menu_config_views.cc index d0b4844..005a7cb 100644 --- a/ui/views/controls/menu/menu_config_views.cc +++ b/ui/views/controls/menu/menu_config_views.cc @@ -43,7 +43,6 @@ void MenuConfig::InitAura(const ui::NativeTheme* theme) { separator_spacing_height = 7; separator_lower_height = 8; separator_upper_height = 8; - font = rb.GetFont(ResourceBundle::BaseFont); label_to_arrow_padding = 20; label_to_minor_text_padding = 20; always_use_icon_to_label_padding = true; diff --git a/ui/views/controls/menu/menu_config_win.cc b/ui/views/controls/menu/menu_config_win.cc index e0bde54..ab038a7 100644 --- a/ui/views/controls/menu/menu_config_win.cc +++ b/ui/views/controls/menu/menu_config_win.cc @@ -43,7 +43,7 @@ void MenuConfig::Init(const NativeTheme* theme) { { base::win::ScopedHFONT new_font(CreateFontIndirect(&metrics.lfMenuFont)); DLOG_ASSERT(new_font.Get()); - font = gfx::Font(new_font); + font_list = gfx::FontList(gfx::Font(new_font)); } NativeTheme::ExtraParams extra; extra.menu_check.is_radio = false; diff --git a/ui/views/controls/menu/menu_delegate.cc b/ui/views/controls/menu/menu_delegate.cc index 5e75915..920fd53 100644 --- a/ui/views/controls/menu/menu_delegate.cc +++ b/ui/views/controls/menu/menu_delegate.cc @@ -17,7 +17,7 @@ base::string16 MenuDelegate::GetLabel(int id) const { return base::string16(); } -const gfx::Font* MenuDelegate::GetLabelFont(int id) const { +const gfx::FontList* MenuDelegate::GetLabelFontList(int id) const { return NULL; } diff --git a/ui/views/controls/menu/menu_delegate.h b/ui/views/controls/menu/menu_delegate.h index 97ce185..e50ec8e 100644 --- a/ui/views/controls/menu/menu_delegate.h +++ b/ui/views/controls/menu/menu_delegate.h @@ -17,7 +17,7 @@ using ui::OSExchangeData; namespace gfx { -class Font; +class FontList; } namespace ui { @@ -64,7 +64,7 @@ class VIEWS_EXPORT MenuDelegate { virtual base::string16 GetLabel(int id) const; // The font for the menu item label. - virtual const gfx::Font* GetLabelFont(int id) const; + virtual const gfx::FontList* GetLabelFontList(int id) const; // Override the text color of a given menu item dependent on the // |command_id| and its |is_hovered| state. Returns true if it chooses to diff --git a/ui/views/controls/menu/menu_item_view.cc b/ui/views/controls/menu/menu_item_view.cc index 4cc6100..15e7db3 100644 --- a/ui/views/controls/menu/menu_item_view.cc +++ b/ui/views/controls/menu/menu_item_view.cc @@ -14,7 +14,10 @@ #include "ui/base/models/menu_model.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/text_utils.h" #include "ui/native_theme/common_theme.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/image_view.h" @@ -686,14 +689,14 @@ int MenuItemView::GetDrawStringFlags() { return flags; } -const gfx::Font& MenuItemView::GetFont() { +const gfx::FontList& MenuItemView::GetFontList() { const MenuDelegate* delegate = GetDelegate(); if (delegate) { - const gfx::Font* font = delegate->GetLabelFont(GetCommand()); - if (font) - return *font; + const gfx::FontList* font_list = delegate->GetLabelFontList(GetCommand()); + if (font_list) + return *font_list; } - return GetMenuConfig().font; + return GetMenuConfig().font_list; } void MenuItemView::AddEmptyMenus() { @@ -803,7 +806,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { &override_foreground_color)) fg_color = override_foreground_color; - const gfx::Font& font = GetFont(); + const gfx::FontList& font_list = GetFontList(); int accel_width = parent_menu_item_->GetSubmenu()->max_minor_text_width(); int label_start = GetLabelStartForThisItem(); @@ -818,19 +821,15 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { int flags = GetDrawStringFlags(); if (mode == PB_FOR_DRAG) flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; - canvas->DrawStringInt(title(), font, fg_color, - text_bounds.x(), text_bounds.y(), text_bounds.width(), - text_bounds.height(), flags); + canvas->DrawStringRectWithFlags(title(), font_list, fg_color, text_bounds, + flags); if (!subtitle_.empty()) { - canvas->DrawStringInt( + canvas->DrawStringRectWithFlags( subtitle_, - font, + font_list, GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_ButtonDisabledColor), - text_bounds.x(), - text_bounds.y() + GetFont().GetHeight(), - text_bounds.width(), - text_bounds.height(), + text_bounds + gfx::Vector2d(0, font_list.GetHeight()), flags); } @@ -855,7 +854,6 @@ void MenuItemView::PaintMinorText(gfx::Canvas* canvas, if (minor_text.empty()) return; - const gfx::Font& font = GetFont(); int available_height = height() - GetTopMargin() - GetBottomMargin(); int max_accel_width = parent_menu_item_->GetSubmenu()->max_minor_text_width(); @@ -871,16 +869,13 @@ void MenuItemView::PaintMinorText(gfx::Canvas* canvas, flags |= gfx::Canvas::TEXT_ALIGN_LEFT; else flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; - canvas->DrawStringInt( + canvas->DrawStringRectWithFlags( minor_text, - font, + GetFontList(), GetNativeTheme()->GetSystemColor(render_selection ? ui::NativeTheme::kColorId_SelectedMenuItemForegroundColor : ui::NativeTheme::kColorId_ButtonDisabledColor), - accel_bounds.x(), - accel_bounds.y(), - accel_bounds.width(), - accel_bounds.height(), + accel_bounds, flags); } @@ -962,7 +957,7 @@ MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() { return dimensions; // Determine the length of the label text. - const gfx::Font& font = GetFont(); + const gfx::FontList& font_list = GetFontList(); // Get Icon margin overrides for this particular item. const MenuDelegate* delegate = GetDelegate(); @@ -977,23 +972,26 @@ MenuItemView::MenuItemDimensions MenuItemView::CalculateDimensions() { } int label_start = GetLabelStartForThisItem(); - int string_width = font.GetStringWidth(title_); - if (!subtitle_.empty()) - string_width = std::max(string_width, font.GetStringWidth(subtitle_)); + int string_width = gfx::GetStringWidth(title_, font_list); + if (!subtitle_.empty()) { + string_width = std::max(string_width, + gfx::GetStringWidth(subtitle_, font_list)); + } dimensions.standard_width = string_width + label_start + item_right_margin_; // Determine the length of the right-side text. base::string16 minor_text = GetMinorText(); dimensions.minor_text_width = - minor_text.empty() ? 0 : GetFont().GetStringWidth(minor_text); + minor_text.empty() ? 0 : gfx::GetStringWidth(minor_text, font_list); // Determine the height to use. + dimensions.height = + std::max(dimensions.height, + (subtitle_.empty() ? 0 : font_list.GetHeight()) + + font_list.GetHeight() + GetBottomMargin() + GetTopMargin()); dimensions.height = std::max(dimensions.height, - (subtitle_.empty() ? 0 : font.GetHeight()) + - font.GetHeight() + GetBottomMargin() + GetTopMargin()); - dimensions.height = std::max(dimensions.height, - GetMenuConfig().item_min_height); + GetMenuConfig().item_min_height); return dimensions; } diff --git a/ui/views/controls/menu/menu_item_view.h b/ui/views/controls/menu/menu_item_view.h index 3dcb70e..61fbf0f 100644 --- a/ui/views/controls/menu/menu_item_view.h +++ b/ui/views/controls/menu/menu_item_view.h @@ -24,7 +24,7 @@ #endif namespace gfx { -class Font; +class FontList; } namespace views { @@ -375,8 +375,8 @@ class VIEWS_EXPORT MenuItemView : public View { // Returns the flags passed to DrawStringInt. int GetDrawStringFlags(); - // Returns the font to use for menu text. - const gfx::Font& GetFont(); + // Returns the font list to use for menu text. + const gfx::FontList& GetFontList(); // If this menu item has no children a child is added showing it has no // children. Otherwise AddEmtpyMenus is recursively invoked on child menu diff --git a/ui/views/controls/menu/menu_model_adapter.cc b/ui/views/controls/menu/menu_model_adapter.cc index 6b29e7e..fb6ea6a 100644 --- a/ui/views/controls/menu/menu_model_adapter.cc +++ b/ui/views/controls/menu/menu_model_adapter.cc @@ -181,17 +181,17 @@ base::string16 MenuModelAdapter::GetLabel(int id) const { return base::string16(); } -const gfx::Font* MenuModelAdapter::GetLabelFont(int id) const { +const gfx::FontList* MenuModelAdapter::GetLabelFontList(int id) const { ui::MenuModel* model = menu_model_; int index = 0; if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) { - const gfx::Font* font = model->GetLabelFontAt(index); - if (font) - return font; + const gfx::FontList* font_list = model->GetLabelFontListAt(index); + if (font_list) + return font_list; } // This line may be reached for the empty menu item. - return MenuDelegate::GetLabelFont(id); + return MenuDelegate::GetLabelFontList(id); } bool MenuModelAdapter::IsCommandEnabled(int id) const { diff --git a/ui/views/controls/menu/menu_model_adapter.h b/ui/views/controls/menu/menu_model_adapter.h index f8f6e19..644864d 100644 --- a/ui/views/controls/menu/menu_model_adapter.h +++ b/ui/views/controls/menu/menu_model_adapter.h @@ -69,7 +69,7 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate { virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; virtual base::string16 GetLabel(int id) const OVERRIDE; - virtual const gfx::Font* GetLabelFont(int id) const OVERRIDE; + virtual const gfx::FontList* GetLabelFontList(int id) const OVERRIDE; virtual bool IsCommandEnabled(int id) const OVERRIDE; virtual bool IsItemChecked(int id) const OVERRIDE; virtual void SelectionChanged(MenuItemView* menu) OVERRIDE; diff --git a/ui/views/controls/menu/menu_model_adapter_unittest.cc b/ui/views/controls/menu/menu_model_adapter_unittest.cc index b17f3f0..cba4d2f 100644 --- a/ui/views/controls/menu/menu_model_adapter_unittest.cc +++ b/ui/views/controls/menu/menu_model_adapter_unittest.cc @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ui/views/controls/menu/menu_model_adapter.h" + #include "base/strings/utf_string_conversions.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model_delegate.h" #include "ui/views/controls/menu/menu_item_view.h" -#include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/menu/submenu_view.h" #include "ui/views/test/views_test_base.h" @@ -59,7 +60,7 @@ class MenuModelBase : public ui::MenuModel { return false; } - virtual const gfx::Font* GetLabelFontAt(int index) const OVERRIDE { + virtual const gfx::FontList* GetLabelFontListAt(int index) const OVERRIDE { return NULL; } |