SEBWIN-507: Ensured that the main browser window is always focused after initialization.

This commit is contained in:
Damian Büchel 2021-08-13 14:33:12 +02:00
parent 6b1aa69715
commit 40d2709371
2 changed files with 11 additions and 0 deletions

View file

@ -217,6 +217,7 @@ namespace SafeExamBrowser.Browser
window.ZoomResetRequested += ZoomResetRequested; window.ZoomResetRequested += ZoomResetRequested;
window.UpdateZoomLevel(CalculateZoomPercentage()); window.UpdateZoomLevel(CalculateZoomPercentage());
window.Show(); window.Show();
window.BringToForeground();
Handle = window.Handle; Handle = window.Handle;

View file

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
using System;
using CefSharp; using CefSharp;
using CefSharp.WinForms; using CefSharp.WinForms;
using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser;
@ -85,6 +86,7 @@ namespace SafeExamBrowser.Browser
public void Initialize() public void Initialize()
{ {
AddressChanged += (o, args) => addressChanged?.Invoke(args.Address); AddressChanged += (o, args) => addressChanged?.Invoke(args.Address);
IsBrowserInitializedChanged += BrowserControl_IsBrowserInitializedChanged;
LoadError += BrowserControl_LoadError; LoadError += BrowserControl_LoadError;
LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading); LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading);
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title); TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
@ -133,6 +135,14 @@ namespace SafeExamBrowser.Browser
GetBrowser().SetZoomLevel(level); GetBrowser().SetZoomLevel(level);
} }
private void BrowserControl_IsBrowserInitializedChanged(object sender, EventArgs e)
{
if (IsBrowserInitialized)
{
GetBrowser().GetHost().SetFocus(true);
}
}
private void BrowserControl_LoadError(object sender, LoadErrorEventArgs e) private void BrowserControl_LoadError(object sender, LoadErrorEventArgs e)
{ {
loadFailed?.Invoke((int) e.ErrorCode, e.ErrorText, e.FailedUrl); loadFailed?.Invoke((int) e.ErrorCode, e.ErrorText, e.FailedUrl);