Chromium Code Reviews| Index: chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc |
| diff --git a/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc b/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc |
| index c2a762bdccd8fc03f4bf1d7af44ef8ca9e2b30f5..18ccb2a43a791f28ef34d93dd7d6a51b9b927dbb 100644 |
| --- a/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc |
| +++ b/chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc |
| @@ -15,6 +15,12 @@ |
| #include "ui/web_dialogs/web_dialog_delegate.h" |
| #include "ui/web_dialogs/web_dialog_ui.h" |
| +#if defined(USE_AURA) |
| +#include "content/public/browser/render_widget_host_view.h" |
| +#include "ui/aura/client/focus_change_observer.h" |
| +#include "ui/aura/client/focus_client.h" |
| +#endif |
| + |
| using ui::WebDialogDelegate; |
| using ui::WebDialogWebContentsDelegate; |
| @@ -59,6 +65,45 @@ class ConstrainedWebDialogDelegateViews |
| DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); |
| }; |
| +#if defined(USE_AURA) |
| +// TODO(msw): Make this part of WebView? Modify various WebContentsDelegates? |
| +class WebViewFocusHelper : public aura::client::FocusChangeObserver { |
| + public: |
| + explicit WebViewFocusHelper(views::WebView* web_view) |
| + : web_view_(web_view), |
| + native_view_(NULL), |
| + focus_client_(NULL) { |
| + if (web_view_ && web_view_->web_contents()) { |
| + content::RenderWidgetHostView* host_view = |
| + web_view_->web_contents()->GetRenderWidgetHostView(); |
| + native_view_ = host_view ? host_view->GetNativeView() : NULL; |
| + } |
| + if (native_view_) |
| + focus_client_ = aura::client::GetFocusClient(native_view_); |
| + if (focus_client_) |
| + focus_client_->AddObserver(this); |
| + } |
| + |
| + virtual ~WebViewFocusHelper() { |
| + if (focus_client_) |
| + focus_client_->RemoveObserver(this); |
| + } |
| + |
| + virtual void OnWindowFocused(aura::Window* gained_focus, |
| + aura::Window* lost_focus) { |
| + if (gained_focus == native_view_ && !web_view_->HasFocus()) |
| + web_view_->RequestFocus(); |
| + } |
| + |
| + private: |
| + views::WebView* web_view_; |
| + gfx::NativeView native_view_; |
|
Ben Goodger (Google)
2014/07/31 18:20:15
may as well just use aura::Window* here
msw
2014/07/31 18:35:14
Done.
|
| + aura::client::FocusClient* focus_client_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebViewFocusHelper); |
| +}; |
| +#endif |
| + |
| class ConstrainedWebDialogDelegateViewViews |
| : public views::WebView, |
| public ConstrainedWebDialogDelegate, |
| @@ -147,8 +192,17 @@ class ConstrainedWebDialogDelegateViewViews |
| return gfx::Size(); |
| } |
| + void OnShow() { |
| +#if defined(USE_AURA) |
| + web_view_focus_helper_.reset(new WebViewFocusHelper(this)); |
| +#endif |
| + } |
| + |
| private: |
| scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; |
| +#if defined(USE_AURA) |
| + scoped_ptr<WebViewFocusHelper> web_view_focus_helper_; |
| +#endif |
| DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); |
| }; |
| @@ -164,5 +218,6 @@ ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| new ConstrainedWebDialogDelegateViewViews( |
| browser_context, delegate, tab_delegate); |
| ShowWebModalDialogViews(dialog, web_contents); |
| + dialog->OnShow(); |
| return dialog; |
| } |