Execute the CefFocusHandler::OnSetFocus callback for calls to CefBrowser::SetFocus and mouse clicks on the view (issue #563).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@568 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-04-02 16:28:56 +00:00
parent 0872b047a4
commit b59fc7633d
4 changed files with 41 additions and 21 deletions

View File

@ -169,6 +169,7 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
can_go_forward_(false), can_go_forward_(false),
has_document_(false), has_document_(false),
is_dropping_(false), is_dropping_(false),
is_in_onsetfocus_(false),
unique_id_(0) unique_id_(0)
#if defined(OS_WIN) #if defined(OS_WIN)
, opener_was_disabled_by_modal_loop_(false), , opener_was_disabled_by_modal_loop_(false),
@ -229,6 +230,26 @@ void CefBrowserImpl::StopLoad() {
void CefBrowserImpl::SetFocus(bool enable) { void CefBrowserImpl::SetFocus(bool enable) {
if (CefThread::CurrentlyOn(CefThread::UI)) { if (CefThread::CurrentlyOn(CefThread::UI)) {
// If SetFocus() is called from inside the OnSetFocus() callback do not re-
// enter the callback.
if (enable && !is_in_onsetfocus_) {
WebViewHost* host = UIT_GetWebViewHost();
if (host) {
CefRefPtr<CefClient> client = GetClient();
if (client.get()) {
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
if (handler.get()) {
is_in_onsetfocus_ = true;
bool handled = handler->OnSetFocus(this, FOCUS_SOURCE_SYSTEM);
is_in_onsetfocus_ = false;
if (handled)
return;
}
}
}
}
UIT_SetFocus(UIT_GetWebViewHost(), enable); UIT_SetFocus(UIT_GetWebViewHost(), enable);
} else { } else {
CefThread::PostTask(CefThread::UI, FROM_HERE, CefThread::PostTask(CefThread::UI, FROM_HERE,
@ -1003,7 +1024,6 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
return true; return true;
} }
void CefBrowserImpl::UIT_SetSize(PaintElementType type, int width, int height) { void CefBrowserImpl::UIT_SetSize(PaintElementType type, int width, int height) {
if (type == PET_VIEW) { if (type == PET_VIEW) {
WebViewHost* host = UIT_GetWebViewHost(); WebViewHost* host = UIT_GetWebViewHost();

View File

@ -399,6 +399,10 @@ class CefBrowserImpl : public CefBrowser {
// True if a drop action is occuring. // True if a drop action is occuring.
bool is_dropping_; bool is_dropping_;
// True if currently in the OnSetFocus callback. Only accessed on the UI
// thread.
bool is_in_onsetfocus_;
#if defined(OS_WIN) #if defined(OS_WIN)
// Context object used to manage printing. // Context object used to manage printing.
printing::PrintingContext print_context_; printing::PrintingContext print_context_;

View File

@ -104,21 +104,8 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
return 0; return 0;
case WM_SETFOCUS: case WM_SETFOCUS:
if (browser) { if (browser)
WebViewHost* host = browser->UIT_GetWebViewHost(); browser->SetFocus(true);
if (host) {
bool handled = false;
CefRefPtr<CefClient> client = browser->GetClient();
if (client.get()) {
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
if (handler.get())
handled = handler->OnSetFocus(browser, FOCUS_SOURCE_SYSTEM);
}
if (!handled)
browser->UIT_SetFocus(host, true);
}
}
return 0; return 0;
case WM_ERASEBKGND: case WM_ERASEBKGND:

View File

@ -7,6 +7,7 @@
#include <commctrl.h> #include <commctrl.h>
#include "libcef/webwidget_host.h" #include "libcef/webwidget_host.h"
#include "libcef/browser_impl.h"
#include "libcef/cef_thread.h" #include "libcef/cef_thread.h"
#include "base/bind.h" #include "base/bind.h"
@ -599,11 +600,19 @@ void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
case WebInputEvent::MouseDown: case WebInputEvent::MouseDown:
if (!popup()) { if (!popup()) {
SetCapture(view_); SetCapture(view_);
HWND parent_hwnd = ::GetParent(view_);
if (parent_hwnd) {
CefRefPtr<CefBrowserImpl> browser =
static_cast<CefBrowserImpl*>(ui::GetWindowUserData(parent_hwnd));
if (browser.get()) {
// This mimics a temporary workaround in RenderWidgetHostViewWin // This mimics a temporary workaround in RenderWidgetHostViewWin
// for bug 765011 to get focus when the mouse is clicked. This // for bug 765011 to get focus when the mouse is clicked. This
// happens after the mouse down event is sent to the renderer // happens after the mouse down event is sent to the renderer
// because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN. // because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN.
::SetFocus(view_); browser->SetFocus(true);
}
}
} }
break; break;
case WebInputEvent::MouseUp: case WebInputEvent::MouseUp: