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-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "grit/app_strings.h" | 10 #include "grit/app_strings.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // EmptyMenuMenuItem --------------------------------------------------------- | 30 // EmptyMenuMenuItem --------------------------------------------------------- |
31 | 31 |
32 // EmptyMenuMenuItem is used when a menu has no menu items. EmptyMenuMenuItem | 32 // EmptyMenuMenuItem is used when a menu has no menu items. EmptyMenuMenuItem |
33 // is itself a MenuItemView, but it uses a different ID so that it isn't | 33 // is itself a MenuItemView, but it uses a different ID so that it isn't |
34 // identified as a MenuItemView. | 34 // identified as a MenuItemView. |
35 | 35 |
36 class EmptyMenuMenuItem : public MenuItemView { | 36 class EmptyMenuMenuItem : public MenuItemView { |
37 public: | 37 public: |
38 explicit EmptyMenuMenuItem(MenuItemView* parent) | 38 explicit EmptyMenuMenuItem(MenuItemView* parent) |
39 : MenuItemView(parent, 0, NORMAL) { | 39 : MenuItemView(parent, 0, NORMAL) { |
| 40 // Set this so that we're not identified as a normal menu item. |
| 41 SetID(kEmptyMenuItemViewID); |
40 SetTitle(UTF16ToWide( | 42 SetTitle(UTF16ToWide( |
41 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU))); | 43 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU))); |
42 // Set this so that we're not identified as a normal menu item. | |
43 SetID(kEmptyMenuItemViewID); | |
44 SetEnabled(false); | 44 SetEnabled(false); |
45 } | 45 } |
46 | 46 |
47 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { | 47 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { |
48 // Empty menu items shouldn't have a tooltip. | 48 // Empty menu items shouldn't have a tooltip. |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 private: | 52 private: |
53 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); | 53 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 int width = 0; | 731 int width = 0; |
732 for (int i = 0; i < child_count(); ++i) { | 732 for (int i = 0; i < child_count(); ++i) { |
733 if (i) | 733 if (i) |
734 width += kChildXPadding; | 734 width += kChildXPadding; |
735 width += GetChildViewAt(i)->GetPreferredSize().width(); | 735 width += GetChildViewAt(i)->GetPreferredSize().width(); |
736 } | 736 } |
737 return width; | 737 return width; |
738 } | 738 } |
739 | 739 |
740 string16 MenuItemView::GetAcceleratorText() { | 740 string16 MenuItemView::GetAcceleratorText() { |
| 741 if (GetID() == kEmptyMenuItemViewID) { |
| 742 // Don't query the delegate for menus that represent no children. |
| 743 return string16(); |
| 744 } |
| 745 |
741 Accelerator accelerator; | 746 Accelerator accelerator; |
742 return (GetDelegate() && | 747 return (GetDelegate() && |
743 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 748 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? |
744 accelerator.GetShortcutText() : string16(); | 749 accelerator.GetShortcutText() : string16(); |
745 } | 750 } |
746 | 751 |
747 } // namespace views | 752 } // namespace views |
OLD | NEW |