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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 icon_view_(NULL), | 103 icon_view_(NULL), |
104 top_margin_(-1), | 104 top_margin_(-1), |
105 bottom_margin_(-1), | 105 bottom_margin_(-1), |
106 left_icon_margin_(0), | 106 left_icon_margin_(0), |
107 right_icon_margin_(0), | 107 right_icon_margin_(0), |
108 requested_menu_position_(POSITION_BEST_FIT), | 108 requested_menu_position_(POSITION_BEST_FIT), |
109 actual_menu_position_(requested_menu_position_), | 109 actual_menu_position_(requested_menu_position_), |
110 use_right_margin_(true) { | 110 use_right_margin_(true) { |
111 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a | 111 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a |
112 // NULL delegate. | 112 // NULL delegate. |
113 // Note: This class also has a protected constructor and a common Init | |
114 // function to initialize both. | |
Finnur
2014/02/13 10:19:43
I was hoping to see this comment on line 91 (above
| |
113 Init(NULL, 0, SUBMENU, delegate); | 115 Init(NULL, 0, SUBMENU, delegate); |
114 } | 116 } |
115 | 117 |
116 void MenuItemView::ChildPreferredSizeChanged(View* child) { | 118 void MenuItemView::ChildPreferredSizeChanged(View* child) { |
117 invalidate_dimensions(); | 119 invalidate_dimensions(); |
118 PreferredSizeChanged(); | 120 PreferredSizeChanged(); |
119 } | 121 } |
120 | 122 |
121 bool MenuItemView::GetTooltipText(const gfx::Point& p, | 123 bool MenuItemView::GetTooltipText(const gfx::Point& p, |
122 base::string16* tooltip) const { | 124 base::string16* tooltip) const { |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 show_mnemonics_(false), | 576 show_mnemonics_(false), |
575 has_icons_(false), | 577 has_icons_(false), |
576 icon_view_(NULL), | 578 icon_view_(NULL), |
577 top_margin_(-1), | 579 top_margin_(-1), |
578 bottom_margin_(-1), | 580 bottom_margin_(-1), |
579 left_icon_margin_(0), | 581 left_icon_margin_(0), |
580 right_icon_margin_(0), | 582 right_icon_margin_(0), |
581 requested_menu_position_(POSITION_BEST_FIT), | 583 requested_menu_position_(POSITION_BEST_FIT), |
582 actual_menu_position_(requested_menu_position_), | 584 actual_menu_position_(requested_menu_position_), |
583 use_right_margin_(true) { | 585 use_right_margin_(true) { |
586 // Note: This class also has a public constructor and a common Init function | |
587 // to initialize both. | |
Finnur
2014/02/13 10:19:43
Same here, move to line 564.
| |
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 |