focus address bar by pressing Ctrl+L

This commit is contained in:
Jonas Sourlier 2022-05-02 15:18:38 +02:00
parent ffe424725d
commit a4e56ead3d
6 changed files with 31 additions and 2 deletions

View file

@ -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();

View file

@ -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<bool> 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();

View file

@ -140,5 +140,7 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser
/// Sets the focus to the browser.
/// </summary>
void FocusBrowser();
void FocusAddressBar();
}
}

View file

@ -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);
}
}
}

View file

@ -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();
}));
}
}
}

View file

@ -471,5 +471,10 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows
{
throw new NotImplementedException();
}
public void FocusAddressBar()
{
this.UrlTextBox.Focus();
}
}
}