OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_item_view.h" | 5 #include "ui/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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 Type type) { | 207 Type type) { |
208 DCHECK_NE(type, EMPTY); | 208 DCHECK_NE(type, EMPTY); |
209 DCHECK_LE(0, index); | 209 DCHECK_LE(0, index); |
210 if (!submenu_) | 210 if (!submenu_) |
211 CreateSubmenu(); | 211 CreateSubmenu(); |
212 DCHECK_GE(submenu_->child_count(), index); | 212 DCHECK_GE(submenu_->child_count(), index); |
213 if (type == SEPARATOR) { | 213 if (type == SEPARATOR) { |
214 submenu_->AddChildViewAt(new MenuSeparator(), index); | 214 submenu_->AddChildViewAt(new MenuSeparator(), index); |
215 return NULL; | 215 return NULL; |
216 } | 216 } |
217 MenuItemView* item = new MenuItemView(this, item_id, type); | 217 MenuItemView* item = AllocateMenuItemView(this, item_id, type); |
218 if (label.empty() && GetDelegate()) | 218 if (label.empty() && GetDelegate()) |
219 item->SetTitle(GetDelegate()->GetLabel(item_id)); | 219 item->SetTitle(GetDelegate()->GetLabel(item_id)); |
220 else | 220 else |
221 item->SetTitle(label); | 221 item->SetTitle(label); |
222 item->SetIcon(icon); | 222 item->SetIcon(icon); |
223 if (type == SUBMENU) | 223 if (type == SUBMENU) |
224 item->CreateSubmenu(); | 224 item->CreateSubmenu(); |
225 submenu_->AddChildViewAt(item, index); | 225 submenu_->AddChildViewAt(item, index); |
226 return item; | 226 return item; |
227 } | 227 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 | 524 |
525 MenuItemView::~MenuItemView() { | 525 MenuItemView::~MenuItemView() { |
526 delete submenu_; | 526 delete submenu_; |
527 STLDeleteElements(&removed_items_); | 527 STLDeleteElements(&removed_items_); |
528 } | 528 } |
529 | 529 |
530 std::string MenuItemView::GetClassName() const { | 530 std::string MenuItemView::GetClassName() const { |
531 return kViewClassName; | 531 return kViewClassName; |
532 } | 532 } |
533 | 533 |
| 534 MenuItemView* MenuItemView::AllocateMenuItemView(MenuItemView* parent, |
| 535 int item_id, |
| 536 Type type) { |
| 537 return new MenuItemView(parent, item_id, type); |
| 538 } |
| 539 |
534 // Calculates all sizes that we can from the OS. | 540 // Calculates all sizes that we can from the OS. |
535 // | 541 // |
536 // This is invoked prior to Running a menu. | 542 // This is invoked prior to Running a menu. |
537 void MenuItemView::UpdateMenuPartSizes(bool has_icons) { | 543 void MenuItemView::UpdateMenuPartSizes(bool has_icons) { |
538 MenuConfig::Reset(); | 544 MenuConfig::Reset(); |
539 const MenuConfig& config = MenuConfig::instance(); | 545 const MenuConfig& config = MenuConfig::instance(); |
540 | 546 |
541 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width + | 547 item_right_margin_ = config.label_to_arrow_padding + config.arrow_width + |
542 config.arrow_to_edge_padding; | 548 config.arrow_to_edge_padding; |
543 | 549 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 } | 783 } |
778 | 784 |
779 bool MenuItemView::IsContainer() const { | 785 bool MenuItemView::IsContainer() const { |
780 // Let the first child take over |this| when we only have one child and no | 786 // Let the first child take over |this| when we only have one child and no |
781 // title. Note that what child_count() returns is the number of children, | 787 // title. Note that what child_count() returns is the number of children, |
782 // not the number of menu items. | 788 // not the number of menu items. |
783 return child_count() == 1 && title_.empty(); | 789 return child_count() == 1 && title_.empty(); |
784 } | 790 } |
785 | 791 |
786 } // namespace views | 792 } // namespace views |
OLD | NEW |