From d8aed5b52d9ba356c6b828787030494248d50ba0 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 4 Apr 2014 22:26:39 +0000 Subject: [PATCH] Windows: Fix assignment of keyboard focus (issue #1248). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1643 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/browser_host_impl.cc | 9 +++++++++ libcef/browser/browser_host_impl.h | 2 ++ libcef/browser/browser_host_impl_win.cc | 22 ++++++++++++++++++++++ patch/patches/views_widget_180.patch | 12 ++++++++++++ 4 files changed, 45 insertions(+) diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 8a9fd5ee9..11e4674f2 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -1689,6 +1689,15 @@ void CefBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { if (web_contents_.get()) web_contents_->GetView()->Focus(); + +#if defined(OS_WIN) + if (!IsWindowRenderingDisabled()) { + // When windowed rendering is used in combination with Aura on Windows we + // need to explicitly set focus to the native window handle. Otherwise, + // the window doesn't get keyboard focus. + PlatformSetViewFocus(); + } +#endif // defined(OS_WIN) } else { CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::OnSetFocus, this, source)); diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index b2528dbb9..b653b6062 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -456,6 +456,8 @@ class CefBrowserHostImpl : public CefBrowserHost, static LPCTSTR GetWndClass(); static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + + void PlatformSetViewFocus(); #endif // Create the window. diff --git a/libcef/browser/browser_host_impl_win.cc b/libcef/browser/browser_host_impl_win.cc index 1a79b0b61..86b77f4b5 100644 --- a/libcef/browser/browser_host_impl_win.cc +++ b/libcef/browser/browser_host_impl_win.cc @@ -32,12 +32,14 @@ #include "net/base/mime_util.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "third_party/WebKit/public/web/win/WebInputEventFactory.h" +#include "ui/aura/window.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/win/shell.h" #include "ui/gfx/win/hwnd_util.h" #include "ui/views/background.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/layout/fill_layout.h" +#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" @@ -62,6 +64,21 @@ void SetAeroGlass(HWND hWnd) { DwmExtendFrameIntoClientArea(hWnd, &mgMarInset); } +HWND GetHWND(views::Widget* widget) { + gfx::NativeWindow window = widget->GetNativeWindow(); + DCHECK(window); + if (!window) + return NULL; + views::DesktopWindowTreeHostWin* host = + static_cast(window->GetHost()); + DCHECK(host); + if (!host) + return NULL; + HWND hwnd = host->GetHWND(); + DCHECK(hwnd); + return hwnd; +} + void WriteTempFileAndView(scoped_refptr str) { CEF_REQUIRE_FILET(); @@ -709,6 +726,11 @@ LRESULT CALLBACK CefBrowserHostImpl::WndProc(HWND hwnd, UINT message, return DefWindowProc(hwnd, message, wParam, lParam); } +void CefBrowserHostImpl::PlatformSetViewFocus() { + if (window_widget_) + ::SetFocus(GetHWND(window_widget_)); +} + ui::PlatformCursor CefBrowserHostImpl::GetPlatformCursor( blink::WebCursorInfo::Type type) { HMODULE module_handle = NULL; diff --git a/patch/patches/views_widget_180.patch b/patch/patches/views_widget_180.patch index 196a2ad2c..29f6527a7 100644 --- a/patch/patches/views_widget_180.patch +++ b/patch/patches/views_widget_180.patch @@ -26,6 +26,18 @@ Index: desktop_aura/desktop_window_tree_host_win.cc parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget(); message_handler_->set_remove_standard_frame(params.remove_standard_frame); +Index: desktop_aura/desktop_window_tree_host_win.h +=================================================================== +--- desktop_aura/desktop_window_tree_host_win.h (revision 261035) ++++ desktop_aura/desktop_window_tree_host_win.h (working copy) +@@ -214,6 +214,7 @@ + LPARAM l_param) OVERRIDE; + virtual bool HandleScrollEvent(const ui::ScrollEvent& event) OVERRIDE; + ++ public: + Widget* GetWidget(); + const Widget* GetWidget() const; + HWND GetHWND() const; Index: widget.cc =================================================================== --- widget.cc (revision 261035)