SEBWIN-226: Implemented configuration for main / additional browser windows and handled forward / backward navigation buttons.

This commit is contained in:
dbuechel 2019-01-23 09:37:47 +01:00
parent 6436f98e3f
commit c6556a7765
17 changed files with 188 additions and 105 deletions

View file

@ -95,13 +95,13 @@ namespace SafeExamBrowser.Browser
logger.Info("Terminated browser."); logger.Info("Terminated browser.");
} }
private void CreateNewInstance(BrowserSettings custom = null) private void CreateNewInstance(string url = null)
{ {
var id = new BrowserInstanceIdentifier(++instanceIdCounter); var id = new BrowserInstanceIdentifier(++instanceIdCounter);
var isMainInstance = instances.Count == 0; var isMainInstance = instances.Count == 0;
var instanceLogger = logger.CloneFor($"BrowserInstance {id}"); var instanceLogger = logger.CloneFor($"BrowserInstance {id}");
var instanceSettings = custom ?? settings; var startUrl = url ?? settings.StartUrl;
var instance = new BrowserApplicationInstance(appConfig, instanceSettings, id, isMainInstance, messageBox, instanceLogger, text, uiFactory); var instance = new BrowserApplicationInstance(appConfig, settings, id, isMainInstance, messageBox, instanceLogger, text, uiFactory, startUrl);
instance.Initialize(); instance.Initialize();
instance.ConfigurationDownloadRequested += (fileName, args) => ConfigurationDownloadRequested?.Invoke(fileName, args); instance.ConfigurationDownloadRequested += (fileName, args) => ConfigurationDownloadRequested?.Invoke(fileName, args);
@ -149,24 +149,8 @@ namespace SafeExamBrowser.Browser
private void Instance_PopupRequested(PopupRequestedEventArgs args) private void Instance_PopupRequested(PopupRequestedEventArgs args)
{ {
// TODO: Use settings for additional browser windows!
var popupSettings = new BrowserSettings
{
AllowAddressBar = false,
AllowBackwardNavigation = false,
AllowConfigurationDownloads = settings.AllowConfigurationDownloads,
AllowDeveloperConsole = settings.AllowDeveloperConsole,
AllowDownloads = settings.AllowDownloads,
AllowForwardNavigation = false,
AllowPageZoom = settings.AllowPageZoom,
AllowPopups = settings.AllowPopups,
AllowReloading = settings.AllowReloading,
ShowReloadWarning = settings.ShowReloadWarning,
StartUrl = args.Url
};
logger.Info($"Received request to create new instance for '{args.Url}'..."); logger.Info($"Received request to create new instance for '{args.Url}'...");
CreateNewInstance(popupSettings); CreateNewInstance(args.Url);
} }
private void Instance_Terminated(InstanceIdentifier id) private void Instance_Terminated(InstanceIdentifier id)

View file

@ -33,6 +33,12 @@ namespace SafeExamBrowser.Browser
private BrowserSettings settings; private BrowserSettings settings;
private IText text; private IText text;
private IUserInterfaceFactory uiFactory; private IUserInterfaceFactory uiFactory;
private string url;
private BrowserWindowSettings WindowSettings
{
get { return isMainInstance ? settings.MainWindowSettings : settings.AdditionalWindowSettings; }
}
public InstanceIdentifier Id { get; private set; } public InstanceIdentifier Id { get; private set; }
public string Name { get; private set; } public string Name { get; private set; }
@ -52,7 +58,8 @@ namespace SafeExamBrowser.Browser
IMessageBox messageBox, IMessageBox messageBox,
IModuleLogger logger, IModuleLogger logger,
IText text, IText text,
IUserInterfaceFactory uiFactory) IUserInterfaceFactory uiFactory,
string url)
{ {
this.appConfig = appConfig; this.appConfig = appConfig;
this.Id = id; this.Id = id;
@ -62,6 +69,7 @@ namespace SafeExamBrowser.Browser
this.settings = settings; this.settings = settings;
this.text = text; this.text = text;
this.uiFactory = uiFactory; this.uiFactory = uiFactory;
this.url = url;
} }
internal void Initialize() internal void Initialize()
@ -82,7 +90,7 @@ namespace SafeExamBrowser.Browser
keyboardHandler.ZoomResetRequested += ZoomResetRequested; keyboardHandler.ZoomResetRequested += ZoomResetRequested;
lifeSpanHandler.PopupRequested += LifeSpanHandler_PopupRequested; lifeSpanHandler.PopupRequested += LifeSpanHandler_PopupRequested;
control = new BrowserControl(contextMenuHandler, displayHandler, downloadHandler, keyboardHandler, lifeSpanHandler, requestHandler, settings.StartUrl); control = new BrowserControl(contextMenuHandler, displayHandler, downloadHandler, keyboardHandler, lifeSpanHandler, requestHandler, url);
control.AddressChanged += Control_AddressChanged; control.AddressChanged += Control_AddressChanged;
control.LoadingStateChanged += Control_LoadingStateChanged; control.LoadingStateChanged += Control_LoadingStateChanged;
control.TitleChanged += Control_TitleChanged; control.TitleChanged += Control_TitleChanged;
@ -90,8 +98,7 @@ namespace SafeExamBrowser.Browser
logger.Debug("Initialized browser control."); logger.Debug("Initialized browser control.");
window = uiFactory.CreateBrowserWindow(control, settings); window = uiFactory.CreateBrowserWindow(control, settings, isMainInstance);
window.IsMainWindow = isMainInstance;
window.Closing += () => Terminated?.Invoke(Id); window.Closing += () => Terminated?.Invoke(Id);
window.AddressChanged += Window_AddressChanged; window.AddressChanged += Window_AddressChanged;
window.ReloadRequested += ReloadRequested; window.ReloadRequested += ReloadRequested;
@ -112,6 +119,8 @@ namespace SafeExamBrowser.Browser
private void Control_LoadingStateChanged(bool isLoading) private void Control_LoadingStateChanged(bool isLoading)
{ {
window.CanNavigateBackwards = WindowSettings.AllowBackwardNavigation && control.CanNavigateBackwards;
window.CanNavigateForwards = WindowSettings.AllowForwardNavigation && control.CanNavigateForwards;
window.UpdateLoadingState(isLoading); window.UpdateLoadingState(isLoading);
} }
@ -158,7 +167,7 @@ namespace SafeExamBrowser.Browser
private void ReloadRequested() private void ReloadRequested()
{ {
if (settings.AllowReloading && settings.ShowReloadWarning) if (WindowSettings.AllowReloading && WindowSettings.ShowReloadWarning)
{ {
var result = messageBox.Show(TextKey.MessageBox_ReloadConfirmation, TextKey.MessageBox_ReloadConfirmationTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question, window); var result = messageBox.Show(TextKey.MessageBox_ReloadConfirmation, TextKey.MessageBox_ReloadConfirmationTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question, window);
@ -172,7 +181,7 @@ namespace SafeExamBrowser.Browser
logger.Debug("The user aborted reloading the current page."); logger.Debug("The user aborted reloading the current page.");
} }
} }
else if (settings.AllowReloading) else if (WindowSettings.AllowReloading)
{ {
logger.Debug("Reloading current page..."); logger.Debug("Reloading current page...");
control.Reload(); control.Reload();
@ -191,13 +200,13 @@ namespace SafeExamBrowser.Browser
private void Window_BackwardNavigationRequested() private void Window_BackwardNavigationRequested()
{ {
logger.Debug($"Navigating forwards..."); logger.Debug($"Navigating backwards...");
control.NavigateBackwards(); control.NavigateBackwards();
} }
private void Window_ForwardNavigationRequested() private void Window_ForwardNavigationRequested()
{ {
logger.Debug($"Navigating backwards..."); logger.Debug($"Navigating forwards...");
control.NavigateForwards(); control.NavigateForwards();
} }

View file

@ -28,6 +28,9 @@ namespace SafeExamBrowser.Browser
private LoadingStateChangedEventHandler loadingStateChanged; private LoadingStateChangedEventHandler loadingStateChanged;
private TitleChangedEventHandler titleChanged; private TitleChangedEventHandler titleChanged;
public bool CanNavigateBackwards => GetBrowser().CanGoBack;
public bool CanNavigateForwards => GetBrowser().CanGoForward;
event AddressChangedEventHandler IBrowserControl.AddressChanged event AddressChangedEventHandler IBrowserControl.AddressChanged
{ {
add { addressChanged += value; } add { addressChanged += value; }

View file

@ -17,8 +17,17 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
{ {
if (value is bool allow) if (value is bool allow)
{ {
settings.Browser.AllowBackwardNavigation = allow; settings.Browser.MainWindowSettings.AllowBackwardNavigation = allow;
settings.Browser.AllowForwardNavigation = allow; settings.Browser.MainWindowSettings.AllowForwardNavigation = allow;
}
}
private void MapAllowNavigationAdditionalWindow(Settings settings, object value)
{
if (value is bool allow)
{
settings.Browser.AdditionalWindowSettings.AllowBackwardNavigation = allow;
settings.Browser.AdditionalWindowSettings.AllowForwardNavigation = allow;
} }
} }
@ -42,7 +51,15 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
{ {
if (value is bool allow) if (value is bool allow)
{ {
settings.Browser.AllowReloading = allow; settings.Browser.MainWindowSettings.AllowReloading = allow;
}
}
private void MapAllowReloadAdditionalWindow(Settings settings, object value)
{
if (value is bool allow)
{
settings.Browser.AdditionalWindowSettings.AllowReloading = allow;
} }
} }
@ -52,7 +69,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
if (value is int mode) if (value is int mode)
{ {
settings.Browser.FullScreenMode = mode == FULLSCREEN; settings.Browser.MainWindowSettings.FullScreenMode = mode == FULLSCREEN;
} }
} }
@ -60,7 +77,15 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
{ {
if (value is bool show) if (value is bool show)
{ {
settings.Browser.ShowReloadWarning = show; settings.Browser.MainWindowSettings.ShowReloadWarning = show;
}
}
private void MapShowReloadWarningAdditionalWindow(Settings settings, object value)
{
if (value is bool show)
{
settings.Browser.AdditionalWindowSettings.ShowReloadWarning = show;
} }
} }

View file

@ -30,6 +30,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.AllowNavigation: case Keys.Browser.AllowNavigation:
MapAllowNavigation(settings, value); MapAllowNavigation(settings, value);
break; break;
case Keys.Browser.AllowNavigationAdditionalWindow:
MapAllowNavigationAdditionalWindow(settings, value);
break;
case Keys.Browser.AllowPageZoom: case Keys.Browser.AllowPageZoom:
MapAllowPageZoom(settings, value); MapAllowPageZoom(settings, value);
break; break;
@ -39,12 +42,18 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.AllowReload: case Keys.Browser.AllowReload:
MapAllowReload(settings, value); MapAllowReload(settings, value);
break; break;
case Keys.Browser.AllowReloadAdditionalWindow:
MapAllowReloadAdditionalWindow(settings, value);
break;
case Keys.Browser.MainWindowMode: case Keys.Browser.MainWindowMode:
MapMainWindowMode(settings, value); MapMainWindowMode(settings, value);
break; break;
case Keys.Browser.ShowReloadWarning: case Keys.Browser.ShowReloadWarning:
MapShowReloadWarning(settings, value); MapShowReloadWarning(settings, value);
break; break;
case Keys.Browser.ShowReloadWarningAdditionalWindow:
MapShowReloadWarningAdditionalWindow(settings, value);
break;
case Keys.ConfigurationFile.ConfigurationPurpose: case Keys.ConfigurationFile.ConfigurationPurpose:
MapConfigurationMode(settings, value); MapConfigurationMode(settings, value);
break; break;

View file

@ -89,15 +89,23 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
var settings = new Settings(); var settings = new Settings();
settings.Browser.StartUrl = "https://www.safeexambrowser.org/start"; settings.Browser.StartUrl = "https://www.safeexambrowser.org/start";
settings.Browser.AllowAddressBar = false;
settings.Browser.AllowBackwardNavigation = false;
settings.Browser.AllowConfigurationDownloads = true; settings.Browser.AllowConfigurationDownloads = true;
settings.Browser.AllowDeveloperConsole = false; settings.Browser.AllowDeveloperConsole = false;
settings.Browser.AllowDownloads = false; settings.Browser.AllowDownloads = false;
settings.Browser.AllowForwardNavigation = false;
settings.Browser.AllowPageZoom = true; settings.Browser.AllowPageZoom = true;
settings.Browser.AllowPopups = true; settings.Browser.AllowPopups = true;
settings.Browser.AllowReloading = true; settings.Browser.AdditionalWindowSettings.AllowAddressBar = false;
settings.Browser.AdditionalWindowSettings.AllowBackwardNavigation = true;
settings.Browser.AdditionalWindowSettings.AllowForwardNavigation = true;
settings.Browser.AdditionalWindowSettings.AllowReloading = true;
settings.Browser.AdditionalWindowSettings.FullScreenMode = false;
settings.Browser.AdditionalWindowSettings.ShowReloadWarning = false;
settings.Browser.MainWindowSettings.AllowAddressBar = false;
settings.Browser.MainWindowSettings.AllowBackwardNavigation = false;
settings.Browser.MainWindowSettings.AllowForwardNavigation = false;
settings.Browser.MainWindowSettings.AllowReloading = true;
settings.Browser.MainWindowSettings.FullScreenMode = false;
settings.Browser.MainWindowSettings.ShowReloadWarning = true;
settings.Keyboard.AllowAltEsc = false; settings.Keyboard.AllowAltEsc = false;
settings.Keyboard.AllowAltF4 = false; settings.Keyboard.AllowAltF4 = false;
@ -133,18 +141,10 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Taskbar.AllowWirelessNetwork = false; settings.Taskbar.AllowWirelessNetwork = false;
settings.Taskbar.ShowClock = true; settings.Taskbar.ShowClock = true;
// TODO: Default values for alpha version only, remove for final release! // TODO: Default values for testing of alpha version only, remove for final release!
settings.Browser.AllowAddressBar = true;
settings.Browser.AllowBackwardNavigation = true;
settings.Browser.AllowConfigurationDownloads = true;
settings.Browser.AllowDeveloperConsole = true; settings.Browser.AllowDeveloperConsole = true;
settings.Browser.AllowDownloads = true;
settings.Browser.AllowForwardNavigation = true;
settings.Browser.AllowReloading = true;
settings.KioskMode = KioskMode.None; settings.KioskMode = KioskMode.None;
settings.ServicePolicy = ServicePolicy.Optional;
settings.Taskbar.AllowApplicationLog = true; settings.Taskbar.AllowApplicationLog = true;
settings.Taskbar.AllowWirelessNetwork = true;
return settings; return settings;
} }

View file

@ -21,13 +21,16 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal static class Browser internal static class Browser
{ {
internal const string AllowNavigation = "allowBrowsingBackForward"; internal const string AllowNavigation = "allowBrowsingBackForward";
internal const string AllowNavigationAdditionalWindow = "newBrowserWindowNavigation";
internal const string AllowPageZoom = "enableZoomPage"; internal const string AllowPageZoom = "enableZoomPage";
internal const string AllowPopups = "blockPopUpWindows"; internal const string AllowPopups = "blockPopUpWindows";
internal const string AllowReload = "browserWindowAllowReload"; internal const string AllowReload = "browserWindowAllowReload";
internal const string AllowReloadAdditionalWindow = "newBrowserWindowAllowReload";
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom"; internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom"; internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
internal const string MainWindowMode = "browserViewMode"; internal const string MainWindowMode = "browserViewMode";
internal const string ShowReloadWarning = "showReloadWarning"; internal const string ShowReloadWarning = "showReloadWarning";
internal const string ShowReloadWarningAdditionalWindow = "newBrowserWindowShowReloadWarning";
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode"; internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode"; internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";
} }

View file

@ -11,20 +11,15 @@ using System;
namespace SafeExamBrowser.Contracts.Configuration.Settings namespace SafeExamBrowser.Contracts.Configuration.Settings
{ {
/// <summary> /// <summary>
/// Defines all configuration options for the browser of the application. /// Defines all configuration options for the browser engine of the application.
/// </summary> /// </summary>
[Serializable] [Serializable]
public class BrowserSettings public class BrowserSettings
{ {
/// <summary> /// <summary>
/// Determines whether the user will be allowed to change the URL of a browser window. /// The configuration to be used for additional browser windows.
/// </summary> /// </summary>
public bool AllowAddressBar { get; set; } public BrowserWindowSettings AdditionalWindowSettings { get; set; }
/// <summary>
/// Determines whether the user will be allowed to navigate backwards in a browser window.
/// </summary>
public bool AllowBackwardNavigation { get; set; }
/// <summary> /// <summary>
/// Determines whether the user will be allowed to download configuration files. /// Determines whether the user will be allowed to download configuration files.
@ -41,11 +36,6 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings
/// </summary> /// </summary>
public bool AllowDownloads { get; set; } public bool AllowDownloads { get; set; }
/// <summary>
/// Determines whether the user will be allowed to navigate forwards in a browser window.
/// </summary>
public bool AllowForwardNavigation { get; set; }
/// <summary> /// <summary>
/// Determines whether the user will be allowed to zoom webpages. /// Determines whether the user will be allowed to zoom webpages.
/// </summary> /// </summary>
@ -56,28 +46,18 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings
/// </summary> /// </summary>
public bool AllowPopups { get; set; } public bool AllowPopups { get; set; }
/// <summary>
/// Determines whether the user will be allowed to reload webpages.
/// </summary>
public bool AllowReloading { get; set; }
/// <summary> /// <summary>
/// The custom user agent to optionally be used for all requests. /// The custom user agent to optionally be used for all requests.
/// </summary> /// </summary>
public string CustomUserAgent { get; set; } public string CustomUserAgent { get; set; }
/// <summary> /// <summary>
/// Determines whether the main browser window will be rendered in fullscreen mode, i.e. without window frame. /// The configuration to be used for the main browser window.
/// </summary> /// </summary>
public bool FullScreenMode { get; set; } public BrowserWindowSettings MainWindowSettings { get; set; }
/// <summary> /// <summary>
/// Determines whether the user will need to confirm every reload attempt. /// The URL with which the main browser window will be loaded.
/// </summary>
public bool ShowReloadWarning { get; set; }
/// <summary>
/// The start URL with which a new browser window will be loaded.
/// </summary> /// </summary>
public string StartUrl { get; set; } public string StartUrl { get; set; }
@ -85,5 +65,11 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings
/// Determines whether a custom user agent will be used for all requests, see <see cref="CustomUserAgent"/>. /// Determines whether a custom user agent will be used for all requests, see <see cref="CustomUserAgent"/>.
/// </summary> /// </summary>
public bool UseCustomUserAgent { get; set; } public bool UseCustomUserAgent { get; set; }
public BrowserSettings()
{
AdditionalWindowSettings = new BrowserWindowSettings();
MainWindowSettings = new BrowserWindowSettings();
}
} }
} }

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 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/.
*/
using System;
namespace SafeExamBrowser.Contracts.Configuration.Settings
{
/// <summary>
/// Defines all configuration options for a window of the browser engine.
/// </summary>
[Serializable]
public class BrowserWindowSettings
{
/// <summary>
/// Determines whether the user will be allowed to change the URL in the address bar.
/// </summary>
public bool AllowAddressBar { get; set; }
/// <summary>
/// Determines whether the user will be allowed to navigate backwards.
/// </summary>
public bool AllowBackwardNavigation { get; set; }
/// <summary>
/// Determines whether the user will be allowed to navigate forwards.
/// </summary>
public bool AllowForwardNavigation { get; set; }
/// <summary>
/// Determines whether the user will be allowed to reload webpages.
/// </summary>
public bool AllowReloading { get; set; }
/// <summary>
/// Determines whether the browser window will be rendered in fullscreen mode, i.e. without window frame.
/// </summary>
public bool FullScreenMode { get; set; }
/// <summary>
/// Determines whether the user will need to confirm every reload attempt.
/// </summary>
public bool ShowReloadWarning { get; set; }
}
}

View file

@ -70,6 +70,7 @@
<Compile Include="Configuration\DataResources\IResourceLoader.cs" /> <Compile Include="Configuration\DataResources\IResourceLoader.cs" />
<Compile Include="Configuration\DataResources\IResourceSaver.cs" /> <Compile Include="Configuration\DataResources\IResourceSaver.cs" />
<Compile Include="Configuration\SaveStatus.cs" /> <Compile Include="Configuration\SaveStatus.cs" />
<Compile Include="Configuration\Settings\BrowserWindowSettings.cs" />
<Compile Include="Configuration\Settings\UserInterfaceMode.cs" /> <Compile Include="Configuration\Settings\UserInterfaceMode.cs" />
<Compile Include="Core\Events\IconChangedEventHandler.cs" /> <Compile Include="Core\Events\IconChangedEventHandler.cs" />
<Compile Include="Core\Events\InstanceTerminatedEventHandler.cs" /> <Compile Include="Core\Events\InstanceTerminatedEventHandler.cs" />

View file

@ -16,6 +16,16 @@ namespace SafeExamBrowser.Contracts.UserInterface.Browser
/// </summary> /// </summary>
public interface IBrowserControl public interface IBrowserControl
{ {
/// <summary>
/// Indicates whether a backward navigation can be performed.
/// </summary>
bool CanNavigateBackwards { get; }
/// <summary>
/// Indicates whether a forward navigation can be performed.
/// </summary>
bool CanNavigateForwards { get; }
/// <summary> /// <summary>
/// Event fired when the address of the browser control changes. /// Event fired when the address of the browser control changes.
/// </summary> /// </summary>

View file

@ -17,6 +17,16 @@ namespace SafeExamBrowser.Contracts.UserInterface.Browser
/// </summary> /// </summary>
public interface IBrowserWindow : IWindow public interface IBrowserWindow : IWindow
{ {
/// <summary>
/// Enables the backward navigation button.
/// </summary>
bool CanNavigateBackwards { set; }
/// <summary>
/// Enables the forward navigation button.
/// </summary>
bool CanNavigateForwards { set; }
/// <summary> /// <summary>
/// Event fired when the user changed the URL. /// Event fired when the user changed the URL.
/// </summary> /// </summary>
@ -52,11 +62,6 @@ namespace SafeExamBrowser.Contracts.UserInterface.Browser
/// </summary> /// </summary>
event ActionRequestedEventHandler ZoomResetRequested; event ActionRequestedEventHandler ZoomResetRequested;
/// <summary>
/// Determines whether this window is the main browser window.
/// </summary>
bool IsMainWindow { get; set; }
/// <summary> /// <summary>
/// Updates the address bar of the browser window to the given value; /// Updates the address bar of the browser window to the given value;
/// </summary> /// </summary>

View file

@ -36,7 +36,7 @@ namespace SafeExamBrowser.Contracts.UserInterface
/// <summary> /// <summary>
/// Creates a new browser window loaded with the given browser control and settings. /// Creates a new browser window loaded with the given browser control and settings.
/// </summary> /// </summary>
IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings); IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings, bool isMainWindow);
/// <summary> /// <summary>
/// Creates a system control which allows to change the keyboard layout of the computer. /// Creates a system control which allows to change the keyboard layout of the computer.

View file

@ -29,7 +29,7 @@
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Name="BackButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" /> <Button Grid.Column="0" x:Name="BackwardButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
<Button Grid.Column="1" x:Name="ForwardButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" /> <Button Grid.Column="1" x:Name="ForwardButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
<Button Grid.Column="2" x:Name="ReloadButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" /> <Button Grid.Column="2" x:Name="ReloadButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
<Grid Grid.Column="3" Height="25" Margin="5,0"> <Grid Grid.Column="3" Height="25" Margin="5,0">

View file

@ -31,19 +31,14 @@ namespace SafeExamBrowser.UserInterface.Desktop
private IText text; private IText text;
private WindowClosingEventHandler closing; private WindowClosingEventHandler closing;
public bool IsMainWindow private BrowserWindowSettings WindowSettings
{ {
get get { return isMainWindow ? settings.MainWindowSettings : settings.AdditionalWindowSettings; }
{
return isMainWindow;
}
set
{
isMainWindow = value;
ApplySettings();
}
} }
public bool CanNavigateBackwards { set => Dispatcher.Invoke(() => BackwardButton.IsEnabled = value); }
public bool CanNavigateForwards { set => Dispatcher.Invoke(() => ForwardButton.IsEnabled = value); }
public event AddressChangedEventHandler AddressChanged; public event AddressChangedEventHandler AddressChanged;
public event ActionRequestedEventHandler BackwardNavigationRequested; public event ActionRequestedEventHandler BackwardNavigationRequested;
public event ActionRequestedEventHandler ForwardNavigationRequested; public event ActionRequestedEventHandler ForwardNavigationRequested;
@ -58,8 +53,9 @@ namespace SafeExamBrowser.UserInterface.Desktop
remove { closing -= value; } remove { closing -= value; }
} }
public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings, IText text) public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings, bool isMainWindow, IText text)
{ {
this.isMainWindow = isMainWindow;
this.settings = settings; this.settings = settings;
this.text = text; this.text = text;
@ -128,7 +124,7 @@ namespace SafeExamBrowser.UserInterface.Desktop
BrowserControlHost.Child = control; BrowserControlHost.Child = control;
} }
BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); BackwardButton.Click += (o, args) => BackwardNavigationRequested?.Invoke();
Closing += (o, args) => closing?.Invoke(); Closing += (o, args) => closing?.Invoke();
ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen;
@ -180,9 +176,9 @@ namespace SafeExamBrowser.UserInterface.Desktop
private void ApplySettings() private void ApplySettings()
{ {
if (IsMainWindow) if (isMainWindow)
{ {
if (settings.FullScreenMode) if (WindowSettings.FullScreenMode)
{ {
MaxHeight = SystemParameters.WorkArea.Height; MaxHeight = SystemParameters.WorkArea.Height;
ResizeMode = ResizeMode.NoResize; ResizeMode = ResizeMode.NoResize;
@ -202,16 +198,16 @@ namespace SafeExamBrowser.UserInterface.Desktop
Width = SystemParameters.WorkArea.Width / 2; Width = SystemParameters.WorkArea.Width / 2;
} }
UrlTextBox.IsEnabled = settings.AllowAddressBar; UrlTextBox.IsEnabled = WindowSettings.AllowAddressBar;
ReloadButton.IsEnabled = settings.AllowReloading; ReloadButton.IsEnabled = WindowSettings.AllowReloading;
ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed; ReloadButton.Visibility = WindowSettings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
BackButton.IsEnabled = settings.AllowBackwardNavigation; BackwardButton.IsEnabled = WindowSettings.AllowBackwardNavigation;
BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed; BackwardButton.Visibility = WindowSettings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
ForwardButton.IsEnabled = settings.AllowForwardNavigation; ForwardButton.IsEnabled = WindowSettings.AllowForwardNavigation;
ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed; ForwardButton.Visibility = WindowSettings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
} }
private void LoadIcons() private void LoadIcons()
@ -220,12 +216,12 @@ namespace SafeExamBrowser.UserInterface.Desktop
var forwardUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml"); var forwardUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/NavigateForward.xaml");
var menuUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml"); var menuUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Menu.xaml");
var reloadUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml"); var reloadUri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Reload.xaml");
var back = new XamlIconResource(backUri); var backward = new XamlIconResource(backUri);
var forward = new XamlIconResource(forwardUri); var forward = new XamlIconResource(forwardUri);
var menu = new XamlIconResource(menuUri); var menu = new XamlIconResource(menuUri);
var reload = new XamlIconResource(reloadUri); var reload = new XamlIconResource(reloadUri);
BackButton.Content = IconResourceLoader.Load(back); BackwardButton.Content = IconResourceLoader.Load(backward);
ForwardButton.Content = IconResourceLoader.Load(forward); ForwardButton.Content = IconResourceLoader.Load(forward);
MenuButton.Content = IconResourceLoader.Load(menu); MenuButton.Content = IconResourceLoader.Load(menu);
ReloadButton.Content = IconResourceLoader.Load(reload); ReloadButton.Content = IconResourceLoader.Load(reload);

View file

@ -28,6 +28,9 @@
RenderOptions.BitmapScalingMode="HighQuality" VerticalAlignment="{TemplateBinding VerticalAlignment}" /> RenderOptions.BitmapScalingMode="HighQuality" VerticalAlignment="{TemplateBinding VerticalAlignment}" />
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ButtonContent" Property="Opacity" Value="0.25" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="ButtonContent" Property="Background" Value="LightBlue" /> <Setter TargetName="ButtonContent" Property="Background" Value="LightBlue" />
<Setter TargetName="ButtonContent" Property="BorderBrush" Value="DodgerBlue" /> <Setter TargetName="ButtonContent" Property="BorderBrush" Value="DodgerBlue" />

View file

@ -43,9 +43,9 @@ namespace SafeExamBrowser.UserInterface.Desktop
return new ApplicationButton(info); return new ApplicationButton(info);
} }
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings) public IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings, bool isMainWindow)
{ {
return new BrowserWindow(control, settings, text); return new BrowserWindow(control, settings, isMainWindow, text);
} }
public ISystemKeyboardLayoutControl CreateKeyboardLayoutControl() public ISystemKeyboardLayoutControl CreateKeyboardLayoutControl()