SEBWIN-219: Implemented simple loading state indicator for browser window.
This commit is contained in:
parent
40fd49126f
commit
f2e3b35730
8 changed files with 150 additions and 116 deletions
|
@ -32,6 +32,7 @@ namespace SafeExamBrowser.Browser
|
|||
|
||||
control = new BrowserControl(settings, text);
|
||||
control.AddressChanged += Control_AddressChanged;
|
||||
control.LoadingStateChanged += Control_LoadingStateChanged;
|
||||
control.TitleChanged += Control_TitleChanged;
|
||||
|
||||
window = uiFactory.CreateBrowserWindow(control, settings);
|
||||
|
@ -48,6 +49,11 @@ namespace SafeExamBrowser.Browser
|
|||
window.UpdateAddress(address);
|
||||
}
|
||||
|
||||
private void Control_LoadingStateChanged(bool isLoading)
|
||||
{
|
||||
window.UpdateLoadingState(isLoading);
|
||||
}
|
||||
|
||||
private void Control_TitleChanged(string title)
|
||||
{
|
||||
window.UpdateTitle(title);
|
||||
|
|
|
@ -15,19 +15,27 @@ using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.Browser
|
|||
|
||||
namespace SafeExamBrowser.Browser
|
||||
{
|
||||
class BrowserControl : ChromiumWebBrowser, IBrowserControl
|
||||
internal class BrowserControl : ChromiumWebBrowser, IBrowserControl
|
||||
{
|
||||
private AddressChangedEventHandler addressChanged;
|
||||
private BrowserSettings settings;
|
||||
private TitleChangedEventHandler titleChanged;
|
||||
private IText text;
|
||||
|
||||
private AddressChangedEventHandler addressChanged;
|
||||
private LoadingStateChangedEventHandler loadingStateChanged;
|
||||
private TitleChangedEventHandler titleChanged;
|
||||
|
||||
event AddressChangedEventHandler IBrowserControl.AddressChanged
|
||||
{
|
||||
add { addressChanged += value; }
|
||||
remove { addressChanged -= value; }
|
||||
}
|
||||
|
||||
event LoadingStateChangedEventHandler IBrowserControl.LoadingStateChanged
|
||||
{
|
||||
add { loadingStateChanged += value; }
|
||||
remove { loadingStateChanged -= value; }
|
||||
}
|
||||
|
||||
event TitleChangedEventHandler IBrowserControl.TitleChanged
|
||||
{
|
||||
add { titleChanged += value; }
|
||||
|
@ -68,6 +76,7 @@ namespace SafeExamBrowser.Browser
|
|||
private void Initialize()
|
||||
{
|
||||
AddressChanged += (o, args) => addressChanged?.Invoke(args.Address);
|
||||
LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading);
|
||||
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
|
||||
|
||||
MenuHandler = new BrowserContextMenuHandler(settings, text);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
namespace SafeExamBrowser.Contracts.UserInterface
|
||||
{
|
||||
public delegate void AddressChangedEventHandler(string address);
|
||||
public delegate void LoadingStateChangedEventHandler(bool isLoading);
|
||||
public delegate void TitleChangedEventHandler(string title);
|
||||
|
||||
public interface IBrowserControl
|
||||
|
@ -18,6 +19,11 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
|||
/// </summary>
|
||||
event AddressChangedEventHandler AddressChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the loading state of the browser control changes.
|
||||
/// </summary>
|
||||
event LoadingStateChangedEventHandler LoadingStateChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when the current page (and thus the title) of the browser control changes.
|
||||
/// </summary>
|
||||
|
|
|
@ -42,6 +42,11 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
|||
/// </summary>
|
||||
void UpdateAddress(string adress);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the loading state according to the given value.
|
||||
/// </summary>
|
||||
void UpdateLoadingState(bool isLoading);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the title of the browser window to the given value;
|
||||
/// </summary>
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:fa="http://schemas.fontawesome.io/icons/"
|
||||
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Classic"
|
||||
mc:Ignorable="d" Title="BrowserWindow" Background="#FFF0F0F0" Height="500" Width="500" WindowState="Maximized" Icon=".\Images\SafeExamBrowser.ico">
|
||||
mc:Ignorable="d" Title="BrowserWindow" Background="#FFF0F0F0" Height="500" Width="750" WindowState="Maximized" Icon=".\Images\SafeExamBrowser.ico">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
@ -26,7 +27,10 @@
|
|||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column="0" x:Name="UrlTextBox" Height="25" HorizontalAlignment="Stretch" Padding="5,0" Margin="10" VerticalContentAlignment="Center" />
|
||||
<Grid Grid.Column="0" Height="25" Margin="10">
|
||||
<TextBox x:Name="UrlTextBox" HorizontalAlignment="Stretch" Padding="5,0" VerticalContentAlignment="Center" />
|
||||
<fa:ImageAwesome x:Name="LoadingIcon" Foreground="Gray" HorizontalAlignment="Right" Icon="Spinner" Margin="5,3" Spin="True" SpinDuration="1.5" Visibility="Collapsed" />
|
||||
</Grid>
|
||||
<Button Grid.Column="1" x:Name="ReloadButton" Height="30" HorizontalAlignment="Center" Margin="2.5,5,2.5,5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
|
||||
<Button Grid.Column="2" x:Name="BackButton" Height="30" HorizontalAlignment="Center" Margin="2.5,5,2.5,5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
|
||||
<Button Grid.Column="3" x:Name="ForwardButton" Height="30" HorizontalAlignment="Center" Margin="2.5,5,5,5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
|
||||
|
|
|
@ -86,6 +86,11 @@ namespace SafeExamBrowser.UserInterface.Classic
|
|||
Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
||||
}
|
||||
|
||||
public void UpdateLoadingState(bool isLoading)
|
||||
{
|
||||
Dispatcher.Invoke(() => LoadingIcon.Visibility = isLoading ? Visibility.Visible : Visibility.Collapsed);
|
||||
}
|
||||
|
||||
public void UpdateTitle(string title)
|
||||
{
|
||||
Dispatcher.Invoke(() => Title = title);
|
||||
|
|
|
@ -7,141 +7,138 @@
|
|||
*/
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
||||
using SafeExamBrowser.Contracts.UserInterface;
|
||||
|
||||
namespace SafeExamBrowser.UserInterface.Windows10
|
||||
{
|
||||
public partial class BrowserWindow : Window, IBrowserWindow
|
||||
public partial class BrowserWindow : Window // TODO, IBrowserWindow
|
||||
{
|
||||
private bool isMainWindow;
|
||||
private BrowserSettings settings;
|
||||
public WindowClosingEventHandler closing;
|
||||
//private bool isMainWindow;
|
||||
//private BrowserSettings settings;
|
||||
//public WindowClosingEventHandler closing;
|
||||
|
||||
public bool IsMainWindow
|
||||
{
|
||||
get
|
||||
{
|
||||
return isMainWindow;
|
||||
}
|
||||
set
|
||||
{
|
||||
isMainWindow = value;
|
||||
ApplySettings();
|
||||
}
|
||||
}
|
||||
//public bool IsMainWindow
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return isMainWindow;
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// isMainWindow = value;
|
||||
// ApplySettings();
|
||||
// }
|
||||
//}
|
||||
|
||||
public event AddressChangedEventHandler AddressChanged;
|
||||
public event ActionRequestedEventHandler BackwardNavigationRequested;
|
||||
public event ActionRequestedEventHandler ForwardNavigationRequested;
|
||||
public event ActionRequestedEventHandler ReloadRequested;
|
||||
//public event AddressChangedEventHandler AddressChanged;
|
||||
//public event ActionRequestedEventHandler BackwardNavigationRequested;
|
||||
//public event ActionRequestedEventHandler ForwardNavigationRequested;
|
||||
//public event ActionRequestedEventHandler ReloadRequested;
|
||||
|
||||
event WindowClosingEventHandler IWindow.Closing
|
||||
{
|
||||
add { closing += value; }
|
||||
remove { closing -= value; }
|
||||
}
|
||||
//event WindowClosingEventHandler IWindow.Closing
|
||||
//{
|
||||
// add { closing += value; }
|
||||
// remove { closing -= value; }
|
||||
//}
|
||||
|
||||
public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
//public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings)
|
||||
//{
|
||||
// this.settings = settings;
|
||||
|
||||
InitializeComponent();
|
||||
InitializeBrowserWindow(browserControl);
|
||||
}
|
||||
// InitializeComponent();
|
||||
// InitializeBrowserWindow(browserControl);
|
||||
//}
|
||||
|
||||
public void BringToForeground()
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
//public void BringToForeground()
|
||||
//{
|
||||
// Dispatcher.Invoke(() =>
|
||||
// {
|
||||
// if (WindowState == WindowState.Minimized)
|
||||
// {
|
||||
// WindowState = WindowState.Normal;
|
||||
// }
|
||||
|
||||
Activate();
|
||||
});
|
||||
}
|
||||
// Activate();
|
||||
// });
|
||||
//}
|
||||
|
||||
public new void Close()
|
||||
{
|
||||
Dispatcher.Invoke(base.Close);
|
||||
}
|
||||
//public new void Close()
|
||||
//{
|
||||
// Dispatcher.Invoke(base.Close);
|
||||
//}
|
||||
|
||||
public new void Hide()
|
||||
{
|
||||
Dispatcher.Invoke(base.Hide);
|
||||
}
|
||||
//public new void Hide()
|
||||
//{
|
||||
// Dispatcher.Invoke(base.Hide);
|
||||
//}
|
||||
|
||||
public new void Show()
|
||||
{
|
||||
Dispatcher.Invoke(base.Show);
|
||||
}
|
||||
//public new void Show()
|
||||
//{
|
||||
// Dispatcher.Invoke(base.Show);
|
||||
//}
|
||||
|
||||
public void UpdateAddress(string url)
|
||||
{
|
||||
Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
||||
}
|
||||
//public void UpdateAddress(string url)
|
||||
//{
|
||||
// Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
||||
//}
|
||||
|
||||
public void UpdateTitle(string title)
|
||||
{
|
||||
Dispatcher.Invoke(() => Title = title);
|
||||
}
|
||||
//public void UpdateTitle(string title)
|
||||
//{
|
||||
// Dispatcher.Invoke(() => Title = title);
|
||||
//}
|
||||
|
||||
private void InitializeBrowserWindow(IBrowserControl browserControl)
|
||||
{
|
||||
if (browserControl is System.Windows.Forms.Control control)
|
||||
{
|
||||
BrowserControlHost.Child = control;
|
||||
}
|
||||
//private void InitializeBrowserWindow(IBrowserControl browserControl)
|
||||
//{
|
||||
// if (browserControl is System.Windows.Forms.Control control)
|
||||
// {
|
||||
// BrowserControlHost.Child = control;
|
||||
// }
|
||||
|
||||
Closing += (o, args) => closing?.Invoke();
|
||||
KeyUp += BrowserWindow_KeyUp;
|
||||
UrlTextBox.KeyUp += UrlTextBox_KeyUp;
|
||||
ReloadButton.Click += (o, args) => ReloadRequested?.Invoke();
|
||||
BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke();
|
||||
ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
|
||||
// Closing += (o, args) => closing?.Invoke();
|
||||
// KeyUp += BrowserWindow_KeyUp;
|
||||
// UrlTextBox.KeyUp += UrlTextBox_KeyUp;
|
||||
// ReloadButton.Click += (o, args) => ReloadRequested?.Invoke();
|
||||
// BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke();
|
||||
// ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
|
||||
|
||||
ApplySettings();
|
||||
}
|
||||
// ApplySettings();
|
||||
//}
|
||||
|
||||
private void BrowserWindow_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.F5)
|
||||
{
|
||||
ReloadRequested?.Invoke();
|
||||
}
|
||||
}
|
||||
//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)
|
||||
{
|
||||
AddressChanged?.Invoke(UrlTextBox.Text);
|
||||
}
|
||||
}
|
||||
//private void UrlTextBox_KeyUp(object sender, KeyEventArgs e)
|
||||
//{
|
||||
// if (e.Key == Key.Enter)
|
||||
// {
|
||||
// AddressChanged?.Invoke(UrlTextBox.Text);
|
||||
// }
|
||||
//}
|
||||
|
||||
private void ApplySettings()
|
||||
{
|
||||
if (IsMainWindow && settings.FullScreenMode)
|
||||
{
|
||||
MaxHeight = SystemParameters.WorkArea.Height;
|
||||
ResizeMode = ResizeMode.NoResize;
|
||||
WindowState = WindowState.Maximized;
|
||||
WindowStyle = WindowStyle.None;
|
||||
}
|
||||
//private void ApplySettings()
|
||||
//{
|
||||
// if (IsMainWindow && settings.FullScreenMode)
|
||||
// {
|
||||
// MaxHeight = SystemParameters.WorkArea.Height;
|
||||
// ResizeMode = ResizeMode.NoResize;
|
||||
// WindowState = WindowState.Maximized;
|
||||
// WindowStyle = WindowStyle.None;
|
||||
// }
|
||||
|
||||
UrlTextBox.IsEnabled = settings.AllowAddressBar;
|
||||
// UrlTextBox.IsEnabled = settings.AllowAddressBar;
|
||||
|
||||
ReloadButton.IsEnabled = settings.AllowReloading;
|
||||
ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
|
||||
// ReloadButton.IsEnabled = settings.AllowReloading;
|
||||
// ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
BackButton.IsEnabled = settings.AllowBackwardNavigation;
|
||||
BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
// BackButton.IsEnabled = settings.AllowBackwardNavigation;
|
||||
// BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
ForwardButton.IsEnabled = settings.AllowForwardNavigation;
|
||||
ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
// ForwardButton.IsEnabled = settings.AllowForwardNavigation;
|
||||
// ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ namespace SafeExamBrowser.UserInterface.Windows10
|
|||
|
||||
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings)
|
||||
{
|
||||
return new BrowserWindow(control, settings);
|
||||
// TODO
|
||||
// return new BrowserWindow(control, settings);
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IWindow CreateLogWindow(ILogger logger)
|
||||
|
|
Loading…
Reference in a new issue