SEBWIN-852: Ensured page zoom via CTRL+MOUSEWHEEL also works according to the respective configuration value.

This commit is contained in:
Damian Büchel 2024-08-29 10:08:36 +02:00
parent 4c0f3cfa6c
commit d5b182ae2f
6 changed files with 43 additions and 3 deletions

View file

@ -18,6 +18,7 @@ namespace SafeExamBrowser.Browser.Content
private string api;
private string clipboard;
private string pageZoom;
internal ContentLoader(IText text)
{
@ -97,5 +98,22 @@ namespace SafeExamBrowser.Browser.Content
return clipboard;
}
internal string LoadPageZoom()
{
if (pageZoom == default)
{
var assembly = Assembly.GetAssembly(typeof(ContentLoader));
var path = $"{typeof(ContentLoader).Namespace}.PageZoom.js";
using (var stream = assembly.GetManifestResourceStream(path))
using (var reader = new StreamReader(stream))
{
pageZoom = reader.ReadToEnd();
}
}
return pageZoom;
}
}
}

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
*
* 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/.
*/
function disableMouseWheelZoom(e) {
if (e.ctrlKey) {
e.preventDefault();
e.stopPropagation();
}
}
document.addEventListener('wheel', disableMouseWheelZoom, { passive: false });

View file

@ -40,9 +40,15 @@ namespace SafeExamBrowser.Browser.Handlers
var configurationKey = keyGenerator.CalculateConfigurationKeyHash(settings.ConfigurationKey, frame.Url);
var api = contentLoader.LoadApi(browserExamKey, configurationKey, appConfig.ProgramBuildVersion);
var clipboardScript = contentLoader.LoadClipboard();
var pageZoomScript = contentLoader.LoadPageZoom();
frame.ExecuteJavaScriptAsync(api);
if (!settings.AllowPageZoom)
{
frame.ExecuteJavaScriptAsync(pageZoomScript);
}
if (!settings.AllowPrint)
{
frame.ExecuteJavaScriptAsync($"window.print = function() {{ alert('{text.Get(TextKey.Browser_PrintNotAllowed)}') }}");

View file

@ -194,7 +194,9 @@
<ItemGroup>
<EmbeddedResource Include="Content\Clipboard.js" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="Content\PageZoom.js" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>

View file

@ -533,7 +533,6 @@ if (typeof __SEB_focusElement === 'undefined') {
ForwardButton.Visibility = WindowSettings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
HomeButton.IsEnabled = WindowSettings.ShowHomeButton;
HomeButton.Visibility = WindowSettings.ShowHomeButton ? Visibility.Visible : Visibility.Collapsed;
MenuButton.IsEnabled = settings.AllowPageZoom || WindowSettings.AllowDeveloperConsole;
ReloadButton.IsEnabled = WindowSettings.AllowReloading;
ReloadButton.Visibility = WindowSettings.ShowReloadButton ? Visibility.Visible : Visibility.Collapsed;
Toolbar.Visibility = WindowSettings.ShowToolbar ? Visibility.Visible : Visibility.Collapsed;

View file

@ -528,7 +528,6 @@ if (typeof __SEB_focusElement === 'undefined') {
ForwardButton.Visibility = WindowSettings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
HomeButton.IsEnabled = WindowSettings.ShowHomeButton;
HomeButton.Visibility = WindowSettings.ShowHomeButton ? Visibility.Visible : Visibility.Collapsed;
MenuButton.IsEnabled = settings.AllowPageZoom || WindowSettings.AllowDeveloperConsole;
ReloadButton.IsEnabled = WindowSettings.AllowReloading;
ReloadButton.Visibility = WindowSettings.ShowReloadButton ? Visibility.Visible : Visibility.Collapsed;
Toolbar.Visibility = WindowSettings.ShowToolbar ? Visibility.Visible : Visibility.Collapsed;