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" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Prevents attachment if the WebView isn't already in a Widget, or it's | 173 // Prevents attachment if the WebView isn't already in a Widget, or it's |
174 // already attached. | 174 // already attached. |
175 if (!GetWidget() || !web_contents_ || | 175 if (!GetWidget() || !web_contents_ || |
176 wcv_holder_->native_view() == web_contents_->GetNativeView()) { | 176 wcv_holder_->native_view() == web_contents_->GetNativeView()) { |
177 return; | 177 return; |
178 } | 178 } |
179 | 179 |
180 if (web_contents_) { | 180 if (web_contents_) { |
181 wcv_holder_->Attach(web_contents_->GetNativeView()); | 181 wcv_holder_->Attach(web_contents_->GetNativeView()); |
182 | 182 |
| 183 // The WebContentsView will not be focused automatically when it is |
| 184 // attached, so we need to pass on focus to it if the FocusManager thinks |
| 185 // the WebView is focused. Note that not every Widget has a focus manager. |
| 186 FocusManager* focus_manager = GetFocusManager(); |
| 187 if (focus_manager && focus_manager->GetFocusedView() == this) |
| 188 web_contents_->Focus(); |
| 189 |
183 registrar_.Add( | 190 registrar_.Add( |
184 this, | 191 this, |
185 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 192 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
186 content::Source<content::NavigationController>( | 193 content::Source<content::NavigationController>( |
187 &web_contents_->GetController())); | 194 &web_contents_->GetController())); |
188 registrar_.Add( | 195 registrar_.Add( |
189 this, | 196 this, |
190 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 197 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
191 content::Source<content::WebContents>(web_contents_)); | 198 content::Source<content::WebContents>(web_contents_)); |
192 } | 199 } |
(...skipping 18 matching lines...) Expand all Loading... |
211 if (GetFocusManager()->GetFocusedView() == this) | 218 if (GetFocusManager()->GetFocusedView() == this) |
212 web_contents_->Focus(); | 219 web_contents_->Focus(); |
213 } | 220 } |
214 | 221 |
215 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { | 222 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { |
216 DCHECK(web_contents == web_contents_); | 223 DCHECK(web_contents == web_contents_); |
217 SetWebContents(NULL); | 224 SetWebContents(NULL); |
218 } | 225 } |
219 | 226 |
220 } // namespace views | 227 } // namespace views |
OLD | NEW |