| 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/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); | 49 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 // Padding between child views. | 54 // Padding between child views. |
| 55 static const int kChildXPadding = 8; | 55 static const int kChildXPadding = 8; |
| 56 | 56 |
| 57 #if defined(TOUCH_UI) | |
| 58 const int kMinItemHeightTouch = 40; | |
| 59 #endif | |
| 60 | |
| 61 // MenuItemView --------------------------------------------------------------- | 57 // MenuItemView --------------------------------------------------------------- |
| 62 | 58 |
| 63 // static | 59 // static |
| 64 const int MenuItemView::kMenuItemViewID = 1001; | 60 const int MenuItemView::kMenuItemViewID = 1001; |
| 65 | 61 |
| 66 // static | 62 // static |
| 67 const int MenuItemView::kEmptyMenuItemViewID = | 63 const int MenuItemView::kEmptyMenuItemViewID = |
| 68 MenuItemView::kMenuItemViewID + 1; | 64 MenuItemView::kMenuItemViewID + 1; |
| 69 | 65 |
| 70 // static | 66 // static |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 | 739 |
| 744 gfx::Size MenuItemView::CalculatePreferredSize() { | 740 gfx::Size MenuItemView::CalculatePreferredSize() { |
| 745 gfx::Size child_size = GetChildPreferredSize(); | 741 gfx::Size child_size = GetChildPreferredSize(); |
| 746 if (IsContainer()) { | 742 if (IsContainer()) { |
| 747 return gfx::Size( | 743 return gfx::Size( |
| 748 child_size.width(), | 744 child_size.width(), |
| 749 child_size.height() + GetBottomMargin() + GetTopMargin()); | 745 child_size.height() + GetBottomMargin() + GetTopMargin()); |
| 750 } | 746 } |
| 751 | 747 |
| 752 const gfx::Font& font = GetFont(); | 748 const gfx::Font& font = GetFont(); |
| 753 #if defined(TOUCH_UI) | |
| 754 int height = std::max(font.GetHeight(), kMinItemHeightTouch); | |
| 755 #else | |
| 756 int height = font.GetHeight(); | 749 int height = font.GetHeight(); |
| 757 #endif | |
| 758 return gfx::Size( | 750 return gfx::Size( |
| 759 font.GetStringWidth(title_) + label_start_ + | 751 font.GetStringWidth(title_) + label_start_ + |
| 760 item_right_margin_ + child_size.width(), | 752 item_right_margin_ + child_size.width(), |
| 761 std::max(height, child_size.height()) + GetBottomMargin() + | 753 std::max(height, child_size.height()) + GetBottomMargin() + |
| 762 GetTopMargin()); | 754 GetTopMargin()); |
| 763 } | 755 } |
| 764 | 756 |
| 765 string16 MenuItemView::GetAcceleratorText() { | 757 string16 MenuItemView::GetAcceleratorText() { |
| 766 if (id() == kEmptyMenuItemViewID) { | 758 if (id() == kEmptyMenuItemViewID) { |
| 767 // Don't query the delegate for menus that represent no children. | 759 // Don't query the delegate for menus that represent no children. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 778 } | 770 } |
| 779 | 771 |
| 780 bool MenuItemView::IsContainer() const { | 772 bool MenuItemView::IsContainer() const { |
| 781 // Let the first child take over |this| when we only have one child and no | 773 // Let the first child take over |this| when we only have one child and no |
| 782 // title. Note that what child_count() returns is the number of children, | 774 // title. Note that what child_count() returns is the number of children, |
| 783 // not the number of menu items. | 775 // not the number of menu items. |
| 784 return child_count() == 1 && title_.empty(); | 776 return child_count() == 1 && title_.empty(); |
| 785 } | 777 } |
| 786 | 778 |
| 787 } // namespace views | 779 } // namespace views |
| OLD | NEW |