Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: chrome/browser/views/toolbar_view.cc

Issue 465130: Share the code that builds the page menu in a common model, make Mac and Win ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/views/toolbar_view.h" 5 #include "chrome/browser/views/toolbar_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/drag_drop_types.h" 9 #include "app/drag_drop_types.h"
10 #include "app/gfx/canvas.h" 10 #include "app/gfx/canvas.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Padding to the right of the location bar 70 // Padding to the right of the location bar
71 static const int kPaddingRight = 2; 71 static const int kPaddingRight = 2;
72 72
73 static const int kPopupTopSpacingNonGlass = 3; 73 static const int kPopupTopSpacingNonGlass = 3;
74 static const int kPopupBottomSpacingNonGlass = 2; 74 static const int kPopupBottomSpacingNonGlass = 2;
75 static const int kPopupBottomSpacingGlass = 1; 75 static const int kPopupBottomSpacingGlass = 1;
76 76
77 static SkBitmap* kPopupBackgroundEdge = NULL; 77 static SkBitmap* kPopupBackgroundEdge = NULL;
78 78
79 //////////////////////////////////////////////////////////////////////////////// 79 ////////////////////////////////////////////////////////////////////////////////
80 // EncodingMenuModel
81
82 EncodingMenuModel::EncodingMenuModel(Browser* browser)
83 : SimpleMenuModel(this),
84 browser_(browser) {
85 Build();
86 }
87
88 void EncodingMenuModel::Build() {
89 EncodingMenuController::EncodingMenuItemList encoding_menu_items;
90 EncodingMenuController encoding_menu_controller;
91 encoding_menu_controller.GetEncodingMenuItems(browser_->profile(),
92 &encoding_menu_items);
93
94 int group_id = 0;
95 EncodingMenuController::EncodingMenuItemList::iterator it =
96 encoding_menu_items.begin();
97 for (; it != encoding_menu_items.end(); ++it) {
98 int id = it->first;
99 string16& label = it->second;
100 if (id == 0) {
101 AddSeparator();
102 } else {
103 if (id == IDC_ENCODING_AUTO_DETECT) {
104 AddCheckItem(id, label);
105 } else {
106 // Use the id of the first radio command as the id of the group.
107 if (group_id <= 0)
108 group_id = id;
109 AddRadioItem(id, label, group_id);
110 }
111 }
112 }
113 }
114
115 bool EncodingMenuModel::IsCommandIdChecked(int command_id) const {
116 TabContents* current_tab = browser_->GetSelectedTabContents();
117 EncodingMenuController controller;
118 return controller.IsItemChecked(browser_->profile(),
119 current_tab->encoding(), command_id);
120 }
121
122 bool EncodingMenuModel::IsCommandIdEnabled(int command_id) const {
123 return browser_->command_updater()->IsCommandEnabled(command_id);
124 }
125
126 bool EncodingMenuModel::GetAcceleratorForCommandId(
127 int command_id,
128 menus::Accelerator* accelerator) {
129 return false;
130 }
131
132 void EncodingMenuModel::ExecuteCommand(int command_id) {
133 browser_->ExecuteCommand(command_id);
134 }
135
136 ////////////////////////////////////////////////////////////////////////////////
137 // EncodingMenuModel
138
139 ZoomMenuModel::ZoomMenuModel(menus::SimpleMenuModel::Delegate* delegate)
140 : SimpleMenuModel(delegate) {
141 Build();
142 }
143
144 void ZoomMenuModel::Build() {
145 AddItemWithStringId(IDC_ZOOM_PLUS, IDS_ZOOM_PLUS);
146 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL);
147 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS);
148 }
149
150 ////////////////////////////////////////////////////////////////////////////////
151 // ToolbarView, public: 80 // ToolbarView, public:
152 81
153 ToolbarView::ToolbarView(Browser* browser) 82 ToolbarView::ToolbarView(Browser* browser)
154 : model_(browser->toolbar_model()), 83 : model_(browser->toolbar_model()),
155 back_(NULL), 84 back_(NULL),
156 forward_(NULL), 85 forward_(NULL),
157 reload_(NULL), 86 reload_(NULL),
158 home_(NULL), 87 home_(NULL),
159 star_(NULL), 88 star_(NULL),
160 location_bar_(NULL), 89 location_bar_(NULL),
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 if (UILayoutIsRightToLeft()) 757 if (UILayoutIsRightToLeft())
829 app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME_RTL)); 758 app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME_RTL));
830 else 759 else
831 app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME)); 760 app_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_CHROME));
832 761
833 if (bookmark_menu_ != NULL) 762 if (bookmark_menu_ != NULL)
834 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK)); 763 bookmark_menu_->SetIcon(*tp->GetBitmapNamed(IDR_MENU_BOOKMARK));
835 } 764 }
836 765
837 void ToolbarView::RunPageMenu(const gfx::Point& pt) { 766 void ToolbarView::RunPageMenu(const gfx::Point& pt) {
838 CreatePageMenu(); 767 page_menu_model_.reset(new PageMenuModel(this, browser_));
768 page_menu_menu_.reset(new views::Menu2(page_menu_model_.get()));
839 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 769 page_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
840 } 770 }
841 771
842 void ToolbarView::RunAppMenu(const gfx::Point& pt) { 772 void ToolbarView::RunAppMenu(const gfx::Point& pt) {
843 CreateAppMenu(); 773 CreateAppMenu();
844 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 774 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
845 } 775 }
846 776
847 void ToolbarView::CreatePageMenu() {
848 if (page_menu_contents_.get())
849 return;
850
851 page_menu_contents_.reset(new menus::SimpleMenuModel(this));
852 page_menu_contents_->AddItemWithStringId(IDC_CREATE_SHORTCUTS,
853 IDS_CREATE_SHORTCUTS);
854 page_menu_contents_->AddSeparator();
855 page_menu_contents_->AddItemWithStringId(IDC_CUT, IDS_CUT);
856 page_menu_contents_->AddItemWithStringId(IDC_COPY, IDS_COPY);
857 page_menu_contents_->AddItemWithStringId(IDC_PASTE, IDS_PASTE);
858 page_menu_contents_->AddSeparator();
859 page_menu_contents_->AddItemWithStringId(IDC_FIND, IDS_FIND);
860 page_menu_contents_->AddItemWithStringId(IDC_SAVE_PAGE, IDS_SAVE_PAGE);
861 page_menu_contents_->AddItemWithStringId(IDC_PRINT, IDS_PRINT);
862 page_menu_contents_->AddSeparator();
863
864 zoom_menu_contents_.reset(new ZoomMenuModel(this));
865 page_menu_contents_->AddSubMenuWithStringId(
866 IDS_ZOOM_MENU, zoom_menu_contents_.get());
867
868 encoding_menu_contents_.reset(new EncodingMenuModel(browser_));
869 page_menu_contents_->AddSubMenuWithStringId(
870 IDS_ENCODING_MENU, encoding_menu_contents_.get());
871
872 #if defined(OS_WIN)
873 CreateDevToolsMenuContents();
874 page_menu_contents_->AddSeparator();
875 page_menu_contents_->AddSubMenuWithStringId(
876 IDS_DEVELOPER_MENU, devtools_menu_contents_.get());
877
878 page_menu_contents_->AddSeparator();
879 page_menu_contents_->AddItemWithStringId(IDC_REPORT_BUG, IDS_REPORT_BUG);
880 #else
881 NOTIMPLEMENTED();
882 #endif
883
884 page_menu_menu_.reset(new views::Menu2(page_menu_contents_.get()));
885 }
886
887 #if defined(OS_WIN)
888 void ToolbarView::CreateDevToolsMenuContents() {
889 devtools_menu_contents_.reset(new menus::SimpleMenuModel(this));
890 devtools_menu_contents_->AddItem(IDC_VIEW_SOURCE,
891 l10n_util::GetString(IDS_VIEW_SOURCE));
892 if (g_browser_process->have_inspector_files()) {
893 devtools_menu_contents_->AddItem(IDC_DEV_TOOLS,
894 l10n_util::GetString(IDS_DEV_TOOLS));
895 devtools_menu_contents_->AddItem(
896 IDC_DEV_TOOLS_CONSOLE,
897 l10n_util::GetString(IDS_DEV_TOOLS_CONSOLE));
898 }
899 devtools_menu_contents_->AddItem(IDC_TASK_MANAGER,
900 l10n_util::GetString(IDS_TASK_MANAGER));
901 }
902 #endif
903
904 void ToolbarView::CreateAppMenu() { 777 void ToolbarView::CreateAppMenu() {
905 // We always rebuild the app menu so that we can get the current state of 778 // We always rebuild the app menu so that we can get the current state of
906 // the sync system. 779 // the sync system.
907 780
908 app_menu_contents_.reset(new menus::SimpleMenuModel(this)); 781 app_menu_contents_.reset(new menus::SimpleMenuModel(this));
909 app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); 782 app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
910 app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); 783 app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
911 app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, 784 app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW,
912 IDS_NEW_INCOGNITO_WINDOW); 785 IDS_NEW_INCOGNITO_WINDOW);
913 // Enumerate profiles asynchronously and then create the parent menu item. 786 // Enumerate profiles asynchronously and then create the parent menu item.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 IDS_ABOUT, 836 IDS_ABOUT,
964 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 837 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
965 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); 838 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
966 if (browser_defaults::kShowExitMenuItem) { 839 if (browser_defaults::kShowExitMenuItem) {
967 app_menu_contents_->AddSeparator(); 840 app_menu_contents_->AddSeparator();
968 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); 841 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT);
969 } 842 }
970 843
971 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); 844 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get()));
972 } 845 }
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698