Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinForms - Opening file picker via <input type="file"> does not correctly restores focus after canceling/picking a file #4692

Open
1 task done
MaTToX3 opened this issue Jan 24, 2024 · 5 comments

Comments

@MaTToX3
Copy link

MaTToX3 commented Jan 24, 2024

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

120.2.70

Operating System

Windows 10

Architecture

x64

.Net Version

NET 4.7.2

Implementation

WinForms

Reproduction Steps

Repo (using MinimalExample): https://github.com/MaTToX3/cefsharp-winforms-focus-issue

When opening a file picker on a website via simple and picking a file/canceling it, the focus is not correctly restored to the browser component. How do I know: having a keyup event listener on that page the event is not triggered until website is manually clicked again.

Expected behavior

The focus should be correctly restored back to the browser component - e.g. keyup listener should be triggered if any key is pressed.

Actual behavior

Focus is not correctly restored until manually clicked.

Regression?

Issue exists since v102.0.90, the last version this works correctly is 101.0.180

Known Workarounds

No workaround found, I tried some options with manually focusing back to control but it did not work:
https://stackoverflow.com/questions/77865196/cefsharp-chromiumbrowser-looses-focus-when-opening-file-picker-via-input-type

Does this problem also occur in the CEF Sample Application

No, focus is correctly restored in a CEF Sample App (tried Winforms version).

Other information

No response

@amaitland amaitland changed the title Opening file picker via <input type="file"> does not correctly restores focus after canceling/picking a file WinForms - Opening file picker via <input type="file"> does not correctly restores focus after canceling/picking a file Jan 24, 2024
amaitland added a commit to cefsharp/cefsharp.github.io that referenced this issue Jan 25, 2024
@amaitland
Copy link
Member

Issue exists since v102.0.90, the last version this works correctly is 101.0.180

Likely the result of this upstream change. CEF switched to using Chromium dialogs.

@MaTToX3
Copy link
Author

MaTToX3 commented Jan 25, 2024

I see. I wonder, how come I cant just work around this and do browser.Focus() on the Form.Activated event (which is correctly triggered when file browser is closed)? Why does the Focus() return false? Or even when it does returns true, it still does not focus on the browser control. What would be the proper way to focus on the browser manually?

@MaTToX3
Copy link
Author

MaTToX3 commented Jan 29, 2024

Issue exists since v102.0.90, the last version this works correctly is 101.0.180

Likely the result of this upstream change. CEF switched to using Chromium dialogs.

Seems like there are multiple issues regarding that change. We have a DownloadHandler implemented, where we are specifying the download path manually and it is being ignored - the last path is always used for the dialog.

var fileName = downloadItem.SuggestedFileName;
var pathToDownload = Path.Combine(path, fileName); 
callback.Continue(pathToDownload, showDialog: true); // no matter what the value of pathToDownload is, the dialog always points to last used download path

@amaitland
Copy link
Member

You can show your own custom dialog for downloading files and you should be able to do the same for the file picker as well.

https://cefsharp.github.io/api/118.6.x/html/M_CefSharp_Handler_DialogHandler_OnFileDialog.htm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants