OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA); | 22 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xDC, 0xE4, 0xFA); |
23 #else | 23 #else |
24 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); | 24 static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); |
25 #endif | 25 #endif |
26 | 26 |
27 #if defined(TOUCH_UI) | 27 #if defined(TOUCH_UI) |
28 const int kMinTouchHeight = 46; | 28 const int kMinTouchHeight = 46; |
29 #endif | 29 #endif |
30 | 30 |
31 gfx::Size MenuItemView::CalculatePreferredSize() { | 31 gfx::Size MenuItemView::CalculatePreferredSize() { |
| 32 gfx::Size child_size = GetChildPreferredSize(); |
| 33 if (child_count() == 1 && title_.size() == 0) { |
| 34 return gfx::Size( |
| 35 child_size.width(), |
| 36 child_size.height() + GetBottomMargin() + GetTopMargin()); |
| 37 } |
| 38 |
32 const gfx::Font& font = GetFont(); | 39 const gfx::Font& font = GetFont(); |
33 #if defined(TOUCH_UI) | 40 #if defined(TOUCH_UI) |
34 int height = std::max(font.GetHeight(), kMinTouchHeight); | 41 int height = std::max(font.GetHeight(), kMinTouchHeight); |
35 #else | 42 #else |
36 int height = font.GetHeight(); | 43 int height = font.GetHeight(); |
37 #endif | 44 #endif |
38 gfx::Size child_size = GetChildPreferredSize(); | |
39 return gfx::Size( | 45 return gfx::Size( |
40 font.GetStringWidth(title_) + label_start_ + | 46 font.GetStringWidth(title_) + label_start_ + |
41 item_right_margin_ + child_size.width(), | 47 item_right_margin_ + child_size.width(), |
42 std::max(height, child_size.height()) + GetBottomMargin() + | 48 std::max(height, child_size.height()) + GetBottomMargin() + |
43 GetTopMargin()); | 49 GetTopMargin()); |
44 } | 50 } |
45 | 51 |
46 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { | 52 void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { |
47 const MenuConfig& config = MenuConfig::instance(); | 53 const MenuConfig& config = MenuConfig::instance(); |
48 bool render_selection = | 54 bool render_selection = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 top_margin + (available_height - | 132 top_margin + (available_height - |
127 config.arrow_width) / 2, | 133 config.arrow_width) / 2, |
128 config.arrow_width, height()); | 134 config.arrow_width, height()); |
129 AdjustBoundsForRTLUI(&arrow_bounds); | 135 AdjustBoundsForRTLUI(&arrow_bounds); |
130 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), | 136 canvas->DrawBitmapInt(*GetSubmenuArrowImage(), |
131 arrow_bounds.x(), arrow_bounds.y()); | 137 arrow_bounds.x(), arrow_bounds.y()); |
132 } | 138 } |
133 } | 139 } |
134 | 140 |
135 } // namespace views | 141 } // namespace views |
OLD | NEW |