| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 int item_id, | 230 int item_id, |
| 231 const base::string16& label, | 231 const base::string16& label, |
| 232 const base::string16& sublabel, | 232 const base::string16& sublabel, |
| 233 const base::string16& minor_text, | 233 const base::string16& minor_text, |
| 234 const gfx::ImageSkia& icon, | 234 const gfx::ImageSkia& icon, |
| 235 Type type, | 235 Type type, |
| 236 ui::MenuSeparatorType separator_style) { | 236 ui::MenuSeparatorType separator_style) { |
| 237 DCHECK_NE(type, EMPTY); | 237 DCHECK_NE(type, EMPTY); |
| 238 DCHECK_LE(0, index); | 238 DCHECK_LE(0, index); |
| 239 if (!submenu_) | 239 if (!submenu_) |
| 240 CreateSubmenu(); | 240 submenu_ = CreateSubmenu(); |
| 241 DCHECK_GE(submenu_->child_count(), index); | 241 DCHECK_GE(submenu_->child_count(), index); |
| 242 if (type == SEPARATOR) { | 242 if (type == SEPARATOR) { |
| 243 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); | 243 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); |
| 244 return NULL; | 244 return NULL; |
| 245 } | 245 } |
| 246 MenuItemView* item = new MenuItemView(this, item_id, type); | 246 MenuItemView* item = new MenuItemView(this, item_id, type); |
| 247 if (label.empty() && GetDelegate()) | 247 if (label.empty() && GetDelegate()) |
| 248 item->SetTitle(GetDelegate()->GetLabel(item_id)); | 248 item->SetTitle(GetDelegate()->GetLabel(item_id)); |
| 249 else | 249 else |
| 250 item->SetTitle(label); | 250 item->SetTitle(label); |
| 251 item->SetSubtitle(sublabel); | 251 item->SetSubtitle(sublabel); |
| 252 item->SetMinorText(minor_text); | 252 item->SetMinorText(minor_text); |
| 253 if (!icon.isNull()) | 253 if (!icon.isNull()) |
| 254 item->SetIcon(icon); | 254 item->SetIcon(icon); |
| 255 if (type == SUBMENU) | 255 if (type == SUBMENU && !item->HasSubmenu()) |
| 256 item->CreateSubmenu(); | 256 item->submenu_ = CreateSubmenu(); |
| 257 if (GetDelegate() && !GetDelegate()->IsCommandVisible(item_id)) | 257 if (GetDelegate() && !GetDelegate()->IsCommandVisible(item_id)) |
| 258 item->SetVisible(false); | 258 item->SetVisible(false); |
| 259 submenu_->AddChildViewAt(item, index); | 259 submenu_->AddChildViewAt(item, index); |
| 260 return item; | 260 return item; |
| 261 } | 261 } |
| 262 | 262 |
| 263 void MenuItemView::RemoveMenuItemAt(int index) { | 263 void MenuItemView::RemoveMenuItemAt(int index) { |
| 264 DCHECK(submenu_); | 264 DCHECK(submenu_); |
| 265 DCHECK_LE(0, index); | 265 DCHECK_LE(0, index); |
| 266 DCHECK_GT(submenu_->child_count(), index); | 266 DCHECK_GT(submenu_->child_count(), index); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 const base::string16& minor_text, | 324 const base::string16& minor_text, |
| 325 const gfx::ImageSkia& icon, | 325 const gfx::ImageSkia& icon, |
| 326 Type type, | 326 Type type, |
| 327 ui::MenuSeparatorType separator_style) { | 327 ui::MenuSeparatorType separator_style) { |
| 328 const int index = submenu_ ? submenu_->child_count() : 0; | 328 const int index = submenu_ ? submenu_->child_count() : 0; |
| 329 return AddMenuItemAt(index, item_id, label, sublabel, minor_text, icon, type, | 329 return AddMenuItemAt(index, item_id, label, sublabel, minor_text, icon, type, |
| 330 separator_style); | 330 separator_style); |
| 331 } | 331 } |
| 332 | 332 |
| 333 SubmenuView* MenuItemView::CreateSubmenu() { | 333 SubmenuView* MenuItemView::CreateSubmenu() { |
| 334 if (!submenu_) | 334 return new SubmenuView(this); |
| 335 submenu_ = new SubmenuView(this); | |
| 336 return submenu_; | |
| 337 } | 335 } |
| 338 | 336 |
| 339 bool MenuItemView::HasSubmenu() const { | 337 bool MenuItemView::HasSubmenu() const { |
| 340 return (submenu_ != NULL); | 338 return (submenu_ != NULL); |
| 341 } | 339 } |
| 342 | 340 |
| 343 SubmenuView* MenuItemView::GetSubmenu() const { | 341 SubmenuView* MenuItemView::GetSubmenu() const { |
| 344 return submenu_; | 342 return submenu_; |
| 345 } | 343 } |
| 346 | 344 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 SetEnabled(root_delegate->IsCommandEnabled(command)); | 657 SetEnabled(root_delegate->IsCommandEnabled(command)); |
| 660 } | 658 } |
| 661 | 659 |
| 662 void MenuItemView::PrepareForRun(bool is_first_menu, | 660 void MenuItemView::PrepareForRun(bool is_first_menu, |
| 663 bool has_mnemonics, | 661 bool has_mnemonics, |
| 664 bool show_mnemonics) { | 662 bool show_mnemonics) { |
| 665 // Currently we only support showing the root. | 663 // Currently we only support showing the root. |
| 666 DCHECK(!parent_menu_item_); | 664 DCHECK(!parent_menu_item_); |
| 667 | 665 |
| 668 // Force us to have a submenu. | 666 // Force us to have a submenu. |
| 669 CreateSubmenu(); | 667 if (!submenu_) |
| 668 submenu_ = CreateSubmenu(); |
| 670 actual_menu_position_ = requested_menu_position_; | 669 actual_menu_position_ = requested_menu_position_; |
| 671 canceled_ = false; | 670 canceled_ = false; |
| 672 | 671 |
| 673 has_mnemonics_ = has_mnemonics; | 672 has_mnemonics_ = has_mnemonics; |
| 674 show_mnemonics_ = has_mnemonics && show_mnemonics; | 673 show_mnemonics_ = has_mnemonics && show_mnemonics; |
| 675 | 674 |
| 676 AddEmptyMenus(); | 675 AddEmptyMenus(); |
| 677 | 676 |
| 678 if (is_first_menu) { | 677 if (is_first_menu) { |
| 679 // Only update the menu size if there are no menus showing, otherwise | 678 // Only update the menu size if there are no menus showing, otherwise |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 } else { | 1072 } else { |
| 1074 const Type& type = menu_item->GetType(); | 1073 const Type& type = menu_item->GetType(); |
| 1075 if (type == CHECKBOX || type == RADIO) | 1074 if (type == CHECKBOX || type == RADIO) |
| 1076 return true; | 1075 return true; |
| 1077 } | 1076 } |
| 1078 } | 1077 } |
| 1079 return false; | 1078 return false; |
| 1080 } | 1079 } |
| 1081 | 1080 |
| 1082 } // namespace views | 1081 } // namespace views |
| OLD | NEW |