diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-13 20:21:58 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-13 20:21:58 +0000 |
commit | 3803088091ca375b9dc4896ec5a3c85c5e99cbea (patch) | |
tree | 4a4c3b60eccae52d0dcb02f8d726663cc61c5920 | |
parent | 760d03d9bdf2b69e9f526869a5513fbcae80017e (diff) | |
download | chromium_src-3803088091ca375b9dc4896ec5a3c85c5e99cbea.zip chromium_src-3803088091ca375b9dc4896ec5a3c85c5e99cbea.tar.gz chromium_src-3803088091ca375b9dc4896ec5a3c85c5e99cbea.tar.bz2 |
Puts chrome menus on a slimfast diet: they are no longer chubby. I
added an option such that menus can be rendered in two ways, chubby or
skinny. The only places that uses the taller menus is the bookmark
bar.
I also made the menus use the right font.
BUG=1074332
TEST=none
Review URL: http://codereview.chromium.org/10865
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5367 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 1 | ||||
-rw-r--r-- | chrome/views/chrome_menu.cc | 66 | ||||
-rw-r--r-- | chrome/views/chrome_menu.h | 12 |
3 files changed, 65 insertions, 14 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index a5f6fdf..49e758d6 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -364,6 +364,7 @@ class MenuRunner : public views::MenuDelegate, menu_(this) { int next_menu_id = 1; menu_id_to_node_map_[menu_.GetCommand()] = node; + menu_.set_has_icons(true); BuildMenu(node, start_child_index, &menu_, &next_menu_id); } diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc index 275a5c7..959c442 100644 --- a/chrome/views/chrome_menu.cc +++ b/chrome/views/chrome_menu.cc @@ -38,6 +38,10 @@ static const int kItemTopMargin = 3; // Margins between the bottom of the item and the label. static const int kItemBottomMargin = 4; +// Margins used if the menu doesn't have icons. +static const int kItemNoIconTopMargin = 1; +static const int kItemNoIconBottomMargin = 3; + // Margins between the left of the item and the icon. static const int kItemLeftMargin = 4; @@ -117,10 +121,22 @@ using gfx::NativeTheme; namespace views { +namespace { + +// Returns the font menus are to use. +ChromeFont GetMenuFont() { + NONCLIENTMETRICS metrics; + win_util::GetNonClientMetrics(&metrics); + + HFONT font = CreateFontIndirect(&metrics.lfMenuFont); + DLOG_ASSERT(font); + return ChromeFont::CreateFont(font); +} + // Calculates all sizes that we can from the OS. // // This is invoked prior to Running a menu. -void UpdateMenuPartSizes() { +void UpdateMenuPartSizes(bool has_icons) { HDC dc = GetDC(NULL); RECT bounds = { 0, 0, 200, 200 }; SIZE check_size; @@ -168,7 +184,13 @@ void UpdateMenuPartSizes() { item_right_margin = kLabelToArrowPadding + arrow_width + kArrowToEdgePadding; - label_start = kItemLeftMargin + check_width + kIconToLabelPadding; + if (has_icons) { + label_start = kItemLeftMargin + check_width + kIconToLabelPadding; + } else { + // If there are no icons don't pad by the icon to label padding. This + // makes us look close to system menus. + label_start = kItemLeftMargin + check_width; + } if (render_gutter) label_start += gutter_width + kGutterToLabel; @@ -179,8 +201,6 @@ void UpdateMenuPartSizes() { pref_menu_height = menu_item.GetPreferredSize().height(); } -namespace { - // Convenience for scrolling the view such that the origin is visible. static void ScrollToVisible(View* view) { view->ScrollRectToVisible(0, 0, view->width(), view->height()); @@ -1167,9 +1187,10 @@ void MenuItemView::Paint(ChromeCanvas* canvas) { } gfx::Size MenuItemView::GetPreferredSize() { + ChromeFont& font = GetRootMenuItem()->font_; return gfx::Size( - font_.GetStringWidth(title_) + label_start + item_right_margin, - font_.height() + kItemBottomMargin + kItemTopMargin); + font.GetStringWidth(title_) + label_start + item_right_margin, + font.height() + GetBottomMargin() + GetTopMargin()); } MenuController* MenuItemView::GetMenuController() { @@ -1229,6 +1250,7 @@ void MenuItemView::Init(MenuItemView* parent, submenu_ = NULL; // Assign our ID, this allows SubmenuItemView to find MenuItemViews. SetID(kMenuItemViewID); + has_icons_ = false; MenuDelegate* root_delegate = GetDelegate(); if (root_delegate) @@ -1307,7 +1329,9 @@ void MenuItemView::PrepareForRun(bool has_mnemonics) { AddEmptyMenus(); - UpdateMenuPartSizes(); + UpdateMenuPartSizes(has_icons_); + + font_ = GetMenuFont(); BOOL show_cues; show_mnemonics = @@ -1394,8 +1418,10 @@ void MenuItemView::Paint(ChromeCanvas* canvas, bool for_drag) { } int icon_x = kItemLeftMargin; - int icon_y = kItemTopMargin + (height() - kItemTopMargin - - kItemBottomMargin - check_height) / 2; + int top_margin = GetTopMargin(); + int bottom_margin = GetBottomMargin(); + int icon_y = top_margin + (height() - kItemTopMargin - + bottom_margin - check_height) / 2; int icon_height = check_height; int icon_width = check_width; @@ -1427,17 +1453,18 @@ void MenuItemView::Paint(ChromeCanvas* canvas, bool for_drag) { SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, default_sys_color); int width = this->width() - item_right_margin - label_start; - gfx::Rect text_bounds(label_start, kItemTopMargin, width, font_.height()); + ChromeFont& font = GetRootMenuItem()->font_; + gfx::Rect text_bounds(label_start, top_margin, width, font.height()); text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); - canvas->DrawStringInt(GetTitle(), font_, fg_color, text_bounds.x(), - text_bounds.y(), text_bounds.width(), + canvas->DrawStringInt(GetTitle(), font, fg_color, + text_bounds.x(), text_bounds.y(), text_bounds.width(), text_bounds.height(), GetRootMenuItem()->GetDrawStringFlags()); if (icon_.width() > 0) { gfx::Rect icon_bounds(kItemLeftMargin, - kItemTopMargin + (height() - kItemTopMargin - - kItemBottomMargin - icon_.height()) / 2, + top_margin + (height() - top_margin - + bottom_margin - icon_.height()) / 2, icon_.width(), icon_.height()); icon_bounds.set_x(MirroredLeftPointForRect(icon_bounds)); @@ -1478,6 +1505,17 @@ void MenuItemView::DestroyAllMenuHosts() { } } +int MenuItemView::GetTopMargin() { + MenuItemView* root = GetRootMenuItem(); + return root && root->has_icons_ ? kItemTopMargin : kItemNoIconTopMargin; +} + +int MenuItemView::GetBottomMargin() { + MenuItemView* root = GetRootMenuItem(); + return root && root->has_icons_ ? + kItemBottomMargin : kItemNoIconBottomMargin; +} + // MenuController ------------------------------------------------------------ // static diff --git a/chrome/views/chrome_menu.h b/chrome/views/chrome_menu.h index e1ed347..ec31e35 100644 --- a/chrome/views/chrome_menu.h +++ b/chrome/views/chrome_menu.h @@ -368,6 +368,12 @@ class MenuItemView : public View { // doesn't have a mnemonic. wchar_t GetMnemonic(); + // Do we have icons? This only has effect on the top menu. Turning this on + // makes the menus slightly wider and taller. + void set_has_icons(bool has_icons) { + has_icons_ = has_icons; + } + protected: // Creates a MenuItemView. This is used by the various AddXXX methods. MenuItemView(MenuItemView* parent, int command, Type type); @@ -419,6 +425,10 @@ class MenuItemView : public View { // the windows used to display all descendants. void DestroyAllMenuHosts(); + // Returns the various margins. + int GetTopMargin(); + int GetBottomMargin(); + // The delegate. This is only valid for the root menu item. You shouldn't // use this directly, instead use GetDelegate() which walks the tree as // as necessary. @@ -459,6 +469,8 @@ class MenuItemView : public View { // Does the title have a mnemonic? bool has_mnemonics_; + bool has_icons_; + DISALLOW_EVIL_CONSTRUCTORS(MenuItemView); }; |