Avoid calling OnSetFocus multiple times (issue #563).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@569 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2012-04-02 19:05:42 +00:00
parent b59fc7633d
commit 0a1fd8b040
4 changed files with 34 additions and 20 deletions

View File

@@ -130,12 +130,16 @@ void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) {
if (!host) if (!host)
return; return;
NSView* view = host->view_handle(); BrowserWebView* browserView = (BrowserWebView*)host->view_handle();
if (!view) if (!browserView)
return; return;
if (enable) if (enable) {
[[view window] makeFirstResponder:view]; // Guard against calling OnSetFocus twice.
browserView.in_setfocus = true;
[[browserView window] makeFirstResponder:browserView];
browserView.in_setfocus = false;
}
} }
bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame) { bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame) {

View File

@@ -22,6 +22,7 @@ struct WebDropData;
@private @private
CefBrowserImpl* browser_; // weak CefBrowserImpl* browser_; // weak
NSTrackingArea* trackingArea_; NSTrackingArea* trackingArea_;
bool is_in_setfocus_;
scoped_nsobject<WebDragSource> dragSource_; scoped_nsobject<WebDragSource> dragSource_;
scoped_nsobject<WebDropTarget> dropTarget_; scoped_nsobject<WebDropTarget> dropTarget_;
@@ -58,6 +59,7 @@ struct WebDropData;
offset:(NSPoint)offset; offset:(NSPoint)offset;
@property (nonatomic, assign) CefBrowserImpl* browser; @property (nonatomic, assign) CefBrowserImpl* browser;
@property (nonatomic, assign) bool in_setfocus;
@end @end

View File

@@ -21,6 +21,7 @@
@implementation BrowserWebView @implementation BrowserWebView
@synthesize browser = browser_; @synthesize browser = browser_;
@synthesize in_setfocus = is_in_setfocus_;
- (id)initWithFrame:(NSRect)frame { - (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame]; self = [super initWithFrame:frame];
@@ -163,12 +164,14 @@
- (BOOL)becomeFirstResponder { - (BOOL)becomeFirstResponder {
if (browser_ && browser_->UIT_GetWebView()) { if (browser_ && browser_->UIT_GetWebView()) {
CefRefPtr<CefClient> client = browser_->GetClient(); if (!is_in_setfocus_) {
if (client.get()) { CefRefPtr<CefClient> client = browser_->GetClient();
CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler(); if (client.get()) {
if (handler.get() && CefRefPtr<CefFocusHandler> handler = client->GetFocusHandler();
handler->OnSetFocus(browser_, FOCUS_SOURCE_SYSTEM)) { if (handler.get() &&
return NO; handler->OnSetFocus(browser_, FOCUS_SOURCE_SYSTEM)) {
return NO;
}
} }
} }

View File

@@ -601,16 +601,21 @@ void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
if (!popup()) { if (!popup()) {
SetCapture(view_); SetCapture(view_);
HWND parent_hwnd = ::GetParent(view_); if (::GetFocus() != view_) {
if (parent_hwnd) { // Set focus to this window.
CefRefPtr<CefBrowserImpl> browser = HWND parent_hwnd = ::GetParent(view_);
static_cast<CefBrowserImpl*>(ui::GetWindowUserData(parent_hwnd)); if (parent_hwnd) {
if (browser.get()) { CefRefPtr<CefBrowserImpl> browser =
// This mimics a temporary workaround in RenderWidgetHostViewWin static_cast<CefBrowserImpl*>(
// for bug 765011 to get focus when the mouse is clicked. This ui::GetWindowUserData(parent_hwnd));
// happens after the mouse down event is sent to the renderer if (browser.get()) {
// because normally Windows does a WM_SETFOCUS after WM_LBUTTONDOWN. // This mimics a temporary workaround in RenderWidgetHostViewWin
browser->SetFocus(true); // 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);
}
} }
} }
} }