Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: ui/views/controls/webview/webview.cc

Issue 173803002: Redesigns the text input focus handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added an unittest and thread checker. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
msw 2014/04/18 19:57:57 nit: remove blank line
Yuki 2014/04/22 09:09:02 Done.
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
106 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 127 void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
107 // In most cases, the holder is simply sized to fill this WebView's bounds. 128 // 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 129 // Only WebContentses that are in fullscreen mode and being screen-captured
109 // will engage the special layout/sizing behavior. 130 // will engage the special layout/sizing behavior.
110 gfx::Rect holder_bounds(bounds().size()); 131 gfx::Rect holder_bounds(bounds().size());
111 if (!embed_fullscreen_widget_mode_enabled_ || 132 if (!embed_fullscreen_widget_mode_enabled_ ||
112 !web_contents() || 133 !web_contents() ||
113 web_contents()->GetCapturerCount() == 0 || 134 web_contents()->GetCapturerCount() == 0 ||
114 web_contents()->GetPreferredSize().IsEmpty() || 135 web_contents()->GetPreferredSize().IsEmpty() ||
115 !(is_embedding_fullscreen_widget_ || 136 !(is_embedding_fullscreen_widget_ ||
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 243 }
223 244
224 bool WebView::EmbedsFullscreenWidget() const { 245 bool WebView::EmbedsFullscreenWidget() const {
225 DCHECK(wc_owner_.get()); 246 DCHECK(wc_owner_.get());
226 return embed_fullscreen_widget_mode_enabled_; 247 return embed_fullscreen_widget_mode_enabled_;
227 } 248 }
228 249
229 //////////////////////////////////////////////////////////////////////////////// 250 ////////////////////////////////////////////////////////////////////////////////
230 // WebView, content::WebContentsObserver implementation: 251 // WebView, content::WebContentsObserver implementation:
231 252
253 void WebView::RenderViewDeleted(content::RenderViewHost* render_view_host) {
254 NotifyMaybeTextInputClientChanged();
255 }
256
232 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, 257 void WebView::RenderViewHostChanged(content::RenderViewHost* old_host,
233 content::RenderViewHost* new_host) { 258 content::RenderViewHost* new_host) {
234 FocusManager* const focus_manager = GetFocusManager(); 259 FocusManager* const focus_manager = GetFocusManager();
235 if (focus_manager && focus_manager->GetFocusedView() == this) 260 if (focus_manager && focus_manager->GetFocusedView() == this)
236 OnFocus(); 261 OnFocus();
262 NotifyMaybeTextInputClientChanged();
237 } 263 }
238 264
239 void WebView::DidShowFullscreenWidget(int routing_id) { 265 void WebView::DidShowFullscreenWidget(int routing_id) {
240 if (embed_fullscreen_widget_mode_enabled_) 266 if (embed_fullscreen_widget_mode_enabled_)
241 ReattachForFullscreenChange(true); 267 ReattachForFullscreenChange(true);
242 } 268 }
243 269
244 void WebView::DidDestroyFullscreenWidget(int routing_id) { 270 void WebView::DidDestroyFullscreenWidget(int routing_id) {
245 if (embed_fullscreen_widget_mode_enabled_) 271 if (embed_fullscreen_widget_mode_enabled_)
246 ReattachForFullscreenChange(false); 272 ReattachForFullscreenChange(false);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // widget. Need to detach and re-attach to a different native view. 328 // widget. Need to detach and re-attach to a different native view.
303 DetachWebContents(); 329 DetachWebContents();
304 is_embedding_fullscreen_widget_ = 330 is_embedding_fullscreen_widget_ =
305 enter_fullscreen && web_contents_has_separate_fs_widget; 331 enter_fullscreen && web_contents_has_separate_fs_widget;
306 AttachWebContents(); 332 AttachWebContents();
307 } else { 333 } else {
308 // Entering or exiting "non-Flash" fullscreen mode, where the native view is 334 // Entering or exiting "non-Flash" fullscreen mode, where the native view is
309 // the same. So, do not change attachment. 335 // the same. So, do not change attachment.
310 OnBoundsChanged(bounds()); 336 OnBoundsChanged(bounds());
311 } 337 }
338 NotifyMaybeTextInputClientChanged();
339 }
340
341 void WebView::NotifyMaybeTextInputClientChanged() {
342 // Update the TextInputClient as needed; see GetTextInputClient().
343 FocusManager* const focus_manager = GetFocusManager();
msw 2014/04/18 19:57:57 nit: remove const.
Yuki 2014/04/22 09:09:02 I'm okay to remove this const, but this is the sty
msw 2014/04/22 17:12:56 Okay, the style guide says encourages putting cons
Yuki 2014/04/23 03:53:40 Thanks. Just FYI, const T* and T* const have diff
msw 2014/04/23 04:50:12 Right, I'm aware of the significance, but I believ
344 if (focus_manager)
345 focus_manager->OnTextInputClientChanged(this);
312 } 346 }
313 347
314 content::WebContents* WebView::CreateWebContents( 348 content::WebContents* WebView::CreateWebContents(
315 content::BrowserContext* browser_context) { 349 content::BrowserContext* browser_context) {
316 content::WebContents* contents = NULL; 350 content::WebContents* contents = NULL;
317 if (ViewsDelegate::views_delegate) { 351 if (ViewsDelegate::views_delegate) {
318 contents = ViewsDelegate::views_delegate->CreateWebContents( 352 contents = ViewsDelegate::views_delegate->CreateWebContents(
319 browser_context, NULL); 353 browser_context, NULL);
320 } 354 }
321 355
322 if (!contents) { 356 if (!contents) {
323 content::WebContents::CreateParams create_params( 357 content::WebContents::CreateParams create_params(
324 browser_context, NULL); 358 browser_context, NULL);
325 return content::WebContents::Create(create_params); 359 return content::WebContents::Create(create_params);
326 } 360 }
327 361
328 return contents; 362 return contents;
329 } 363 }
330 364
331 } // namespace views 365 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698