From 40d2709371b4d951f49602a680d4a2a890992ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Fri, 13 Aug 2021 14:33:12 +0200 Subject: [PATCH] SEBWIN-507: Ensured that the main browser window is always focused after initialization. --- SafeExamBrowser.Browser/BrowserApplicationInstance.cs | 1 + SafeExamBrowser.Browser/BrowserControl.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs index ef17c798..a945bab5 100644 --- a/SafeExamBrowser.Browser/BrowserApplicationInstance.cs +++ b/SafeExamBrowser.Browser/BrowserApplicationInstance.cs @@ -217,6 +217,7 @@ namespace SafeExamBrowser.Browser window.ZoomResetRequested += ZoomResetRequested; window.UpdateZoomLevel(CalculateZoomPercentage()); window.Show(); + window.BringToForeground(); Handle = window.Handle; diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index f76c60b3..e9c539f3 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using CefSharp; using CefSharp.WinForms; using SafeExamBrowser.UserInterface.Contracts.Browser; @@ -85,6 +86,7 @@ namespace SafeExamBrowser.Browser public void Initialize() { AddressChanged += (o, args) => addressChanged?.Invoke(args.Address); + IsBrowserInitializedChanged += BrowserControl_IsBrowserInitializedChanged; LoadError += BrowserControl_LoadError; LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading); TitleChanged += (o, args) => titleChanged?.Invoke(args.Title); @@ -133,6 +135,14 @@ namespace SafeExamBrowser.Browser 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) { loadFailed?.Invoke((int) e.ErrorCode, e.ErrorText, e.FailedUrl);