OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/webview/webview.h" | 5 #include "ui/views/controls/webview/webview.h" |
6 | 6 |
7 #include "content/public/browser/browser_context.h" | 7 #include "content/public/browser/browser_context.h" |
8 #include "content/public/browser/navigation_controller.h" | 8 #include "content/public/browser/navigation_controller.h" |
9 #include "content/public/browser/notification_details.h" | 9 #include "content/public/browser/notification_details.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
11 #include "content/public/browser/notification_source.h" | 11 #include "content/public/browser/notification_source.h" |
12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
13 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 14 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_view.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 #include "ui/base/accessibility/accessibility_types.h" | 18 #include "ui/base/accessibility/accessibility_types.h" |
18 #include "ui/base/accessibility/accessible_view_state.h" | 19 #include "ui/base/accessibility/accessible_view_state.h" |
19 #include "ui/base/events/event.h" | 20 #include "ui/base/events/event.h" |
20 #include "ui/views/controls/native/native_view_host.h" | 21 #include "ui/views/controls/native/native_view_host.h" |
21 #include "ui/views/focus/focus_manager.h" | 22 #include "ui/views/focus/focus_manager.h" |
22 #include "ui/views/views_delegate.h" | 23 #include "ui/views/views_delegate.h" |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 | 26 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 bool WebView::IsFocusable() const { | 117 bool WebView::IsFocusable() const { |
117 // We need to be focusable when our contents is not a view hierarchy, as | 118 // We need to be focusable when our contents is not a view hierarchy, as |
118 // clicking on the contents needs to focus us. | 119 // clicking on the contents needs to focus us. |
119 return !!web_contents_; | 120 return !!web_contents_; |
120 } | 121 } |
121 | 122 |
122 void WebView::OnFocus() { | 123 void WebView::OnFocus() { |
123 if (web_contents_) | 124 if (web_contents_) |
124 web_contents_->Focus(); | 125 web_contents_->GetView()->Focus(); |
125 } | 126 } |
126 | 127 |
127 void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) { | 128 void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
128 if (web_contents_) | 129 if (web_contents_) |
129 web_contents_->FocusThroughTabTraversal(reverse); | 130 web_contents_->FocusThroughTabTraversal(reverse); |
130 } | 131 } |
131 | 132 |
132 void WebView::GetAccessibleState(ui::AccessibleViewState* state) { | 133 void WebView::GetAccessibleState(ui::AccessibleViewState* state) { |
133 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 134 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
134 } | 135 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 OnWebContentsFocused(web_contents_); | 181 OnWebContentsFocused(web_contents_); |
181 } | 182 } |
182 | 183 |
183 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
184 // WebView, private: | 185 // WebView, private: |
185 | 186 |
186 void WebView::AttachWebContents() { | 187 void WebView::AttachWebContents() { |
187 // Prevents attachment if the WebView isn't already in a Widget, or it's | 188 // Prevents attachment if the WebView isn't already in a Widget, or it's |
188 // already attached. | 189 // already attached. |
189 if (!GetWidget() || !web_contents_ || | 190 if (!GetWidget() || !web_contents_ || |
190 wcv_holder_->native_view() == web_contents_->GetNativeView()) { | 191 wcv_holder_->native_view() == web_contents_->GetView()->GetNativeView()) { |
191 return; | 192 return; |
192 } | 193 } |
193 | 194 |
194 if (web_contents_) { | 195 if (web_contents_) { |
195 wcv_holder_->Attach(web_contents_->GetNativeView()); | 196 wcv_holder_->Attach(web_contents_->GetView()->GetNativeView()); |
196 | 197 |
197 // The WebContentsView will not be focused automatically when it is | 198 // The WebContentsView will not be focused automatically when it is |
198 // attached, so we need to pass on focus to it if the FocusManager thinks | 199 // attached, so we need to pass on focus to it if the FocusManager thinks |
199 // the WebView is focused. Note that not every Widget has a focus manager. | 200 // the WebView is focused. Note that not every Widget has a focus manager. |
200 FocusManager* focus_manager = GetFocusManager(); | 201 FocusManager* focus_manager = GetFocusManager(); |
201 if (focus_manager && focus_manager->GetFocusedView() == this) | 202 if (focus_manager && focus_manager->GetFocusedView() == this) |
202 web_contents_->Focus(); | 203 web_contents_->GetView()->Focus(); |
203 | 204 |
204 registrar_.Add( | 205 registrar_.Add( |
205 this, | 206 this, |
206 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 207 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
207 content::Source<content::NavigationController>( | 208 content::Source<content::NavigationController>( |
208 &web_contents_->GetController())); | 209 &web_contents_->GetController())); |
209 registrar_.Add( | 210 registrar_.Add( |
210 this, | 211 this, |
211 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 212 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
212 content::Source<content::WebContents>(web_contents_)); | 213 content::Source<content::WebContents>(web_contents_)); |
213 } | 214 } |
214 } | 215 } |
215 | 216 |
216 void WebView::DetachWebContents() { | 217 void WebView::DetachWebContents() { |
217 if (web_contents_) { | 218 if (web_contents_) { |
218 wcv_holder_->Detach(); | 219 wcv_holder_->Detach(); |
219 #if defined(OS_WIN) && !defined(USE_AURA) | 220 #if defined(OS_WIN) && !defined(USE_AURA) |
220 // TODO(beng): This should either not be necessary, or be done implicitly by | 221 // TODO(beng): This should either not be necessary, or be done implicitly by |
221 // NativeViewHostWin on Detach(). As it stands, this is needed so that the | 222 // NativeViewHostWin on Detach(). As it stands, this is needed so that the |
222 // view of the detached contents knows to tell the renderer it's been | 223 // view of the detached contents knows to tell the renderer it's been |
223 // hidden. | 224 // hidden. |
224 // | 225 // |
225 // Moving this out of here would also mean we wouldn't be potentially | 226 // Moving this out of here would also mean we wouldn't be potentially |
226 // calling member functions on a half-destroyed WebContents. | 227 // calling member functions on a half-destroyed WebContents. |
227 ShowWindow(web_contents_->GetNativeView(), SW_HIDE); | 228 ShowWindow(web_contents_->GetView()->GetNativeView(), SW_HIDE); |
228 #endif | 229 #endif |
229 } | 230 } |
230 registrar_.RemoveAll(); | 231 registrar_.RemoveAll(); |
231 } | 232 } |
232 | 233 |
233 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 234 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
234 content::RenderViewHost* new_host) { | 235 content::RenderViewHost* new_host) { |
235 if (GetFocusManager()->GetFocusedView() == this) | 236 if (GetFocusManager()->GetFocusedView() == this) |
236 web_contents_->Focus(); | 237 web_contents_->GetView()->Focus(); |
237 } | 238 } |
238 | 239 |
239 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { | 240 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { |
240 DCHECK(web_contents == web_contents_); | 241 DCHECK(web_contents == web_contents_); |
241 SetWebContents(NULL); | 242 SetWebContents(NULL); |
242 } | 243 } |
243 | 244 |
244 content::WebContents* WebView::CreateWebContents( | 245 content::WebContents* WebView::CreateWebContents( |
245 content::BrowserContext* browser_context, | 246 content::BrowserContext* browser_context, |
246 content::SiteInstance* site_instance) { | 247 content::SiteInstance* site_instance) { |
247 content::WebContents* contents = NULL; | 248 content::WebContents* contents = NULL; |
248 if (ViewsDelegate::views_delegate) { | 249 if (ViewsDelegate::views_delegate) { |
249 contents = ViewsDelegate::views_delegate->CreateWebContents( | 250 contents = ViewsDelegate::views_delegate->CreateWebContents( |
250 browser_context, site_instance); | 251 browser_context, site_instance); |
251 } | 252 } |
252 | 253 |
253 if (!contents) { | 254 if (!contents) { |
254 content::WebContents::CreateParams create_params( | 255 content::WebContents::CreateParams create_params( |
255 browser_context, site_instance); | 256 browser_context, site_instance); |
256 return content::WebContents::Create(create_params); | 257 return content::WebContents::Create(create_params); |
257 } | 258 } |
258 | 259 |
259 return contents; | 260 return contents; |
260 } | 261 } |
261 | 262 |
262 } // namespace views | 263 } // namespace views |
OLD | NEW |