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:
parent
0872b047a4
commit
b59fc7633d
|
@ -169,6 +169,7 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
|
|||
can_go_forward_(false),
|
||||
has_document_(false),
|
||||
is_dropping_(false),
|
||||
is_in_onsetfocus_(false),
|
||||
unique_id_(0)
|
||||
#if defined(OS_WIN)
|
||||
, opener_was_disabled_by_modal_loop_(false),
|
||||
|
@ -229,6 +230,26 @@ void CefBrowserImpl::StopLoad() {
|
|||
|
||||
void CefBrowserImpl::SetFocus(bool enable) {
|
||||
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);
|
||||
} else {
|
||||
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
||||
|
@ -1003,7 +1024,6 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CefBrowserImpl::UIT_SetSize(PaintElementType type, int width, int height) {
|
||||
if (type == PET_VIEW) {
|
||||
WebViewHost* host = UIT_GetWebViewHost();
|
||||
|
|
|
@ -399,6 +399,10 @@ class CefBrowserImpl : public CefBrowser {
|
|||
// True if a drop action is occuring.
|
||||
bool is_dropping_;
|
||||
|
||||
// True if currently in the OnSetFocus callback. Only accessed on the UI
|
||||
// thread.
|
||||
bool is_in_onsetfocus_;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Context object used to manage printing.
|
||||
printing::PrintingContext print_context_;
|
||||
|
|
|
@ -104,21 +104,8 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
|||
return 0;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
if (browser) {
|
||||
WebViewHost* host = browser->UIT_GetWebViewHost();
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (browser)
|
||||
browser->SetFocus(true);
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <commctrl.h>
|
||||
|
||||
#include "libcef/webwidget_host.h"
|
||||
#include "libcef/browser_impl.h"
|
||||
#include "libcef/cef_thread.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
|
@ -599,11 +600,19 @@ void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
|||
case WebInputEvent::MouseDown:
|
||||
if (!popup()) {
|
||||
SetCapture(view_);
|
||||
// This mimics a temporary workaround in RenderWidgetHostViewWin
|
||||
// for bug 765011 to get focus when the mouse is clicked. This
|
||||
// happens after the mouse down event is sent to the renderer
|
||||
// because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN.
|
||||
::SetFocus(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
|
||||
// for bug 765011 to get focus when the mouse is clicked. This
|
||||
// happens after the mouse down event is sent to the renderer
|
||||
// because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN.
|
||||
browser->SetFocus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WebInputEvent::MouseUp:
|
||||
|
|
Loading…
Reference in New Issue