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 "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 // static | 82 // static |
83 int MenuItemView::item_right_margin_; | 83 int MenuItemView::item_right_margin_; |
84 | 84 |
85 // static | 85 // static |
86 int MenuItemView::pref_menu_height_; | 86 int MenuItemView::pref_menu_height_; |
87 | 87 |
88 // static | 88 // static |
89 const char MenuItemView::kViewClassName[] = "MenuItemView"; | 89 const char MenuItemView::kViewClassName[] = "MenuItemView"; |
90 | 90 |
| 91 // Note: This class also has a protected constructor and a common Init function |
| 92 // to initialize both. |
91 MenuItemView::MenuItemView(MenuDelegate* delegate) | 93 MenuItemView::MenuItemView(MenuDelegate* delegate) |
92 : delegate_(delegate), | 94 : delegate_(delegate), |
93 controller_(NULL), | 95 controller_(NULL), |
94 canceled_(false), | 96 canceled_(false), |
95 parent_menu_item_(NULL), | 97 parent_menu_item_(NULL), |
96 type_(SUBMENU), | 98 type_(SUBMENU), |
97 selected_(false), | 99 selected_(false), |
98 command_(0), | 100 command_(0), |
99 submenu_(NULL), | 101 submenu_(NULL), |
100 has_mnemonics_(false), | 102 has_mnemonics_(false), |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 invalidate_dimensions(); | 554 invalidate_dimensions(); |
553 } | 555 } |
554 | 556 |
555 const MenuConfig& MenuItemView::GetMenuConfig() const { | 557 const MenuConfig& MenuItemView::GetMenuConfig() const { |
556 const MenuController* controller = GetMenuController(); | 558 const MenuController* controller = GetMenuController(); |
557 if (controller) | 559 if (controller) |
558 return controller->menu_config_; | 560 return controller->menu_config_; |
559 return MenuConfig::instance(NULL); | 561 return MenuConfig::instance(NULL); |
560 } | 562 } |
561 | 563 |
| 564 // Note: This class also has a public constructor and a common Init function |
| 565 // to initialize both. |
562 MenuItemView::MenuItemView(MenuItemView* parent, | 566 MenuItemView::MenuItemView(MenuItemView* parent, |
563 int command, | 567 int command, |
564 MenuItemView::Type type) | 568 MenuItemView::Type type) |
565 : delegate_(NULL), | 569 : delegate_(NULL), |
566 controller_(NULL), | 570 controller_(NULL), |
567 canceled_(false), | 571 canceled_(false), |
568 parent_menu_item_(parent), | 572 parent_menu_item_(parent), |
569 type_(type), | 573 type_(type), |
570 selected_(false), | 574 selected_(false), |
571 command_(command), | 575 command_(command), |
572 submenu_(NULL), | 576 submenu_(NULL), |
573 has_mnemonics_(false), | 577 has_mnemonics_(false), |
574 show_mnemonics_(false), | 578 show_mnemonics_(false), |
575 has_icons_(false), | 579 has_icons_(false), |
576 icon_view_(NULL), | 580 icon_view_(NULL), |
577 top_margin_(-1), | 581 top_margin_(-1), |
578 bottom_margin_(-1), | 582 bottom_margin_(-1), |
579 left_icon_margin_(0), | 583 left_icon_margin_(0), |
580 right_icon_margin_(0), | 584 right_icon_margin_(0), |
581 requested_menu_position_(POSITION_BEST_FIT), | 585 requested_menu_position_(POSITION_BEST_FIT), |
582 actual_menu_position_(requested_menu_position_), | 586 actual_menu_position_(requested_menu_position_), |
583 use_right_margin_(true) { | 587 use_right_margin_(true) { |
584 Init(parent, command, type, NULL); | 588 Init(parent, command, type, NULL); |
585 } | 589 } |
586 | 590 |
587 MenuItemView::~MenuItemView() { | 591 MenuItemView::~MenuItemView() { |
588 delete submenu_; | 592 delete submenu_; |
589 STLDeleteElements(&removed_items_); | 593 STLDeleteElements(&removed_items_); |
| 594 if (lifecycle_observer_) |
| 595 lifecycle_observer_->OnDeleted(this); |
590 } | 596 } |
591 | 597 |
592 const char* MenuItemView::GetClassName() const { | 598 const char* MenuItemView::GetClassName() const { |
593 return kViewClassName; | 599 return kViewClassName; |
594 } | 600 } |
595 | 601 |
596 // Calculates all sizes that we can from the OS. | 602 // Calculates all sizes that we can from the OS. |
597 // | 603 // |
598 // This is invoked prior to Running a menu. | 604 // This is invoked prior to Running a menu. |
599 void MenuItemView::UpdateMenuPartSizes() { | 605 void MenuItemView::UpdateMenuPartSizes() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 canceled_ = false; | 640 canceled_ = false; |
635 parent_menu_item_ = parent; | 641 parent_menu_item_ = parent; |
636 type_ = type; | 642 type_ = type; |
637 selected_ = false; | 643 selected_ = false; |
638 command_ = command; | 644 command_ = command; |
639 submenu_ = NULL; | 645 submenu_ = NULL; |
640 show_mnemonics_ = false; | 646 show_mnemonics_ = false; |
641 // Assign our ID, this allows SubmenuItemView to find MenuItemViews. | 647 // Assign our ID, this allows SubmenuItemView to find MenuItemViews. |
642 set_id(kMenuItemViewID); | 648 set_id(kMenuItemViewID); |
643 has_icons_ = false; | 649 has_icons_ = false; |
| 650 lifecycle_observer_ = NULL; |
644 | 651 |
645 // Don't request enabled status from the root menu item as it is just | 652 // Don't request enabled status from the root menu item as it is just |
646 // a container for real items. EMPTY items will be disabled. | 653 // a container for real items. EMPTY items will be disabled. |
647 MenuDelegate* root_delegate = GetDelegate(); | 654 MenuDelegate* root_delegate = GetDelegate(); |
648 if (parent && type != EMPTY && root_delegate) | 655 if (parent && type != EMPTY && root_delegate) |
649 SetEnabled(root_delegate->IsCommandEnabled(command)); | 656 SetEnabled(root_delegate->IsCommandEnabled(command)); |
650 } | 657 } |
651 | 658 |
652 void MenuItemView::PrepareForRun(bool is_first_menu, | 659 void MenuItemView::PrepareForRun(bool is_first_menu, |
653 bool has_mnemonics, | 660 bool has_mnemonics, |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 } else { | 1067 } else { |
1061 const Type& type = menu_item->GetType(); | 1068 const Type& type = menu_item->GetType(); |
1062 if (type == CHECKBOX || type == RADIO) | 1069 if (type == CHECKBOX || type == RADIO) |
1063 return true; | 1070 return true; |
1064 } | 1071 } |
1065 } | 1072 } |
1066 return false; | 1073 return false; |
1067 } | 1074 } |
1068 | 1075 |
1069 } // namespace views | 1076 } // namespace views |
OLD | NEW |