Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/public/browser/browser_accessibility_state.h" | 10 #include "content/public/browser/browser_accessibility_state.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 void WebView::RenderViewReady() { | 264 void WebView::RenderViewReady() { |
| 265 NotifyAccessibilityWebContentsChanged(); | 265 NotifyAccessibilityWebContentsChanged(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { | 268 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { |
| 269 NotifyAccessibilityWebContentsChanged(); | 269 NotifyAccessibilityWebContentsChanged(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 272 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
| 273 content::RenderViewHost* new_host) { | 273 content::RenderViewHost* new_host) { |
| 274 FocusManager* const focus_manager = GetFocusManager(); | 274 if (HasFocus()) |
| 275 if (focus_manager && focus_manager->GetFocusedView() == this) | |
| 276 OnFocus(); | 275 OnFocus(); |
| 277 NotifyAccessibilityWebContentsChanged(); | 276 NotifyAccessibilityWebContentsChanged(); |
| 278 } | 277 } |
| 279 | 278 |
| 280 void WebView::WebContentsDestroyed() { | 279 void WebView::WebContentsDestroyed() { |
| 281 if (observing_render_process_host_) { | 280 if (observing_render_process_host_) { |
| 282 observing_render_process_host_->RemoveObserver(this); | 281 observing_render_process_host_->RemoveObserver(this); |
| 283 observing_render_process_host_ = nullptr; | 282 observing_render_process_host_ = nullptr; |
| 284 } | 283 } |
| 285 NotifyAccessibilityWebContentsChanged(); | 284 NotifyAccessibilityWebContentsChanged(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 303 | 302 |
| 304 void WebView::DidAttachInterstitialPage() { | 303 void WebView::DidAttachInterstitialPage() { |
| 305 NotifyAccessibilityWebContentsChanged(); | 304 NotifyAccessibilityWebContentsChanged(); |
| 306 } | 305 } |
| 307 | 306 |
| 308 void WebView::DidDetachInterstitialPage() { | 307 void WebView::DidDetachInterstitialPage() { |
| 309 NotifyAccessibilityWebContentsChanged(); | 308 NotifyAccessibilityWebContentsChanged(); |
| 310 } | 309 } |
| 311 | 310 |
| 312 void WebView::OnWebContentsFocused() { | 311 void WebView::OnWebContentsFocused() { |
| 313 FocusManager* focus_manager = GetFocusManager(); | 312 RequestFocus(); |
| 314 if (focus_manager) | |
| 315 focus_manager->SetFocusedView(this); | |
| 316 } | 313 } |
| 317 | 314 |
| 318 //////////////////////////////////////////////////////////////////////////////// | 315 //////////////////////////////////////////////////////////////////////////////// |
| 319 // WebView, private: | 316 // WebView, private: |
| 320 | 317 |
| 321 void WebView::AttachWebContents() { | 318 void WebView::AttachWebContents() { |
| 322 // Prevents attachment if the WebView isn't already in a Widget, or it's | 319 // Prevents attachment if the WebView isn't already in a Widget, or it's |
| 323 // already attached. | 320 // already attached. |
| 324 if (!GetWidget() || !web_contents()) | 321 if (!GetWidget() || !web_contents()) |
| 325 return; | 322 return; |
| 326 | 323 |
| 327 const gfx::NativeView view_to_attach = is_embedding_fullscreen_widget_ ? | 324 const gfx::NativeView view_to_attach = is_embedding_fullscreen_widget_ ? |
| 328 web_contents()->GetFullscreenRenderWidgetHostView()->GetNativeView() : | 325 web_contents()->GetFullscreenRenderWidgetHostView()->GetNativeView() : |
| 329 web_contents()->GetNativeView(); | 326 web_contents()->GetNativeView(); |
| 330 OnBoundsChanged(bounds()); | 327 OnBoundsChanged(bounds()); |
| 331 if (holder_->native_view() == view_to_attach) | 328 if (holder_->native_view() == view_to_attach) |
| 332 return; | 329 return; |
| 333 | 330 |
| 334 holder_->Attach(view_to_attach); | 331 holder_->Attach(view_to_attach); |
| 335 | 332 |
| 336 // The view will not be focused automatically when it is attached, so we need | 333 // The WebContents will not be focused automatically when it is attached, so |
| 337 // to pass on focus to it if the FocusManager thinks the view is focused. Note | 334 // we need to pass on focus to if focused. |
|
msw
2017/03/10 17:47:08
nit: clarify 'pass on focus to if focused'?
sky
2017/03/10 18:06:11
Done.
| |
| 338 // that not every Widget has a focus manager. | 335 if (HasFocus()) |
| 339 FocusManager* const focus_manager = GetFocusManager(); | |
| 340 if (focus_manager && focus_manager->GetFocusedView() == this) | |
| 341 OnFocus(); | 336 OnFocus(); |
| 342 | 337 |
| 343 OnWebContentsAttached(); | 338 OnWebContentsAttached(); |
| 344 } | 339 } |
| 345 | 340 |
| 346 void WebView::DetachWebContents() { | 341 void WebView::DetachWebContents() { |
| 347 if (web_contents()) | 342 if (web_contents()) |
| 348 holder_->Detach(); | 343 holder_->Detach(); |
| 349 } | 344 } |
| 350 | 345 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 if (!contents) { | 378 if (!contents) { |
| 384 content::WebContents::CreateParams create_params( | 379 content::WebContents::CreateParams create_params( |
| 385 browser_context, NULL); | 380 browser_context, NULL); |
| 386 return content::WebContents::Create(create_params); | 381 return content::WebContents::Create(create_params); |
| 387 } | 382 } |
| 388 | 383 |
| 389 return contents; | 384 return contents; |
| 390 } | 385 } |
| 391 | 386 |
| 392 } // namespace views | 387 } // namespace views |
| OLD | NEW |