| 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_accessibility_state.h" | 7 #include "content/public/browser/browser_accessibility_state.h" |
| 8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/navigation_controller.h" | 9 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 15 #include "ui/accessibility/ax_enums.h" | 15 #include "ui/accessibility/ax_enums.h" |
| 16 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
| 17 #include "ui/base/ui_base_switches_util.h" |
| 17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 18 #include "ui/views/accessibility/native_view_accessibility.h" | 19 #include "ui/views/accessibility/native_view_accessibility.h" |
| 19 #include "ui/views/controls/native/native_view_host.h" | 20 #include "ui/views/controls/native/native_view_host.h" |
| 20 #include "ui/views/focus/focus_manager.h" | 21 #include "ui/views/focus/focus_manager.h" |
| 21 #include "ui/views/views_delegate.h" | 22 #include "ui/views/views_delegate.h" |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 | 25 |
| 25 // static | 26 // static |
| 26 const char WebView::kViewClassName[] = "WebView"; | 27 const char WebView::kViewClassName[] = "WebView"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // web_contents() now returns |replacement| from here onwards. | 61 // web_contents() now returns |replacement| from here onwards. |
| 61 if (wc_owner_ != replacement) | 62 if (wc_owner_ != replacement) |
| 62 wc_owner_.reset(); | 63 wc_owner_.reset(); |
| 63 if (embed_fullscreen_widget_mode_enabled_) { | 64 if (embed_fullscreen_widget_mode_enabled_) { |
| 64 is_embedding_fullscreen_widget_ = | 65 is_embedding_fullscreen_widget_ = |
| 65 web_contents() && web_contents()->GetFullscreenRenderWidgetHostView(); | 66 web_contents() && web_contents()->GetFullscreenRenderWidgetHostView(); |
| 66 } else { | 67 } else { |
| 67 DCHECK(!is_embedding_fullscreen_widget_); | 68 DCHECK(!is_embedding_fullscreen_widget_); |
| 68 } | 69 } |
| 69 AttachWebContents(); | 70 AttachWebContents(); |
| 71 NotifyMaybeTextInputClientChanged(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void WebView::SetEmbedFullscreenWidgetMode(bool enable) { | 74 void WebView::SetEmbedFullscreenWidgetMode(bool enable) { |
| 73 DCHECK(!web_contents()) | 75 DCHECK(!web_contents()) |
| 74 << "Cannot change mode while a WebContents is attached."; | 76 << "Cannot change mode while a WebContents is attached."; |
| 75 embed_fullscreen_widget_mode_enabled_ = enable; | 77 embed_fullscreen_widget_mode_enabled_ = enable; |
| 76 } | 78 } |
| 77 | 79 |
| 78 void WebView::LoadInitialURL(const GURL& url) { | 80 void WebView::LoadInitialURL(const GURL& url) { |
| 79 GetWebContents()->GetController().LoadURL( | 81 GetWebContents()->GetController().LoadURL( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 PreferredSizeChanged(); | 98 PreferredSizeChanged(); |
| 97 } | 99 } |
| 98 | 100 |
| 99 //////////////////////////////////////////////////////////////////////////////// | 101 //////////////////////////////////////////////////////////////////////////////// |
| 100 // WebView, View overrides: | 102 // WebView, View overrides: |
| 101 | 103 |
| 102 const char* WebView::GetClassName() const { | 104 const char* WebView::GetClassName() const { |
| 103 return kViewClassName; | 105 return kViewClassName; |
| 104 } | 106 } |
| 105 | 107 |
| 108 ui::TextInputClient* WebView::GetTextInputClient() { |
| 109 // This function delegates the text input handling to the underlying |
| 110 // content::RenderWidgetHostView. So when the underlying RWHV is destroyed or |
| 111 // replaced with another one, we have to notify the FocusManager through |
| 112 // FocusManager::OnTextInputClientChanged() that the focused TextInputClient |
| 113 // needs to be updated. |
| 114 if (switches::IsTextInputFocusManagerEnabled() && |
| 115 web_contents() && !web_contents()->IsBeingDestroyed()) { |
| 116 content::RenderWidgetHostView* host_view = |
| 117 is_embedding_fullscreen_widget_ ? |
| 118 web_contents()->GetFullscreenRenderWidgetHostView() : |
| 119 web_contents()->GetRenderWidgetHostView(); |
| 120 if (host_view) |
| 121 return host_view->GetTextInputClient(); |
| 122 } |
| 123 return NULL; |
| 124 } |
| 125 |
| 106 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 126 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 107 // In most cases, the holder is simply sized to fill this WebView's bounds. | 127 // In most cases, the holder is simply sized to fill this WebView's bounds. |
| 108 // Only WebContentses that are in fullscreen mode and being screen-captured | 128 // Only WebContentses that are in fullscreen mode and being screen-captured |
| 109 // will engage the special layout/sizing behavior. | 129 // will engage the special layout/sizing behavior. |
| 110 gfx::Rect holder_bounds(bounds().size()); | 130 gfx::Rect holder_bounds(bounds().size()); |
| 111 if (!embed_fullscreen_widget_mode_enabled_ || | 131 if (!embed_fullscreen_widget_mode_enabled_ || |
| 112 !web_contents() || | 132 !web_contents() || |
| 113 web_contents()->GetCapturerCount() == 0 || | 133 web_contents()->GetCapturerCount() == 0 || |
| 114 web_contents()->GetPreferredSize().IsEmpty() || | 134 web_contents()->GetPreferredSize().IsEmpty() || |
| 115 !(is_embedding_fullscreen_widget_ || | 135 !(is_embedding_fullscreen_widget_ || |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 242 } |
| 223 | 243 |
| 224 bool WebView::EmbedsFullscreenWidget() const { | 244 bool WebView::EmbedsFullscreenWidget() const { |
| 225 DCHECK(wc_owner_.get()); | 245 DCHECK(wc_owner_.get()); |
| 226 return embed_fullscreen_widget_mode_enabled_; | 246 return embed_fullscreen_widget_mode_enabled_; |
| 227 } | 247 } |
| 228 | 248 |
| 229 //////////////////////////////////////////////////////////////////////////////// | 249 //////////////////////////////////////////////////////////////////////////////// |
| 230 // WebView, content::WebContentsObserver implementation: | 250 // WebView, content::WebContentsObserver implementation: |
| 231 | 251 |
| 252 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { |
| 253 NotifyMaybeTextInputClientChanged(); |
| 254 } |
| 255 |
| 232 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 256 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
| 233 content::RenderViewHost* new_host) { | 257 content::RenderViewHost* new_host) { |
| 234 FocusManager* const focus_manager = GetFocusManager(); | 258 FocusManager* const focus_manager = GetFocusManager(); |
| 235 if (focus_manager && focus_manager->GetFocusedView() == this) | 259 if (focus_manager && focus_manager->GetFocusedView() == this) |
| 236 OnFocus(); | 260 OnFocus(); |
| 261 NotifyMaybeTextInputClientChanged(); |
| 237 } | 262 } |
| 238 | 263 |
| 239 void WebView::DidShowFullscreenWidget(int routing_id) { | 264 void WebView::DidShowFullscreenWidget(int routing_id) { |
| 240 if (embed_fullscreen_widget_mode_enabled_) | 265 if (embed_fullscreen_widget_mode_enabled_) |
| 241 ReattachForFullscreenChange(true); | 266 ReattachForFullscreenChange(true); |
| 242 } | 267 } |
| 243 | 268 |
| 244 void WebView::DidDestroyFullscreenWidget(int routing_id) { | 269 void WebView::DidDestroyFullscreenWidget(int routing_id) { |
| 245 if (embed_fullscreen_widget_mode_enabled_) | 270 if (embed_fullscreen_widget_mode_enabled_) |
| 246 ReattachForFullscreenChange(false); | 271 ReattachForFullscreenChange(false); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // widget. Need to detach and re-attach to a different native view. | 327 // widget. Need to detach and re-attach to a different native view. |
| 303 DetachWebContents(); | 328 DetachWebContents(); |
| 304 is_embedding_fullscreen_widget_ = | 329 is_embedding_fullscreen_widget_ = |
| 305 enter_fullscreen && web_contents_has_separate_fs_widget; | 330 enter_fullscreen && web_contents_has_separate_fs_widget; |
| 306 AttachWebContents(); | 331 AttachWebContents(); |
| 307 } else { | 332 } else { |
| 308 // Entering or exiting "non-Flash" fullscreen mode, where the native view is | 333 // Entering or exiting "non-Flash" fullscreen mode, where the native view is |
| 309 // the same. So, do not change attachment. | 334 // the same. So, do not change attachment. |
| 310 OnBoundsChanged(bounds()); | 335 OnBoundsChanged(bounds()); |
| 311 } | 336 } |
| 337 NotifyMaybeTextInputClientChanged(); |
| 338 } |
| 339 |
| 340 void WebView::NotifyMaybeTextInputClientChanged() { |
| 341 // Update the TextInputClient as needed; see GetTextInputClient(). |
| 342 FocusManager* const focus_manager = GetFocusManager(); |
| 343 if (focus_manager) |
| 344 focus_manager->OnTextInputClientChanged(this); |
| 312 } | 345 } |
| 313 | 346 |
| 314 content::WebContents* WebView::CreateWebContents( | 347 content::WebContents* WebView::CreateWebContents( |
| 315 content::BrowserContext* browser_context) { | 348 content::BrowserContext* browser_context) { |
| 316 content::WebContents* contents = NULL; | 349 content::WebContents* contents = NULL; |
| 317 if (ViewsDelegate::views_delegate) { | 350 if (ViewsDelegate::views_delegate) { |
| 318 contents = ViewsDelegate::views_delegate->CreateWebContents( | 351 contents = ViewsDelegate::views_delegate->CreateWebContents( |
| 319 browser_context, NULL); | 352 browser_context, NULL); |
| 320 } | 353 } |
| 321 | 354 |
| 322 if (!contents) { | 355 if (!contents) { |
| 323 content::WebContents::CreateParams create_params( | 356 content::WebContents::CreateParams create_params( |
| 324 browser_context, NULL); | 357 browser_context, NULL); |
| 325 return content::WebContents::Create(create_params); | 358 return content::WebContents::Create(create_params); |
| 326 } | 359 } |
| 327 | 360 |
| 328 return contents; | 361 return contents; |
| 329 } | 362 } |
| 330 | 363 |
| 331 } // namespace views | 364 } // namespace views |
| OLD | NEW |