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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 type_(SUBMENU), | 86 type_(SUBMENU), |
87 selected_(false), | 87 selected_(false), |
88 command_(0), | 88 command_(0), |
89 submenu_(NULL), | 89 submenu_(NULL), |
90 has_mnemonics_(false), | 90 has_mnemonics_(false), |
91 show_mnemonics_(false), | 91 show_mnemonics_(false), |
92 has_icons_(false), | 92 has_icons_(false), |
93 icon_view_(NULL), | 93 icon_view_(NULL), |
94 top_margin_(-1), | 94 top_margin_(-1), |
95 bottom_margin_(-1), | 95 bottom_margin_(-1), |
96 requested_menu_position_(POSITION_BEST_FIT), | 96 menu_position_(POSITION_BEST_FIT), |
97 actual_menu_position_(requested_menu_position_), | |
98 use_right_margin_(true) { | 97 use_right_margin_(true) { |
99 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes supplies a | 98 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes supplies a |
100 // NULL delegate. | 99 // NULL delegate. |
101 Init(NULL, 0, SUBMENU, delegate); | 100 Init(NULL, 0, SUBMENU, delegate); |
102 } | 101 } |
103 | 102 |
104 void MenuItemView::ChildPreferredSizeChanged(View* child) { | 103 void MenuItemView::ChildPreferredSizeChanged(View* child) { |
105 pref_size_.SetSize(0, 0); | 104 pref_size_.SetSize(0, 0); |
106 PreferredSizeChanged(); | 105 PreferredSizeChanged(); |
107 } | 106 } |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 type_(type), | 548 type_(type), |
550 selected_(false), | 549 selected_(false), |
551 command_(command), | 550 command_(command), |
552 submenu_(NULL), | 551 submenu_(NULL), |
553 has_mnemonics_(false), | 552 has_mnemonics_(false), |
554 show_mnemonics_(false), | 553 show_mnemonics_(false), |
555 has_icons_(false), | 554 has_icons_(false), |
556 icon_view_(NULL), | 555 icon_view_(NULL), |
557 top_margin_(-1), | 556 top_margin_(-1), |
558 bottom_margin_(-1), | 557 bottom_margin_(-1), |
559 requested_menu_position_(POSITION_BEST_FIT), | 558 menu_position_(POSITION_BEST_FIT) { |
560 actual_menu_position_(requested_menu_position_) { | |
561 Init(parent, command, type, NULL); | 559 Init(parent, command, type, NULL); |
562 } | 560 } |
563 | 561 |
564 MenuItemView::~MenuItemView() { | 562 MenuItemView::~MenuItemView() { |
565 delete submenu_; | 563 delete submenu_; |
566 STLDeleteElements(&removed_items_); | 564 STLDeleteElements(&removed_items_); |
567 } | 565 } |
568 | 566 |
569 std::string MenuItemView::GetClassName() const { | 567 std::string MenuItemView::GetClassName() const { |
570 return kViewClassName; | 568 return kViewClassName; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 if (parent && type != EMPTY && root_delegate) | 621 if (parent && type != EMPTY && root_delegate) |
624 SetEnabled(root_delegate->IsCommandEnabled(command)); | 622 SetEnabled(root_delegate->IsCommandEnabled(command)); |
625 } | 623 } |
626 | 624 |
627 void MenuItemView::PrepareForRun(bool has_mnemonics, bool show_mnemonics) { | 625 void MenuItemView::PrepareForRun(bool has_mnemonics, bool show_mnemonics) { |
628 // Currently we only support showing the root. | 626 // Currently we only support showing the root. |
629 DCHECK(!parent_menu_item_); | 627 DCHECK(!parent_menu_item_); |
630 | 628 |
631 // Force us to have a submenu. | 629 // Force us to have a submenu. |
632 CreateSubmenu(); | 630 CreateSubmenu(); |
633 actual_menu_position_ = requested_menu_position_; | |
634 canceled_ = false; | 631 canceled_ = false; |
635 | 632 |
636 has_mnemonics_ = has_mnemonics; | 633 has_mnemonics_ = has_mnemonics; |
637 show_mnemonics_ = has_mnemonics && show_mnemonics; | 634 show_mnemonics_ = has_mnemonics && show_mnemonics; |
638 | 635 |
639 AddEmptyMenus(); | 636 AddEmptyMenus(); |
640 | 637 |
641 if (!MenuController::GetActiveInstance()) { | 638 if (!MenuController::GetActiveInstance()) { |
642 // Only update the menu size if there are no menus showing, otherwise | 639 // Only update the menu size if there are no menus showing, otherwise |
643 // things may shift around. | 640 // things may shift around. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 temp_width = menu_item->GetMaxIconViewWidth(); | 843 temp_width = menu_item->GetMaxIconViewWidth(); |
847 } else if (menu_item->icon_view()) { | 844 } else if (menu_item->icon_view()) { |
848 temp_width = menu_item->icon_view()->GetPreferredSize().width(); | 845 temp_width = menu_item->icon_view()->GetPreferredSize().width(); |
849 } | 846 } |
850 width = std::max(width, temp_width); | 847 width = std::max(width, temp_width); |
851 } | 848 } |
852 return width; | 849 return width; |
853 } | 850 } |
854 | 851 |
855 } // namespace views | 852 } // namespace views |
OLD | NEW |