From d2ce65040ee491bbb1b5c115648c565c643bdf7c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 1 Feb 2011 15:37:47 +0000 Subject: [PATCH] Do not activate the select list window on Windows (issue #169). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@179 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_impl.cc | 25 ++++++++++ libcef/browser_impl.h | 2 + libcef/browser_impl_gtk.cc | 36 +++----------- libcef/browser_impl_mac.mm | 35 +++---------- libcef/browser_impl_win.cc | 68 ++++++++++---------------- libcef/browser_webview_delegate.cc | 8 +++ libcef/browser_webview_delegate_gtk.cc | 9 ---- libcef/browser_webview_delegate_mac.mm | 9 ---- libcef/browser_webview_delegate_win.cc | 14 ++---- libcef/webwidget_host.h | 8 ++- libcef/webwidget_host_gtk.cc | 1 + libcef/webwidget_host_mac.mm | 1 + libcef/webwidget_host_win.cc | 28 ++++++++--- 13 files changed, 109 insertions(+), 135 deletions(-) diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 554e6d14d..5aa35f247 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -545,6 +545,12 @@ void CefBrowserImpl::UIT_DestroyBrowser() _Context->RemoveBrowser(this); } +void CefBrowserImpl::UIT_CloseBrowser() +{ + REQUIRE_UIT(); + UIT_CloseView(UIT_GetMainWndHandle()); +} + void CefBrowserImpl::UIT_LoadURL(CefRefPtr frame, const CefString& url) { @@ -798,6 +804,25 @@ CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow( return browser; } +WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget() +{ + REQUIRE_UIT(); + + DCHECK(!popuphost_); + popuphost_ = WebWidgetHost::Create(UIT_GetMainWndHandle(), + popup_delegate_.get()); + popuphost_->set_popup(true); + return popuphost_->webwidget(); +} + +void CefBrowserImpl::UIT_ClosePopupWidget() +{ + REQUIRE_UIT(); + + UIT_CloseView(UIT_GetPopupWndHandle()); + popuphost_ = NULL; +} + void CefBrowserImpl::UIT_Show(WebKit::WebNavigationPolicy policy) { REQUIRE_UIT(); diff --git a/libcef/browser_impl.h b/libcef/browser_impl.h index 4ae249c4c..96b99b6c6 100644 --- a/libcef/browser_impl.h +++ b/libcef/browser_impl.h @@ -269,6 +269,8 @@ public: static bool ImplementsThreadSafeReferenceCounting() { return true; } protected: + static void UIT_CloseView(gfx::NativeView view); + void UIT_CreateDevToolsClient(BrowserDevToolsAgent* agent); void UIT_DestroyDevToolsClient(); diff --git a/libcef/browser_impl_gtk.cc b/libcef/browser_impl_gtk.cc index a32c6355f..a9c4edaaa 100644 --- a/libcef/browser_impl_gtk.cc +++ b/libcef/browser_impl_gtk.cc @@ -70,15 +70,6 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) UIT_LoadURL(GetMainFrame(), url); } -void CefBrowserImpl::UIT_CloseBrowser() -{ - REQUIRE_UIT(); - DCHECK(!_Context->shutting_down()); - - // TODO(port): Close the browser window. - NOTREACHED(); -} - void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) { REQUIRE_UIT(); @@ -89,26 +80,6 @@ void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) gtk_widget_grab_focus(host->view_handle()); } -WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget() -{ - REQUIRE_UIT(); - - DCHECK(!popuphost_); - popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get()); - - // TODO(port): Show window. - - return popuphost_->webwidget(); -} - -void CefBrowserImpl::UIT_ClosePopupWidget() -{ - REQUIRE_UIT(); - - // TODO(port): Close window. - popuphost_ = NULL; -} - bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame) { REQUIRE_UIT(); @@ -142,3 +113,10 @@ int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) NOTIMPLEMENTED(); return 0; } + +// static +void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) +{ + MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction( + >k_widget_destroy, GTK_WIDGET(view))); +} diff --git a/libcef/browser_impl_mac.mm b/libcef/browser_impl_mac.mm index c1630d8c0..22bc77339 100644 --- a/libcef/browser_impl_mac.mm +++ b/libcef/browser_impl_mac.mm @@ -75,15 +75,6 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) UIT_LoadURL(GetMainFrame(), url); } -void CefBrowserImpl::UIT_CloseBrowser() -{ - REQUIRE_UIT(); - DCHECK(!_Context->shutting_down()); - - // TODO(port): Close the browser window. - NOTREACHED(); -} - void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) { REQUIRE_UIT(); @@ -98,26 +89,6 @@ void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) [[view window] makeFirstResponder:view]; } -WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget() -{ - REQUIRE_UIT(); - - DCHECK(!popuphost_); - popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get()); - - // TODO(port): Show window. - - return popuphost_->webwidget(); -} - -void CefBrowserImpl::UIT_ClosePopupWidget() -{ - REQUIRE_UIT(); - - // TODO(port): Close window. - popuphost_ = NULL; -} - bool CefBrowserImpl::UIT_ViewDocumentString(WebKit::WebFrame *frame) { REQUIRE_UIT(); @@ -151,3 +122,9 @@ int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) NOTIMPLEMENTED(); return 0; } + +// static +void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) +{ + [view performSelector:@selector(performClose:) withObject:nil afterDelay:0]; +} diff --git a/libcef/browser_impl_win.cc b/libcef/browser_impl_win.cc index 8136355f5..6f39c8bcb 100644 --- a/libcef/browser_impl_win.cc +++ b/libcef/browser_impl_win.cc @@ -153,14 +153,6 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) UIT_LoadURL(GetMainFrame(), url); } -void CefBrowserImpl::UIT_CloseBrowser() -{ - REQUIRE_UIT(); - DCHECK(!_Context->shutting_down()); - - PostMessage(UIT_GetMainWndHandle(), WM_CLOSE, 0, 0); -} - void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) { REQUIRE_UIT(); @@ -173,26 +165,6 @@ void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) ::SetFocus(NULL); } -WebKit::WebWidget* CefBrowserImpl::UIT_CreatePopupWidget() -{ - REQUIRE_UIT(); - - DCHECK(!popuphost_); - popuphost_ = WebWidgetHost::Create(NULL, popup_delegate_.get()); - ShowWindow(UIT_GetPopupWndHandle(), SW_SHOW); - - return popuphost_->webwidget(); -} - -void CefBrowserImpl::UIT_ClosePopupWidget() -{ - REQUIRE_UIT(); - - PostMessage(UIT_GetPopupWndHandle(), WM_CLOSE, 0, 0); - popuphost_ = NULL; -} - - static void WriteTextToFile(const std::string& data, const std::wstring& file_path) { @@ -252,8 +224,10 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages, const int src_size_x = canvas_size.width(); const int src_size_y = canvas_size.height(); - const int dest_size_x = settings.page_setup_pixels().printable_area().width(); - const int dest_size_y = settings.page_setup_pixels().printable_area().height(); + const int dest_size_x = + settings.page_setup_pixels().printable_area().width(); + const int dest_size_y = + settings.page_setup_pixels().printable_area().height(); print_context_.NewPage(); @@ -267,21 +241,25 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages, skia::VectorCanvas canvas(hDC, dest_size_x, dest_size_y); - //The hDC 0 coord is the left most printeable area and not physical area of the paper - //so subtract that out of our canvas translate. - const int left_margin_offset = settings.page_setup_pixels().effective_margins().left - - settings.page_setup_pixels().printable_area().x(); - const int top_margin_offset = settings.page_setup_pixels().effective_margins().top - - settings.page_setup_pixels().printable_area().y(); + // The hDC 0 coord is the left most printeable area and not physical area of + // the paper so subtract that out of our canvas translate. + const int left_margin_offset = + settings.page_setup_pixels().effective_margins().left - + settings.page_setup_pixels().printable_area().x(); + const int top_margin_offset = + settings.page_setup_pixels().effective_margins().top - + settings.page_setup_pixels().printable_area().y(); // Adjust for the margin offset. canvas.translate(static_cast(left_margin_offset), static_cast(top_margin_offset)); // Apply the print scaling factor. - const float print_scale_x = static_cast(settings.page_setup_pixels().content_area().width()) + const float print_scale_x = + static_cast(settings.page_setup_pixels().content_area().width()) / src_size_x; - const float print_scale_y = static_cast(settings.page_setup_pixels().content_area().height()) + const float print_scale_y = + static_cast(settings.page_setup_pixels().content_area().height()) / src_size_y; canvas.scale(print_scale_x, print_scale_y); @@ -306,7 +284,8 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages, rect.left = left_margin_offset; rect.top = settings.page_setup_pixels().effective_margins().header - settings.page_setup_pixels().printable_area().y(); - rect.right = left_margin_offset + settings.page_setup_pixels().content_area().width(); + rect.right = left_margin_offset + + settings.page_setup_pixels().content_area().width(); rect.bottom = settings.page_setup_pixels().printable_area().height() - (settings.page_setup_pixels().effective_margins().footer - (settings.page_setup_pixels().physical_size().height() - @@ -408,7 +387,8 @@ void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) { settings.UpdatePrintOptions(print_options); // Ask the handler if they want to update the print options. - if (handler_.get() && RV_HANDLED == handler_->HandlePrintOptions(this, print_options)) { + if (handler_.get() && RV_HANDLED == + handler_->HandlePrintOptions(this, print_options)) { settings.UpdateFromPrintOptions(print_options); print_context_.InitWithSettings(settings); } @@ -465,7 +445,7 @@ void CefBrowserImpl::UIT_PrintPages(WebKit::WebFrame* frame) { int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) { - REQUIRE_UIT(); + REQUIRE_UIT(); printing::PrintParams params; const printing::PrintSettings &settings = print_context_.settings(); @@ -494,3 +474,9 @@ int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) return page_count; } + +// static +void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) +{ + PostMessage(view, WM_CLOSE, 0, 0); +} diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 75ef75df9..9530b1237 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -506,6 +506,14 @@ void BrowserWebViewDelegate::didBlur() { browser_->UIT_SetFocus(host, false); } +void BrowserWebViewDelegate::closeWidgetSoon() { + if (this == browser_->UIT_GetWebViewDelegate()) { + browser_->UIT_CloseBrowser(); + } else if (this == browser_->UIT_GetPopupDelegate()) { + browser_->UIT_ClosePopupWidget(); + } +} + WebScreenInfo BrowserWebViewDelegate::screenInfo() { if (WebWidgetHost* host = GetWidgetHost()) return host->GetScreenInfo(); diff --git a/libcef/browser_webview_delegate_gtk.cc b/libcef/browser_webview_delegate_gtk.cc index 4fa93e7ec..905ec6d09 100644 --- a/libcef/browser_webview_delegate_gtk.cc +++ b/libcef/browser_webview_delegate_gtk.cc @@ -101,15 +101,6 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) { gtk_widget_show_all(window); } -void BrowserWebViewDelegate::closeWidgetSoon() { - if (this == browser_->UIT_GetWebViewDelegate()) { - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableFunction( - >k_widget_destroy, GTK_WIDGET(browser_->UIT_GetMainWndHandle()))); - } else if (this == browser_->UIT_GetPopupDelegate()) { - browser_->UIT_ClosePopupWidget(); - } -} - void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) { current_cursor_.InitFromCursorInfo(cursor_info); GdkCursorType cursor_type = diff --git a/libcef/browser_webview_delegate_mac.mm b/libcef/browser_webview_delegate_mac.mm index 6b9e6b0a8..8b99200cb 100644 --- a/libcef/browser_webview_delegate_mac.mm +++ b/libcef/browser_webview_delegate_mac.mm @@ -97,15 +97,6 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) { } } -void BrowserWebViewDelegate::closeWidgetSoon() { - if (this == browser_->UIT_GetWebViewDelegate()) { - NSWindow *win = browser_->UIT_GetMainWndHandle(); - [win performSelector:@selector(performClose:) withObject:nil afterDelay:0]; - } else if (this == browser_->UIT_GetPopupDelegate()) { - browser_->UIT_ClosePopupWidget(); - } -} - void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) { NSCursor* ns_cursor = WebCursor(cursor_info).GetCursor(); [ns_cursor set]; diff --git a/libcef/browser_webview_delegate_win.cc b/libcef/browser_webview_delegate_win.cc index d68f6fb3f..f7ad3a509 100644 --- a/libcef/browser_webview_delegate_win.cc +++ b/libcef/browser_webview_delegate_win.cc @@ -56,18 +56,14 @@ WebWidget* BrowserWebViewDelegate::createPopupMenu( // WebWidgetClient ------------------------------------------------------------ void BrowserWebViewDelegate::show(WebNavigationPolicy) { - if (WebWidgetHost* host = GetWidgetHost()) { - HWND root = GetAncestor(host->view_handle(), GA_ROOT); + if (this == browser_->UIT_GetWebViewDelegate()) { + // Restore the window and bring it to the top. + HWND root = GetAncestor(browser_->UIT_GetMainWndHandle(), GA_ROOT); ShowWindow(root, SW_SHOWNORMAL); SetWindowPos(root, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); - } -} - -void BrowserWebViewDelegate::closeWidgetSoon() { - if (this == browser_->UIT_GetWebViewDelegate()) { - PostMessage(browser_->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0); } else if (this == browser_->UIT_GetPopupDelegate()) { - browser_->UIT_ClosePopupWidget(); + // Show popup widgets without activation. + ShowWindow(browser_->UIT_GetPopupWndHandle(), SW_SHOWNA); } } diff --git a/libcef/webwidget_host.h b/libcef/webwidget_host.h index 97b865100..b1c8c2970 100644 --- a/libcef/webwidget_host.h +++ b/libcef/webwidget_host.h @@ -72,6 +72,9 @@ class WebWidgetHost { void SetTooltipText(const CefString& tooltip_text); + void set_popup(bool popup) { popup_ = popup; } + bool popup() { return popup_; } + protected: WebWidgetHost(); ~WebWidgetHost(); @@ -126,7 +129,7 @@ class WebWidgetHost { painting_ = value; #endif } - + void EnsureTooltip(); void ResetTooltip(); @@ -134,6 +137,9 @@ class WebWidgetHost { WebKit::WebWidget* webwidget_; scoped_ptr canvas_; + // True if this widget is a popup widget. + bool popup_; + // specifies the portion of the webwidget that needs painting gfx::Rect paint_rect_; diff --git a/libcef/webwidget_host_gtk.cc b/libcef/webwidget_host_gtk.cc index 37e36d5e7..612ec1bef 100644 --- a/libcef/webwidget_host_gtk.cc +++ b/libcef/webwidget_host_gtk.cc @@ -332,6 +332,7 @@ void WebWidgetHost::ScheduleComposite() { WebWidgetHost::WebWidgetHost() : view_(NULL), webwidget_(NULL), + popup_(false), scroll_dx_(0), scroll_dy_(0) { set_painting(false); diff --git a/libcef/webwidget_host_mac.mm b/libcef/webwidget_host_mac.mm index 25fc019a6..5050e55a4 100644 --- a/libcef/webwidget_host_mac.mm +++ b/libcef/webwidget_host_mac.mm @@ -140,6 +140,7 @@ void WebWidgetHost::DiscardBackingStore() { WebWidgetHost::WebWidgetHost() : view_(NULL), webwidget_(NULL), + popup_(false), scroll_dx_(0), scroll_dy_(0) { set_painting(false); diff --git a/libcef/webwidget_host_win.cc b/libcef/webwidget_host_win.cc index 57d31aaa3..4987fbec4 100644 --- a/libcef/webwidget_host_win.cc +++ b/libcef/webwidget_host_win.cc @@ -108,6 +108,13 @@ LRESULT CALLBACK WebWidgetHost::WndProc(HWND hwnd, UINT message, WPARAM wparam, host->WheelEvent(wparam, lparam); break; + case WM_MOUSEACTIVATE: + if (host->popup()) { + // Do not activate popup widgets on mouse click. + return MA_NOACTIVATE; + } + break; + case WM_CAPTURECHANGED: case WM_CANCELMODE: host->CaptureLostEvent(); @@ -206,6 +213,7 @@ void WebWidgetHost::DiscardBackingStore() { WebWidgetHost::WebWidgetHost() : view_(NULL), webwidget_(NULL), + popup_(false), track_mouse_leave_(false), scroll_dx_(0), scroll_dy_(0), @@ -317,16 +325,20 @@ void WebWidgetHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) { TrackMouseLeave(false); break; case WebInputEvent::MouseDown: - 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_); + 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_); + } break; case WebInputEvent::MouseUp: - if (GetCapture() == view_) - ReleaseCapture(); + if (!popup()) { + if (GetCapture() == view_) + ReleaseCapture(); + } break; } webwidget_->handleInputEvent(event);