OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "gfx/canvas.h" | 8 #include "gfx/canvas.h" |
9 #include "gfx/favicon_size.h" | 9 #include "gfx/favicon_size.h" |
10 #include "grit/app_resources.h" | 10 #include "grit/app_resources.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); | 21 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); |
22 #endif | 22 #endif |
23 | 23 |
24 gfx::Size MenuItemView::GetPreferredSize() { | 24 gfx::Size MenuItemView::GetPreferredSize() { |
25 const gfx::Font& font = MenuConfig::instance().font; | 25 const gfx::Font& font = MenuConfig::instance().font; |
26 // TODO(sky): this is a workaround until I figure out why font.height() | 26 // TODO(sky): this is a workaround until I figure out why font.height() |
27 // isn't returning the right thing. We really only want to include | 27 // isn't returning the right thing. We really only want to include |
28 // kFavIconSize if we're showing icons. | 28 // kFavIconSize if we're showing icons. |
29 int content_height = std::max(kFavIconSize, font.height()); | 29 int content_height = std::max(kFavIconSize, font.height()); |
30 return gfx::Size( | 30 return gfx::Size( |
31 font.GetStringWidth(title_) + label_start_ + item_right_margin_, | 31 font.GetStringWidth(title_) + label_start_ + item_right_margin_ + |
| 32 GetChildPreferredWidth(), |
32 content_height + GetBottomMargin() + GetTopMargin()); | 33 content_height + GetBottomMargin() + GetTopMargin()); |
33 } | 34 } |
34 | 35 |
35 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { | 36 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { |
36 const MenuConfig& config = MenuConfig::instance(); | 37 const MenuConfig& config = MenuConfig::instance(); |
37 bool render_selection = | 38 bool render_selection = |
38 (!for_drag && IsSelected() && | 39 (!for_drag && IsSelected() && |
39 parent_menu_item_->GetSubmenu()->GetShowSelection(this)); | 40 parent_menu_item_->GetSubmenu()->GetShowSelection(this) && |
| 41 GetChildViewCount() == 0); |
40 | 42 |
41 int icon_x = config.item_left_margin; | 43 int icon_x = config.item_left_margin; |
42 int top_margin = GetTopMargin(); | 44 int top_margin = GetTopMargin(); |
43 int bottom_margin = GetBottomMargin(); | 45 int bottom_margin = GetBottomMargin(); |
44 int icon_y = top_margin + (height() - config.item_top_margin - | 46 int icon_y = top_margin + (height() - config.item_top_margin - |
45 bottom_margin - config.check_height) / 2; | 47 bottom_margin - config.check_height) / 2; |
46 int icon_height = config.check_height; | 48 int icon_height = config.check_height; |
47 int available_height = height() - top_margin - bottom_margin; | 49 int available_height = height() - top_margin - bottom_margin; |
48 | 50 |
49 // Render the background. As MenuScrollViewContainer draws the background, we | 51 // Render the background. As MenuScrollViewContainer draws the background, we |
(...skipping 14 matching lines...) Expand all Loading... |
64 | 66 |
65 // Render the foreground. | 67 // Render the foreground. |
66 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
67 SkColor fg_color = | 69 SkColor fg_color = |
68 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); | 70 IsEnabled() ? SK_ColorBLACK : SkColorSetRGB(0x80, 0x80, 0x80); |
69 #else | 71 #else |
70 SkColor fg_color = | 72 SkColor fg_color = |
71 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; | 73 IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; |
72 #endif | 74 #endif |
73 int width = this->width() - item_right_margin_ - label_start_; | 75 int width = this->width() - item_right_margin_ - label_start_; |
74 const gfx::Font& font = MenuConfig::instance().font; | 76 const gfx::Font& font = GetChildViewCount() > 0 ? |
| 77 MenuConfig::instance().font_with_controls : MenuConfig::instance().font; |
75 gfx::Rect text_bounds(label_start_, top_margin + | 78 gfx::Rect text_bounds(label_start_, top_margin + |
76 (available_height - font.height()) / 2, width, | 79 (available_height - font.height()) / 2, width, |
77 font.height()); | 80 font.height()); |
78 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 81 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
79 canvas->DrawStringInt(GetTitle(), font, fg_color, | 82 canvas->DrawStringInt(GetTitle(), font, fg_color, |
80 text_bounds.x(), text_bounds.y(), text_bounds.width(), | 83 text_bounds.x(), text_bounds.y(), text_bounds.width(), |
81 text_bounds.height(), | 84 text_bounds.height(), |
82 GetRootMenuItem()->GetDrawStringFlags()); | 85 GetRootMenuItem()->GetDrawStringFlags()); |
83 | 86 |
84 // Render the icon. | 87 // Render the icon. |
(...skipping 15 matching lines...) Expand all Loading... |
100 config.arrow_width) / 2, | 103 config.arrow_width) / 2, |
101 config.arrow_width, height()); | 104 config.arrow_width, height()); |
102 AdjustBoundsForRTLUI(&arrow_bounds); | 105 AdjustBoundsForRTLUI(&arrow_bounds); |
103 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 106 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
104 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), | 107 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), |
105 arrow_bounds.x(), arrow_bounds.y()); | 108 arrow_bounds.x(), arrow_bounds.y()); |
106 } | 109 } |
107 } | 110 } |
108 | 111 |
109 } // namespace views | 112 } // namespace views |
OLD | NEW |