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

Unified Diff: chrome/browser/ui/views/constrained_web_dialog_delegate_views.cc

Issue 431573003: Fix views::WebView focus for Print Preview and other web dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing OVERRIDE keyword. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..402385db1f70e0a3b9bd09271cb8e23dc402968c 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,44 @@ 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),
+ window_(NULL),
+ focus_client_(NULL) {
+ if (web_view_ && web_view_->web_contents()) {
+ content::RenderWidgetHostView* host_view =
+ web_view_->web_contents()->GetRenderWidgetHostView();
+ window_ = host_view ? host_view->GetNativeView() : NULL;
+ }
+ focus_client_ = window_ ? aura::client::GetFocusClient(window_) : NULL;
+ 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) OVERRIDE {
+ if (gained_focus == window_ && !web_view_->HasFocus())
+ web_view_->RequestFocus();
+ }
+
+ private:
+ views::WebView* web_view_;
+ aura::Window* window_;
+ aura::client::FocusClient* focus_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebViewFocusHelper);
+};
+#endif
+
class ConstrainedWebDialogDelegateViewViews
: public views::WebView,
public ConstrainedWebDialogDelegate,
@@ -147,8 +191,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 +217,6 @@ ConstrainedWebDialogDelegate* CreateConstrainedWebDialog(
new ConstrainedWebDialogDelegateViewViews(
browser_context, delegate, tab_delegate);
ShowWebModalDialogViews(dialog, web_contents);
+ dialog->OnShow();
return dialog;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698