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

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

Issue 678653003: Remove Downcasting RVContextMenuBase in ContextMenuDeleagate implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove virtual keyword when override is specified Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "athena/content/render_view_context_menu_impl.h" 5 #include "athena/content/render_view_context_menu_impl.h"
6 6
7 #include "athena/strings/grit/athena_strings.h" 7 #include "athena/strings/grit/athena_strings.h"
8 #include "components/renderer_context_menu/context_menu_content_type.h" 8 #include "components/renderer_context_menu/context_menu_content_type.h"
9 #include "components/renderer_context_menu/views/toolkit_delegate_views.h" 9 #include "components/renderer_context_menu/views/toolkit_delegate_views.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
12 #include "third_party/WebKit/public/web/WebContextMenuData.h" 13 #include "third_party/WebKit/public/web/WebContextMenuData.h"
14 #include "ui/aura/client/screen_position_client.h"
15 #include "ui/aura/window.h"
13 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/views/widget/widget.h"
14 18
15 namespace athena { 19 namespace athena {
16 using blink::WebContextMenuData; 20 using blink::WebContextMenuData;
17 21
18 namespace { 22 namespace {
19 23
20 enum { 24 enum {
21 // Nativation 25 // Nativation
22 CMD_BACK = 0, 26 CMD_BACK = 0,
23 CMD_FORWARD, 27 CMD_FORWARD,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 RenderViewContextMenuImpl::~RenderViewContextMenuImpl() { 107 RenderViewContextMenuImpl::~RenderViewContextMenuImpl() {
104 } 108 }
105 109
106 void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent, 110 void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent,
107 const gfx::Point& point, 111 const gfx::Point& point,
108 ui::MenuSourceType type) { 112 ui::MenuSourceType type) {
109 static_cast<ToolkitDelegateViews*>(toolkit_delegate()) 113 static_cast<ToolkitDelegateViews*>(toolkit_delegate())
110 ->RunMenuAt(parent, point, type); 114 ->RunMenuAt(parent, point, type);
111 } 115 }
112 116
117 void RenderViewContextMenuImpl::Show() {
118 // Menus need a Widget to work. If we're not the active tab we won't
119 // necessarily be in a widget.
120 views::Widget* top_level_widget = GetTopLevelWidget();
121 if (!top_level_widget)
122 return;
123
124 // Don't show empty menus.
125 if (menu_model().GetItemCount() == 0)
126 return;
127
128 gfx::Point screen_point(params().x, params().y);
129
130 // Convert from target window coordinates to root window coordinates.
131 aura::Window* target_window = GetActiveNativeView();
132 aura::Window* root_window = target_window->GetRootWindow();
133 aura::client::ScreenPositionClient* screen_position_client =
134 aura::client::GetScreenPositionClient(root_window);
135 if (screen_position_client)
136 screen_position_client->ConvertPointToScreen(target_window, &screen_point);
137
138 // Enable recursive tasks on the message loop so we can get updates while
139 // the context menu is being displayed.
140 base::MessageLoop::ScopedNestableTaskAllower allow(
141 base::MessageLoop::current());
142 RunMenuAt(top_level_widget, screen_point, params().source_type);
143 }
144
113 void RenderViewContextMenuImpl::InitMenu() { 145 void RenderViewContextMenuImpl::InitMenu() {
114 RenderViewContextMenuBase::InitMenu(); 146 RenderViewContextMenuBase::InitMenu();
115 bool needs_separator = false; 147 bool needs_separator = false;
116 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) { 148 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) {
117 AppendPageItems(&menu_model_); 149 AppendPageItems(&menu_model_);
118 needs_separator = true; 150 needs_separator = true;
119 } 151 }
120 152
121 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) { 153 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) {
122 if (needs_separator) 154 if (needs_separator)
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 case CMD_DELETE: 304 case CMD_DELETE:
273 source_web_contents_->Delete(); 305 source_web_contents_->Delete();
274 break; 306 break;
275 307
276 case CMD_SELECT_ALL: 308 case CMD_SELECT_ALL:
277 source_web_contents_->SelectAll(); 309 source_web_contents_->SelectAll();
278 break; 310 break;
279 } 311 }
280 } 312 }
281 313
314 views::Widget* RenderViewContextMenuImpl::GetTopLevelWidget() {
315 return views::Widget::GetTopLevelWidgetForNativeView(GetActiveNativeView());
316 }
317
318 aura::Window* RenderViewContextMenuImpl::GetActiveNativeView() {
319 content::WebContents* web_contents =
320 content::WebContents::FromRenderFrameHost(GetRenderFrameHost());
321 if (!web_contents) {
322 LOG(ERROR) << "RenderViewContextMenuImpl::Show, couldn't find WebContents";
323 return NULL;
324 }
325
326 return web_contents->GetFullscreenRenderWidgetHostView()
327 ? web_contents->GetFullscreenRenderWidgetHostView()
328 ->GetNativeView()
329 : web_contents->GetNativeView();
330 }
331
282 } // namespace athena 332 } // namespace athena
OLDNEW
« no previous file with comments | « athena/content/render_view_context_menu_impl.h ('k') | athena/content/web_contents_view_delegate_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698