From 65840f646e988d5646e832e0079d34926f71fdc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Fri, 24 Mar 2023 18:18:02 +0100 Subject: [PATCH] SEBWIN-667: Fixed crash when third-party application has no title. --- .../ActionCenter/ApplicationButton.xaml.cs | 20 ++++++++++++------- .../ActionCenter/AudioControl.xaml.cs | 18 ++++++++++++----- .../ActionCenter/KeyboardLayoutButton.xaml.cs | 4 +++- .../KeyboardLayoutControl.xaml.cs | 12 ++++++----- .../ActionCenter/NotificationButton.xaml.cs | 2 +- .../Taskbar/ApplicationControl.xaml.cs | 9 +++++++-- .../Controls/Taskbar/AudioControl.xaml.cs | 16 +++++++++++---- .../Taskbar/KeyboardLayoutButton.xaml.cs | 4 +++- .../Taskbar/KeyboardLayoutControl.xaml.cs | 11 ++++++---- .../Taskbar/NotificationButton.xaml.cs | 6 ++++-- .../ActionCenter/ApplicationButton.xaml.cs | 20 ++++++++++++------- .../ActionCenter/AudioControl.xaml.cs | 16 +++++++++++---- .../ActionCenter/KeyboardLayoutButton.xaml.cs | 4 +++- .../KeyboardLayoutControl.xaml.cs | 10 ++++++---- .../ActionCenter/NotificationButton.xaml.cs | 2 +- .../Taskbar/ApplicationControl.xaml.cs | 9 +++++++-- .../Controls/Taskbar/AudioControl.xaml.cs | 16 +++++++++++---- .../Taskbar/KeyboardLayoutButton.xaml.cs | 4 +++- .../Taskbar/KeyboardLayoutControl.xaml.cs | 9 ++++++--- .../Taskbar/NotificationButton.xaml.cs | 5 ++++- 20 files changed, 137 insertions(+), 60 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/ApplicationButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/ApplicationButton.xaml.cs index f6e72ef2..811e1b82 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/ApplicationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/ApplicationButton.xaml.cs @@ -7,6 +7,7 @@ */ using System; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Core.Contracts.Resources.Icons; @@ -16,8 +17,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter { internal partial class ApplicationButton : UserControl { - private IApplication application; - private IApplicationWindow window; + private readonly IApplication application; + private readonly IApplicationWindow window; internal event EventHandler Clicked; @@ -32,14 +33,19 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter private void InitializeApplicationInstanceButton() { + var tooltip = window?.Title ?? application.Tooltip; + + Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); + Button.ToolTip = tooltip; Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon); Text.Text = window?.Title ?? application.Name; - Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); - var tooltip = window?.Title ?? application.Tooltip; - Button.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(Button, tooltip); - if (window != null) + if (tooltip != default) + { + AutomationProperties.SetName(Button, string.Empty); + } + + if (window != default) { window.IconChanged += Window_IconChanged; window.TitleChanged += Window_TitleChanged; diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs index ae03a587..67f06011 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs @@ -9,6 +9,7 @@ using System; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -52,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -140,27 +143,32 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter this.muted = muted; Button.ToolTip = info; - System.Windows.Automation.AutomationProperties.SetName(Button, info); Text.Text = info; Volume.ValueChanged -= Volume_ValueChanged; Volume.Value = Math.Round(volume * 100); Volume.ValueChanged += Volume_ValueChanged; + AutomationProperties.SetName(Button, info); + if (muted) { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon); + + AutomationProperties.SetName(MuteButton, tooltip); } else { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); ButtonIcon.Content = LoadIcon(volume); PopupIcon.Content = LoadIcon(volume); + + AutomationProperties.SetName(MuteButton, tooltip); } } @@ -178,7 +186,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter { var icon = volume > 0.66 ? "100" : (volume > 0.33 ? "66" : "33"); var uri = new Uri($"pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Light_{icon}.xaml"); - var resource = new XamlIconResource { Uri = uri}; + var resource = new XamlIconResource { Uri = uri }; return IconResourceLoader.Load(resource); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs index da3d8b51..2b7456d7 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs @@ -8,6 +8,7 @@ using System; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.SystemComponents.Contracts.Keyboard; @@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter CultureCodeTextBlock.Text = layout.CultureCode; CultureNameTextBlock.Text = layout.CultureName; LayoutNameTextBlock.Text = layout.LayoutName; - System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName); + + AutomationProperties.SetName(Button, layout.CultureName); } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index 8e51c0de..175ac9dc 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; using System.Threading.Tasks; using System.Windows.Automation; using System.Windows.Controls; @@ -19,8 +18,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter { internal partial class KeyboardLayoutControl : UserControl, ISystemControl { - private IKeyboard keyboard; - private IText text; + private readonly IKeyboard keyboard; + private readonly IText text; internal KeyboardLayoutControl(IKeyboard keyboard, IText text) { @@ -46,7 +45,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter Button.Click += (o, args) => { Popup.IsOpen = !Popup.IsOpen; - this.Dispatcher.BeginInvoke((System.Action)(() => + this.Dispatcher.BeginInvoke((System.Action) (() => { LayoutsStackPanel.Children[0].Focus(); })); @@ -54,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -124,6 +125,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter Text.Text = layout.CultureName; Button.ToolTip = tooltip; + AutomationProperties.SetName(Button, tooltip); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NotificationButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NotificationButton.xaml.cs index f72362b9..3afc8f8e 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NotificationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NotificationButton.xaml.cs @@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter { internal partial class NotificationButton : UserControl, INotificationControl { - private INotification notification; + private readonly INotification notification; internal NotificationButton(INotification notification) { diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/ApplicationControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/ApplicationControl.xaml.cs index b16b6cea..4f6af2e6 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/ApplicationControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/ApplicationControl.xaml.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -44,10 +45,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar Button.MouseEnter += (o, args) => WindowPopup.IsOpen = WindowStackPanel.Children.Count > 0; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = WindowPopup.IsMouseOver || ActiveBar.IsMouseOver)); Button.ToolTip = application.Tooltip; - System.Windows.Automation.AutomationProperties.SetName(Button, application.Tooltip); WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback); WindowPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = IsMouseOver)); + if (application.Tooltip != default) + { + AutomationProperties.SetName(Button, application.Tooltip); + } + WindowPopup.Opened += (o, args) => { ActiveBar.Width = double.NaN; @@ -106,7 +111,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar } else { - single = default(IApplicationWindow); + single = default; } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs index 804db44e..c02ac578 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs @@ -9,6 +9,7 @@ using System; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -51,7 +52,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -155,26 +158,31 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar this.muted = muted; Button.ToolTip = info; - System.Windows.Automation.AutomationProperties.SetName(Button, info); Volume.ValueChanged -= Volume_ValueChanged; Volume.Value = Math.Round(volume * 100); Volume.ValueChanged += Volume_ValueChanged; + AutomationProperties.SetName(Button, info); + if (muted) { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); PopupIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); + + AutomationProperties.SetName(MuteButton, tooltip); } else { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); PopupIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume); + + AutomationProperties.SetName(MuteButton, tooltip); } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs index 965dbb3e..1dfa1c8b 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutButton.xaml.cs @@ -8,6 +8,7 @@ using System; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.SystemComponents.Contracts.Keyboard; @@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar CultureCodeTextBlock.Text = layout.CultureCode; CultureNameTextBlock.Text = layout.CultureName; LayoutNameTextBlock.Text = layout.LayoutName; - System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName); + + AutomationProperties.SetName(Button, layout.CultureName); } } } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index 7f662125..219b283c 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -22,8 +22,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { internal partial class KeyboardLayoutControl : UserControl, ISystemControl { - private IKeyboard keyboard; - private IText text; + private readonly IKeyboard keyboard; + private readonly IText text; internal KeyboardLayoutControl(IKeyboard keyboard, IText text) { @@ -49,7 +49,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar Button.Click += (o, args) => { Popup.IsOpen = !Popup.IsOpen; - Task.Delay(200).ContinueWith(_ => this.Dispatcher.BeginInvoke((System.Action)(() => + Task.Delay(200).ContinueWith(_ => this.Dispatcher.BeginInvoke((System.Action) (() => { ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); }))); @@ -57,7 +57,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -144,6 +146,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar LayoutCultureCode.Text = layout.CultureCode; Button.ToolTip = tooltip; + AutomationProperties.SetName(Button, tooltip); } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NotificationButton.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NotificationButton.xaml.cs index 6c38b5ee..65ee7892 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NotificationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NotificationButton.xaml.cs @@ -7,6 +7,7 @@ */ using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.Core.Contracts.Notifications; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -16,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { internal partial class NotificationButton : UserControl, INotificationControl { - private INotification notification; + private readonly INotification notification; internal NotificationButton(INotification notification) { @@ -41,7 +42,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { IconButton.ToolTip = notification.Tooltip; IconButton.Content = IconResourceLoader.Load(notification.IconResource); - System.Windows.Automation.AutomationProperties.SetName(this, notification.Tooltip); + + AutomationProperties.SetName(this, notification.Tooltip); } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/ApplicationButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/ApplicationButton.xaml.cs index f66bb3ad..c307bdee 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/ApplicationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/ApplicationButton.xaml.cs @@ -7,6 +7,7 @@ */ using System; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Core.Contracts.Resources.Icons; @@ -16,8 +17,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter { internal partial class ApplicationButton : UserControl { - private IApplication application; - private IApplicationWindow window; + private readonly IApplication application; + private readonly IApplicationWindow window; internal event EventHandler Clicked; @@ -32,14 +33,19 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter private void InitializeApplicationInstanceButton() { + var tooltip = window?.Title ?? application.Tooltip; + + Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); + Button.ToolTip = tooltip; Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon); Text.Text = window?.Title ?? application.Name; - Button.Click += (o, args) => Clicked?.Invoke(this, EventArgs.Empty); - var tooltip = window?.Title ?? application.Tooltip; - Button.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(Button, tooltip); - if (window != null) + if (tooltip != default) + { + AutomationProperties.SetName(Button, tooltip); + } + + if (window != default) { window.IconChanged += Window_IconChanged; window.TitleChanged += Window_TitleChanged; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs index a24f6474..3dc2cc5b 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs @@ -9,6 +9,7 @@ using System; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -52,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -139,27 +142,32 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter this.muted = muted; Button.ToolTip = info; - System.Windows.Automation.AutomationProperties.SetName(Button, info); Text.Text = info; Volume.ValueChanged -= Volume_ValueChanged; Volume.Value = Math.Round(volume * 100); Volume.ValueChanged += Volume_ValueChanged; + AutomationProperties.SetName(Button, info); + if (muted) { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon); + + AutomationProperties.SetName(MuteButton, tooltip); } else { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); ButtonIcon.Content = LoadIcon(volume); PopupIcon.Content = LoadIcon(volume); + + AutomationProperties.SetName(MuteButton, tooltip); } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs index 8f35a88e..1cbb127f 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutButton.xaml.cs @@ -8,6 +8,7 @@ using System; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.SystemComponents.Contracts.Keyboard; @@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter CultureCodeTextBlock.Text = layout.CultureCode; CultureNameTextBlock.Text = layout.CultureName; LayoutNameTextBlock.Text = layout.LayoutName; - System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName); + + AutomationProperties.SetName(Button, layout.CultureName); } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index 7868a6db..707c99ac 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using System; using System.Threading.Tasks; using System.Windows.Automation; using System.Windows.Controls; @@ -19,8 +18,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter { internal partial class KeyboardLayoutControl : UserControl, ISystemControl { - private IKeyboard keyboard; - private IText text; + private readonly IKeyboard keyboard; + private readonly IText text; internal KeyboardLayoutControl(IKeyboard keyboard, IText text) { @@ -54,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -124,6 +125,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter Text.Text = layout.CultureName; Button.ToolTip = tooltip; + AutomationProperties.SetName(Button, tooltip); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NotificationButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NotificationButton.xaml.cs index ea6858f6..ed11d110 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NotificationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NotificationButton.xaml.cs @@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter { internal partial class NotificationButton : UserControl, INotificationControl { - private INotification notification; + private readonly INotification notification; internal NotificationButton(INotification notification) { diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/ApplicationControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/ApplicationControl.xaml.cs index 759b1919..6e9aa8f2 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/ApplicationControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/ApplicationControl.xaml.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -44,10 +45,14 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar Button.MouseEnter += (o, args) => WindowPopup.IsOpen = WindowStackPanel.Children.Count > 0; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = WindowPopup.IsMouseOver || ActiveBar.IsMouseOver)); Button.ToolTip = application.Tooltip; - System.Windows.Automation.AutomationProperties.SetName(Button, application.Tooltip); WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback); WindowPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = IsMouseOver)); + if (application.Tooltip != default) + { + AutomationProperties.SetName(Button, application.Tooltip); + } + WindowPopup.Opened += (o, args) => { ActiveBar.Width = double.NaN; @@ -106,7 +111,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar } else { - single = default(IApplicationWindow); + single = default; } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs index 84f68eaa..2b661459 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs @@ -9,6 +9,7 @@ using System; using System.Threading.Tasks; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -51,7 +52,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -155,26 +158,31 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar this.muted = muted; Button.ToolTip = info; - System.Windows.Automation.AutomationProperties.SetName(Button, info); Volume.ValueChanged -= Volume_ValueChanged; Volume.Value = Math.Round(volume * 100); Volume.ValueChanged += Volume_ValueChanged; + AutomationProperties.SetName(Button, info); + if (muted) { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); PopupIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); + + AutomationProperties.SetName(MuteButton, tooltip); } else { var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); + MuteButton.ToolTip = tooltip; - System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip); PopupIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume); + + AutomationProperties.SetName(MuteButton, tooltip); } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutButton.xaml.cs index 649fbe9f..28308c43 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutButton.xaml.cs @@ -8,6 +8,7 @@ using System; using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.SystemComponents.Contracts.Keyboard; @@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar CultureCodeTextBlock.Text = layout.CultureCode; CultureNameTextBlock.Text = layout.CultureName; LayoutNameTextBlock.Text = layout.LayoutName; - System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName); + + AutomationProperties.SetName(Button, layout.CultureName); } } } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index 3c395069..8e6219d3 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -22,8 +22,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { internal partial class KeyboardLayoutControl : UserControl, ISystemControl { - private IKeyboard keyboard; - private IText text; + private readonly IKeyboard keyboard; + private readonly IText text; internal KeyboardLayoutControl(IKeyboard keyboard, IText text) { @@ -57,7 +57,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar var lastOpenedBySpacePress = false; Button.PreviewKeyDown += (o, args) => { - if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + // For some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, + // we record the space bar event and leave the popup open for at least 3 seconds. + if (args.Key == System.Windows.Input.Key.Space) { lastOpenedBySpacePress = true; } @@ -144,6 +146,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar LayoutCultureCode.Text = layout.CultureCode; Button.ToolTip = tooltip; + AutomationProperties.SetName(Button, tooltip); } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NotificationButton.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NotificationButton.xaml.cs index 98828056..fb1b1e45 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NotificationButton.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NotificationButton.xaml.cs @@ -7,6 +7,7 @@ */ using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using SafeExamBrowser.Core.Contracts.Notifications; using SafeExamBrowser.UserInterface.Contracts.Shell; @@ -16,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { internal partial class NotificationButton : UserControl, INotificationControl { - private INotification notification; + private readonly INotification notification; internal NotificationButton(INotification notification) { @@ -41,6 +42,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { IconButton.ToolTip = notification.Tooltip; IconButton.Content = IconResourceLoader.Load(notification.IconResource); + + AutomationProperties.SetName(this, notification.Tooltip); } } }