SEBWIN-667: Fixed crash when third-party application has no title.

This commit is contained in:
Damian Büchel 2023-03-24 18:18:02 +01:00
parent 4aa856f98a
commit 65840f646e
20 changed files with 137 additions and 60 deletions

View file

@ -7,6 +7,7 @@
*/ */
using System; using System;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts;
using SafeExamBrowser.Core.Contracts.Resources.Icons; using SafeExamBrowser.Core.Contracts.Resources.Icons;
@ -16,8 +17,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
{ {
internal partial class ApplicationButton : UserControl internal partial class ApplicationButton : UserControl
{ {
private IApplication application; private readonly IApplication application;
private IApplicationWindow window; private readonly IApplicationWindow window;
internal event EventHandler Clicked; internal event EventHandler Clicked;
@ -32,14 +33,19 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
private void InitializeApplicationInstanceButton() 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); Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon);
Text.Text = window?.Title ?? application.Name; 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.IconChanged += Window_IconChanged;
window.TitleChanged += Window_TitleChanged; window.TitleChanged += Window_TitleChanged;

View file

@ -9,6 +9,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; using System.Windows.Media;
@ -52,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -140,27 +143,32 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
this.muted = muted; this.muted = muted;
Button.ToolTip = info; Button.ToolTip = info;
System.Windows.Automation.AutomationProperties.SetName(Button, info);
Text.Text = info; Text.Text = info;
Volume.ValueChanged -= Volume_ValueChanged; Volume.ValueChanged -= Volume_ValueChanged;
Volume.Value = Math.Round(volume * 100); Volume.Value = Math.Round(volume * 100);
Volume.ValueChanged += Volume_ValueChanged; Volume.ValueChanged += Volume_ValueChanged;
AutomationProperties.SetName(Button, info);
if (muted) if (muted)
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon);
PopupIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon);
AutomationProperties.SetName(MuteButton, tooltip);
} }
else else
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
ButtonIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume);
PopupIcon.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 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 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); return IconResourceLoader.Load(resource);
} }

View file

@ -8,6 +8,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.SystemComponents.Contracts.Keyboard; using SafeExamBrowser.SystemComponents.Contracts.Keyboard;
@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
CultureCodeTextBlock.Text = layout.CultureCode; CultureCodeTextBlock.Text = layout.CultureCode;
CultureNameTextBlock.Text = layout.CultureName; CultureNameTextBlock.Text = layout.CultureName;
LayoutNameTextBlock.Text = layout.LayoutName; LayoutNameTextBlock.Text = layout.LayoutName;
System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName);
AutomationProperties.SetName(Button, layout.CultureName);
} }
} }
} }

View file

@ -6,7 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Automation; using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
@ -19,8 +18,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
{ {
internal partial class KeyboardLayoutControl : UserControl, ISystemControl internal partial class KeyboardLayoutControl : UserControl, ISystemControl
{ {
private IKeyboard keyboard; private readonly IKeyboard keyboard;
private IText text; private readonly IText text;
internal KeyboardLayoutControl(IKeyboard keyboard, IText text) internal KeyboardLayoutControl(IKeyboard keyboard, IText text)
{ {
@ -46,7 +45,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
Button.Click += (o, args) => Button.Click += (o, args) =>
{ {
Popup.IsOpen = !Popup.IsOpen; Popup.IsOpen = !Popup.IsOpen;
this.Dispatcher.BeginInvoke((System.Action)(() => this.Dispatcher.BeginInvoke((System.Action) (() =>
{ {
LayoutsStackPanel.Children[0].Focus(); LayoutsStackPanel.Children[0].Focus();
})); }));
@ -54,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -124,6 +125,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
Text.Text = layout.CultureName; Text.Text = layout.CultureName;
Button.ToolTip = tooltip; Button.ToolTip = tooltip;
AutomationProperties.SetName(Button, tooltip); AutomationProperties.SetName(Button, tooltip);
} }

View file

@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter
{ {
internal partial class NotificationButton : UserControl, INotificationControl internal partial class NotificationButton : UserControl, INotificationControl
{ {
private INotification notification; private readonly INotification notification;
internal NotificationButton(INotification notification) internal NotificationButton(INotification notification)
{ {

View file

@ -9,6 +9,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; 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.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.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = WindowPopup.IsMouseOver || ActiveBar.IsMouseOver));
Button.ToolTip = application.Tooltip; Button.ToolTip = application.Tooltip;
System.Windows.Automation.AutomationProperties.SetName(Button, application.Tooltip);
WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback); WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback);
WindowPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = IsMouseOver)); 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) => WindowPopup.Opened += (o, args) =>
{ {
ActiveBar.Width = double.NaN; ActiveBar.Width = double.NaN;
@ -106,7 +111,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
} }
else else
{ {
single = default(IApplicationWindow); single = default;
} }
} }
} }

View file

@ -9,6 +9,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; using System.Windows.Media;
@ -51,7 +52,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -155,26 +158,31 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
this.muted = muted; this.muted = muted;
Button.ToolTip = info; Button.ToolTip = info;
System.Windows.Automation.AutomationProperties.SetName(Button, info);
Volume.ValueChanged -= Volume_ValueChanged; Volume.ValueChanged -= Volume_ValueChanged;
Volume.Value = Math.Round(volume * 100); Volume.Value = Math.Round(volume * 100);
Volume.ValueChanged += Volume_ValueChanged; Volume.ValueChanged += Volume_ValueChanged;
AutomationProperties.SetName(Button, info);
if (muted) if (muted)
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
PopupIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon);
ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon);
AutomationProperties.SetName(MuteButton, tooltip);
} }
else else
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
PopupIcon.Content = LoadIcon(volume); PopupIcon.Content = LoadIcon(volume);
ButtonIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume);
AutomationProperties.SetName(MuteButton, tooltip);
} }
} }

View file

@ -8,6 +8,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.SystemComponents.Contracts.Keyboard; using SafeExamBrowser.SystemComponents.Contracts.Keyboard;
@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
CultureCodeTextBlock.Text = layout.CultureCode; CultureCodeTextBlock.Text = layout.CultureCode;
CultureNameTextBlock.Text = layout.CultureName; CultureNameTextBlock.Text = layout.CultureName;
LayoutNameTextBlock.Text = layout.LayoutName; LayoutNameTextBlock.Text = layout.LayoutName;
System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName);
AutomationProperties.SetName(Button, layout.CultureName);
} }
} }
} }

View file

@ -22,8 +22,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
{ {
internal partial class KeyboardLayoutControl : UserControl, ISystemControl internal partial class KeyboardLayoutControl : UserControl, ISystemControl
{ {
private IKeyboard keyboard; private readonly IKeyboard keyboard;
private IText text; private readonly IText text;
internal KeyboardLayoutControl(IKeyboard keyboard, IText text) internal KeyboardLayoutControl(IKeyboard keyboard, IText text)
{ {
@ -49,7 +49,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
Button.Click += (o, args) => Button.Click += (o, args) =>
{ {
Popup.IsOpen = !Popup.IsOpen; 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(); ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus();
}))); })));
@ -57,7 +57,9 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -144,6 +146,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
LayoutCultureCode.Text = layout.CultureCode; LayoutCultureCode.Text = layout.CultureCode;
Button.ToolTip = tooltip; Button.ToolTip = tooltip;
AutomationProperties.SetName(Button, tooltip); AutomationProperties.SetName(Button, tooltip);
} }

View file

@ -7,6 +7,7 @@
*/ */
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Core.Contracts.Notifications; using SafeExamBrowser.Core.Contracts.Notifications;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
@ -16,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
{ {
internal partial class NotificationButton : UserControl, INotificationControl internal partial class NotificationButton : UserControl, INotificationControl
{ {
private INotification notification; private readonly INotification notification;
internal NotificationButton(INotification notification) internal NotificationButton(INotification notification)
{ {
@ -41,7 +42,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar
{ {
IconButton.ToolTip = notification.Tooltip; IconButton.ToolTip = notification.Tooltip;
IconButton.Content = IconResourceLoader.Load(notification.IconResource); IconButton.Content = IconResourceLoader.Load(notification.IconResource);
System.Windows.Automation.AutomationProperties.SetName(this, notification.Tooltip);
AutomationProperties.SetName(this, notification.Tooltip);
} }
} }
} }

View file

@ -7,6 +7,7 @@
*/ */
using System; using System;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Applications.Contracts; using SafeExamBrowser.Applications.Contracts;
using SafeExamBrowser.Core.Contracts.Resources.Icons; using SafeExamBrowser.Core.Contracts.Resources.Icons;
@ -16,8 +17,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
{ {
internal partial class ApplicationButton : UserControl internal partial class ApplicationButton : UserControl
{ {
private IApplication application; private readonly IApplication application;
private IApplicationWindow window; private readonly IApplicationWindow window;
internal event EventHandler Clicked; internal event EventHandler Clicked;
@ -32,14 +33,19 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
private void InitializeApplicationInstanceButton() 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); Icon.Content = IconResourceLoader.Load(window?.Icon ?? application.Icon);
Text.Text = window?.Title ?? application.Name; 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.IconChanged += Window_IconChanged;
window.TitleChanged += Window_TitleChanged; window.TitleChanged += Window_TitleChanged;

View file

@ -9,6 +9,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; using System.Windows.Media;
@ -52,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -139,27 +142,32 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
this.muted = muted; this.muted = muted;
Button.ToolTip = info; Button.ToolTip = info;
System.Windows.Automation.AutomationProperties.SetName(Button, info);
Text.Text = info; Text.Text = info;
Volume.ValueChanged -= Volume_ValueChanged; Volume.ValueChanged -= Volume_ValueChanged;
Volume.Value = Math.Round(volume * 100); Volume.Value = Math.Round(volume * 100);
Volume.ValueChanged += Volume_ValueChanged; Volume.ValueChanged += Volume_ValueChanged;
AutomationProperties.SetName(Button, info);
if (muted) if (muted)
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon);
PopupIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon);
AutomationProperties.SetName(MuteButton, tooltip);
} }
else else
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
ButtonIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume);
PopupIcon.Content = LoadIcon(volume); PopupIcon.Content = LoadIcon(volume);
AutomationProperties.SetName(MuteButton, tooltip);
} }
} }

View file

@ -8,6 +8,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.SystemComponents.Contracts.Keyboard; using SafeExamBrowser.SystemComponents.Contracts.Keyboard;
@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
CultureCodeTextBlock.Text = layout.CultureCode; CultureCodeTextBlock.Text = layout.CultureCode;
CultureNameTextBlock.Text = layout.CultureName; CultureNameTextBlock.Text = layout.CultureName;
LayoutNameTextBlock.Text = layout.LayoutName; LayoutNameTextBlock.Text = layout.LayoutName;
System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName);
AutomationProperties.SetName(Button, layout.CultureName);
} }
} }
} }

View file

@ -6,7 +6,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Automation; using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
@ -19,8 +18,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
{ {
internal partial class KeyboardLayoutControl : UserControl, ISystemControl internal partial class KeyboardLayoutControl : UserControl, ISystemControl
{ {
private IKeyboard keyboard; private readonly IKeyboard keyboard;
private IText text; private readonly IText text;
internal KeyboardLayoutControl(IKeyboard keyboard, IText text) internal KeyboardLayoutControl(IKeyboard keyboard, IText text)
{ {
@ -54,7 +53,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -124,6 +125,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
Text.Text = layout.CultureName; Text.Text = layout.CultureName;
Button.ToolTip = tooltip; Button.ToolTip = tooltip;
AutomationProperties.SetName(Button, tooltip); AutomationProperties.SetName(Button, tooltip);
} }

View file

@ -16,7 +16,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter
{ {
internal partial class NotificationButton : UserControl, INotificationControl internal partial class NotificationButton : UserControl, INotificationControl
{ {
private INotification notification; private readonly INotification notification;
internal NotificationButton(INotification notification) internal NotificationButton(INotification notification)
{ {

View file

@ -9,6 +9,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; 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.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.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = WindowPopup.IsMouseOver || ActiveBar.IsMouseOver));
Button.ToolTip = application.Tooltip; Button.ToolTip = application.Tooltip;
System.Windows.Automation.AutomationProperties.SetName(Button, application.Tooltip);
WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback); WindowPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(WindowPopup_PlacementCallback);
WindowPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => WindowPopup.IsOpen = IsMouseOver)); 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) => WindowPopup.Opened += (o, args) =>
{ {
ActiveBar.Width = double.NaN; ActiveBar.Width = double.NaN;
@ -106,7 +111,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
} }
else else
{ {
single = default(IApplicationWindow); single = default;
} }
} }
} }

View file

@ -9,6 +9,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Media; using System.Windows.Media;
@ -51,7 +52,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -155,26 +158,31 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
this.muted = muted; this.muted = muted;
Button.ToolTip = info; Button.ToolTip = info;
System.Windows.Automation.AutomationProperties.SetName(Button, info);
Volume.ValueChanged -= Volume_ValueChanged; Volume.ValueChanged -= Volume_ValueChanged;
Volume.Value = Math.Round(volume * 100); Volume.Value = Math.Round(volume * 100);
Volume.ValueChanged += Volume_ValueChanged; Volume.ValueChanged += Volume_ValueChanged;
AutomationProperties.SetName(Button, info);
if (muted) if (muted)
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceUnmuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
PopupIcon.Content = IconResourceLoader.Load(MutedIcon); PopupIcon.Content = IconResourceLoader.Load(MutedIcon);
ButtonIcon.Content = IconResourceLoader.Load(MutedIcon); ButtonIcon.Content = IconResourceLoader.Load(MutedIcon);
AutomationProperties.SetName(MuteButton, tooltip);
} }
else else
{ {
var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip); var tooltip = text.Get(TextKey.SystemControl_AudioDeviceMuteTooltip);
MuteButton.ToolTip = tooltip; MuteButton.ToolTip = tooltip;
System.Windows.Automation.AutomationProperties.SetName(MuteButton, tooltip);
PopupIcon.Content = LoadIcon(volume); PopupIcon.Content = LoadIcon(volume);
ButtonIcon.Content = LoadIcon(volume); ButtonIcon.Content = LoadIcon(volume);
AutomationProperties.SetName(MuteButton, tooltip);
} }
} }

View file

@ -8,6 +8,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.SystemComponents.Contracts.Keyboard; using SafeExamBrowser.SystemComponents.Contracts.Keyboard;
@ -43,7 +44,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
CultureCodeTextBlock.Text = layout.CultureCode; CultureCodeTextBlock.Text = layout.CultureCode;
CultureNameTextBlock.Text = layout.CultureName; CultureNameTextBlock.Text = layout.CultureName;
LayoutNameTextBlock.Text = layout.LayoutName; LayoutNameTextBlock.Text = layout.LayoutName;
System.Windows.Automation.AutomationProperties.SetName(Button, layout.CultureName);
AutomationProperties.SetName(Button, layout.CultureName);
} }
} }
} }

View file

@ -22,8 +22,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
{ {
internal partial class KeyboardLayoutControl : UserControl, ISystemControl internal partial class KeyboardLayoutControl : UserControl, ISystemControl
{ {
private IKeyboard keyboard; private readonly IKeyboard keyboard;
private IText text; private readonly IText text;
internal KeyboardLayoutControl(IKeyboard keyboard, IText text) internal KeyboardLayoutControl(IKeyboard keyboard, IText text)
{ {
@ -57,7 +57,9 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
var lastOpenedBySpacePress = false; var lastOpenedBySpacePress = false;
Button.PreviewKeyDown += (o, args) => 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; lastOpenedBySpacePress = true;
} }
@ -144,6 +146,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
LayoutCultureCode.Text = layout.CultureCode; LayoutCultureCode.Text = layout.CultureCode;
Button.ToolTip = tooltip; Button.ToolTip = tooltip;
AutomationProperties.SetName(Button, tooltip); AutomationProperties.SetName(Button, tooltip);
} }

View file

@ -7,6 +7,7 @@
*/ */
using System.Windows; using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls; using System.Windows.Controls;
using SafeExamBrowser.Core.Contracts.Notifications; using SafeExamBrowser.Core.Contracts.Notifications;
using SafeExamBrowser.UserInterface.Contracts.Shell; using SafeExamBrowser.UserInterface.Contracts.Shell;
@ -16,7 +17,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
{ {
internal partial class NotificationButton : UserControl, INotificationControl internal partial class NotificationButton : UserControl, INotificationControl
{ {
private INotification notification; private readonly INotification notification;
internal NotificationButton(INotification notification) internal NotificationButton(INotification notification)
{ {
@ -41,6 +42,8 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar
{ {
IconButton.ToolTip = notification.Tooltip; IconButton.ToolTip = notification.Tooltip;
IconButton.Content = IconResourceLoader.Load(notification.IconResource); IconButton.Content = IconResourceLoader.Load(notification.IconResource);
AutomationProperties.SetName(this, notification.Tooltip);
} }
} }
} }