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

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

Issue 122027: Remove the Menu object, converting all the remaining callers to use Menu2. I'... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months 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') | views/controls/menu/menu_2.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 home_(NULL), 164 home_(NULL),
165 star_(NULL), 165 star_(NULL),
166 location_bar_(NULL), 166 location_bar_(NULL),
167 go_(NULL), 167 go_(NULL),
168 page_menu_(NULL), 168 page_menu_(NULL),
169 app_menu_(NULL), 169 app_menu_(NULL),
170 bookmark_menu_(NULL), 170 bookmark_menu_(NULL),
171 profile_(NULL), 171 profile_(NULL),
172 browser_(browser), 172 browser_(browser),
173 tab_(NULL), 173 tab_(NULL),
174 profiles_menu_(NULL), 174 profiles_menu_contents_(NULL),
175 profiles_helper_(new GetProfilesHelper(this)) { 175 ALLOW_THIS_IN_INITIALIZER_LIST(
176 profiles_helper_(new GetProfilesHelper(this))) {
176 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); 177 browser_->command_updater()->AddCommandObserver(IDC_BACK, this);
177 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); 178 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this);
178 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); 179 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this);
179 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); 180 browser_->command_updater()->AddCommandObserver(IDC_HOME, this);
180 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); 181 browser_->command_updater()->AddCommandObserver(IDC_STAR, this);
181 back_menu_model_.reset(new BackForwardMenuModelViews( 182 back_menu_model_.reset(new BackForwardMenuModelViews(
182 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); 183 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE));
183 forward_menu_model_.reset(new BackForwardMenuModelViews( 184 forward_menu_model_.reset(new BackForwardMenuModelViews(
184 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); 185 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE));
185 if (browser->type() == Browser::TYPE_NORMAL) 186 if (browser->type() == Browser::TYPE_NORMAL)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 247 }
247 // Returns the next available button index, or if no button is available in 248 // Returns the next available button index, or if no button is available in
248 // the specified direction, remains where it was. 249 // the specified direction, remains where it was.
249 return view_index; 250 return view_index;
250 } 251 }
251 252
252 //////////////////////////////////////////////////////////////////////////////// 253 ////////////////////////////////////////////////////////////////////////////////
253 // ToolbarView, Menu::BaseControllerDelegate overrides: 254 // ToolbarView, Menu::BaseControllerDelegate overrides:
254 255
255 bool ToolbarView::GetAcceleratorInfo(int id, views::Accelerator* accel) { 256 bool ToolbarView::GetAcceleratorInfo(int id, views::Accelerator* accel) {
256 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators
257 // anywhere so we need to check for them explicitly here.
258 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings.
259 switch (id) {
260 case IDC_CUT:
261 *accel = views::Accelerator(L'X', false, true, false);
262 return true;
263 case IDC_COPY:
264 *accel = views::Accelerator(L'C', false, true, false);
265 return true;
266 case IDC_PASTE:
267 *accel = views::Accelerator(L'V', false, true, false);
268 return true;
269 }
270 // Else, we retrieve the accelerator information from the frame.
271 return GetWidget()->GetAccelerator(id, accel); 257 return GetWidget()->GetAccelerator(id, accel);
272 } 258 }
273 259
274 //////////////////////////////////////////////////////////////////////////////// 260 ////////////////////////////////////////////////////////////////////////////////
275 // ToolbarView, views::MenuDelegate implementation: 261 // ToolbarView, views::MenuDelegate implementation:
276 262
277 void ToolbarView::RunMenu(views::View* source, const gfx::Point& pt, 263 void ToolbarView::RunMenu(views::View* source, const gfx::Point& pt,
278 gfx::NativeView parent) { 264 gfx::NativeView parent) {
279 switch (source->GetID()) { 265 switch (source->GetID()) {
280 case VIEW_ID_PAGE_MENU: 266 case VIEW_ID_PAGE_MENU:
281 RunPageMenu(pt, parent); 267 RunPageMenu(pt, parent);
282 break; 268 break;
283 case VIEW_ID_APP_MENU: 269 case VIEW_ID_APP_MENU:
284 RunAppMenu(pt, parent); 270 RunAppMenu(pt, parent);
285 break; 271 break;
286 default: 272 default:
287 NOTREACHED() << "Invalid source menu."; 273 NOTREACHED() << "Invalid source menu.";
288 } 274 }
289 } 275 }
290 276
291 //////////////////////////////////////////////////////////////////////////////// 277 ////////////////////////////////////////////////////////////////////////////////
292 // ToolbarView, GetProfilesHelper::Delegate implementation: 278 // ToolbarView, GetProfilesHelper::Delegate implementation:
293 279
294 void ToolbarView::OnGetProfilesDone( 280 void ToolbarView::OnGetProfilesDone(
295 const std::vector<std::wstring>& profiles) { 281 const std::vector<std::wstring>& profiles) {
296 // Nothing to do if the menu has gone away. 282 // Nothing to do if the menu has gone away.
297 if (!profiles_menu_) 283 if (!profiles_menu_contents_.get())
298 return; 284 return;
299 285
300 // Store the latest list of profiles in the browser. 286 // Store the latest list of profiles in the browser.
301 browser_->set_user_data_dir_profiles(profiles); 287 browser_->set_user_data_dir_profiles(profiles);
302 288
303 // Add direct sub menu items for profiles. 289 // Add direct sub menu items for profiles.
304 std::vector<std::wstring>::const_iterator iter = profiles.begin(); 290 std::vector<std::wstring>::const_iterator iter = profiles.begin();
305 for (int i = IDC_NEW_WINDOW_PROFILE_0; 291 for (int i = IDC_NEW_WINDOW_PROFILE_0;
306 (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end()); 292 (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end());
307 ++i, ++iter) 293 ++i, ++iter)
308 profiles_menu_->AppendMenuItemWithLabel(i, *iter); 294 profiles_menu_contents_->AddItem(i, *iter);
309 295
310 // If there are more profiles then show "Other" link. 296 // If there are more profiles then show "Other" link.
311 if (iter != profiles.end()) { 297 if (iter != profiles.end()) {
312 profiles_menu_->AppendSeparator(); 298 profiles_menu_contents_->AddSeparator();
313 profiles_menu_->AppendMenuItemWithLabel( 299 profiles_menu_contents_->AddItemWithStringId(IDC_SELECT_PROFILE,
314 IDC_SELECT_PROFILE, l10n_util::GetString(IDS_SELECT_PROFILE)); 300 IDS_SELECT_PROFILE);
315 } 301 }
316 302
317 // Always show a link to select a new profile. 303 // Always show a link to select a new profile.
318 profiles_menu_->AppendSeparator(); 304 profiles_menu_contents_->AddSeparator();
319 profiles_menu_->AppendMenuItemWithLabel( 305 profiles_menu_contents_->AddItemWithStringId(
320 IDC_NEW_PROFILE, 306 IDC_NEW_PROFILE,
321 l10n_util::GetString(IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY)); 307 IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY);
322 } 308 }
323 309
324 //////////////////////////////////////////////////////////////////////////////// 310 ////////////////////////////////////////////////////////////////////////////////
325 // ToolbarView, LocationBarView::Delegate implementation: 311 // ToolbarView, LocationBarView::Delegate implementation:
326 312
327 TabContents* ToolbarView::GetTabContents() { 313 TabContents* ToolbarView::GetTabContents() {
328 return tab_; 314 return tab_;
329 } 315 }
330 316
331 void ToolbarView::OnInputInProgress(bool in_progress) { 317 void ToolbarView::OnInputInProgress(bool in_progress) {
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 1047
1062 void ToolbarView::CreateAppMenu() { 1048 void ToolbarView::CreateAppMenu() {
1063 if (app_menu_contents_.get()) 1049 if (app_menu_contents_.get())
1064 return; 1050 return;
1065 1051
1066 app_menu_contents_.reset(new views::SimpleMenuModel(this)); 1052 app_menu_contents_.reset(new views::SimpleMenuModel(this));
1067 app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); 1053 app_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
1068 app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW); 1054 app_menu_contents_->AddItemWithStringId(IDC_NEW_WINDOW, IDS_NEW_WINDOW);
1069 app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW, 1055 app_menu_contents_->AddItemWithStringId(IDC_NEW_INCOGNITO_WINDOW,
1070 IDS_NEW_INCOGNITO_WINDOW); 1056 IDS_NEW_INCOGNITO_WINDOW);
1057 // Enumerate profiles asynchronously and then create the parent menu item.
1058 // We will create the child menu items for this once the asynchronous call is
1059 // done. See OnGetProfilesDone().
1060 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1061 if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) {
1062 profiles_helper_->GetProfiles(NULL);
1063 profiles_menu_contents_.reset(new views::SimpleMenuModel(this));
1064 app_menu_contents_->AddSubMenuWithStringId(IDS_PROFILE_MENU,
1065 profiles_menu_contents_.get());
1066 }
1067
1071 app_menu_contents_->AddSeparator(); 1068 app_menu_contents_->AddSeparator();
1072 app_menu_contents_->AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR, 1069 app_menu_contents_->AddCheckItemWithStringId(IDC_SHOW_BOOKMARK_BAR,
1073 IDS_SHOW_BOOKMARK_BAR); 1070 IDS_SHOW_BOOKMARK_BAR);
1074 app_menu_contents_->AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN); 1071 app_menu_contents_->AddItemWithStringId(IDC_FULLSCREEN, IDS_FULLSCREEN);
1075 app_menu_contents_->AddSeparator(); 1072 app_menu_contents_->AddSeparator();
1076 app_menu_contents_->AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY); 1073 app_menu_contents_->AddItemWithStringId(IDC_SHOW_HISTORY, IDS_SHOW_HISTORY);
1077 app_menu_contents_->AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, 1074 app_menu_contents_->AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER,
1078 IDS_BOOKMARK_MANAGER); 1075 IDS_BOOKMARK_MANAGER);
1079 app_menu_contents_->AddItemWithStringId(IDC_SHOW_DOWNLOADS, 1076 app_menu_contents_->AddItemWithStringId(IDC_SHOW_DOWNLOADS,
1080 IDS_SHOW_DOWNLOADS); 1077 IDS_SHOW_DOWNLOADS);
(...skipping 17 matching lines...) Expand all
1098 app_menu_contents_->AddItem(IDC_ABOUT, 1095 app_menu_contents_->AddItem(IDC_ABOUT,
1099 l10n_util::GetStringF( 1096 l10n_util::GetStringF(
1100 IDS_ABOUT, 1097 IDS_ABOUT,
1101 l10n_util::GetString(IDS_PRODUCT_NAME))); 1098 l10n_util::GetString(IDS_PRODUCT_NAME)));
1102 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); 1099 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
1103 app_menu_contents_->AddSeparator(); 1100 app_menu_contents_->AddSeparator();
1104 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); 1101 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT);
1105 1102
1106 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); 1103 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get()));
1107 } 1104 }
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | views/controls/menu/menu_2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698