From 12246bd0f55a159f4e6d39025925266780d91ff5 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Wed, 2 Aug 2017 14:01:20 +0200 Subject: [PATCH] Renamed EventController to RuntimeController, added F5 key handling to browser window / control and enhanced about window. --- SafeExamBrowser.Browser/BrowserControl.cs | 2 ++ .../BrowserContextMenuHandler.cs | 2 +- .../Handlers/BrowserKeyboardHandler.cs | 31 +++++++++++++++++++ .../SafeExamBrowser.Browser.csproj | 3 +- ...entController.cs => IRuntimeController.cs} | 2 +- .../SafeExamBrowser.Contracts.csproj | 2 +- ...llerTests.cs => RuntimeControllerTests.cs} | 6 ++-- .../SafeExamBrowser.Core.UnitTests.csproj | 2 +- .../Operations/EventControllerOperation.cs | 4 +-- ...ventController.cs => RuntimeController.cs} | 4 +-- .../SafeExamBrowser.Core.csproj | 2 +- .../AboutWindow.xaml | 6 ++-- .../AboutWindow.xaml.cs | 2 +- .../BrowserWindow.xaml.cs | 9 ++++++ SafeExamBrowser/CompositionRoot.cs | 6 ++-- 15 files changed, 63 insertions(+), 20 deletions(-) rename SafeExamBrowser.Browser/{ => Handlers}/BrowserContextMenuHandler.cs (97%) create mode 100644 SafeExamBrowser.Browser/Handlers/BrowserKeyboardHandler.cs rename SafeExamBrowser.Contracts/Behaviour/{IEventController.cs => IRuntimeController.cs} (93%) rename SafeExamBrowser.Core.UnitTests/Behaviour/{EventControllerTests.cs => RuntimeControllerTests.cs} (97%) rename SafeExamBrowser.Core/Behaviour/{EventController.cs => RuntimeController.cs} (96%) diff --git a/SafeExamBrowser.Browser/BrowserControl.cs b/SafeExamBrowser.Browser/BrowserControl.cs index 206f5ddd..604f38a0 100644 --- a/SafeExamBrowser.Browser/BrowserControl.cs +++ b/SafeExamBrowser.Browser/BrowserControl.cs @@ -8,6 +8,7 @@ using System; using CefSharp.WinForms; +using SafeExamBrowser.Browser.Handlers; using SafeExamBrowser.Contracts.I18n; using SafeExamBrowser.Contracts.UserInterface; using IBrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.IBrowserSettings; @@ -70,6 +71,7 @@ namespace SafeExamBrowser.Browser TitleChanged += (o, args) => titleChanged?.Invoke(args.Title); MenuHandler = new BrowserContextMenuHandler(settings, text); + KeyboardHandler = new BrowserKeyboardHandler(); } } } diff --git a/SafeExamBrowser.Browser/BrowserContextMenuHandler.cs b/SafeExamBrowser.Browser/Handlers/BrowserContextMenuHandler.cs similarity index 97% rename from SafeExamBrowser.Browser/BrowserContextMenuHandler.cs rename to SafeExamBrowser.Browser/Handlers/BrowserContextMenuHandler.cs index ebb5a784..339c59c1 100644 --- a/SafeExamBrowser.Browser/BrowserContextMenuHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/BrowserContextMenuHandler.cs @@ -10,7 +10,7 @@ using CefSharp; using SafeExamBrowser.Contracts.I18n; using IBrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.IBrowserSettings; -namespace SafeExamBrowser.Browser +namespace SafeExamBrowser.Browser.Handlers { /// /// See https://cefsharp.github.io/api/57.0.0/html/T_CefSharp_IContextMenuHandler.htm. diff --git a/SafeExamBrowser.Browser/Handlers/BrowserKeyboardHandler.cs b/SafeExamBrowser.Browser/Handlers/BrowserKeyboardHandler.cs new file mode 100644 index 00000000..10a739a3 --- /dev/null +++ b/SafeExamBrowser.Browser/Handlers/BrowserKeyboardHandler.cs @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017 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.Windows.Forms; +using CefSharp; + +namespace SafeExamBrowser.Browser.Handlers +{ + class BrowserKeyboardHandler : IKeyboardHandler + { + public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) + { + return false; + } + + public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) + { + if (type == KeyType.KeyUp && windowsKeyCode == (int) Keys.F5) + { + browserControl.Reload(); + } + + return false; + } + } +} diff --git a/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj index 5d206b91..2437a811 100644 --- a/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj +++ b/SafeExamBrowser.Browser/SafeExamBrowser.Browser.csproj @@ -67,11 +67,12 @@ - + Component + diff --git a/SafeExamBrowser.Contracts/Behaviour/IEventController.cs b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs similarity index 93% rename from SafeExamBrowser.Contracts/Behaviour/IEventController.cs rename to SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs index 6b518de1..9bc74702 100644 --- a/SafeExamBrowser.Contracts/Behaviour/IEventController.cs +++ b/SafeExamBrowser.Contracts/Behaviour/IRuntimeController.cs @@ -8,7 +8,7 @@ namespace SafeExamBrowser.Contracts.Behaviour { - public interface IEventController + public interface IRuntimeController { /// /// Wires up the event handling, i.e. subscribes to all relevant application events. diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj index 6850991e..1b0e5c21 100644 --- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj +++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj @@ -59,7 +59,7 @@ - + diff --git a/SafeExamBrowser.Core.UnitTests/Behaviour/EventControllerTests.cs b/SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs similarity index 97% rename from SafeExamBrowser.Core.UnitTests/Behaviour/EventControllerTests.cs rename to SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs index 918d6bf5..6aa694e3 100644 --- a/SafeExamBrowser.Core.UnitTests/Behaviour/EventControllerTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Behaviour/RuntimeControllerTests.cs @@ -19,7 +19,7 @@ using SafeExamBrowser.Core.Behaviour; namespace SafeExamBrowser.Core.UnitTests.Behaviour { [TestClass] - public class EventControllerTests + public class RuntimeControllerTests { private Mock loggerMock; private Mock processMonitorMock; @@ -27,7 +27,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour private Mock windowMonitorMock; private Mock workingAreaMock; - private IEventController sut; + private IRuntimeController sut; [TestInitialize] public void Initialize() @@ -38,7 +38,7 @@ namespace SafeExamBrowser.Core.UnitTests.Behaviour windowMonitorMock= new Mock(); workingAreaMock = new Mock(); - sut = new EventController( + sut = new RuntimeController( loggerMock.Object, processMonitorMock.Object, taskbarMock.Object, diff --git a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj index 231829da..e111280a 100644 --- a/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj +++ b/SafeExamBrowser.Core.UnitTests/SafeExamBrowser.Core.UnitTests.csproj @@ -72,7 +72,7 @@ - + diff --git a/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs index c859d9b3..de7f1e0f 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/EventControllerOperation.cs @@ -16,11 +16,11 @@ namespace SafeExamBrowser.Core.Behaviour.Operations public class EventControllerOperation : IOperation { private ILogger logger; - private IEventController controller; + private IRuntimeController controller; public ISplashScreen SplashScreen { private get; set; } - public EventControllerOperation(IEventController controller, ILogger logger) + public EventControllerOperation(IRuntimeController controller, ILogger logger) { this.controller = controller; this.logger = logger; diff --git a/SafeExamBrowser.Core/Behaviour/EventController.cs b/SafeExamBrowser.Core/Behaviour/RuntimeController.cs similarity index 96% rename from SafeExamBrowser.Core/Behaviour/EventController.cs rename to SafeExamBrowser.Core/Behaviour/RuntimeController.cs index b76e30dd..6b2788ef 100644 --- a/SafeExamBrowser.Core/Behaviour/EventController.cs +++ b/SafeExamBrowser.Core/Behaviour/RuntimeController.cs @@ -15,7 +15,7 @@ using SafeExamBrowser.Contracts.UserInterface; namespace SafeExamBrowser.Core.Behaviour { - public class EventController : IEventController + public class RuntimeController : IRuntimeController { private ILogger logger; private IProcessMonitor processMonitor; @@ -23,7 +23,7 @@ namespace SafeExamBrowser.Core.Behaviour private IWindowMonitor windowMonitor; private IWorkingArea workingArea; - public EventController( + public RuntimeController( ILogger logger, IProcessMonitor processMonitor, ITaskbar taskbar, diff --git a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj index bd8c6692..938b2f0b 100644 --- a/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj +++ b/SafeExamBrowser.Core/SafeExamBrowser.Core.csproj @@ -58,7 +58,7 @@ - + diff --git a/SafeExamBrowser.UserInterface/AboutWindow.xaml b/SafeExamBrowser.UserInterface/AboutWindow.xaml index 55d9c2e4..f59c562b 100644 --- a/SafeExamBrowser.UserInterface/AboutWindow.xaml +++ b/SafeExamBrowser.UserInterface/AboutWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SafeExamBrowser.UserInterface" mc:Ignorable="d" - Title="About" Height="350" Width="450" ResizeMode="NoResize" Icon="./Images/SafeExamBrowser.ico" + Title="About Safe Exam Browser" Height="350" Width="450" ResizeMode="NoResize" Icon="./Images/SafeExamBrowser.ico" ShowInTaskbar="False" WindowStartupLocation="CenterScreen"> @@ -19,8 +19,8 @@ - - + + This application is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed diff --git a/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs b/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs index 4db14eff..1e51a2ba 100644 --- a/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface/AboutWindow.xaml.cs @@ -46,7 +46,7 @@ namespace SafeExamBrowser.UserInterface VersionInfo.Inlines.Add(new Run($"{text.Get(Key.Version)} {settings.ProgramVersion}") { FontStyle = FontStyles.Italic }); VersionInfo.Inlines.Add(new LineBreak()); VersionInfo.Inlines.Add(new LineBreak()); - VersionInfo.Inlines.Add(new Run(settings.ProgramCopyright)); + VersionInfo.Inlines.Add(new Run(settings.ProgramCopyright) { FontSize = 10 }); } } } diff --git a/SafeExamBrowser.UserInterface/BrowserWindow.xaml.cs b/SafeExamBrowser.UserInterface/BrowserWindow.xaml.cs index 61d5cf26..9c6ee1be 100644 --- a/SafeExamBrowser.UserInterface/BrowserWindow.xaml.cs +++ b/SafeExamBrowser.UserInterface/BrowserWindow.xaml.cs @@ -79,6 +79,7 @@ namespace SafeExamBrowser.UserInterface } Closing += (o, args) => closing?.Invoke(); + KeyUp += BrowserWindow_KeyUp; UrlTextBox.KeyUp += UrlTextBox_KeyUp; ReloadButton.Click += (o, args) => ReloadRequested?.Invoke(); BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke(); @@ -87,6 +88,14 @@ namespace SafeExamBrowser.UserInterface ApplySettings(); } + private void BrowserWindow_KeyUp(object sender, KeyEventArgs e) + { + if (e.Key == Key.F5) + { + ReloadRequested?.Invoke(); + } + } + private void UrlTextBox_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) diff --git a/SafeExamBrowser/CompositionRoot.cs b/SafeExamBrowser/CompositionRoot.cs index fc19a8dd..ea4026a7 100644 --- a/SafeExamBrowser/CompositionRoot.cs +++ b/SafeExamBrowser/CompositionRoot.cs @@ -32,7 +32,7 @@ namespace SafeExamBrowser { private IApplicationController browserController; private IApplicationInfo browserInfo; - private IEventController eventController; + private IRuntimeController runtimeController; private ILogger logger; private INativeMethods nativeMethods; private IProcessMonitor processMonitor; @@ -66,7 +66,7 @@ namespace SafeExamBrowser windowMonitor = new WindowMonitor(new ModuleLogger(logger, typeof(WindowMonitor)), nativeMethods); workingArea = new WorkingArea(new ModuleLogger(logger, typeof(WorkingArea)), nativeMethods); - eventController = new EventController(new ModuleLogger(logger, typeof(EventController)), processMonitor, Taskbar, windowMonitor, workingArea); + runtimeController = new RuntimeController(new ModuleLogger(logger, typeof(RuntimeController)), processMonitor, Taskbar, windowMonitor, workingArea); ShutdownController = new ShutdownController(logger, settings, text, uiFactory); StartupController = new StartupController(logger, settings, text, uiFactory); @@ -76,7 +76,7 @@ namespace SafeExamBrowser StartupOperations.Enqueue(new WorkingAreaOperation(logger, Taskbar, workingArea)); StartupOperations.Enqueue(new TaskbarOperation(logger, settings, Taskbar, text, uiFactory)); StartupOperations.Enqueue(new BrowserOperation(browserController, browserInfo, logger, Taskbar, uiFactory)); - StartupOperations.Enqueue(new EventControllerOperation(eventController, logger)); + StartupOperations.Enqueue(new EventControllerOperation(runtimeController, logger)); } } }