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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 PreferredSizeChanged(); | 104 PreferredSizeChanged(); |
104 } | 105 } |
105 | 106 |
106 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
107 // WebView, View overrides: | 108 // WebView, View overrides: |
108 | 109 |
109 const char* WebView::GetClassName() const { | 110 const char* WebView::GetClassName() const { |
110 return kViewClassName; | 111 return kViewClassName; |
111 } | 112 } |
112 | 113 |
114 ui::TextInputClient* WebView::GetTextInputClient() { | |
115 if (switches::IsTextInputFocusManagerEnabled() && | |
116 web_contents() && !web_contents()->IsBeingDestroyed()) { | |
117 content::RenderWidgetHostView* host_view = | |
118 is_embedding_fullscreen_widget_ ? | |
119 web_contents()->GetFullscreenRenderWidgetHostView() : | |
120 web_contents()->GetRenderWidgetHostView(); | |
121 if (host_view) | |
122 return host_view->GetTextInputClient(); | |
123 } | |
124 return NULL; | |
125 } | |
126 | |
113 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 127 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
114 wcv_holder_->SetSize(bounds().size()); | 128 wcv_holder_->SetSize(bounds().size()); |
115 } | 129 } |
116 | 130 |
117 void WebView::ViewHierarchyChanged( | 131 void WebView::ViewHierarchyChanged( |
118 const ViewHierarchyChangedDetails& details) { | 132 const ViewHierarchyChangedDetails& details) { |
119 if (details.is_add) | 133 if (details.is_add) |
120 AttachWebContents(); | 134 AttachWebContents(); |
121 } | 135 } |
122 | 136 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 } | 201 } |
188 | 202 |
189 bool WebView::EmbedsFullscreenWidget() const { | 203 bool WebView::EmbedsFullscreenWidget() const { |
190 DCHECK(wc_owner_.get()); | 204 DCHECK(wc_owner_.get()); |
191 return embed_fullscreen_widget_mode_enabled_; | 205 return embed_fullscreen_widget_mode_enabled_; |
192 } | 206 } |
193 | 207 |
194 //////////////////////////////////////////////////////////////////////////////// | 208 //////////////////////////////////////////////////////////////////////////////// |
195 // WebView, content::WebContentsObserver implementation: | 209 // WebView, content::WebContentsObserver implementation: |
196 | 210 |
211 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) { | |
212 // WebView::GetTextInputClient() delegates the text input handling to the | |
msw
2014/03/12 20:56:15
With three nearly duplicate code and comment block
Yuki
2014/03/14 15:25:22
Done with option A.
| |
213 // underlying content::RenderWidgetHostView. So when the underlying RWHV is | |
214 // destroyed, we have to notify the FocusManager that the focused | |
215 // TextInputClient needs to be updated. | |
216 FocusManager* const focus_manager = GetFocusManager(); | |
217 if (focus_manager) | |
218 focus_manager->OnTextInputClientChanged(this); | |
219 } | |
220 | |
197 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 221 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
198 content::RenderViewHost* new_host) { | 222 content::RenderViewHost* new_host) { |
199 FocusManager* const focus_manager = GetFocusManager(); | 223 FocusManager* const focus_manager = GetFocusManager(); |
200 if (focus_manager && focus_manager->GetFocusedView() == this) | 224 if (focus_manager && focus_manager->GetFocusedView() == this) |
201 OnFocus(); | 225 OnFocus(); |
202 } | 226 } |
203 | 227 |
204 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { | 228 void WebView::WebContentsDestroyed(content::WebContents* web_contents) { |
205 // We watch for destruction of WebContents that we host but do not own. If we | 229 // We watch for destruction of WebContents that we host but do not own. If we |
206 // own a WebContents that is being destroyed, we're doing the destroying, so | 230 // own a WebContents that is being destroyed, we're doing the destroying, so |
(...skipping 21 matching lines...) Expand all Loading... | |
228 if (!GetWidget() || !web_contents()) | 252 if (!GetWidget() || !web_contents()) |
229 return; | 253 return; |
230 | 254 |
231 const gfx::NativeView view_to_attach = is_embedding_fullscreen_widget_ ? | 255 const gfx::NativeView view_to_attach = is_embedding_fullscreen_widget_ ? |
232 web_contents()->GetFullscreenRenderWidgetHostView()->GetNativeView() : | 256 web_contents()->GetFullscreenRenderWidgetHostView()->GetNativeView() : |
233 web_contents()->GetView()->GetNativeView(); | 257 web_contents()->GetView()->GetNativeView(); |
234 if (wcv_holder_->native_view() == view_to_attach) | 258 if (wcv_holder_->native_view() == view_to_attach) |
235 return; | 259 return; |
236 wcv_holder_->Attach(view_to_attach); | 260 wcv_holder_->Attach(view_to_attach); |
237 | 261 |
238 // The view will not be focused automatically when it is attached, so we need | |
239 // to pass on focus to it if the FocusManager thinks the view is focused. Note | |
240 // that not every Widget has a focus manager. | |
241 FocusManager* const focus_manager = GetFocusManager(); | 262 FocusManager* const focus_manager = GetFocusManager(); |
242 if (focus_manager && focus_manager->GetFocusedView() == this) | 263 if (focus_manager) { |
243 OnFocus(); | 264 // WebView::GetTextInputClient() delegates the text input handling to the |
265 // underlying content::RenderWidgetHostView. So when the underlying RWHV is | |
266 // changed, we have to notify the FocusManager that the focused | |
267 // TextInputClient needs to be updated. | |
268 focus_manager->OnTextInputClientChanged(this); | |
269 | |
270 // The view will not be focused automatically when it is attached, so we | |
271 // need to pass on focus to it if the FocusManager thinks the view is | |
272 // focused. | |
273 if (focus_manager->GetFocusedView() == this) | |
274 OnFocus(); | |
275 } | |
244 | 276 |
245 #if defined(OS_WIN) | 277 #if defined(OS_WIN) |
246 if (!is_embedding_fullscreen_widget_) { | 278 if (!is_embedding_fullscreen_widget_) { |
247 web_contents()->SetParentNativeViewAccessible( | 279 web_contents()->SetParentNativeViewAccessible( |
248 parent()->GetNativeViewAccessible()); | 280 parent()->GetNativeViewAccessible()); |
249 } | 281 } |
250 #endif | 282 #endif |
251 } | 283 } |
252 | 284 |
253 void WebView::DetachWebContents() { | 285 void WebView::DetachWebContents() { |
254 if (web_contents()) { | 286 if (web_contents()) { |
255 wcv_holder_->Detach(); | 287 wcv_holder_->Detach(); |
288 | |
289 // WebView::GetTextInputClient() delegates the text input handling to the | |
290 // underlying content::RenderWidgetHostView. So when the underlying RWHV is | |
291 // changed, we have to notify the FocusManager that the focused | |
292 // TextInputClient needs to be updated. | |
293 FocusManager* const focus_manager = GetFocusManager(); | |
294 if (focus_manager) | |
295 focus_manager->OnTextInputClientChanged(this); | |
msw
2014/03/12 20:56:15
Will WebView::GetTextInputClient return a differen
Yuki
2014/03/14 15:25:22
Even after the call to wcv_holder_->Detach(), GetT
msw
2014/03/17 19:48:58
Actually, that was my concern. [Attach|Detach]WebC
Yuki
2014/04/16 09:24:08
Thanks for the comment. I'll add a webview review
| |
296 | |
256 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
257 if (!is_embedding_fullscreen_widget_) { | 298 if (!is_embedding_fullscreen_widget_) { |
258 #if !defined(USE_AURA) | 299 #if !defined(USE_AURA) |
msw
2014/03/12 20:56:15
nit: Rebase, this code is no longer present.
Yuki
2014/03/14 15:25:22
Done.
| |
259 // TODO(beng): This should either not be necessary, or be done implicitly | 300 // TODO(beng): This should either not be necessary, or be done implicitly |
260 // by NativeViewHostWin on Detach(). As it stands, this is needed so that | 301 // by NativeViewHostWin on Detach(). As it stands, this is needed so that |
261 // the of the detached contents knows to tell the renderer it's been | 302 // the of the detached contents knows to tell the renderer it's been |
262 // hidden. | 303 // hidden. |
263 // | 304 // |
264 // Moving this out of here would also mean we wouldn't be potentially | 305 // Moving this out of here would also mean we wouldn't be potentially |
265 // calling member functions on a half-destroyed WebContents. | 306 // calling member functions on a half-destroyed WebContents. |
266 ShowWindow(web_contents()->GetView()->GetNativeView(), SW_HIDE); | 307 ShowWindow(web_contents()->GetView()->GetNativeView(), SW_HIDE); |
267 #else | 308 #else |
268 web_contents()->SetParentNativeViewAccessible(NULL); | 309 web_contents()->SetParentNativeViewAccessible(NULL); |
(...skipping 21 matching lines...) Expand all Loading... | |
290 if (!contents) { | 331 if (!contents) { |
291 content::WebContents::CreateParams create_params( | 332 content::WebContents::CreateParams create_params( |
292 browser_context, NULL); | 333 browser_context, NULL); |
293 return content::WebContents::Create(create_params); | 334 return content::WebContents::Create(create_params); |
294 } | 335 } |
295 | 336 |
296 return contents; | 337 return contents; |
297 } | 338 } |
298 | 339 |
299 } // namespace views | 340 } // namespace views |
OLD | NEW |