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

Side by Side Diff: athena/content/web_contents_view_delegate_factory_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
« no previous file with comments | « athena/content/render_view_context_menu_impl.cc ('k') | athena/main/athena_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/web_contents_view_delegate_creator.h"
6
7 #include "athena/content/render_view_context_menu_impl.h"
8 #include "components/web_modal/popup_manager.h"
9 #include "components/web_modal/single_web_contents_dialog_manager.h"
10 #include "components/web_modal/web_contents_modal_dialog_host.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_view_delegate.h"
16 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/window.h"
18 #include "ui/views/widget/widget.h"
19
20 namespace athena {
21 namespace {
22
23 class WebContentsViewDelegateImpl : public content::WebContentsViewDelegate {
24 public:
25 explicit WebContentsViewDelegateImpl(content::WebContents* web_contents)
26 : web_contents_(web_contents) {}
27 virtual ~WebContentsViewDelegateImpl() {}
28
29 virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE {
30 // TODO(oshima): crbug.com/401610
31 return NULL;
32 }
33
34 virtual bool Focus() OVERRIDE {
35 web_modal::PopupManager* popup_manager =
36 web_modal::PopupManager::FromWebContents(web_contents_);
37 if (popup_manager)
38 popup_manager->WasFocused(web_contents_);
39 return false;
40 }
41
42 virtual void TakeFocus(bool reverse) OVERRIDE {}
43 virtual void StoreFocus() OVERRIDE {}
44 virtual void RestoreFocus() OVERRIDE {}
45
46 virtual void ShowContextMenu(
47 content::RenderFrameHost* render_frame_host,
48 const content::ContextMenuParams& params) OVERRIDE {
49 ShowMenu(BuildMenu(
50 content::WebContents::FromRenderFrameHost(render_frame_host), params));
51 }
52
53 virtual void SizeChanged(const gfx::Size& size) OVERRIDE {
54 // TODO(oshima|sadrul): Implement this when sad_tab is componentized.
55 // See c/b/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc
56 }
57
58 scoped_ptr<RenderViewContextMenuImpl> BuildMenu(
59 content::WebContents* web_contents,
60 const content::ContextMenuParams& params) {
61 scoped_ptr<RenderViewContextMenuImpl> menu;
62 content::RenderFrameHost* focused_frame = web_contents->GetFocusedFrame();
63 // If the frame tree does not have a focused frame at this point, do not
64 // bother creating RenderViewContextMenuViews.
65 // This happens if the frame has navigated to a different page before
66 // ContextMenu message was received by the current RenderFrameHost.
67 if (focused_frame) {
68 menu.reset(new RenderViewContextMenuImpl(focused_frame, params));
69 menu->Init();
70 }
71 return menu.Pass();
72 }
73
74 void ShowMenu(scoped_ptr<RenderViewContextMenuImpl> menu) {
75 context_menu_.reset(menu.release());
76
77 if (!context_menu_.get())
78 return;
79
80 // Menus need a Widget to work. If we're not the active tab we won't
81 // necessarily be in a widget.
82 views::Widget* top_level_widget = GetTopLevelWidget();
83 if (!top_level_widget)
84 return;
85
86 const content::ContextMenuParams& params = context_menu_->params();
87 // Don't show empty menus.
88 if (context_menu_->menu_model().GetItemCount() == 0)
89 return;
90
91 gfx::Point screen_point(params.x, params.y);
92
93 // Convert from target window coordinates to root window coordinates.
94 aura::Window* target_window = GetActiveNativeView();
95 aura::Window* root_window = target_window->GetRootWindow();
96 aura::client::ScreenPositionClient* screen_position_client =
97 aura::client::GetScreenPositionClient(root_window);
98 if (screen_position_client) {
99 screen_position_client->ConvertPointToScreen(target_window,
100 &screen_point);
101 }
102 // Enable recursive tasks on the message loop so we can get updates while
103 // the context menu is being displayed.
104 base::MessageLoop::ScopedNestableTaskAllower allow(
105 base::MessageLoop::current());
106 context_menu_->RunMenuAt(
107 top_level_widget, screen_point, params.source_type);
108 }
109
110 aura::Window* GetActiveNativeView() {
111 return web_contents_->GetFullscreenRenderWidgetHostView()
112 ? web_contents_->GetFullscreenRenderWidgetHostView()
113 ->GetNativeView()
114 : web_contents_->GetNativeView();
115 }
116
117 views::Widget* GetTopLevelWidget() {
118 return views::Widget::GetTopLevelWidgetForNativeView(GetActiveNativeView());
119 }
120
121 views::FocusManager* GetFocusManager() {
122 views::Widget* toplevel_widget = GetTopLevelWidget();
123 return toplevel_widget ? toplevel_widget->GetFocusManager() : NULL;
124 }
125
126 void SetInitialFocus() {
127 if (web_contents_->FocusLocationBarByDefault()) {
128 if (web_contents_->GetDelegate())
129 web_contents_->GetDelegate()->SetFocusToLocationBar(false);
130 } else {
131 web_contents_->Focus();
132 }
133 }
134 scoped_ptr<RenderViewContextMenuImpl> context_menu_;
135 content::WebContents* web_contents_;
136 DISALLOW_COPY_AND_ASSIGN(WebContentsViewDelegateImpl);
137 };
138
139 } // namespace
140
141 content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
142 content::WebContents* web_contents) {
143 return new WebContentsViewDelegateImpl(web_contents);
144 }
145
146 } // namespace athena
147
148 namespace web_modal {
149
150 SingleWebContentsDialogManager*
151 WebContentsModalDialogManager::CreateNativeWebModalManager(
152 NativeWebContentsModalDialog dialog,
153 SingleWebContentsDialogManagerDelegate* native_delegate) {
154 // TODO(oshima): Investigate if we need to implement this.
155 NOTREACHED();
156 return NULL;
157 }
158
159 } // namespace web_modal
OLDNEW
« no previous file with comments | « athena/content/render_view_context_menu_impl.cc ('k') | athena/main/athena_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698