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

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu_win.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
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/tab_contents/render_view_context_menu_win.h" 5 #include "chrome/browser/tab_contents/render_view_context_menu_win.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
11 11
12 ////////////////////////////////////////////////////////////////////////////////
13 // RenderViewContextMenuWin, public:
14
12 RenderViewContextMenuWin::RenderViewContextMenuWin( 15 RenderViewContextMenuWin::RenderViewContextMenuWin(
13 TabContents* tab_contents, 16 TabContents* tab_contents,
14 const ContextMenuParams& params, 17 const ContextMenuParams& params)
15 HWND owner)
16 : RenderViewContextMenu(tab_contents, params), 18 : RenderViewContextMenu(tab_contents, params),
17 sub_menu_(NULL), 19 current_radio_group_id_(-1),
18 owner_(owner) { 20 sub_menu_contents_(NULL) {
19 // anchor_position set per http://crbug.com/10827. 21 menu_contents_.reset(new views::SimpleMenuModel(this));
20 views::Menu::AnchorPoint anchor_position = views::Menu::TOPLEFT; 22 InitMenu(params.node);
21 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 23 menu_.reset(new views::Menu2(menu_contents_.get()));
22 anchor_position = views::Menu::TOPRIGHT;
23 menu_.reset(new views::MenuWin(this, anchor_position, owner_));
24 } 24 }
25 25
26 RenderViewContextMenuWin::~RenderViewContextMenuWin() { 26 RenderViewContextMenuWin::~RenderViewContextMenuWin() {
27 } 27 }
28 28
29 void RenderViewContextMenuWin::RunMenuAt(int x, int y) { 29 void RenderViewContextMenuWin::RunMenuAt(int x, int y) {
30 menu_->RunMenuAt(x, y); 30 menu_->RunContextMenuAt(gfx::Point(x, y));
31 } 31 }
32 32
33 void RenderViewContextMenuWin::AppendMenuItem(int id) { 33 ////////////////////////////////////////////////////////////////////////////////
34 AppendItem(id, l10n_util::GetString(id), views::Menu::NORMAL); 34 // RenderViewContextMenuWin, views::SimpleMenuModel::Delegate implementation:
35
36 bool RenderViewContextMenuWin::IsCommandIdChecked(int command_id) const {
37 return ItemIsChecked(command_id);
35 } 38 }
36 39
37 void RenderViewContextMenuWin::AppendMenuItem(int id, 40 bool RenderViewContextMenuWin::IsCommandIdEnabled(int command_id) const {
38 const std::wstring& label) { 41 return IsItemCommandEnabled(command_id);
39 AppendItem(id, label, views::Menu::NORMAL);
40 } 42 }
41 43
42 void RenderViewContextMenuWin::AppendRadioMenuItem(int id, 44 bool RenderViewContextMenuWin::GetAcceleratorForCommandId(
43 const std::wstring& label) { 45 int command_id,
44 AppendItem(id, label, views::Menu::RADIO);
45 }
46
47 void RenderViewContextMenuWin::AppendCheckboxMenuItem(int id,
48 const std::wstring& label) {
49 AppendItem(id, label, views::Menu::CHECKBOX);
50 }
51
52 void RenderViewContextMenuWin::AppendSeparator() {
53 views::Menu* menu = sub_menu_ ? sub_menu_ : menu_.get();
54 menu->AppendSeparator();
55 }
56
57 void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
58 if (sub_menu_) {
59 NOTREACHED();
60 return;
61 }
62 sub_menu_ = menu_->AppendSubMenu(id, label);
63 }
64
65 void RenderViewContextMenuWin::FinishSubMenu() {
66 DCHECK(sub_menu_);
67 sub_menu_ = NULL;
68 }
69
70 void RenderViewContextMenuWin::AppendItem(
71 int id,
72 const std::wstring& label,
73 views::Menu::MenuItemType type) {
74 views::Menu* menu = sub_menu_ ? sub_menu_ : menu_.get();
75 menu->AppendMenuItem(id, label, type);
76 }
77
78 bool RenderViewContextMenuWin::IsCommandEnabled(int id) const {
79 return IsItemCommandEnabled(id);
80 }
81
82 bool RenderViewContextMenuWin::IsItemChecked(int id) const {
83 return ItemIsChecked(id);
84 }
85
86 void RenderViewContextMenuWin::ExecuteCommand(int id) {
87 ExecuteItemCommand(id);
88 }
89
90 bool RenderViewContextMenuWin::GetAcceleratorInfo(
91 int id,
92 views::Accelerator* accel) { 46 views::Accelerator* accel) {
93 // There are no formally defined accelerators we can query so we assume 47 // There are no formally defined accelerators we can query so we assume
94 // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do. 48 // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
95 switch (id) { 49 switch (command_id) {
96 case IDS_CONTENT_CONTEXT_UNDO: 50 case IDS_CONTENT_CONTEXT_UNDO:
97 *accel = views::Accelerator(L'Z', false, true, false); 51 *accel = views::Accelerator(L'Z', false, true, false);
98 return true; 52 return true;
99 53
100 case IDS_CONTENT_CONTEXT_REDO: 54 case IDS_CONTENT_CONTEXT_REDO:
101 *accel = views::Accelerator(L'Z', true, true, false); 55 *accel = views::Accelerator(L'Z', true, true, false);
102 return true; 56 return true;
103 57
104 case IDS_CONTENT_CONTEXT_CUT: 58 case IDS_CONTENT_CONTEXT_CUT:
105 *accel = views::Accelerator(L'X', false, true, false); 59 *accel = views::Accelerator(L'X', false, true, false);
106 return true; 60 return true;
107 61
108 case IDS_CONTENT_CONTEXT_COPY: 62 case IDS_CONTENT_CONTEXT_COPY:
109 *accel = views::Accelerator(L'C', false, true, false); 63 *accel = views::Accelerator(L'C', false, true, false);
110 return true; 64 return true;
111 65
112 case IDS_CONTENT_CONTEXT_PASTE: 66 case IDS_CONTENT_CONTEXT_PASTE:
113 *accel = views::Accelerator(L'V', false, true, false); 67 *accel = views::Accelerator(L'V', false, true, false);
114 return true; 68 return true;
115 69
116 case IDS_CONTENT_CONTEXT_SELECTALL: 70 case IDS_CONTENT_CONTEXT_SELECTALL:
117 *accel = views::Accelerator(L'A', false, true, false); 71 *accel = views::Accelerator(L'A', false, true, false);
118 return true; 72 return true;
119 73
120 default: 74 default:
121 return false; 75 return false;
122 } 76 }
123 } 77 }
78
79 void RenderViewContextMenuWin::ExecuteCommand(int command_id) {
80 ExecuteItemCommand(command_id);
81 }
82
83 ////////////////////////////////////////////////////////////////////////////////
84 // RenderViewContextMenuWin, protected:
85
86 void RenderViewContextMenuWin::AppendMenuItem(int id) {
87 current_radio_group_id_ = -1;
88 GetTargetModel()->AddItemWithStringId(id, id);
89 }
90
91 void RenderViewContextMenuWin::AppendMenuItem(int id,
92 const std::wstring& label) {
93 current_radio_group_id_ = -1;
94 GetTargetModel()->AddItem(id, label);
95 }
96
97 void RenderViewContextMenuWin::AppendRadioMenuItem(int id,
98 const std::wstring& label) {
99 if (current_radio_group_id_ < 0)
100 current_radio_group_id_ = id;
101 GetTargetModel()->AddRadioItem(id, label, current_radio_group_id_);
102 }
103
104 void RenderViewContextMenuWin::AppendCheckboxMenuItem(
105 int id,
106 const std::wstring& label) {
107 current_radio_group_id_ = -1;
108 GetTargetModel()->AddCheckItem(id, label);
109 }
110
111 void RenderViewContextMenuWin::AppendSeparator() {
112 current_radio_group_id_ = -1;
113 GetTargetModel()->AddSeparator();
114 }
115
116 void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
117 if (sub_menu_contents_) {
118 NOTREACHED() << "nested submenus not supported yet";
119 return;
120 }
121 current_radio_group_id_ = -1;
122 sub_menu_contents_ = new views::SimpleMenuModel(this);
123 menu_contents_->AddSubMenu(label, sub_menu_contents_);
124 submenu_models_.push_back(sub_menu_contents_);
125 }
126
127 void RenderViewContextMenuWin::FinishSubMenu() {
128 DCHECK(sub_menu_contents_);
129 current_radio_group_id_ = -1;
130 sub_menu_contents_ = NULL;
131 }
132
133 ////////////////////////////////////////////////////////////////////////////////
134 // RenderViewContextMenuWin, private:
135
136 views::SimpleMenuModel* RenderViewContextMenuWin::GetTargetModel() const {
137 return sub_menu_contents_ ? sub_menu_contents_ : menu_contents_.get();
138 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu_win.h ('k') | chrome/browser/tab_contents/tab_contents_view_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698