OLD | NEW |
| (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/renderer_context_menu/context_menu_delegate.h" | |
9 #include "components/web_modal/popup_manager.h" | |
10 #include "components/web_modal/single_web_contents_dialog_manager.h" | |
11 #include "components/web_modal/web_contents_modal_dialog_host.h" | |
12 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
13 #include "content/public/browser/render_widget_host_view.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "content/public/browser/web_contents_delegate.h" | |
16 #include "content/public/browser/web_contents_view_delegate.h" | |
17 #include "ui/aura/client/screen_position_client.h" | |
18 #include "ui/aura/window.h" | |
19 #include "ui/views/widget/widget.h" | |
20 | |
21 namespace athena { | |
22 namespace { | |
23 | |
24 class WebContentsViewDelegateImpl : public content::WebContentsViewDelegate, | |
25 public ContextMenuDelegate { | |
26 public: | |
27 explicit WebContentsViewDelegateImpl(content::WebContents* web_contents) | |
28 : ContextMenuDelegate(web_contents), web_contents_(web_contents) {} | |
29 ~WebContentsViewDelegateImpl() override {} | |
30 | |
31 content::WebDragDestDelegate* GetDragDestDelegate() override { | |
32 // TODO(oshima): crbug.com/401610 | |
33 NOTIMPLEMENTED(); | |
34 return nullptr; | |
35 } | |
36 | |
37 bool Focus() override { | |
38 web_modal::PopupManager* popup_manager = | |
39 web_modal::PopupManager::FromWebContents(web_contents_); | |
40 if (popup_manager) | |
41 popup_manager->WasFocused(web_contents_); | |
42 return false; | |
43 } | |
44 | |
45 void ShowContextMenu(content::RenderFrameHost* render_frame_host, | |
46 const content::ContextMenuParams& params) override { | |
47 ShowMenu(BuildMenu( | |
48 content::WebContents::FromRenderFrameHost(render_frame_host), params)); | |
49 } | |
50 | |
51 void SizeChanged(const gfx::Size& size) override { | |
52 // TODO(oshima|sadrul): Implement this when sad_tab is componentized. | |
53 // See c/b/ui/views/tab_contents/chrome_web_contents_view_delegate_views.cc | |
54 } | |
55 | |
56 void ShowDisambiguationPopup( | |
57 const gfx::Rect& target_rect, | |
58 const SkBitmap& zoomed_bitmap, | |
59 const gfx::NativeView content, | |
60 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, | |
61 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) override { | |
62 NOTIMPLEMENTED(); | |
63 } | |
64 | |
65 void HideDisambiguationPopup() override { NOTIMPLEMENTED(); } | |
66 | |
67 // ContextMenuDelegate: | |
68 scoped_ptr<RenderViewContextMenuBase> BuildMenu( | |
69 content::WebContents* web_contents, | |
70 const content::ContextMenuParams& params) override { | |
71 scoped_ptr<RenderViewContextMenuBase> menu; | |
72 content::RenderFrameHost* focused_frame = web_contents->GetFocusedFrame(); | |
73 // If the frame tree does not have a focused frame at this point, do not | |
74 // bother creating RenderViewContextMenuViews. | |
75 // This happens if the frame has navigated to a different page before | |
76 // ContextMenu message was received by the current RenderFrameHost. | |
77 if (focused_frame) { | |
78 menu.reset(new RenderViewContextMenuImpl(focused_frame, params)); | |
79 menu->Init(); | |
80 } | |
81 return menu.Pass(); | |
82 } | |
83 void ShowMenu(scoped_ptr<RenderViewContextMenuBase> menu) override { | |
84 context_menu_.reset(menu.release()); | |
85 | |
86 if (!context_menu_) | |
87 return; | |
88 | |
89 context_menu_->Show(); | |
90 } | |
91 | |
92 aura::Window* GetActiveNativeView() { | |
93 return web_contents_->GetFullscreenRenderWidgetHostView() | |
94 ? web_contents_->GetFullscreenRenderWidgetHostView() | |
95 ->GetNativeView() | |
96 : web_contents_->GetNativeView(); | |
97 } | |
98 | |
99 views::Widget* GetTopLevelWidget() { | |
100 return views::Widget::GetTopLevelWidgetForNativeView(GetActiveNativeView()); | |
101 } | |
102 | |
103 views::FocusManager* GetFocusManager() { | |
104 views::Widget* toplevel_widget = GetTopLevelWidget(); | |
105 return toplevel_widget ? toplevel_widget->GetFocusManager() : nullptr; | |
106 } | |
107 | |
108 void SetInitialFocus() { | |
109 if (web_contents_->FocusLocationBarByDefault()) { | |
110 if (web_contents_->GetDelegate()) | |
111 web_contents_->GetDelegate()->SetFocusToLocationBar(false); | |
112 } else { | |
113 web_contents_->Focus(); | |
114 } | |
115 } | |
116 scoped_ptr<RenderViewContextMenuBase> context_menu_; | |
117 content::WebContents* web_contents_; | |
118 DISALLOW_COPY_AND_ASSIGN(WebContentsViewDelegateImpl); | |
119 }; | |
120 | |
121 } // namespace | |
122 | |
123 content::WebContentsViewDelegate* CreateWebContentsViewDelegate( | |
124 content::WebContents* web_contents) { | |
125 return new WebContentsViewDelegateImpl(web_contents); | |
126 } | |
127 | |
128 } // namespace athena | |
OLD | NEW |