Windows: Fix assignment of keyboard focus (issue #1248).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1750@1644 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-04-04 22:27:32 +00:00
parent 2a9bdaad37
commit 93ead673ea
4 changed files with 51 additions and 4 deletions

View File

@ -1640,6 +1640,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));

View File

@ -449,6 +449,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.

View File

@ -31,12 +31,15 @@
#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/root_window.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_root_window_host_win.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "webkit/common/cursors/webcursor.h"
@ -62,6 +65,22 @@ void SetAeroGlass(HWND hWnd) {
DwmExtendFrameIntoClientArea(hWnd, &mgMarInset);
}
HWND GetHWND(views::Widget* widget) {
gfx::NativeWindow window = widget->GetNativeWindow();
DCHECK(window);
if (!window)
return NULL;
views::DesktopRootWindowHostWin* host =
static_cast<views::DesktopRootWindowHostWin*>(
window->GetDispatcher()->host());
DCHECK(host);
if (!host)
return NULL;
HWND hwnd = host->GetHWND();
DCHECK(hwnd);
return hwnd;
}
void WriteTempFileAndView(scoped_refptr<base::RefCountedString> str) {
CEF_REQUIRE_FILET();
@ -709,6 +728,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;

View File

@ -1,6 +1,6 @@
Index: desktop_aura/desktop_root_window_host_win.cc
===================================================================
--- desktop_aura/desktop_root_window_host_win.cc (revision 252094)
--- desktop_aura/desktop_root_window_host_win.cc (revision 258314)
+++ desktop_aura/desktop_root_window_host_win.cc (working copy)
@@ -132,7 +132,9 @@
native_widget_delegate_);
@ -22,9 +22,21 @@ Index: desktop_aura/desktop_root_window_host_win.cc
native_widget_delegate_->OnNativeWidgetCreated(true);
Index: desktop_aura/desktop_root_window_host_win.h
===================================================================
--- desktop_aura/desktop_root_window_host_win.h (revision 258314)
+++ desktop_aura/desktop_root_window_host_win.h (working copy)
@@ -210,6 +210,7 @@
LPARAM l_param) OVERRIDE;
virtual bool HandleScrollEvent(const ui::ScrollEvent& event) OVERRIDE;
+ public:
Widget* GetWidget();
const Widget* GetWidget() const;
HWND GetHWND() const;
Index: desktop_aura/desktop_screen_win.cc
===================================================================
--- desktop_aura/desktop_screen_win.cc (revision 252094)
--- desktop_aura/desktop_screen_win.cc (revision 258314)
+++ desktop_aura/desktop_screen_win.cc (working copy)
@@ -54,6 +54,8 @@
}
@ -37,7 +49,7 @@ Index: desktop_aura/desktop_screen_win.cc
}
Index: widget.cc
===================================================================
--- widget.cc (revision 252094)
--- widget.cc (revision 258314)
+++ widget.cc (working copy)
@@ -126,6 +126,7 @@
show_state(ui::SHOW_STATE_DEFAULT),
@ -71,7 +83,7 @@ Index: widget.cc
}
Index: widget.h
===================================================================
--- widget.h (revision 252094)
--- widget.h (revision 258314)
+++ widget.h (working copy)
@@ -201,6 +201,7 @@
// Should the widget be double buffered? Default is false.