seb-win-refactoring/SafeExamBrowser.Browser/BrowserControl.cs

77 lines
1.9 KiB
C#

/*
* 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;
using CefSharp.WinForms;
using SafeExamBrowser.Browser.Handlers;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.UserInterface;
using IBrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.IBrowserSettings;
namespace SafeExamBrowser.Browser
{
class BrowserControl : ChromiumWebBrowser, IBrowserControl
{
private AddressChangedEventHandler addressChanged;
private IBrowserSettings settings;
private TitleChangedEventHandler titleChanged;
private IText text;
event AddressChangedEventHandler IBrowserControl.AddressChanged
{
add { addressChanged += value; }
remove { addressChanged -= value; }
}
event TitleChangedEventHandler IBrowserControl.TitleChanged
{
add { titleChanged += value; }
remove { titleChanged -= value; }
}
public BrowserControl(IBrowserSettings settings, IText text) : base(settings.StartUrl)
{
this.settings = settings;
this.text = text;
Initialize();
}
public void NavigateBackwards()
{
GetBrowser().GoBack();
}
public void NavigateForwards()
{
GetBrowser().GoForward();
}
public void NavigateTo(string address)
{
if (!String.IsNullOrWhiteSpace(address))
{
Load(address);
}
}
public void Reload()
{
GetBrowser().Reload();
}
private void Initialize()
{
AddressChanged += (o, args) => addressChanged?.Invoke(args.Address);
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
MenuHandler = new BrowserContextMenuHandler(settings, text);
KeyboardHandler = new BrowserKeyboardHandler(settings);
}
}
}