SEBWIN-305: Implemented size and position configuration for browser windows.

This commit is contained in:
dbuechel 2019-12-11 11:09:24 +01:00
parent cf4e229fef
commit 90b73ec8aa
8 changed files with 298 additions and 48 deletions

View file

@ -197,5 +197,111 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
}
}
}
private void MapWindowHeightAdditionalWindow(AppSettings settings, object value)
{
if (value is string raw)
{
if (raw.EndsWith("%") && int.TryParse(raw.Replace("%", string.Empty), out var relativeHeight))
{
settings.Browser.AdditionalWindow.RelativeHeight = relativeHeight;
}
else if (int.TryParse(raw, out var absoluteHeight))
{
settings.Browser.AdditionalWindow.AbsoluteHeight = absoluteHeight;
}
}
}
private void MapWindowHeightMainWindow(AppSettings settings, object value)
{
if (value is string raw)
{
if (raw.EndsWith("%") && int.TryParse(raw.Replace("%", string.Empty), out var relativeHeight))
{
settings.Browser.MainWindow.RelativeHeight = relativeHeight;
}
else if (int.TryParse(raw, out var absoluteHeight))
{
settings.Browser.MainWindow.AbsoluteHeight = absoluteHeight;
}
}
}
private void MapWindowPositionAdditionalWindow(AppSettings settings, object value)
{
const int LEFT = 0;
const int CENTER = 1;
const int RIGHT = 2;
if (value is int position)
{
switch (position)
{
case LEFT:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Left;
break;
case CENTER:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Center;
break;
case RIGHT:
settings.Browser.AdditionalWindow.Position = BrowserWindowPosition.Right;
break;
}
}
}
private void MapWindowPositionMainWindow(AppSettings settings, object value)
{
const int LEFT = 0;
const int CENTER = 1;
const int RIGHT = 2;
if (value is int position)
{
switch (position)
{
case LEFT:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Left;
break;
case CENTER:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Center;
break;
case RIGHT:
settings.Browser.MainWindow.Position = BrowserWindowPosition.Right;
break;
}
}
}
private void MapWindowWidthAdditionalWindow(AppSettings settings, object value)
{
if (value is string raw)
{
if (raw.EndsWith("%") && int.TryParse(raw.Replace("%", string.Empty), out var relativeWidth))
{
settings.Browser.AdditionalWindow.RelativeWidth = relativeWidth;
}
else if (int.TryParse(raw, out var absoluteWidth))
{
settings.Browser.AdditionalWindow.AbsoluteWidth = absoluteWidth;
}
}
}
private void MapWindowWidthMainWindow(AppSettings settings, object value)
{
if (value is string raw)
{
if (raw.EndsWith("%") && int.TryParse(raw.Replace("%", string.Empty), out var relativeWidth))
{
settings.Browser.MainWindow.RelativeWidth = relativeWidth;
}
else if (int.TryParse(raw, out var absoluteWidth))
{
settings.Browser.MainWindow.AbsoluteWidth = absoluteWidth;
}
}
}
}
}

View file

@ -81,9 +81,6 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.AllowPopups:
MapAllowPopups(settings, value);
break;
case Keys.Browser.MainWindowMode:
MapMainWindowMode(settings, value);
break;
case Keys.Browser.AdditionalWindow.AllowAddressBar:
MapAllowAddressBarAdditionalWindow(settings, value);
break;
@ -96,6 +93,15 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.AdditionalWindow.ShowReloadWarning:
MapShowReloadWarningAdditionalWindow(settings, value);
break;
case Keys.Browser.AdditionalWindow.WindowHeight:
MapWindowHeightAdditionalWindow(settings, value);
break;
case Keys.Browser.AdditionalWindow.WindowPosition:
MapWindowPositionAdditionalWindow(settings, value);
break;
case Keys.Browser.AdditionalWindow.WindowWidth:
MapWindowWidthAdditionalWindow(settings, value);
break;
case Keys.Browser.Filter.UrlFilterRules:
MapUrlFilterRules(settings, value);
break;
@ -111,6 +117,18 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
case Keys.Browser.MainWindow.ShowReloadWarning:
MapShowReloadWarning(settings, value);
break;
case Keys.Browser.MainWindow.WindowHeight:
MapWindowHeightMainWindow(settings, value);
break;
case Keys.Browser.MainWindow.WindowMode:
MapMainWindowMode(settings, value);
break;
case Keys.Browser.MainWindow.WindowPosition:
MapWindowPositionMainWindow(settings, value);
break;
case Keys.Browser.MainWindow.WindowWidth:
MapWindowWidthMainWindow(settings, value);
break;
}
}

View file

@ -52,10 +52,20 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string AllowPopups = "blockPopUpWindows";
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
internal const string MainWindowMode = "browserViewMode";
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";
internal static class AdditionalWindow
{
internal const string AllowAddressBar = "newBrowserWindowAllowAddressBar";
internal const string AllowNavigation = "newBrowserWindowNavigation";
internal const string AllowReload = "newBrowserWindowAllowReload";
internal const string ShowReloadWarning = "newBrowserWindowShowReloadWarning";
internal const string WindowHeight = "newBrowserWindowByLinkHeight";
internal const string WindowWidth = "newBrowserWindowByLinkWidth";
internal const string WindowPosition = "newBrowserWindowByLinkPositioning";
}
internal static class Filter
{
internal const string EnableContentRequestFilter = "URLFilterEnableContentFilter";
@ -73,14 +83,10 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string AllowNavigation = "allowBrowsingBackForward";
internal const string AllowReload = "browserWindowAllowReload";
internal const string ShowReloadWarning = "showReloadWarning";
}
internal static class AdditionalWindow
{
internal const string AllowAddressBar = "newBrowserWindowAllowAddressBar";
internal const string AllowNavigation = "newBrowserWindowNavigation";
internal const string AllowReload = "newBrowserWindowAllowReload";
internal const string ShowReloadWarning = "newBrowserWindowShowReloadWarning";
internal const string WindowHeight = "mainBrowserWindowHeight";
internal const string WindowMode = "browserViewMode";
internal const string WindowWidth = "mainBrowserWindowWidth";
internal const string WindowPosition = "mainBrowserWindowPositioning";
}
}

View file

@ -0,0 +1,20 @@
/*
* 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/.
*/
namespace SafeExamBrowser.Settings.Browser
{
/// <summary>
/// Defines the initial position of a browser window.
/// </summary>
public enum BrowserWindowPosition
{
Left,
Center,
Right
}
}

View file

@ -16,6 +16,16 @@ namespace SafeExamBrowser.Settings.Browser
[Serializable]
public class BrowserWindowSettings
{
/// <summary>
/// Optionally defines the height of the browser window in physical pixels.
/// </summary>
public int? AbsoluteHeight { get; set; }
/// <summary>
/// Optionally defines the width of the browser window in physical pixels.
/// </summary>
public int? AbsoluteWidth { get; set; }
/// <summary>
/// Determines whether the user will be allowed to change the URL in the address bar.
/// </summary>
@ -46,6 +56,21 @@ namespace SafeExamBrowser.Settings.Browser
/// </summary>
public bool FullScreenMode { get; set; }
/// <summary>
/// Determines the initial position of the browser window (if it is not maximized).
/// </summary>
public BrowserWindowPosition Position { get; set; }
/// <summary>
/// Optionally defines the height of the browser window as percentage of the working area height.
/// </summary>
public int? RelativeHeight { get; set; }
/// <summary>
/// Optionally defines the width of the browser window as percentage of the working area width.
/// </summary>
public int? RelativeWidth { get; set; }
/// <summary>
/// Determines whether the user will need to confirm every reload attempt.
/// </summary>

View file

@ -59,6 +59,7 @@
<Compile Include="Applications\WhitelistApplication.cs" />
<Compile Include="Browser\BrowserFilterSettings.cs" />
<Compile Include="Browser\BrowserSettings.cs" />
<Compile Include="Browser\BrowserWindowPosition.cs" />
<Compile Include="Browser\BrowserWindowSettings.cs" />
<Compile Include="Browser\FilterResult.cs" />
<Compile Include="Browser\FilterRuleSettings.cs" />

View file

@ -261,28 +261,65 @@ namespace SafeExamBrowser.UserInterface.Desktop
private void InitializeBounds()
{
if (isMainWindow)
if (isMainWindow && WindowSettings.FullScreenMode)
{
if (WindowSettings.FullScreenMode)
{
Top = 0;
Left = 0;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width;
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
}
else
{
WindowState = WindowState.Maximized;
}
Top = 0;
Left = 0;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width;
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
}
else if (WindowSettings.RelativeHeight == 100 && WindowSettings.RelativeWidth == 100)
{
WindowState = WindowState.Maximized;
}
else
{
Top = 0;
Left = SystemParameters.WorkArea.Width / 2;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width / 2;
if (WindowSettings.RelativeHeight > 0)
{
Height = SystemParameters.WorkArea.Height * WindowSettings.RelativeHeight.Value / 100;
Top = (SystemParameters.WorkArea.Height / 2) - (Height / 2);
}
else if (WindowSettings.AbsoluteHeight > 0)
{
Height = this.TransformFromPhysical(0, WindowSettings.AbsoluteHeight.Value).Y;
Top = (SystemParameters.WorkArea.Height / 2) - (Height / 2);
}
if (WindowSettings.RelativeWidth > 0)
{
Width = SystemParameters.WorkArea.Width * WindowSettings.RelativeWidth.Value / 100;
}
else if (WindowSettings.AbsoluteWidth > 0)
{
Width = this.TransformFromPhysical(WindowSettings.AbsoluteWidth.Value, 0).X;
}
if (Height > SystemParameters.WorkArea.Height)
{
Top = 0;
Height = SystemParameters.WorkArea.Height;
}
if (Width > SystemParameters.WorkArea.Width)
{
Left = 0;
Width = SystemParameters.WorkArea.Width;
}
switch (WindowSettings.Position)
{
case BrowserWindowPosition.Left:
Left = 0;
break;
case BrowserWindowPosition.Center:
Left = (SystemParameters.WorkArea.Width / 2) - (Width / 2);
break;
case BrowserWindowPosition.Right:
Left = SystemParameters.WorkArea.Width - Width;
break;
}
}
}

View file

@ -270,28 +270,65 @@ namespace SafeExamBrowser.UserInterface.Mobile
private void InitializeBounds()
{
if (isMainWindow)
if (isMainWindow && WindowSettings.FullScreenMode)
{
if (WindowSettings.FullScreenMode)
{
Top = 0;
Left = 0;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width;
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
}
else
{
WindowState = WindowState.Maximized;
}
Top = 0;
Left = 0;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width;
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
}
else if (WindowSettings.RelativeHeight == 100 && WindowSettings.RelativeWidth == 100)
{
WindowState = WindowState.Maximized;
}
else
{
Top = 0;
Left = SystemParameters.WorkArea.Width / 2;
Height = SystemParameters.WorkArea.Height;
Width = SystemParameters.WorkArea.Width / 2;
if (WindowSettings.RelativeHeight > 0)
{
Height = SystemParameters.WorkArea.Height * WindowSettings.RelativeHeight.Value / 100;
Top = (SystemParameters.WorkArea.Height / 2) - (Height / 2);
}
else if (WindowSettings.AbsoluteHeight > 0)
{
Height = this.TransformFromPhysical(0, WindowSettings.AbsoluteHeight.Value).Y;
Top = (SystemParameters.WorkArea.Height / 2) - (Height / 2);
}
if (WindowSettings.RelativeWidth > 0)
{
Width = SystemParameters.WorkArea.Width * WindowSettings.RelativeWidth.Value / 100;
}
else if (WindowSettings.AbsoluteWidth > 0)
{
Width = this.TransformFromPhysical(WindowSettings.AbsoluteWidth.Value, 0).X;
}
if (Height > SystemParameters.WorkArea.Height)
{
Top = 0;
Height = SystemParameters.WorkArea.Height;
}
if (Width > SystemParameters.WorkArea.Width)
{
Left = 0;
Width = SystemParameters.WorkArea.Width;
}
switch (WindowSettings.Position)
{
case BrowserWindowPosition.Left:
Left = 0;
break;
case BrowserWindowPosition.Center:
Left = (SystemParameters.WorkArea.Width / 2) - (Width / 2);
break;
case BrowserWindowPosition.Right:
Left = SystemParameters.WorkArea.Width - Width;
break;
}
}
}