From 91c241793015d343f696d0b2a9b795887aa09e3e Mon Sep 17 00:00:00 2001 From: dbuechel Date: Tue, 15 Jan 2019 10:44:35 +0100 Subject: [PATCH] SEBWIN-106: Working on browser zoom... --- SafeExamBrowser.Browser/BrowserControl.cs | 18 ++++++++++++++++++ .../ConfigurationData/DataMapper.Browser.cs | 18 ++++++++---------- .../ConfigurationData/DataMapper.cs | 8 +------- .../ConfigurationData/DataValues.cs | 1 + .../ConfigurationData/Keys.cs | 2 -- .../Configuration/Settings/BrowserSettings.cs | 5 +++++ 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index 14fe359d..d214ec95 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -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); + } + }); + } + } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs index 62280af9..715a6644 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.Browser.cs @@ -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 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; - } - } } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs index faf9867e..d106be85 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapper.cs @@ -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; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs index cfde24e6..05b8422e 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataValues.cs @@ -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; diff --git a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs index f1994b9a..dd42e7a2 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/Keys.cs @@ -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 diff --git a/SafeExamBrowser.Contracts/Configuration/Settings/BrowserSettings.cs b/SafeExamBrowser.Contracts/Configuration/Settings/BrowserSettings.cs index aa24d326..7a34172c 100644 --- a/SafeExamBrowser.Contracts/Configuration/Settings/BrowserSettings.cs +++ b/SafeExamBrowser.Contracts/Configuration/Settings/BrowserSettings.cs @@ -46,6 +46,11 @@ namespace SafeExamBrowser.Contracts.Configuration.Settings /// public bool AllowForwardNavigation { get; set; } + /// + /// Determines whether the user should be allowed to zoom webpages. + /// + public bool AllowPageZoom { get; set; } + /// /// Determines whether the user should be allowed to reload webpages. ///