OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "views/controls/menu/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <Vssym32.h> | 9 #include <Vssym32.h> |
10 | 10 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "gfx/canvas.h" | 12 #include "gfx/canvas.h" |
13 #include "gfx/native_theme_win.h" | 13 #include "gfx/native_theme_win.h" |
14 #include "grit/app_strings.h" | 14 #include "grit/app_strings.h" |
15 #include "views/controls/menu/menu_config.h" | 15 #include "views/controls/menu/menu_config.h" |
16 #include "views/controls/menu/submenu_view.h" | 16 #include "views/controls/menu/submenu_view.h" |
17 | 17 |
18 using gfx::NativeTheme; | 18 using gfx::NativeTheme; |
19 | 19 |
20 namespace views { | 20 namespace views { |
21 | 21 |
22 gfx::Size MenuItemView::GetPreferredSize() { | 22 gfx::Size MenuItemView::GetPreferredSize() { |
23 const gfx::Font& font = MenuConfig::instance().font; | 23 const gfx::Font& font = MenuConfig::instance().font; |
24 return gfx::Size( | 24 return gfx::Size( |
25 font.GetStringWidth(title_) + label_start_ + item_right_margin_, | 25 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + |
| 26 GetChildPreferredWidth(), |
26 font.height() + GetBottomMargin() + GetTopMargin()); | 27 font.height() + GetBottomMargin() + GetTopMargin()); |
27 } | 28 } |
28 | 29 |
29 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { | 30 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { |
30 const MenuConfig& config = MenuConfig::instance(); | 31 const MenuConfig& config = MenuConfig::instance(); |
31 bool render_selection = | 32 bool render_selection = |
32 (!for_drag && IsSelected() && | 33 (!for_drag && IsSelected() && |
33 parent_menu_item_->GetSubmenu()->GetShowSelection(this)); | 34 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 35 GetChildViewCount() == 0); |
34 int state = render_selection ? MPI_HOT : | 36 int state = render_selection ? MPI_HOT : |
35 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); | 37 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); |
36 HDC dc = canvas->beginPlatformPaint(); | 38 HDC dc = canvas->beginPlatformPaint(); |
37 | 39 |
38 // The gutter is rendered before the background. | 40 // The gutter is rendered before the background. |
39 if (config.render_gutter && !for_drag) { | 41 if (config.render_gutter && !for_drag) { |
40 gfx::Rect gutter_bounds(label_start_ - config.gutter_to_label - | 42 gfx::Rect gutter_bounds(label_start_ - config.gutter_to_label - |
41 config.gutter_width, 0, config.gutter_width, | 43 config.gutter_width, 0, config.gutter_width, |
42 height()); | 44 height()); |
43 AdjustBoundsForRTLUI(&gutter_bounds); | 45 AdjustBoundsForRTLUI(&gutter_bounds); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 89 |
88 // Render the foreground. | 90 // Render the foreground. |
89 // Menu color is specific to Vista, fallback to classic colors if can't | 91 // Menu color is specific to Vista, fallback to classic colors if can't |
90 // get color. | 92 // get color. |
91 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : | 93 int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT : |
92 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); | 94 (IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT); |
93 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( | 95 SkColor fg_color = NativeTheme::instance()->GetThemeColorWithDefault( |
94 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, | 96 NativeTheme::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR, |
95 default_sys_color); | 97 default_sys_color); |
96 int width = this->width() - item_right_margin_ - label_start_; | 98 int width = this->width() - item_right_margin_ - label_start_; |
97 const gfx::Font& font = MenuConfig::instance().font; | 99 const gfx::Font& font = GetChildViewCount() > 0 ? |
| 100 MenuConfig::instance().font_with_controls : MenuConfig::instance().font; |
98 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); | 101 gfx::Rect text_bounds(label_start_, top_margin, width, font.height()); |
99 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 102 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
100 if (for_drag) { | 103 if (for_drag) { |
101 // With different themes, it's difficult to tell what the correct | 104 // With different themes, it's difficult to tell what the correct |
102 // foreground and background colors are for the text to draw the correct | 105 // foreground and background colors are for the text to draw the correct |
103 // halo. Instead, just draw black on white, which will look good in most | 106 // halo. Instead, just draw black on white, which will look good in most |
104 // cases. | 107 // cases. |
105 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, | 108 canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF, |
106 text_bounds.x(), text_bounds.y(), | 109 text_bounds.x(), text_bounds.y(), |
107 text_bounds.width(), text_bounds.height(), | 110 text_bounds.width(), text_bounds.height(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 144 |
142 RECT arrow_rect = arrow_bounds.ToRECT(); | 145 RECT arrow_rect = arrow_bounds.ToRECT(); |
143 NativeTheme::instance()->PaintMenuArrow( | 146 NativeTheme::instance()->PaintMenuArrow( |
144 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, | 147 NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect, |
145 arrow_direction, render_selection); | 148 arrow_direction, render_selection); |
146 } | 149 } |
147 canvas->endPlatformPaint(); | 150 canvas->endPlatformPaint(); |
148 } | 151 } |
149 | 152 |
150 } // namespace views | 153 } // namespace views |
OLD | NEW |