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 18 matching lines...) Expand all Loading... |
29 | 29 |
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, EMPTY) { |
40 // Set this so that we're not identified as a normal menu item. | 40 // Set this so that we're not identified as a normal menu item. |
41 SetID(kEmptyMenuItemViewID); | 41 SetID(kEmptyMenuItemViewID); |
42 SetTitle(UTF16ToWide( | 42 SetTitle(UTF16ToWide( |
43 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU))); | 43 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU))); |
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; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 case SUBMENU: | 129 case SUBMENU: |
130 state->state |= ui::AccessibilityTypes::STATE_HASPOPUP; | 130 state->state |= ui::AccessibilityTypes::STATE_HASPOPUP; |
131 break; | 131 break; |
132 case CHECKBOX: | 132 case CHECKBOX: |
133 case RADIO: | 133 case RADIO: |
134 state->state |= GetDelegate()->IsItemChecked(GetCommand()) ? | 134 state->state |= GetDelegate()->IsItemChecked(GetCommand()) ? |
135 ui::AccessibilityTypes::STATE_CHECKED : 0; | 135 ui::AccessibilityTypes::STATE_CHECKED : 0; |
136 break; | 136 break; |
137 case NORMAL: | 137 case NORMAL: |
138 case SEPARATOR: | 138 case SEPARATOR: |
| 139 case EMPTY: |
139 // No additional accessibility states currently for these menu states. | 140 // No additional accessibility states currently for these menu states. |
140 break; | 141 break; |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 // static | 145 // static |
145 string16 MenuItemView::GetAccessibleNameForMenuItem( | 146 string16 MenuItemView::GetAccessibleNameForMenuItem( |
146 const string16& item_text, const string16& accelerator_text) { | 147 const string16& item_text, const string16& accelerator_text) { |
147 string16 accessible_name = item_text; | 148 string16 accessible_name = item_text; |
148 | 149 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 canceled_ = true; | 254 canceled_ = true; |
254 controller_->Cancel(MenuController::EXIT_ALL); | 255 controller_->Cancel(MenuController::EXIT_ALL); |
255 } | 256 } |
256 } | 257 } |
257 | 258 |
258 MenuItemView* MenuItemView::AddMenuItemAt(int index, | 259 MenuItemView* MenuItemView::AddMenuItemAt(int index, |
259 int item_id, | 260 int item_id, |
260 const std::wstring& label, | 261 const std::wstring& label, |
261 const SkBitmap& icon, | 262 const SkBitmap& icon, |
262 Type type) { | 263 Type type) { |
| 264 DCHECK_NE(type, EMPTY); |
263 DCHECK_LE(0, index); | 265 DCHECK_LE(0, index); |
264 if (!submenu_) | 266 if (!submenu_) |
265 CreateSubmenu(); | 267 CreateSubmenu(); |
266 DCHECK_GE(submenu_->child_count(), index); | 268 DCHECK_GE(submenu_->child_count(), index); |
267 if (type == SEPARATOR) { | 269 if (type == SEPARATOR) { |
268 submenu_->AddChildViewAt(new MenuSeparator(), index); | 270 submenu_->AddChildViewAt(new MenuSeparator(), index); |
269 return NULL; | 271 return NULL; |
270 } | 272 } |
271 MenuItemView* item = new MenuItemView(this, item_id, type); | 273 MenuItemView* item = new MenuItemView(this, item_id, type); |
272 if (label.empty() && GetDelegate()) | 274 if (label.empty() && GetDelegate()) |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 type_ = type; | 558 type_ = type; |
557 selected_ = false; | 559 selected_ = false; |
558 command_ = command; | 560 command_ = command; |
559 submenu_ = NULL; | 561 submenu_ = NULL; |
560 show_mnemonics_ = false; | 562 show_mnemonics_ = false; |
561 // Assign our ID, this allows SubmenuItemView to find MenuItemViews. | 563 // Assign our ID, this allows SubmenuItemView to find MenuItemViews. |
562 SetID(kMenuItemViewID); | 564 SetID(kMenuItemViewID); |
563 has_icons_ = false; | 565 has_icons_ = false; |
564 | 566 |
565 // Don't request enabled status from the root menu item as it is just | 567 // Don't request enabled status from the root menu item as it is just |
566 // a container for real items. | 568 // a container for real items. EMPTY items will be disabled. |
567 MenuDelegate* root_delegate = GetDelegate(); | 569 MenuDelegate* root_delegate = GetDelegate(); |
568 if (parent && root_delegate) | 570 if (parent && type != EMPTY && root_delegate) |
569 SetEnabled(root_delegate->IsCommandEnabled(command)); | 571 SetEnabled(root_delegate->IsCommandEnabled(command)); |
570 } | 572 } |
571 | 573 |
572 void MenuItemView::DropMenuClosed(bool notify_delegate) { | 574 void MenuItemView::DropMenuClosed(bool notify_delegate) { |
573 DCHECK(controller_); | 575 DCHECK(controller_); |
574 DCHECK(!controller_->IsBlockingRun()); | 576 DCHECK(!controller_->IsBlockingRun()); |
575 if (MenuController::GetActiveInstance() == controller_) | 577 if (MenuController::GetActiveInstance() == controller_) |
576 MenuController::SetActiveInstance(NULL); | 578 MenuController::SetActiveInstance(NULL); |
577 delete controller_; | 579 delete controller_; |
578 controller_ = NULL; | 580 controller_ = NULL; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 return string16(); | 747 return string16(); |
746 } | 748 } |
747 | 749 |
748 Accelerator accelerator; | 750 Accelerator accelerator; |
749 return (GetDelegate() && | 751 return (GetDelegate() && |
750 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 752 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? |
751 accelerator.GetShortcutText() : string16(); | 753 accelerator.GetShortcutText() : string16(); |
752 } | 754 } |
753 | 755 |
754 } // namespace views | 756 } // namespace views |
OLD | NEW |