From a4e56ead3d9b25a8f68bef103a4e60d4ed2865f1 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Mon, 2 May 2022 15:18:38 +0200 Subject: [PATCH] focus address bar by pressing Ctrl+L --- SafeExamBrowser.Browser/BrowserWindow.cs | 6 ++++++ SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs | 6 ++++++ .../Browser/IBrowserWindow.cs | 2 ++ .../Controls/Taskbar/KeyboardLayoutButton.xaml.cs | 2 +- .../Windows/BrowserWindow.xaml.cs | 12 +++++++++++- .../Windows/BrowserWindow.xaml.cs | 5 +++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/SafeExamBrowser.Browser/BrowserWindow.cs b/SafeExamBrowser.Browser/BrowserWindow.cs index b50ac955..691018bd 100644 --- a/SafeExamBrowser.Browser/BrowserWindow.cs +++ b/SafeExamBrowser.Browser/BrowserWindow.cs @@ -165,6 +165,7 @@ namespace SafeExamBrowser.Browser keyboardHandler.ZoomOutRequested += ZoomOutRequested; keyboardHandler.ZoomResetRequested += ZoomResetRequested; keyboardHandler.TabPressed += TabPressed; + keyboardHandler.FocusAddressBarRequested += FocusAddressBarRequested; resourceHandler.SessionIdentifierDetected += (id) => SessionIdentifierDetected?.Invoke(id); requestHandler.QuitUrlVisited += RequestHandler_QuitUrlVisited; requestHandler.RequestBlocked += RequestHandler_RequestBlocked; @@ -458,6 +459,11 @@ namespace SafeExamBrowser.Browser } } + private void FocusAddressBarRequested() + { + window.FocusAddressBar(); + } + private ChromiumHostControl LifeSpanHandler_CreatePopup() { var args = new PopupRequestedEventArgs(); diff --git a/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs b/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs index 34e43f3c..e7b48563 100644 --- a/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs @@ -20,6 +20,7 @@ namespace SafeExamBrowser.Browser.Handlers internal event ActionRequestedEventHandler ZoomInRequested; internal event ActionRequestedEventHandler ZoomOutRequested; internal event ActionRequestedEventHandler ZoomResetRequested; + internal event ActionRequestedEventHandler FocusAddressBarRequested; internal event System.EventHandler TabPressed; private int? currentKeyDown = null; @@ -41,6 +42,11 @@ namespace SafeExamBrowser.Browser.Handlers HomeNavigationRequested?.Invoke(); } + if (ctrl && keyCode == (int) Keys.L) + { + FocusAddressBarRequested?.Invoke(); + } + if ((ctrl && keyCode == (int) Keys.Add) || (ctrl && keyCode == (int) Keys.Oemplus) || (ctrl && shift && keyCode == (int) Keys.D1)) { ZoomInRequested?.Invoke(); diff --git a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs index 5c133e31..72224a74 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs @@ -140,5 +140,7 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser /// Sets the focus to the browser. /// void FocusBrowser(); + + void FocusAddressBar(); } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs index ed716481..ad74c2fa 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs @@ -43,7 +43,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar CultureCodeTextBlock.Text = layout.CultureCode; CultureNameTextBlock.Text = layout.CultureName; LayoutNameTextBlock.Text = layout.LayoutName; - System.Windows.Automation.AutomationProperties.SetHelpText(Button, layout.Name); + System.Windows.Automation.AutomationProperties.SetHelpText(Button, layout.LayoutName); } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index c73fbbee..c46a15e8 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -453,7 +453,9 @@ if (typeof __SEB_focusElement === 'undefined') { .filter(function(e) { return e.el.tabIndex >= 0 && !e.el.disabled && e.el.offsetParent; }) .sort(function(a,b) { return a.el.tabIndex === b.el.tabIndex ? a.i - b.i : (a.el.tabIndex || 9E9) - (b.el.tabIndex || 9E9); }) var item = items[forward ? 1 : items.length - 1]; - setTimeout(function () { item.focus(); }, 20); + if (item && item.focus && typeof item.focus !== 'function') + throw ('item.focus is not a function, ' + typeof item.focus) + setTimeout(function () { item && item.focus && item.focus(); }, 20); } }"; var control = BrowserControlHost.Child as IBrowserControl; @@ -622,5 +624,13 @@ if (typeof __SEB_focusElement === 'undefined') { this.browserControlGetsFocusFromTaskbar = false; })); } + + public void FocusAddressBar() + { + this.Dispatcher.BeginInvoke((Action)(async () => + { + this.UrlTextBox.Focus(); + })); + } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs index 034fca4b..e89d1152 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs @@ -471,5 +471,10 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows { throw new NotImplementedException(); } + + public void FocusAddressBar() + { + this.UrlTextBox.Focus(); + } } }