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

Side by Side Diff: chrome/browser/back_forward_menu_model_views.cc

Issue 126092: Begin to upgrade BackForwardMenuModelViews to use new menu API.... (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
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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/back_forward_menu_model_views.h" 5 #include "chrome/browser/back_forward_menu_model_views.h"
6 6
7 #include "chrome/app/chrome_dll_resource.h"
7 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
8 #include "chrome/browser/metrics/user_metrics.h" 9 #include "chrome/browser/metrics/user_metrics.h"
9 #include "grit/generated_resources.h" 10 #include "views/controls/menu/menu_2.h"
11 #include "views/widget/widget.h"
10 12
11 // static 13 ////////////////////////////////////////////////////////////////////////////////
12 BackForwardMenuModel* BackForwardMenuModel::Create(Browser* browser, 14 // BackForwardMenuModelViews, public:
13 ModelType model_type) { 15
14 return new BackForwardMenuModelViews(browser, model_type); 16 BackForwardMenuModelViews::BackForwardMenuModelViews(Browser* browser,
17 ModelType model_type,
18 views::Widget* frame)
19 : BackForwardMenuModel(browser, model_type),
20 frame_(frame) {
15 } 21 }
16 22
17 BackForwardMenuModelViews::BackForwardMenuModelViews(Browser* browser, 23 ////////////////////////////////////////////////////////////////////////////////
18 ModelType model_type) { 24 // BackForwardMenuModelViews, views::Menu2Model implementation:
19 browser_ = browser; 25
20 model_type_ = model_type; 26 bool BackForwardMenuModelViews::HasIcons() const {
27 return true;
21 } 28 }
22 29
23 std::wstring BackForwardMenuModelViews::GetLabel(int menu_id) const { 30 int BackForwardMenuModelViews::GetItemCount() const {
24 return GetItemLabel(menu_id); 31 return GetTotalItemCount();
25 } 32 }
26 33
27 const SkBitmap& BackForwardMenuModelViews::GetIcon(int menu_id) const { 34 views::Menu2Model::ItemType BackForwardMenuModelViews::GetTypeAt(
28 // Return NULL if the item doesn't have an icon 35 int index) const {
29 if (!ItemHasIcon(menu_id)) 36 if (IsSeparator(GetCommandIdAt(index)))
30 return GetEmptyIcon(); 37 return views::Menu2Model::TYPE_SEPARATOR;
31 38 return views::Menu2Model::TYPE_COMMAND;
32 return GetItemIcon(menu_id);
33 } 39 }
34 40
35 bool BackForwardMenuModelViews::IsItemSeparator(int menu_id) const { 41 int BackForwardMenuModelViews::GetCommandIdAt(int index) const {
36 return IsSeparator(menu_id); 42 return index + 1;
37 } 43 }
38 44
39 bool BackForwardMenuModelViews::HasIcon(int menu_id) const { 45 std::wstring BackForwardMenuModelViews::GetLabelAt(int index) const {
40 return ItemHasIcon(menu_id); 46 return GetItemLabel(GetCommandIdAt(index));
41 } 47 }
42 48
43 bool BackForwardMenuModelViews::SupportsCommand(int menu_id) const { 49 bool BackForwardMenuModelViews::IsLabelDynamicAt(int index) const {
44 return ItemHasCommand(menu_id); 50 return false;
45 } 51 }
46 52
47 bool BackForwardMenuModelViews::IsCommandEnabled(int menu_id) const { 53 bool BackForwardMenuModelViews::GetAcceleratorAt(
48 return ItemHasCommand(menu_id); 54 int index,
55 views::Accelerator* accelerator) const {
56 // Look up the history accelerator.
57 if (GetCommandIdAt(index) == GetTotalItemCount())
58 return frame_->GetAccelerator(IDC_SHOW_HISTORY, accelerator);
59 return false;
49 } 60 }
50 61
51 void BackForwardMenuModelViews::ExecuteCommand(int menu_id) { 62 bool BackForwardMenuModelViews::IsItemCheckedAt(int index) const {
52 ExecuteCommandById(menu_id); 63 return false;
64 }
65
66 int BackForwardMenuModelViews::GetGroupIdAt(int index) const {
67 return -1;
68 }
69
70 bool BackForwardMenuModelViews::GetIconAt(int index, SkBitmap* icon) const {
71 if (ItemHasIcon(GetCommandIdAt(index))) {
72 *icon = GetItemIcon(GetCommandIdAt(index));
73 return true;
74 }
75 return false;
76 }
77
78 bool BackForwardMenuModelViews::IsEnabledAt(int index) const {
79 return true;
80 }
81
82 views::Menu2Model* BackForwardMenuModelViews::GetSubmenuModelAt(
83 int index) const {
84 return NULL;
85 }
86
87 void BackForwardMenuModelViews::HighlightChangedTo(int index) {
88 }
89
90 void BackForwardMenuModelViews::ActivatedAt(int index) {
91 ExecuteCommandById(GetCommandIdAt(index));
53 } 92 }
54 93
55 void BackForwardMenuModelViews::MenuWillShow() { 94 void BackForwardMenuModelViews::MenuWillShow() {
56 UserMetrics::RecordComputedAction(BuildActionName(L"Popup", -1), 95 UserMetrics::RecordComputedAction(BuildActionName(L"Popup", -1),
57 browser_->profile()); 96 browser_->profile());
58 } 97 }
59
60 int BackForwardMenuModelViews::GetItemCount() const {
61 return GetTotalItemCount();
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698