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

Side by Side Diff: athena/content/render_view_context_menu_impl.cc

Issue 448063005: Add minimum Conetxt Menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "athena/content/render_view_context_menu_impl.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/renderer_context_menu/context_menu_content_type.h"
9 #include "components/renderer_context_menu/views/toolkit_delegate_views.h"
10 #include "content/public/browser/web_contents.h"
11 #include "ui/views/controls/menu/menu_item_view.h"
12 #include "ui/views/controls/menu/menu_model_adapter.h"
13 #include "ui/views/controls/menu/menu_runner.h"
14
15 namespace athena {
16 namespace {
17
18 enum {
19 CMD_BACK,
20 CMD_FORWARD,
21 CMD_RELOAD,
22 CMD_VIEW_SOURCE,
23 CMD_LAST,
24 };
25
26 // Max number of custom command ids allowd.
27 const int kNumCustomCommandIds = 1000;
28
29 void AppendPageItems(ui::SimpleMenuModel* menu_model) {
30 menu_model->AddItem(CMD_BACK, base::ASCIIToUTF16("Back"));
31 menu_model->AddItem(CMD_FORWARD, base::ASCIIToUTF16("Forward"));
32 menu_model->AddItem(CMD_RELOAD, base::ASCIIToUTF16("Reload"));
33 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
34 menu_model->AddItem(CMD_VIEW_SOURCE, base::ASCIIToUTF16("View Source"));
35 }
36
37 } // namespace
38
39 RenderViewContextMenuImpl::RenderViewContextMenuImpl(
40 content::RenderFrameHost* render_frame_host,
41 const content::ContextMenuParams& params)
42 : RenderViewContextMenuBase(render_frame_host, params) {
43 SetContentCustomCommandIdRange(CMD_LAST, CMD_LAST + kNumCustomCommandIds);
44 // TODO(oshima): Support other types
45 set_content_type(
46 new ContextMenuContentType(source_web_contents_, params, true));
47 scoped_ptr<ToolkitDelegate> delegate(new ToolkitDelegateViews);
48 set_toolkit_delegate(delegate.Pass());
Jun Mukai 2014/08/07 19:30:59 you can just call as: set_toolkit_delegate(scoped_
oshima 2014/08/07 20:23:07 Done.
49 }
50
51 RenderViewContextMenuImpl::~RenderViewContextMenuImpl() {
52 }
53
54 void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent,
55 const gfx::Point& point,
56 ui::MenuSourceType type) {
57 static_cast<ToolkitDelegateViews*>(toolkit_delegate())
58 ->RunMenuAt(parent, point, type);
Jun Mukai 2014/08/07 19:30:59 usually arrow operator appears at the end of the p
oshima 2014/08/07 20:23:07 This is what git cl format does, and we decided to
59 }
60
61 void RenderViewContextMenuImpl::InitMenu() {
62 RenderViewContextMenuBase::InitMenu();
63
64 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) {
65 AppendPageItems(&menu_model_);
66 }
67 }
68
69 void RenderViewContextMenuImpl::RecordShownItem(int id) {
Jun Mukai 2014/08/07 19:30:59 can you add a TODO comment to implement this?
oshima 2014/08/07 20:23:07 Done.
70 }
71
72 void RenderViewContextMenuImpl::RecordUsedItem(int id) {
Jun Mukai 2014/08/07 19:30:59 ditto
oshima 2014/08/07 20:23:07 Done.
73 }
74
75 #if defined(ENABLE_PLUGINS)
76 void RenderViewContextMenuImpl::HandleAuthorizeAllPlugins() {
77 }
78 #endif
79
80 void RenderViewContextMenuImpl::NotifyMenuShown() {
Jun Mukai 2014/08/07 19:30:58 ditto or is it intentionally blank?
oshima 2014/08/07 20:23:07 This is indeed intentionally blank. The chrome use
81 }
82
83 void RenderViewContextMenuImpl::NotifyURLOpened(
84 const GURL& url,
85 content::WebContents* new_contents) {
86 }
87
88 bool RenderViewContextMenuImpl::GetAcceleratorForCommandId(
89 int command_id,
90 ui::Accelerator* accelerator) {
91 NOTIMPLEMENTED();
92 return false;
93 }
94
95 bool RenderViewContextMenuImpl::IsCommandIdChecked(int command_id) const {
96 return false;
97 }
98
99 bool RenderViewContextMenuImpl::IsCommandIdEnabled(int command_id) const {
100 if (RenderViewContextMenuBase::IsCommandIdEnabled(command_id))
101 return true;
102 switch (command_id) {
103 case CMD_BACK:
104 return source_web_contents_->GetController().CanGoBack();
105 case CMD_FORWARD:
106 return source_web_contents_->GetController().CanGoForward();
107 case CMD_RELOAD:
108 return true;
109 case CMD_VIEW_SOURCE:
110 return source_web_contents_->GetController().CanViewSource();
111 }
112 return false;
113 }
114
115 void RenderViewContextMenuImpl::ExecuteCommand(int command_id,
116 int event_flags) {
117 RenderViewContextMenuBase::ExecuteCommand(command_id, event_flags);
118 if (command_executed_)
119 return;
120 command_executed_ = true;
121 switch (command_id) {
122 case CMD_BACK:
123 source_web_contents_->GetController().GoBack();
124 break;
125 case CMD_FORWARD:
126 source_web_contents_->GetController().GoForward();
127 break;
128 case CMD_RELOAD:
129 source_web_contents_->GetController().Reload(true);
130 break;
131 case CMD_VIEW_SOURCE:
132 source_web_contents_->ViewSource();
133 break;
134 }
135 }
136
137 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698