mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	Windows: Fix focus assignment after dismissing JS dialogs (issue #2584)
This commit is contained in:
		| @@ -707,7 +707,10 @@ LRESULT CALLBACK CefBrowserPlatformDelegateNativeWin::WndProc(HWND hwnd, | |||||||
|       return 0; |       return 0; | ||||||
|  |  | ||||||
|     case WM_SETFOCUS: |     case WM_SETFOCUS: | ||||||
|       if (browser) |       // Selecting "Close window" from the task bar menu may send a focus | ||||||
|  |       // notification even though the window is currently disabled (e.g. while | ||||||
|  |       // a modal JS dialog is displayed). | ||||||
|  |       if (browser && ::IsWindowEnabled(hwnd)) | ||||||
|         browser->SetFocus(true); |         browser->SetFocus(true); | ||||||
|       return 0; |       return 0; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -39,8 +39,7 @@ INT_PTR CALLBACK CefJavaScriptDialogRunnerWin::DialogProc(HWND dialog, | |||||||
|           reinterpret_cast<CefJavaScriptDialogRunnerWin*>( |           reinterpret_cast<CefJavaScriptDialogRunnerWin*>( | ||||||
|               GetWindowLongPtr(dialog, DWLP_USER)); |               GetWindowLongPtr(dialog, DWLP_USER)); | ||||||
|       if (owner) { |       if (owner) { | ||||||
|         owner->Cancel(); |         owner->CloseDialog(false, base::string16()); | ||||||
|         owner->callback_.Run(false, base::string16()); |  | ||||||
|  |  | ||||||
|         // No need for the system to call DestroyWindow() because it will be |         // No need for the system to call DestroyWindow() because it will be | ||||||
|         // called by the Cancel() method. |         // called by the Cancel() method. | ||||||
| @@ -74,8 +73,7 @@ INT_PTR CALLBACK CefJavaScriptDialogRunnerWin::DialogProc(HWND dialog, | |||||||
|           break; |           break; | ||||||
|       } |       } | ||||||
|       if (finish) { |       if (finish) { | ||||||
|         owner->Cancel(); |         owner->CloseDialog(result, user_input); | ||||||
|         owner->callback_.Run(result, user_input); |  | ||||||
|       } |       } | ||||||
|       break; |       break; | ||||||
|     } |     } | ||||||
| @@ -153,12 +151,9 @@ void CefJavaScriptDialogRunnerWin::Run( | |||||||
| } | } | ||||||
|  |  | ||||||
| void CefJavaScriptDialogRunnerWin::Cancel() { | void CefJavaScriptDialogRunnerWin::Cancel() { | ||||||
|   HWND parent = NULL; |  | ||||||
|  |  | ||||||
|   // Re-enable the parent before closing the popup to avoid focus/activation/ |   // Re-enable the parent before closing the popup to avoid focus/activation/ | ||||||
|   // z-order issues. |   // z-order issues. | ||||||
|   if (parent_win_ && IsWindow(parent_win_) && !IsWindowEnabled(parent_win_)) { |   if (parent_win_ && IsWindow(parent_win_) && !IsWindowEnabled(parent_win_)) { | ||||||
|     parent = parent_win_; |  | ||||||
|     EnableWindow(parent_win_, TRUE); |     EnableWindow(parent_win_, TRUE); | ||||||
|     parent_win_ = NULL; |     parent_win_ = NULL; | ||||||
|   } |   } | ||||||
| @@ -169,16 +164,24 @@ void CefJavaScriptDialogRunnerWin::Cancel() { | |||||||
|     dialog_win_ = NULL; |     dialog_win_ = NULL; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Return focus to the parent window. |  | ||||||
|   if (parent) |  | ||||||
|     SetFocus(parent); |  | ||||||
|  |  | ||||||
|   if (hook_installed_) { |   if (hook_installed_) { | ||||||
|     UninstallMessageHook(); |     UninstallMessageHook(); | ||||||
|     hook_installed_ = false; |     hook_installed_ = false; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void CefJavaScriptDialogRunnerWin::CloseDialog( | ||||||
|  |     bool success, | ||||||
|  |     const base::string16& user_input) { | ||||||
|  |   // Run the callback first so that RenderProcessHostImpl::IsBlocked is | ||||||
|  |   // cleared. Otherwise, RenderWidgetHostImpl::IsIgnoringInputEvents will | ||||||
|  |   // return true and RenderWidgetHostViewAura::OnWindowFocused will fail to | ||||||
|  |   // re-assign browser focus. | ||||||
|  |   callback_.Run(success, user_input); | ||||||
|  |   callback_.Reset(); | ||||||
|  |   Cancel(); | ||||||
|  | } | ||||||
|  |  | ||||||
| // static | // static | ||||||
| LRESULT CALLBACK CefJavaScriptDialogRunnerWin::GetMsgProc(int code, | LRESULT CALLBACK CefJavaScriptDialogRunnerWin::GetMsgProc(int code, | ||||||
|                                                           WPARAM wparam, |                                                           WPARAM wparam, | ||||||
|   | |||||||
| @@ -26,6 +26,8 @@ class CefJavaScriptDialogRunnerWin : public CefJavaScriptDialogRunner { | |||||||
|   void Cancel() override; |   void Cancel() override; | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|  |   void CloseDialog(bool success, const base::string16& user_input); | ||||||
|  |  | ||||||
|   HWND dialog_win_; |   HWND dialog_win_; | ||||||
|   HWND parent_win_; |   HWND parent_win_; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -623,7 +623,10 @@ void RootWindowWin::OnPaint() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void RootWindowWin::OnFocus() { | void RootWindowWin::OnFocus() { | ||||||
|   if (browser_window_) |   // Selecting "Close window" from the task bar menu may send a focus | ||||||
|  |   // notification even though the window is currently disabled (e.g. while a | ||||||
|  |   // modal JS dialog is displayed). | ||||||
|  |   if (browser_window_ && ::IsWindowEnabled(hwnd_)) | ||||||
|     browser_window_->SetFocus(true); |     browser_window_->SetFocus(true); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user