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 |comamnd_id| | |
740 // refers to one of recent tabs menu items, else return -1. | |
741 int GetMaxWidthForMenu(int command_id) { | |
742 views::SubmenuView* submenu = menu_item_->GetSubmenu(); | |
sky
2012/11/13 17:41:50
Instead of checking the command make this take the
kuan
2012/11/13 18:52:52
Done.
| |
743 if (!submenu) | |
744 return -1; | |
745 if (command_id < menu_item_->GetCommand() || | |
746 command_id > menu_item_->GetCommand() + submenu->GetMenuItemCount()) { | |
747 return -1; | |
748 } | |
749 const int kMaxMenuItemWidth = 320; | |
750 return kMaxMenuItemWidth; | |
751 } | |
752 | |
739 private: | 753 private: |
740 ui::MenuModel* model_; | 754 ui::MenuModel* model_; |
741 views::MenuItemView* menu_item_; | 755 views::MenuItemView* menu_item_; |
742 | 756 |
743 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); | 757 DISALLOW_COPY_AND_ASSIGN(RecentTabsMenuModelDelegate); |
744 }; | 758 }; |
745 | 759 |
746 // WrenchMenu ------------------------------------------------------------------ | 760 // WrenchMenu ------------------------------------------------------------------ |
747 | 761 |
748 WrenchMenu::WrenchMenu(Browser* browser, | 762 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); | 900 return bookmark_menu_delegate_->WriteDragData(sender, data); |
887 } | 901 } |
888 | 902 |
889 int WrenchMenu::GetDragOperations(MenuItemView* sender) { | 903 int WrenchMenu::GetDragOperations(MenuItemView* sender) { |
890 return is_bookmark_command(sender->GetCommand()) ? | 904 return is_bookmark_command(sender->GetCommand()) ? |
891 bookmark_menu_delegate_->GetDragOperations(sender) : | 905 bookmark_menu_delegate_->GetDragOperations(sender) : |
892 MenuDelegate::GetDragOperations(sender); | 906 MenuDelegate::GetDragOperations(sender); |
893 } | 907 } |
894 | 908 |
895 int WrenchMenu::GetMaxWidthForMenu(MenuItemView* menu) { | 909 int WrenchMenu::GetMaxWidthForMenu(MenuItemView* menu) { |
896 return is_bookmark_command(menu->GetCommand()) ? | 910 if (is_bookmark_command(menu->GetCommand())) |
897 bookmark_menu_delegate_->GetMaxWidthForMenu(menu) : | 911 return bookmark_menu_delegate_->GetMaxWidthForMenu(menu); |
898 MenuDelegate::GetMaxWidthForMenu(menu); | 912 int max_width = -1; |
913 // If recent tabs menu is available, it will decide if |menu| is one of recent | |
914 // tabs; if yes, it would return the menu width for recent tabs. | |
915 // otherwise, it would return -1. | |
916 if (recent_tabs_menu_model_delegate_.get()) { | |
917 max_width = recent_tabs_menu_model_delegate_->GetMaxWidthForMenu( | |
918 menu->GetCommand()); | |
919 } | |
920 if (max_width == -1) | |
921 max_width = MenuDelegate::GetMaxWidthForMenu(menu); | |
922 return max_width; | |
899 } | 923 } |
900 | 924 |
901 bool WrenchMenu::IsItemChecked(int id) const { | 925 bool WrenchMenu::IsItemChecked(int id) const { |
902 if (is_bookmark_command(id)) | 926 if (is_bookmark_command(id)) |
903 return false; | 927 return false; |
904 | 928 |
905 const Entry& entry = id_to_entry_.find(id)->second; | 929 const Entry& entry = id_to_entry_.find(id)->second; |
906 return entry.first->IsItemCheckedAt(entry.second); | 930 return entry.first->IsItemCheckedAt(entry.second); |
907 } | 931 } |
908 | 932 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 bookmark_menu_delegate_.reset( | 1157 bookmark_menu_delegate_.reset( |
1134 new BookmarkMenuDelegate(browser_, | 1158 new BookmarkMenuDelegate(browser_, |
1135 browser_, | 1159 browser_, |
1136 parent, | 1160 parent, |
1137 first_bookmark_command_id_)); | 1161 first_bookmark_command_id_)); |
1138 bookmark_menu_delegate_->Init( | 1162 bookmark_menu_delegate_->Init( |
1139 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 1163 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
1140 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, | 1164 BookmarkMenuDelegate::SHOW_PERMANENT_FOLDERS, |
1141 bookmark_utils::LAUNCH_WRENCH_MENU); | 1165 bookmark_utils::LAUNCH_WRENCH_MENU); |
1142 } | 1166 } |
OLD | NEW |