SEBWIN-106: Working on browser zoom...

This commit is contained in:
dbuechel 2019-01-15 10:44:35 +01:00
parent 20962fab05
commit 91c2417930
6 changed files with 33 additions and 19 deletions

View file

@ -7,6 +7,7 @@
*/
using System;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using SafeExamBrowser.Browser.Handlers;
@ -67,6 +68,7 @@ namespace SafeExamBrowser.Browser
{
AddressChanged += BrowserControl_AddressChanged;
LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading);
MouseWheel += BrowserControl_MouseWheel;
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
DownloadHandler = downloadHandler;
@ -103,5 +105,21 @@ namespace SafeExamBrowser.Browser
logger.Debug($"Navigated to '{args.Address}'.");
addressChanged?.Invoke(args.Address);
}
private void BrowserControl_MouseWheel(object sender, MouseEventArgs e)
{
if (settings.AllowPageZoom && ModifierKeys == Keys.Control)
{
var browser = GetBrowser();
browser.GetZoomLevelAsync().ContinueWith(task =>
{
if (task.IsCompleted)
{
browser.SetZoomLevel(task.Result + e.Delta * 0.1);
}
});
}
}
}
}

View file

@ -23,6 +23,14 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
}
}
private void MapPageZoom(Settings settings, object value)
{
if (value is bool enabled)
{
settings.Browser.AllowPageZoom = enabled;
}
}
private void MapUserAgentMode(IDictionary<string, object> rawData, Settings settings)
{
const int DEFAULT = 0;
@ -41,15 +49,5 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Browser.CustomUserAgent = rawData[Keys.Browser.CustomUserAgentMobile] as string;
}
}
private void MapZoomMode(Settings settings, object value)
{
const int PAGE = 0;
if (value is int mode)
{
// TODO: settings.Browser.ZoomMode = mode == PAGE ? BrowserZoomMode.Page : BrowserZoomMode.Text;
}
}
}
}

View file

@ -28,17 +28,11 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
switch (key)
{
case Keys.Browser.EnablePageZoom:
// TODO: MapPageZoom(settings, value);
break;
case Keys.Browser.EnableTextZoom:
// TODO: MapTextZoom(settings, value);
MapPageZoom(settings, value);
break;
case Keys.Browser.MainWindowMode:
MapMainWindowMode(settings, value);
break;
case Keys.Browser.ZoomMode:
MapZoomMode(settings, value);
break;
case Keys.ConfigurationFile.ConfigurationPurpose:
MapConfigurationMode(settings, value);
break;

View file

@ -96,6 +96,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
settings.Browser.AllowDeveloperConsole = false;
settings.Browser.AllowDownloads = false;
settings.Browser.AllowForwardNavigation = false;
settings.Browser.AllowPageZoom = true;
settings.Browser.AllowReloading = true;
settings.Keyboard.AllowAltEsc = false;

View file

@ -23,11 +23,9 @@ namespace SafeExamBrowser.Configuration.ConfigurationData
internal const string CustomUserAgentDesktop = "browserUserAgentWinDesktopModeCustom";
internal const string CustomUserAgentMobile = "browserUserAgentWinTouchModeCustom";
internal const string EnablePageZoom = "enableZoomPage";
internal const string EnableTextZoom = "enableZoomText";
internal const string MainWindowMode = "browserViewMode";
internal const string UserAgentModeDesktop = "browserUserAgentWinDesktopMode";
internal const string UserAgentModeMobile = "browserUserAgentWinTouchMode";
internal const string ZoomMode = "zoomMode";
}
internal static class ConfigurationFile

View file

@ -46,6 +46,11 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings
/// </summary>
public bool AllowForwardNavigation { get; set; }
/// <summary>
/// Determines whether the user should be allowed to zoom webpages.
/// </summary>
public bool AllowPageZoom { get; set; }
/// <summary>
/// Determines whether the user should be allowed to reload webpages.
/// </summary>