1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/tab_contents/render_view_context_menu_win.h"
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
RenderViewContextMenuWin::RenderViewContextMenuWin(
TabContents* tab_contents,
const ContextMenuParams& params,
HWND owner)
: RenderViewContextMenu(tab_contents, params),
ALLOW_THIS_IN_INITIALIZER_LIST(menu_(this, views::Menu::TOPLEFT, owner)),
sub_menu_(NULL) {
InitMenu(params.node);
}
RenderViewContextMenuWin::~RenderViewContextMenuWin() {
}
void RenderViewContextMenuWin::RunMenuAt(int x, int y) {
menu_.RunMenuAt(x, y);
}
void RenderViewContextMenuWin::AppendMenuItem(int id) {
AppendItem(id, l10n_util::GetString(id), views::Menu::NORMAL);
}
void RenderViewContextMenuWin::AppendMenuItem(int id,
const std::wstring& label) {
AppendItem(id, label, views::Menu::NORMAL);
}
void RenderViewContextMenuWin::AppendRadioMenuItem(int id,
const std::wstring& label) {
AppendItem(id, label, views::Menu::RADIO);
}
void RenderViewContextMenuWin::AppendCheckboxMenuItem(int id,
const std::wstring& label) {
AppendItem(id, label, views::Menu::CHECKBOX);
}
void RenderViewContextMenuWin::AppendSeparator() {
views::Menu* menu = sub_menu_ ? sub_menu_ : &menu_;
menu->AppendSeparator();
}
void RenderViewContextMenuWin::StartSubMenu(int id, const std::wstring& label) {
if (sub_menu_) {
NOTREACHED();
return;
}
sub_menu_ = menu_.AppendSubMenu(id, label);
}
void RenderViewContextMenuWin::FinishSubMenu() {
DCHECK(sub_menu_);
sub_menu_ = NULL;
}
void RenderViewContextMenuWin::AppendItem(
int id,
const std::wstring& label,
views::Menu::MenuItemType type) {
views::Menu* menu = sub_menu_ ? sub_menu_ : &menu_;
menu->AppendMenuItem(id, label, type);
}
bool RenderViewContextMenuWin::IsCommandEnabled(int id) const {
return IsItemCommandEnabled(id);
}
bool RenderViewContextMenuWin::IsItemChecked(int id) const {
return ItemIsChecked(id);
}
void RenderViewContextMenuWin::ExecuteCommand(int id) {
ExecuteItemCommand(id);
}
bool RenderViewContextMenuWin::GetAcceleratorInfo(
int id,
views::Accelerator* accel) {
// There are no formally defined accelerators we can query so we assume
// that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
switch (id) {
case IDS_CONTENT_CONTEXT_UNDO:
*accel = views::Accelerator(L'Z', false, true, false);
return true;
case IDS_CONTENT_CONTEXT_REDO:
*accel = views::Accelerator(L'Z', true, true, false);
return true;
case IDS_CONTENT_CONTEXT_CUT:
*accel = views::Accelerator(L'X', false, true, false);
return true;
case IDS_CONTENT_CONTEXT_COPY:
*accel = views::Accelerator(L'C', false, true, false);
return true;
case IDS_CONTENT_CONTEXT_PASTE:
*accel = views::Accelerator(L'V', false, true, false);
return true;
case IDS_CONTENT_CONTEXT_SELECTALL:
*accel = views::Accelerator(L'A', false, true, false);
return true;
default:
return false;
}
}
|