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 "chrome/browser/ui/views/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // 0, its corresponding command id as used in the children menu item views | 729 // 0, its corresponding command id as used in the children menu item views |
730 // follows that of the parent menu item view |menu_item_|. | 730 // follows that of the parent menu item view |menu_item_|. |
731 int command_id = menu_item_->GetCommand() + 1 + index; | 731 int command_id = menu_item_->GetCommand() + 1 + index; |
732 views::MenuItemView* item = menu_item_->GetMenuItemByID(command_id); | 732 views::MenuItemView* item = menu_item_->GetMenuItemByID(command_id); |
733 DCHECK(item); | 733 DCHECK(item); |
734 gfx::Image icon; | 734 gfx::Image icon; |
735 if (model_->GetIconAt(index, &icon)) | 735 if (model_->GetIconAt(index, &icon)) |
736 item->SetIcon(*icon.ToImageSkia()); | 736 item->SetIcon(*icon.ToImageSkia()); |
737 } | 737 } |
738 | 738 |
| 739 // Return the specific menu width of recent tab menu item if |command_id| |
| 740 // refers to one of recent tabs menu items, else return -1. |
| 741 int GetMaxWidthForMenu(MenuItemView* menu) { |
| 742 views::SubmenuView* submenu = menu_item_->GetSubmenu(); |
| 743 if (!submenu) |
| 744 return -1; |
| 745 const int kMaxMenuItemWidth = 320; |
| 746 return menu->GetCommand() >= menu_item_->GetCommand() && |
| 747 menu->GetCommand() <= |
| 748 menu_item_->GetCommand() + submenu->GetMenuItemCount() ? |
| 749 kMaxMenuItemWidth : -1; |
| 750 } |
| 751 |
739 private: | 752 private: |
740 ui::MenuModel* model_; | 753 ui::MenuModel* model_; |
741 views::MenuItemView* menu_item_; | 754 views::MenuItemView* menu_item_; |
742 | 755 |
743 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); | 756 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); |
744 }; | 757 }; |
745 | 758 |
746 // WrenchMenu ------------------------------------------------------------------ | 759 // WrenchMenu ------------------------------------------------------------------ |
747 | 760 |
748 WrenchMenu::WrenchMenu(Browser* browser, | 761 WrenchMenu::WrenchMenu(Browser* browser, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 return bookmark_menu_delegate_->WriteDragData(sender, data); | 899 return bookmark_menu_delegate_->WriteDragData(sender, data); |
887 } | 900 } |
888 | 901 |
889 int WrenchMenu::GetDragOperations(MenuItemView* sender) { | 902 int WrenchMenu::GetDragOperations(MenuItemView* sender) { |
890 return is_bookmark_command(sender->GetCommand()) ? | 903 return is_bookmark_command(sender->GetCommand()) ? |
891 bookmark_menu_delegate_->GetDragOperations(sender) : | 904 bookmark_menu_delegate_->GetDragOperations(sender) : |
892 MenuDelegate::GetDragOperations(sender); | 905 MenuDelegate::GetDragOperations(sender); |
893 } | 906 } |
894 | 907 |
895 int WrenchMenu::GetMaxWidthForMenu(MenuItemView* menu) { | 908 int WrenchMenu::GetMaxWidthForMenu(MenuItemView* menu) { |
896 return is_bookmark_command(menu->GetCommand()) ? | 909 if (is_bookmark_command(menu->GetCommand())) |
897 bookmark_menu_delegate_->GetMaxWidthForMenu(menu) : | 910 return bookmark_menu_delegate_->GetMaxWidthForMenu(menu); |
898 MenuDelegate::GetMaxWidthForMenu(menu); | 911 int max_width = -1; |
| 912 // If recent tabs menu is available, it will decide if |menu| is one of recent |
| 913 // tabs; if yes, it would return the menu width for recent tabs. |
| 914 // otherwise, it would return -1. |
| 915 if (recent_tabs_menu_model_delegate_.get()) |
| 916 max_width = recent_tabs_menu_model_delegate_->GetMaxWidthForMenu(menu); |
| 917 if (max_width == -1) |
| 918 max_width = MenuDelegate::GetMaxWidthForMenu(menu); |
| 919 return max_width; |
899 } | 920 } |
900 | 921 |
901 bool WrenchMenu::IsItemChecked(int id) const { | 922 bool WrenchMenu::IsItemChecked(int id) const { |
902 if (is_bookmark_command(id)) | 923 if (is_bookmark_command(id)) |
903 return false; | 924 return false; |
904 | 925 |
905 const Entry& entry = id_to_entry_.find(id)->second; | 926 const Entry& entry = id_to_entry_.find(id)->second; |
906 return entry.first->IsItemCheckedAt(entry.second); | 927 return entry.first->IsItemCheckedAt(entry.second); |
907 } | 928 } |
908 | 929 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 bookmark_menu_delegate_.reset( | 1154 bookmark_menu_delegate_.reset( |
1134 new BookmarkMenuDelegate(browser_, | 1155 new BookmarkMenuDelegate(browser_, |
1135 browser_, | 1156 browser_, |
1136 parent, | 1157 parent, |
1137 first_bookmark_command_id_)); | 1158 first_bookmark_command_id_)); |
1138 bookmark_menu_delegate_->Init( | 1159 bookmark_menu_delegate_->Init( |
1139 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1160 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
1140 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1161 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1141 bookmark_utils::LAUNCH_WRENCH_MENU); | 1162 bookmark_utils::LAUNCH_WRENCH_MENU); |
1142 } | 1163 } |
OLD | NEW |