| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 : delegate_(delegate), | 82 : delegate_(delegate), |
| 83 controller_(NULL), | 83 controller_(NULL), |
| 84 canceled_(false), | 84 canceled_(false), |
| 85 parent_menu_item_(NULL), | 85 parent_menu_item_(NULL), |
| 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 is_root_context_menu_(false), |
| 92 has_icons_(false), | 93 has_icons_(false), |
| 93 icon_view_(NULL), | 94 icon_view_(NULL), |
| 94 top_margin_(-1), | 95 top_margin_(-1), |
| 95 bottom_margin_(-1), | 96 bottom_margin_(-1), |
| 96 requested_menu_position_(POSITION_BEST_FIT), | 97 requested_menu_position_(POSITION_BEST_FIT), |
| 97 actual_menu_position_(requested_menu_position_), | 98 actual_menu_position_(requested_menu_position_), |
| 98 use_right_margin_(true) { | 99 use_right_margin_(true) { |
| 99 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes supplies a | 100 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes supplies a |
| 100 // NULL delegate. | 101 // NULL delegate. |
| 101 Init(NULL, 0, SUBMENU, delegate); | 102 Init(NULL, 0, SUBMENU, delegate); |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 set_id(kMenuItemViewID); | 618 set_id(kMenuItemViewID); |
| 618 has_icons_ = false; | 619 has_icons_ = false; |
| 619 | 620 |
| 620 // Don't request enabled status from the root menu item as it is just | 621 // Don't request enabled status from the root menu item as it is just |
| 621 // a container for real items. EMPTY items will be disabled. | 622 // a container for real items. EMPTY items will be disabled. |
| 622 MenuDelegate* root_delegate = GetDelegate(); | 623 MenuDelegate* root_delegate = GetDelegate(); |
| 623 if (parent && type != EMPTY && root_delegate) | 624 if (parent && type != EMPTY && root_delegate) |
| 624 SetEnabled(root_delegate->IsCommandEnabled(command)); | 625 SetEnabled(root_delegate->IsCommandEnabled(command)); |
| 625 } | 626 } |
| 626 | 627 |
| 627 void MenuItemView::PrepareForRun(bool has_mnemonics, bool show_mnemonics) { | 628 void MenuItemView::PrepareForRun(bool has_mnemonics, bool show_mnemonics, |
| 629 bool is_root_context_menu) { |
| 628 // Currently we only support showing the root. | 630 // Currently we only support showing the root. |
| 629 DCHECK(!parent_menu_item_); | 631 DCHECK(!parent_menu_item_); |
| 630 | 632 |
| 631 // Force us to have a submenu. | 633 // Force us to have a submenu. |
| 632 CreateSubmenu(); | 634 CreateSubmenu(); |
| 633 actual_menu_position_ = requested_menu_position_; | 635 actual_menu_position_ = requested_menu_position_; |
| 634 canceled_ = false; | 636 canceled_ = false; |
| 635 | 637 |
| 636 has_mnemonics_ = has_mnemonics; | 638 has_mnemonics_ = has_mnemonics; |
| 637 show_mnemonics_ = has_mnemonics && show_mnemonics; | 639 show_mnemonics_ = has_mnemonics && show_mnemonics; |
| 640 is_root_context_menu_ = is_root_context_menu; |
| 638 | 641 |
| 639 AddEmptyMenus(); | 642 AddEmptyMenus(); |
| 640 | 643 |
| 641 if (!MenuController::GetActiveInstance()) { | 644 if (!MenuController::GetActiveInstance()) { |
| 642 // Only update the menu size if there are no menus showing, otherwise | 645 // Only update the menu size if there are no menus showing, otherwise |
| 643 // things may shift around. | 646 // things may shift around. |
| 644 UpdateMenuPartSizes(); | 647 UpdateMenuPartSizes(); |
| 645 } | 648 } |
| 646 } | 649 } |
| 647 | 650 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 temp_width = menu_item->GetMaxIconViewWidth(); | 849 temp_width = menu_item->GetMaxIconViewWidth(); |
| 847 } else if (menu_item->icon_view()) { | 850 } else if (menu_item->icon_view()) { |
| 848 temp_width = menu_item->icon_view()->GetPreferredSize().width(); | 851 temp_width = menu_item->icon_view()->GetPreferredSize().width(); |
| 849 } | 852 } |
| 850 width = std::max(width, temp_width); | 853 width = std::max(width, temp_width); |
| 851 } | 854 } |
| 852 return width; | 855 return width; |
| 853 } | 856 } |
| 854 | 857 |
| 855 } // namespace views | 858 } // namespace views |
| OLD | NEW |