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