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

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

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Return early if not focused Created 6 years, 4 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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 return web_contents(); 52 return web_contents();
53 } 53 }
54 54
55 void WebView::SetWebContents(content::WebContents* replacement) { 55 void WebView::SetWebContents(content::WebContents* replacement) {
56 if (replacement == web_contents()) 56 if (replacement == web_contents())
57 return; 57 return;
58 DetachWebContents(); 58 DetachWebContents();
59 WebContentsObserver::Observe(replacement); 59 WebContentsObserver::Observe(replacement);
60 // web_contents() now returns |replacement| from here onwards. 60 // web_contents() now returns |replacement| from here onwards.
61 SetFocusable(!!web_contents());
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();
70 NotifyMaybeTextInputClientChanged(); 71 NotifyMaybeTextInputClientChanged();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return FocusManager::IsTabTraversalKeyEvent(event); 192 return FocusManager::IsTabTraversalKeyEvent(event);
192 193
193 // Don't look-up accelerators or tab-traversal if we are showing a non-crashed 194 // Don't look-up accelerators or tab-traversal if we are showing a non-crashed
194 // TabContents. 195 // TabContents.
195 // We'll first give the page a chance to process the key events. If it does 196 // We'll first give the page a chance to process the key events. If it does
196 // not process them, they'll be returned to us and we'll treat them as 197 // not process them, they'll be returned to us and we'll treat them as
197 // accelerators then. 198 // accelerators then.
198 return web_contents() && !web_contents()->IsCrashed(); 199 return web_contents() && !web_contents()->IsCrashed();
199 } 200 }
200 201
201 bool WebView::IsFocusable() const {
202 // We need to be focusable when our contents is not a view hierarchy, as
203 // clicking on the contents needs to focus us.
204 return !!web_contents();
205 }
206
207 void WebView::OnFocus() { 202 void WebView::OnFocus() {
208 if (web_contents()) 203 if (web_contents())
209 web_contents()->Focus(); 204 web_contents()->Focus();
210 } 205 }
211 206
212 void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) { 207 void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) {
213 if (web_contents()) 208 if (web_contents())
214 web_contents()->FocusThroughTabTraversal(reverse); 209 web_contents()->FocusThroughTabTraversal(reverse);
215 } 210 }
216 211
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (!contents) { 365 if (!contents) {
371 content::WebContents::CreateParams create_params( 366 content::WebContents::CreateParams create_params(
372 browser_context, NULL); 367 browser_context, NULL);
373 return content::WebContents::Create(create_params); 368 return content::WebContents::Create(create_params);
374 } 369 }
375 370
376 return contents; 371 return contents;
377 } 372 }
378 373
379 } // namespace views 374 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698