From d040615c6eb9b06782a75b9e05125a1e3e199ff8 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Wed, 24 Nov 2021 08:42:07 +0100 Subject: [PATCH 01/20] accessibility --- .../IBrowserApplication.cs | 12 ++ .../SafeExamBrowser.Browser.Contracts.csproj | 4 + SafeExamBrowser.Browser/BrowserApplication.cs | 11 ++ SafeExamBrowser.Browser/BrowserControl.cs | 9 ++ SafeExamBrowser.Browser/BrowserWindow.cs | 46 +++++++ .../Handlers/KeyboardHandler.cs | 14 +++ SafeExamBrowser.Client/ClientController.cs | 12 ++ .../Browser/IBrowserControl.cs | 5 + .../Browser/IBrowserWindow.cs | 17 +++ .../Events/LoseFocusRequestedEventHandler.cs | 15 +++ ...ExamBrowser.UserInterface.Contracts.csproj | 1 + .../Shell/ITaskbar.cs | 11 ++ .../Windows/BrowserWindow.xaml.cs | 112 ++++++++++++++++++ .../Windows/Taskbar.xaml | 1 + .../Windows/Taskbar.xaml.cs | 82 +++++++++++++ .../Windows/BrowserWindow.xaml.cs | 17 +++ .../Windows/Taskbar.xaml.cs | 15 +++ 17 files changed, 384 insertions(+) create mode 100644 SafeExamBrowser.UserInterface.Contracts/Events/LoseFocusRequestedEventHandler.cs diff --git a/SafeExamBrowser.Browser.Contracts/IBrowserApplication.cs b/SafeExamBrowser.Browser.Contracts/IBrowserApplication.cs index d89f9b57..4cad3bea 100644 --- a/SafeExamBrowser.Browser.Contracts/IBrowserApplication.cs +++ b/SafeExamBrowser.Browser.Contracts/IBrowserApplication.cs @@ -6,8 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Browser.Contracts.Events; +using SafeExamBrowser.UserInterface.Contracts.Events; namespace SafeExamBrowser.Browser.Contracts { @@ -30,5 +32,15 @@ namespace SafeExamBrowser.Browser.Contracts /// Event fired when the browser application detects a request to terminate SEB. /// event TerminationRequestedEventHandler TerminationRequested; + + /// + /// Event fired when the user tries to focus the taskbar. + /// + event LoseFocusRequestedEventHandler LoseFocusRequested; + + /// + /// Transfers the focus to the browser window. + /// + void Focus(bool forward); } } diff --git a/SafeExamBrowser.Browser.Contracts/SafeExamBrowser.Browser.Contracts.csproj b/SafeExamBrowser.Browser.Contracts/SafeExamBrowser.Browser.Contracts.csproj index 542024a9..c0b750b2 100644 --- a/SafeExamBrowser.Browser.Contracts/SafeExamBrowser.Browser.Contracts.csproj +++ b/SafeExamBrowser.Browser.Contracts/SafeExamBrowser.Browser.Contracts.csproj @@ -75,6 +75,10 @@ {30b2d907-5861-4f39-abad-c4abf1b3470e} SafeExamBrowser.Settings + + {c7889e97-6ff6-4a58-b7cb-521ed276b316} + SafeExamBrowser.UserInterface.Contracts + \ No newline at end of file diff --git a/SafeExamBrowser.Browser/BrowserApplication.cs b/SafeExamBrowser.Browser/BrowserApplication.cs index c98f4924..5380034d 100644 --- a/SafeExamBrowser.Browser/BrowserApplication.cs +++ b/SafeExamBrowser.Browser/BrowserApplication.cs @@ -27,6 +27,7 @@ using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Settings.Browser.Proxy; using SafeExamBrowser.Settings.Logging; using SafeExamBrowser.UserInterface.Contracts; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog; using SafeExamBrowser.UserInterface.Contracts.MessageBox; using SafeExamBrowser.WindowsApi.Contracts; @@ -58,6 +59,7 @@ namespace SafeExamBrowser.Browser public event DownloadRequestedEventHandler ConfigurationDownloadRequested; public event SessionIdentifierDetectedEventHandler SessionIdentifierDetected; + public event LoseFocusRequestedEventHandler LoseFocusRequested; public event TerminationRequestedEventHandler TerminationRequested; public event WindowsChangedEventHandler WindowsChanged; @@ -195,6 +197,7 @@ namespace SafeExamBrowser.Browser window.ResetRequested += Window_ResetRequested; window.SessionIdentifierDetected += (i) => SessionIdentifierDetected?.Invoke(i); window.TerminationRequested += () => TerminationRequested?.Invoke(); + window.LoseFocusRequested += (forward) => LoseFocusRequested?.Invoke(forward); window.InitializeControl(); windows.Add(window); @@ -457,5 +460,13 @@ namespace SafeExamBrowser.Browser CreateNewWindow(); logger.Info("Successfully reset browser."); } + + public void Focus(bool forward) + { + windows.ForEach(window => + { + window.Focus(forward); + }); + } } } diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index e9635c6c..54902832 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -143,5 +143,14 @@ namespace SafeExamBrowser.Browser { control.BrowserCore.SetZoomLevel(level); } + + /// + /// Executes the given Javascript code in the browser. + /// + public async void ExecuteJavascript(string javascript, System.Action callback) + { + var result = await this.control.EvaluateScriptAsync(javascript); + callback(result); + } } } diff --git a/SafeExamBrowser.Browser/BrowserWindow.cs b/SafeExamBrowser.Browser/BrowserWindow.cs index e008f31c..b50ac955 100644 --- a/SafeExamBrowser.Browser/BrowserWindow.cs +++ b/SafeExamBrowser.Browser/BrowserWindow.cs @@ -31,6 +31,7 @@ using SafeExamBrowser.Settings.Browser.Filter; using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser.Data; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.FileSystemDialog; using SafeExamBrowser.UserInterface.Contracts.MessageBox; using Syroot.Windows.IO; @@ -80,6 +81,7 @@ namespace SafeExamBrowser.Browser internal event PopupRequestedEventHandler PopupRequested; internal event ResetRequestedEventHandler ResetRequested; internal event SessionIdentifierDetectedEventHandler SessionIdentifierDetected; + internal event LoseFocusRequestedEventHandler LoseFocusRequested; internal event TerminationRequestedEventHandler TerminationRequested; public event IconChangedEventHandler IconChanged; @@ -162,6 +164,7 @@ namespace SafeExamBrowser.Browser keyboardHandler.ZoomInRequested += ZoomInRequested; keyboardHandler.ZoomOutRequested += ZoomOutRequested; keyboardHandler.ZoomResetRequested += ZoomResetRequested; + keyboardHandler.TabPressed += TabPressed; resourceHandler.SessionIdentifierDetected += (id) => SessionIdentifierDetected?.Invoke(id); requestHandler.QuitUrlVisited += RequestHandler_QuitUrlVisited; requestHandler.RequestBlocked += RequestHandler_RequestBlocked; @@ -198,6 +201,7 @@ namespace SafeExamBrowser.Browser window.FindRequested += Window_FindRequested; window.ForwardNavigationRequested += Window_ForwardNavigationRequested; window.HomeNavigationRequested += HomeNavigationRequested; + window.LoseFocusRequested += Window_LoseFocusRequested; window.ReloadRequested += ReloadRequested; window.ZoomInRequested += ZoomInRequested; window.ZoomOutRequested += ZoomOutRequested; @@ -655,6 +659,11 @@ namespace SafeExamBrowser.Browser Control.NavigateForwards(); } + private void Window_LoseFocusRequested(bool forward) + { + LoseFocusRequested?.Invoke(forward); + } + private void ZoomInRequested() { if (settings.AllowPageZoom && CalculateZoomPercentage() < 300) @@ -688,6 +697,43 @@ namespace SafeExamBrowser.Browser } } + private void TabPressed(object sender, bool shiftPressed) + { + this.Control.ExecuteJavascript("document.activeElement.tagName", result => + { + var tagName = result.Result as string; + if (tagName != null) + { + if (tagName.ToUpper() == "BODY") + { + // this means the user is now at the start of the focus / tabIndex chain in the website + if (shiftPressed) + { + window.FocusToolbar(!shiftPressed); + } + else + { + this.LoseFocusRequested?.Invoke(true); + } + } + } + }); + } + + internal void Focus(bool forward) + { + if (forward) + { + window.FocusToolbar(forward); + } + else + { + window.FocusBrowser(); + + this.Activate(); + } + } + private double CalculateZoomPercentage() { return (zoomLevel * 25.0) + 100.0; diff --git a/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs b/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs index ec54b60d..34e43f3c 100644 --- a/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/KeyboardHandler.cs @@ -20,6 +20,9 @@ namespace SafeExamBrowser.Browser.Handlers internal event ActionRequestedEventHandler ZoomInRequested; internal event ActionRequestedEventHandler ZoomOutRequested; internal event ActionRequestedEventHandler ZoomResetRequested; + internal event System.EventHandler TabPressed; + + private int? currentKeyDown = null; public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int keyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { @@ -52,8 +55,14 @@ namespace SafeExamBrowser.Browser.Handlers { ZoomResetRequested?.Invoke(); } + + if (keyCode == (int)Keys.Tab && keyCode == currentKeyDown) + { + TabPressed?.Invoke(this, shift); + } } + currentKeyDown = null; return false; } @@ -66,6 +75,11 @@ namespace SafeExamBrowser.Browser.Handlers return true; } + if (type == KeyType.RawKeyDown || type == KeyType.KeyDown) + { + currentKeyDown = keyCode; + } + return false; } } diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 1a59d1e9..f9ea4e44 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -188,6 +188,7 @@ namespace SafeExamBrowser.Client Browser.ConfigurationDownloadRequested += Browser_ConfigurationDownloadRequested; Browser.SessionIdentifierDetected += Browser_SessionIdentifierDetected; Browser.TerminationRequested += Browser_TerminationRequested; + Browser.LoseFocusRequested += Browser_LoseFocusRequested; ; ClientHost.ExamSelectionRequested += ClientHost_ExamSelectionRequested; ClientHost.MessageBoxRequested += ClientHost_MessageBoxRequested; ClientHost.PasswordRequested += ClientHost_PasswordRequested; @@ -198,6 +199,7 @@ namespace SafeExamBrowser.Client displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged; runtime.ConnectionLost += Runtime_ConnectionLost; systemMonitor.SessionSwitched += SystemMonitor_SessionSwitched; + taskbar.LoseFocusRequested += Taskbar_LoseFocusRequested; taskbar.QuitButtonClicked += Shell_QuitButtonClicked; foreach (var activator in context.Activators.OfType()) @@ -211,6 +213,16 @@ namespace SafeExamBrowser.Client } } + private void Taskbar_LoseFocusRequested(bool forward) + { + this.Browser.Focus(forward); + } + + private void Browser_LoseFocusRequested(bool forward) + { + this.taskbar.Focus(forward); + } + private void DeregisterEvents() { actionCenter.QuitButtonClicked -= Shell_QuitButtonClicked; diff --git a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserControl.cs b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserControl.cs index 3ec45476..7118af86 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserControl.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserControl.cs @@ -61,6 +61,11 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser /// void Destroy(); + /// + /// Executes the given Javascript code in the browser. + /// + void ExecuteJavascript(string javascript, System.Action callback); + /// /// Attempts to find the given term on the current page according to the specified parameters. /// diff --git a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs index 970f2b02..5c133e31 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Browser/IBrowserWindow.cs @@ -10,6 +10,7 @@ using System; using SafeExamBrowser.Core.Contracts.Resources.Icons; using SafeExamBrowser.UserInterface.Contracts.Browser.Data; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Windows; namespace SafeExamBrowser.UserInterface.Contracts.Browser @@ -64,6 +65,11 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser /// event ActionRequestedEventHandler HomeNavigationRequested; + /// + /// Event fired when the browser window wants to lose focus to the taskbar. + /// + event LoseFocusRequestedEventHandler LoseFocusRequested; + /// /// Event fired when the user would like to reload the current page. /// @@ -123,5 +129,16 @@ namespace SafeExamBrowser.UserInterface.Contracts.Browser /// Updates the display value of the current page zoom. Value is expected to be in percentage. /// void UpdateZoomLevel(double value); + + /// + /// Sets the focus to the toolbar. + /// + /// If true, the first focusable control on the toolbar gets focused. If false, the last one. + void FocusToolbar(bool forward); + + /// + /// Sets the focus to the browser. + /// + void FocusBrowser(); } } diff --git a/SafeExamBrowser.UserInterface.Contracts/Events/LoseFocusRequestedEventHandler.cs b/SafeExamBrowser.UserInterface.Contracts/Events/LoseFocusRequestedEventHandler.cs new file mode 100644 index 00000000..72c7fbc7 --- /dev/null +++ b/SafeExamBrowser.UserInterface.Contracts/Events/LoseFocusRequestedEventHandler.cs @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +namespace SafeExamBrowser.UserInterface.Contracts.Events +{ + /// + /// Event handler used to indicate that the user wants to move the focus away from the item. + /// + public delegate void LoseFocusRequestedEventHandler(bool forward); +} diff --git a/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj b/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj index 21563d27..914b6a57 100644 --- a/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj +++ b/SafeExamBrowser.UserInterface.Contracts/SafeExamBrowser.UserInterface.Contracts.csproj @@ -63,6 +63,7 @@ + diff --git a/SafeExamBrowser.UserInterface.Contracts/Shell/ITaskbar.cs b/SafeExamBrowser.UserInterface.Contracts/Shell/ITaskbar.cs index 76721115..bd47eec0 100644 --- a/SafeExamBrowser.UserInterface.Contracts/Shell/ITaskbar.cs +++ b/SafeExamBrowser.UserInterface.Contracts/Shell/ITaskbar.cs @@ -7,6 +7,7 @@ */ using SafeExamBrowser.I18n.Contracts; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; namespace SafeExamBrowser.UserInterface.Contracts.Shell @@ -31,6 +32,11 @@ namespace SafeExamBrowser.UserInterface.Contracts.Shell /// event QuitButtonClickedEventHandler QuitButtonClicked; + /// + /// Event fired when the Taskbar wants to lose focus. + /// + event LoseFocusRequestedEventHandler LoseFocusRequested; + /// /// Adds the given application control to the taskbar. /// @@ -70,5 +76,10 @@ namespace SafeExamBrowser.UserInterface.Contracts.Shell /// Shows the taskbar. /// void Show(); + + /// + /// Puts the focus on the taskbar. + /// + void Focus(bool forward = true); } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index 99f2c2fe..401c2c2a 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -16,11 +16,13 @@ using System.Windows.Interop; using System.Windows.Media.Imaging; using SafeExamBrowser.Core.Contracts.Resources.Icons; using SafeExamBrowser.I18n.Contracts; +using SafeExamBrowser.Logging.Contracts; using SafeExamBrowser.Settings.Browser; using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser.Data; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Contracts.Windows.Events; using SafeExamBrowser.UserInterface.Desktop.Controls.Browser; @@ -36,6 +38,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private WindowClosedEventHandler closed; private WindowClosingEventHandler closing; + private bool browserControlGetsFocusFromTaskbar = false; private WindowSettings WindowSettings { @@ -56,6 +59,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows public event ActionRequestedEventHandler ZoomInRequested; public event ActionRequestedEventHandler ZoomOutRequested; public event ActionRequestedEventHandler ZoomResetRequested; + public event LoseFocusRequestedEventHandler LoseFocusRequested; event WindowClosedEventHandler IWindow.Closed { @@ -199,6 +203,26 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows } } + private void BrowserWindow_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Tab && Toolbar.IsKeyboardFocusWithin) + { + if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) + { + var firstActiveElementInToolbar = Toolbar.PredictFocus(FocusNavigationDirection.Right); + if (firstActiveElementInToolbar is System.Windows.UIElement) + { + var control = firstActiveElementInToolbar as System.Windows.UIElement; + if (control.IsKeyboardFocusWithin) + { + this.LoseFocusRequested?.Invoke(false); + e.Handled = true; + } + } + } + } + } + private void BrowserWindow_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.F5) @@ -215,6 +239,21 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows { ShowFindbar(); } + + if (e.Key == Key.Tab) + { + if (BrowserControlHost.IsFocused && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) + { + if (Findbar.Visibility == Visibility.Hidden || (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) + { + Toolbar.Focus(); + } + else if (Toolbar.Visibility == Visibility.Hidden) + { + Findbar.Focus(); + } + } + } } private void BrowserWindow_Loaded(object sender, RoutedEventArgs e) @@ -324,6 +363,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); MenuPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); + KeyDown += BrowserWindow_KeyDown; KeyUp += BrowserWindow_KeyUp; LocationChanged += (o, args) => { DownloadsPopup.IsOpen = false; MenuPopup.IsOpen = false; }; ReloadButton.Click += (o, args) => ReloadRequested?.Invoke(); @@ -338,6 +378,41 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows ZoomInButton.Click += (o, args) => ZoomInRequested?.Invoke(); ZoomOutButton.Click += (o, args) => ZoomOutRequested?.Invoke(); ZoomResetButton.Click += (o, args) => ZoomResetRequested?.Invoke(); + BrowserControlHost.GotKeyboardFocus += BrowserControlHost_GotKeyboardFocus; + } + + private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) + { + var forward = !this.browserControlGetsFocusFromTaskbar; + + // focus the first / last element on the page + var javascript = @" +if (typeof __SEB_focusElement === 'undefined') { + __SEB_focusElement = function (forward) { + var items = [].map + .call(document.body.querySelectorAll(['input', 'select', 'a[href]', 'textarea', 'button', '[tabindex]']), function(el, i) { return { el, i } }) + .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); + } +}"; + var control = BrowserControlHost.Child as IBrowserControl; + control.ExecuteJavascript(javascript, result => + { + if (!result.Success) + { + //logger.Error($"Javascript error {result.Message}!"); + } + }); + + control.ExecuteJavascript("__SEB_focusElement(" + forward.ToString().ToLower() + ")", result => + { + if (!result.Success) + { + //logger.Error($"Javascript error {result.Message}!"); + } + }); } private void ApplySettings() @@ -444,5 +519,42 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows FindMenuText.Text = text.Get(TextKey.BrowserWindow_FindMenuItem); ZoomText.Text = text.Get(TextKey.BrowserWindow_ZoomMenuItem); } + + public void FocusToolbar(bool forward) + { + this.Dispatcher.BeginInvoke((Action)(async () => + { + this.Activate(); + await Task.Delay(50); + + // focus all elements in the toolbar, such that the last element that is enabled gets focus + var buttons = new System.Windows.Controls.Control[] { ForwardButton, BackwardButton, ReloadButton, UrlTextBox, MenuButton, }; + for (var i = forward ? 0 : buttons.Length - 1; i >= 0 && i < buttons.Length; i += forward ? 1 : -1) + { + if (buttons[i].IsEnabled && buttons[i].Visibility == Visibility.Visible) + { + buttons[i].Focus(); + break; + } + } + })); + } + + public void FocusBrowser() + { + this.Dispatcher.BeginInvoke((Action)(async () => + { + this.FocusToolbar(false); + await Task.Delay(100); + + this.browserControlGetsFocusFromTaskbar = true; + + var focusedElement = FocusManager.GetFocusedElement(this) as UIElement; + focusedElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right)); + + await Task.Delay(150); + this.browserControlGetsFocusFromTaskbar = false; + })); + } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml b/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml index 80199e63..2089f0d7 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar" xmlns:s="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d" Title="Taskbar" Background="{DynamicResource BackgroundBrush}" Height="40" Width="750" WindowStyle="None" Topmost="True" + KeyDown="Window_KeyDown" KeyUp="Window_KeyUp" ResizeMode="NoResize" Icon="../Images/SafeExamBrowser.ico"> diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml.cs index eca46944..f60ed3f0 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/Taskbar.xaml.cs @@ -6,10 +6,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.ComponentModel; using System.Windows; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -20,6 +22,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows { private bool allowClose; private ILogger logger; + private bool isQuitButtonFocusedAtKeyDown; + private bool isFirstChildFocusedAtKeyDown; public bool ShowClock { @@ -31,6 +35,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows set { Dispatcher.Invoke(() => QuitButton.Visibility = value ? Visibility.Visible : Visibility.Collapsed); } } + public event LoseFocusRequestedEventHandler LoseFocusRequested; public event QuitButtonClickedEventHandler QuitButtonClicked; internal Taskbar(ILogger logger) @@ -159,5 +164,82 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows Loaded += (o, args) => InitializeBounds(); QuitButton.Clicked += QuitButton_Clicked; } + + private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + this.isQuitButtonFocusedAtKeyDown = this.QuitButton.IsKeyboardFocusWithin; + this.isFirstChildFocusedAtKeyDown = this.ApplicationStackPanel.Children[0].IsKeyboardFocusWithin; + } + + private void Window_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Tab) + { + var shift = System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftShift); + if (!shift && this.ApplicationStackPanel.Children[0].IsKeyboardFocusWithin && this.isQuitButtonFocusedAtKeyDown) + { + this.LoseFocusRequested?.Invoke(true); + e.Handled = true; + } + else if (shift && this.QuitButton.IsKeyboardFocusWithin && this.isFirstChildFocusedAtKeyDown) + { + this.LoseFocusRequested?.Invoke(false); + e.Handled = true; + } + } + + this.isQuitButtonFocusedAtKeyDown = false; + this.isFirstChildFocusedAtKeyDown = false; + } + + void ITaskbar.Focus(bool forward) + { + this.Dispatcher.BeginInvoke((Action)(() => + { + base.Activate(); + if (forward) + { + this.SetFocusWithin(this.ApplicationStackPanel.Children[0]); + } + else + { + this.QuitButton.Focus(); + } + })); + } + + private bool SetFocusWithin(UIElement uIElement) + { + if (uIElement.Focusable) + { + uIElement.Focus(); + return true; + } + + if (uIElement is System.Windows.Controls.Panel) + { + var panel = uIElement as System.Windows.Controls.Panel; + for (var i = 0; i < panel.Children.Count; i++) + { + if (this.SetFocusWithin(panel.Children[i])) + { + return true; + } + } + + return false; + } + else if (uIElement is System.Windows.Controls.ContentControl) + { + var control = uIElement as System.Windows.Controls.ContentControl; + var content = control.Content as UIElement; + if (content != null) + { + return this.SetFocusWithin(content); + } + } + + return false; + } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs index f2ffe1b4..034fca4b 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/BrowserWindow.xaml.cs @@ -21,6 +21,7 @@ using SafeExamBrowser.UserInterface.Contracts; using SafeExamBrowser.UserInterface.Contracts.Browser; using SafeExamBrowser.UserInterface.Contracts.Browser.Data; using SafeExamBrowser.UserInterface.Contracts.Browser.Events; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Windows; using SafeExamBrowser.UserInterface.Contracts.Windows.Events; using SafeExamBrowser.UserInterface.Mobile.Controls.Browser; @@ -51,6 +52,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows public event ActionRequestedEventHandler DeveloperConsoleRequested; public event FindRequestedEventHandler FindRequested; public event ActionRequestedEventHandler ForwardNavigationRequested; + public event LoseFocusRequestedEventHandler LoseFocusRequested; public event ActionRequestedEventHandler HomeNavigationRequested; public event ActionRequestedEventHandler ReloadRequested; public event ActionRequestedEventHandler ZoomInRequested; @@ -454,5 +456,20 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows FindMenuText.Text = text.Get(TextKey.BrowserWindow_FindMenuItem); ZoomText.Text = text.Get(TextKey.BrowserWindow_ZoomMenuItem); } + + public void FocusToolbar(bool forward) + { + throw new NotImplementedException(); + } + + public void FocusBrowser() + { + throw new NotImplementedException(); + } + + public void Debug() + { + throw new NotImplementedException(); + } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Windows/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Windows/Taskbar.xaml.cs index c47469d8..1e850fc4 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Windows/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Windows/Taskbar.xaml.cs @@ -10,6 +10,7 @@ using System.ComponentModel; using System.Windows; using SafeExamBrowser.I18n.Contracts; using SafeExamBrowser.Logging.Contracts; +using SafeExamBrowser.UserInterface.Contracts.Events; using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell.Events; using SafeExamBrowser.UserInterface.Shared.Utilities; @@ -31,6 +32,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows set { Dispatcher.Invoke(() => QuitButton.Visibility = value ? Visibility.Visible : Visibility.Collapsed); } } + public event LoseFocusRequestedEventHandler LoseFocusRequested; public event QuitButtonClickedEventHandler QuitButtonClicked; internal Taskbar(ILogger logger) @@ -159,5 +161,18 @@ namespace SafeExamBrowser.UserInterface.Mobile.Windows Loaded += (o, args) => InitializeBounds(); QuitButton.Clicked += QuitButton_Clicked; } + + void ITaskbar.Focus(bool fromTop) + { + base.Activate(); + if (fromTop) + { + this.ApplicationStackPanel.Children[0].Focus(); + } + else + { + this.QuitButton.Focus(); + } + } } } From c783578bdfcd335c15ebcdb8b209a82197ffdd04 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Wed, 24 Nov 2021 09:55:04 +0100 Subject: [PATCH 02/20] popup menu accessibility (cherry picked from commit 2b6c2f0ecaa8953ae7f126b562e58b87f98d6d3f) --- .../Windows/BrowserWindow.xaml | 10 +-- .../Windows/BrowserWindow.xaml.cs | 69 +++++++++++++++++-- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml index da5ae188..cd4b266d 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml @@ -62,15 +62,15 @@ - - - @@ -80,7 +80,7 @@ - @@ -90,7 +90,7 @@ - diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index 401c2c2a..5c1170fa 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -8,6 +8,7 @@ using System; using System.ComponentModel; +using System.Reflection; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls.Primitives; @@ -39,6 +40,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private WindowClosedEventHandler closed; private WindowClosingEventHandler closing; private bool browserControlGetsFocusFromTaskbar = false; + private IInputElement tabKeyDownFocusElement = null; private WindowSettings WindowSettings { @@ -205,9 +207,10 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows private void BrowserWindow_KeyDown(object sender, KeyEventArgs e) { - if (e.Key == Key.Tab && Toolbar.IsKeyboardFocusWithin) + if (e.Key == Key.Tab) { - if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) + var hasShift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift; + if (Toolbar.IsKeyboardFocusWithin && hasShift) { var firstActiveElementInToolbar = Toolbar.PredictFocus(FocusNavigationDirection.Right); if (firstActiveElementInToolbar is System.Windows.UIElement) @@ -220,6 +223,12 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows } } } + + tabKeyDownFocusElement = FocusManager.GetFocusedElement(this); + } + else + { + tabKeyDownFocusElement = null; } } @@ -242,9 +251,11 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows if (e.Key == Key.Tab) { - if (BrowserControlHost.IsFocused && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) + var hasCtrl = (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control; + var hasShift = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift; + if (BrowserControlHost.IsFocused && hasCtrl) { - if (Findbar.Visibility == Visibility.Hidden || (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) + if (Findbar.Visibility == Visibility.Hidden || hasShift) { Toolbar.Focus(); } @@ -253,9 +264,51 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows Findbar.Focus(); } } + else if (MenuPopup.IsKeyboardFocusWithin) + { + var focusedElement = FocusManager.GetFocusedElement(this); + var focusedControl = focusedElement as System.Windows.Controls.Control; + var prevFocusedControl = tabKeyDownFocusElement as System.Windows.Controls.Control; + if (focusedControl != null && prevFocusedControl != null) + { + //var commonAncestor = focusedControl.FindCommonVisualAncestor(prevFocusedControl); + //var nextTab = GetNextTab(MenuPopup, this, true); + if (!hasShift && focusedControl.TabIndex < prevFocusedControl.TabIndex) + { + MenuPopup.IsOpen = false; + FocusBrowser(); + } + else if (hasShift && focusedControl.TabIndex > prevFocusedControl.TabIndex) + { + MenuPopup.IsOpen = false; + MenuButton.Focus(); + } + } + } } } + /// + /// Get next tab order element. Copied from https://stackoverflow.com/questions/5756448/in-wpf-how-can-i-get-the-next-control-in-the-tab-order + /// + /// The element to get next tab order + /// The container element owning 'e'. Make sure this is a container of 'e'. + /// True if search only itself and inside of 'container'; otherwise false. + /// If true and next tab order element is outside of 'container', result in null. + /// Next tab order element or null if not found + public DependencyObject GetNextTab(DependencyObject e, DependencyObject container, bool goDownOnly) + { + var navigation = typeof(FrameworkElement) + .GetProperty("KeyboardNavigation", BindingFlags.NonPublic | BindingFlags.Static) + .GetValue(null); + + var method = navigation + .GetType() + .GetMethod("GetNextTab", BindingFlags.NonPublic | BindingFlags.Instance); + + return method.Invoke(navigation, new object[] { e, container, goDownOnly }) as DependencyObject; + } + private void BrowserWindow_Loaded(object sender, RoutedEventArgs e) { Handle = new WindowInteropHelper(this).Handle; @@ -359,7 +412,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); HomeButton.Click += (o, args) => HomeNavigationRequested?.Invoke(); Loaded += BrowserWindow_Loaded; - MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; + MenuButton.Click += MenuButton_Click; MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); MenuPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); @@ -381,6 +434,12 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows BrowserControlHost.GotKeyboardFocus += BrowserControlHost_GotKeyboardFocus; } + private void MenuButton_Click(object sender, RoutedEventArgs e) + { + MenuPopup.IsOpen = !MenuPopup.IsOpen; + ZoomInButton.Focus(); + } + private void BrowserControlHost_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { var forward = !this.browserControlGetsFocusFromTaskbar; From a7b6f9cb87ccf0fa19bb93e689fa504cf6820b25 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Fri, 3 Dec 2021 10:00:16 +0100 Subject: [PATCH 03/20] accessibility for audio and language controls --- .../ActionCenter/KeyboardLayoutButton.xaml | 2 +- .../ActionCenter/KeyboardLayoutControl.xaml | 2 +- .../KeyboardLayoutControl.xaml.cs | 18 +++++++++- .../Controls/Taskbar/AudioControl.xaml | 6 ++-- .../Controls/Taskbar/AudioControl.xaml.cs | 19 ++++++++++ .../Taskbar/KeyboardLayoutButton.xaml | 36 +++++++++---------- .../Taskbar/KeyboardLayoutControl.xaml | 2 +- .../Taskbar/KeyboardLayoutControl.xaml.cs | 18 +++++++++- 8 files changed, 76 insertions(+), 27 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml index abdcaff9..0e1f4445 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml @@ -5,7 +5,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Desktop.Controls" - mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="250"> + mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="250" IsTabStop="True"> diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml index 4ccf82d2..d991f4c1 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml @@ -16,7 +16,7 @@ - + diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index 5a1a09f9..24eaedf8 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -41,7 +41,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter InitializeLayouts(); keyboard.LayoutChanged += Keyboard_LayoutChanged; - Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; + Button.Click += (o, args) => + { + Popup.IsOpen = !Popup.IsOpen; + this.Dispatcher.BeginInvoke((System.Action)(() => + { + LayoutsStackPanel.Children[0].Focus(); + })); + }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; @@ -90,5 +97,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter Text.Text = layout.CultureName; Button.ToolTip = tooltip; } + + private void Popup_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Enter || e.Key == System.Windows.Input.Key.Escape) + { + Popup.IsOpen = false; + Button.Focus(); + } + } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml index cb433bf0..229251fc 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml @@ -16,7 +16,7 @@ - + @@ -24,7 +24,7 @@ - @@ -33,7 +33,7 @@ diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs index 25427637..541416ad 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs @@ -60,6 +60,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { Background = Brushes.LightGray; Button.Background = Brushes.LightGray; + Volume.Focus(); }; Popup.Closed += (o, args) => @@ -167,5 +168,23 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar return IconResourceLoader.Load(resource); } + + private void Popup_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Escape) + { + Popup.IsOpen = false; + Button.Focus(); + } + } + + private void Volume_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Enter) + { + Popup.IsOpen = false; + Button.Focus(); + } + } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml index 90170748..20a0a91d 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml @@ -14,24 +14,22 @@ - - - + + + diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml index 4f745fd4..ca2bcdf8 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml @@ -16,7 +16,7 @@ - + diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index a607a677..da280d12 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -45,7 +45,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar InitializeLayouts(); keyboard.LayoutChanged += Keyboard_LayoutChanged; - Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; + Button.Click += (o, args) => + { + Popup.IsOpen = !Popup.IsOpen; + Task.Delay(200).ContinueWith(_ => this.Dispatcher.BeginInvoke((System.Action)(() => + { + ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); + }))); + }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); @@ -114,5 +121,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar LayoutCultureCode.Text = layout.CultureCode; Button.ToolTip = tooltip; } + + private void Popup_KeyUp(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == System.Windows.Input.Key.Enter || e.Key == System.Windows.Input.Key.Escape) + { + Popup.IsOpen = false; + Button.Focus(); + } + } } } From 9d5792c7ecaeeaf047ad3007b432a68ed1558bbd Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Tue, 8 Feb 2022 10:33:23 +0100 Subject: [PATCH 04/20] reload button accessibility --- SafeExamBrowser.I18n.Contracts/TextKey.cs | 1 + SafeExamBrowser.I18n/Data/en.xml | 3 +++ .../Windows/BrowserWindow.xaml.cs | 1 + 3 files changed, 5 insertions(+) diff --git a/SafeExamBrowser.I18n.Contracts/TextKey.cs b/SafeExamBrowser.I18n.Contracts/TextKey.cs index 5c9271d0..0fc4032c 100644 --- a/SafeExamBrowser.I18n.Contracts/TextKey.cs +++ b/SafeExamBrowser.I18n.Contracts/TextKey.cs @@ -30,6 +30,7 @@ namespace SafeExamBrowser.I18n.Contracts BrowserWindow_DownloadComplete, BrowserWindow_FindCaseSensitive, BrowserWindow_FindMenuItem, + BrowserWindow_ReloadButton, BrowserWindow_ZoomMenuItem, Build, ExamSelectionDialog_Cancel, diff --git a/SafeExamBrowser.I18n/Data/en.xml b/SafeExamBrowser.I18n/Data/en.xml index ab2829f5..316029d1 100644 --- a/SafeExamBrowser.I18n/Data/en.xml +++ b/SafeExamBrowser.I18n/Data/en.xml @@ -48,6 +48,9 @@ Search page... + + Reload button + Page Zoom diff --git a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs index 5c1170fa..cd780b66 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Windows/BrowserWindow.xaml.cs @@ -577,6 +577,7 @@ if (typeof __SEB_focusElement === 'undefined') { FindCaseSensitiveCheckBox.Content = text.Get(TextKey.BrowserWindow_FindCaseSensitive); FindMenuText.Text = text.Get(TextKey.BrowserWindow_FindMenuItem); ZoomText.Text = text.Get(TextKey.BrowserWindow_ZoomMenuItem); + ReloadButton.SetValue(System.Windows.Automation.AutomationProperties.NameProperty, text.Get(TextKey.BrowserWindow_ReloadButton)); } public void FocusToolbar(bool forward) From 8a19b205de44f5ab9eaadabeadd7a9b5170b3d99 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Fri, 11 Feb 2022 10:54:37 +0100 Subject: [PATCH 05/20] added accessibility labels to UI controls --- SafeExamBrowser.I18n.Contracts/TextKey.cs | 6 ++++++ SafeExamBrowser.I18n/Data/en.xml | 20 ++++++++++++++++++- .../Controls/Taskbar/QuitButton.xaml | 4 +++- .../Windows/BrowserWindow.xaml.cs | 6 ++++++ .../Windows/Taskbar.xaml.cs | 4 +++- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/SafeExamBrowser.I18n.Contracts/TextKey.cs b/SafeExamBrowser.I18n.Contracts/TextKey.cs index 0fc4032c..b2ce756d 100644 --- a/SafeExamBrowser.I18n.Contracts/TextKey.cs +++ b/SafeExamBrowser.I18n.Contracts/TextKey.cs @@ -24,13 +24,19 @@ namespace SafeExamBrowser.I18n.Contracts Browser_LoadErrorTitle, Browser_Name, Browser_Tooltip, + BrowserWindow_BackwardButton, BrowserWindow_DeveloperConsoleMenuItem, BrowserWindow_Downloading, BrowserWindow_DownloadCancelled, BrowserWindow_DownloadComplete, + BrowserWindow_DownloadsButton, BrowserWindow_FindCaseSensitive, BrowserWindow_FindMenuItem, + BrowserWindow_ForwardButton, + BrowserWindow_HomeButton, + BrowserWindow_MenuButton, BrowserWindow_ReloadButton, + BrowserWindow_UrlTextBox, BrowserWindow_ZoomMenuItem, Build, ExamSelectionDialog_Cancel, diff --git a/SafeExamBrowser.I18n/Data/en.xml b/SafeExamBrowser.I18n/Data/en.xml index 316029d1..00fb5b46 100644 --- a/SafeExamBrowser.I18n/Data/en.xml +++ b/SafeExamBrowser.I18n/Data/en.xml @@ -49,7 +49,25 @@ Search page... - Reload button + Reload + + + Backward + + + Forward + + + Download + + + Home + + + Menu + + + Enter URL Page Zoom diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/QuitButton.xaml b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/QuitButton.xaml index 27a637d7..592ac0b4 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/QuitButton.xaml +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/QuitButton.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Desktop.Controls" + x:Name="root" mc:Ignorable="d" d:DesignHeight="40" d:DesignWidth="40"> @@ -15,6 +16,7 @@