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 = new BrowserControl(settings, text);
|
||||||
control.AddressChanged += Control_AddressChanged;
|
control.AddressChanged += Control_AddressChanged;
|
||||||
|
control.LoadingStateChanged += Control_LoadingStateChanged;
|
||||||
control.TitleChanged += Control_TitleChanged;
|
control.TitleChanged += Control_TitleChanged;
|
||||||
|
|
||||||
window = uiFactory.CreateBrowserWindow(control, settings);
|
window = uiFactory.CreateBrowserWindow(control, settings);
|
||||||
|
@ -48,6 +49,11 @@ namespace SafeExamBrowser.Browser
|
||||||
window.UpdateAddress(address);
|
window.UpdateAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Control_LoadingStateChanged(bool isLoading)
|
||||||
|
{
|
||||||
|
window.UpdateLoadingState(isLoading);
|
||||||
|
}
|
||||||
|
|
||||||
private void Control_TitleChanged(string title)
|
private void Control_TitleChanged(string title)
|
||||||
{
|
{
|
||||||
window.UpdateTitle(title);
|
window.UpdateTitle(title);
|
||||||
|
|
|
@ -15,19 +15,27 @@ using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.Browser
|
||||||
|
|
||||||
namespace SafeExamBrowser.Browser
|
namespace SafeExamBrowser.Browser
|
||||||
{
|
{
|
||||||
class BrowserControl : ChromiumWebBrowser, IBrowserControl
|
internal class BrowserControl : ChromiumWebBrowser, IBrowserControl
|
||||||
{
|
{
|
||||||
private AddressChangedEventHandler addressChanged;
|
|
||||||
private BrowserSettings settings;
|
private BrowserSettings settings;
|
||||||
private TitleChangedEventHandler titleChanged;
|
|
||||||
private IText text;
|
private IText text;
|
||||||
|
|
||||||
|
private AddressChangedEventHandler addressChanged;
|
||||||
|
private LoadingStateChangedEventHandler loadingStateChanged;
|
||||||
|
private TitleChangedEventHandler titleChanged;
|
||||||
|
|
||||||
event AddressChangedEventHandler IBrowserControl.AddressChanged
|
event AddressChangedEventHandler IBrowserControl.AddressChanged
|
||||||
{
|
{
|
||||||
add { addressChanged += value; }
|
add { addressChanged += value; }
|
||||||
remove { addressChanged -= value; }
|
remove { addressChanged -= value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event LoadingStateChangedEventHandler IBrowserControl.LoadingStateChanged
|
||||||
|
{
|
||||||
|
add { loadingStateChanged += value; }
|
||||||
|
remove { loadingStateChanged -= value; }
|
||||||
|
}
|
||||||
|
|
||||||
event TitleChangedEventHandler IBrowserControl.TitleChanged
|
event TitleChangedEventHandler IBrowserControl.TitleChanged
|
||||||
{
|
{
|
||||||
add { titleChanged += value; }
|
add { titleChanged += value; }
|
||||||
|
@ -68,6 +76,7 @@ namespace SafeExamBrowser.Browser
|
||||||
private void Initialize()
|
private void Initialize()
|
||||||
{
|
{
|
||||||
AddressChanged += (o, args) => addressChanged?.Invoke(args.Address);
|
AddressChanged += (o, args) => addressChanged?.Invoke(args.Address);
|
||||||
|
LoadingStateChanged += (o, args) => loadingStateChanged?.Invoke(args.IsLoading);
|
||||||
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
|
TitleChanged += (o, args) => titleChanged?.Invoke(args.Title);
|
||||||
|
|
||||||
MenuHandler = new BrowserContextMenuHandler(settings, text);
|
MenuHandler = new BrowserContextMenuHandler(settings, text);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
namespace SafeExamBrowser.Contracts.UserInterface
|
namespace SafeExamBrowser.Contracts.UserInterface
|
||||||
{
|
{
|
||||||
public delegate void AddressChangedEventHandler(string address);
|
public delegate void AddressChangedEventHandler(string address);
|
||||||
|
public delegate void LoadingStateChangedEventHandler(bool isLoading);
|
||||||
public delegate void TitleChangedEventHandler(string title);
|
public delegate void TitleChangedEventHandler(string title);
|
||||||
|
|
||||||
public interface IBrowserControl
|
public interface IBrowserControl
|
||||||
|
@ -18,6 +19,11 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event AddressChangedEventHandler AddressChanged;
|
event AddressChangedEventHandler AddressChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event fired when the loading state of the browser control changes.
|
||||||
|
/// </summary>
|
||||||
|
event LoadingStateChangedEventHandler LoadingStateChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event fired when the current page (and thus the title) of the browser control changes.
|
/// Event fired when the current page (and thus the title) of the browser control changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -42,6 +42,11 @@ namespace SafeExamBrowser.Contracts.UserInterface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void UpdateAddress(string adress);
|
void UpdateAddress(string adress);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the loading state according to the given value.
|
||||||
|
/// </summary>
|
||||||
|
void UpdateLoadingState(bool isLoading);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the title of the browser window to the given value;
|
/// Sets the title of the browser window to the given value;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:fa="http://schemas.fontawesome.io/icons/"
|
||||||
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Classic"
|
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>
|
<Window.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
@ -26,7 +27,10 @@
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</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="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="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" />
|
<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);
|
Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateLoadingState(bool isLoading)
|
||||||
|
{
|
||||||
|
Dispatcher.Invoke(() => LoadingIcon.Visibility = isLoading ? Visibility.Visible : Visibility.Collapsed);
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateTitle(string title)
|
public void UpdateTitle(string title)
|
||||||
{
|
{
|
||||||
Dispatcher.Invoke(() => Title = title);
|
Dispatcher.Invoke(() => Title = title);
|
||||||
|
|
|
@ -7,141 +7,138 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
|
||||||
using SafeExamBrowser.Contracts.Configuration.Settings;
|
|
||||||
using SafeExamBrowser.Contracts.UserInterface;
|
|
||||||
|
|
||||||
namespace SafeExamBrowser.UserInterface.Windows10
|
namespace SafeExamBrowser.UserInterface.Windows10
|
||||||
{
|
{
|
||||||
public partial class BrowserWindow : Window, IBrowserWindow
|
public partial class BrowserWindow : Window // TODO, IBrowserWindow
|
||||||
{
|
{
|
||||||
private bool isMainWindow;
|
//private bool isMainWindow;
|
||||||
private BrowserSettings settings;
|
//private BrowserSettings settings;
|
||||||
public WindowClosingEventHandler closing;
|
//public WindowClosingEventHandler closing;
|
||||||
|
|
||||||
public bool IsMainWindow
|
//public bool IsMainWindow
|
||||||
{
|
//{
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
return isMainWindow;
|
// return isMainWindow;
|
||||||
}
|
// }
|
||||||
set
|
// set
|
||||||
{
|
// {
|
||||||
isMainWindow = value;
|
// isMainWindow = value;
|
||||||
ApplySettings();
|
// ApplySettings();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
public event AddressChangedEventHandler AddressChanged;
|
//public event AddressChangedEventHandler AddressChanged;
|
||||||
public event ActionRequestedEventHandler BackwardNavigationRequested;
|
//public event ActionRequestedEventHandler BackwardNavigationRequested;
|
||||||
public event ActionRequestedEventHandler ForwardNavigationRequested;
|
//public event ActionRequestedEventHandler ForwardNavigationRequested;
|
||||||
public event ActionRequestedEventHandler ReloadRequested;
|
//public event ActionRequestedEventHandler ReloadRequested;
|
||||||
|
|
||||||
event WindowClosingEventHandler IWindow.Closing
|
//event WindowClosingEventHandler IWindow.Closing
|
||||||
{
|
//{
|
||||||
add { closing += value; }
|
// add { closing += value; }
|
||||||
remove { closing -= value; }
|
// remove { closing -= value; }
|
||||||
}
|
//}
|
||||||
|
|
||||||
public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings)
|
//public BrowserWindow(IBrowserControl browserControl, BrowserSettings settings)
|
||||||
{
|
//{
|
||||||
this.settings = settings;
|
// this.settings = settings;
|
||||||
|
|
||||||
InitializeComponent();
|
// InitializeComponent();
|
||||||
InitializeBrowserWindow(browserControl);
|
// InitializeBrowserWindow(browserControl);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void BringToForeground()
|
//public void BringToForeground()
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(() =>
|
// Dispatcher.Invoke(() =>
|
||||||
{
|
// {
|
||||||
if (WindowState == WindowState.Minimized)
|
// if (WindowState == WindowState.Minimized)
|
||||||
{
|
// {
|
||||||
WindowState = WindowState.Normal;
|
// WindowState = WindowState.Normal;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Activate();
|
// Activate();
|
||||||
});
|
// });
|
||||||
}
|
//}
|
||||||
|
|
||||||
public new void Close()
|
//public new void Close()
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(base.Close);
|
// Dispatcher.Invoke(base.Close);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public new void Hide()
|
//public new void Hide()
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(base.Hide);
|
// Dispatcher.Invoke(base.Hide);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public new void Show()
|
//public new void Show()
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(base.Show);
|
// Dispatcher.Invoke(base.Show);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void UpdateAddress(string url)
|
//public void UpdateAddress(string url)
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
// Dispatcher.Invoke(() => UrlTextBox.Text = url);
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void UpdateTitle(string title)
|
//public void UpdateTitle(string title)
|
||||||
{
|
//{
|
||||||
Dispatcher.Invoke(() => Title = title);
|
// Dispatcher.Invoke(() => Title = title);
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void InitializeBrowserWindow(IBrowserControl browserControl)
|
//private void InitializeBrowserWindow(IBrowserControl browserControl)
|
||||||
{
|
//{
|
||||||
if (browserControl is System.Windows.Forms.Control control)
|
// if (browserControl is System.Windows.Forms.Control control)
|
||||||
{
|
// {
|
||||||
BrowserControlHost.Child = control;
|
// BrowserControlHost.Child = control;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Closing += (o, args) => closing?.Invoke();
|
// Closing += (o, args) => closing?.Invoke();
|
||||||
KeyUp += BrowserWindow_KeyUp;
|
// KeyUp += BrowserWindow_KeyUp;
|
||||||
UrlTextBox.KeyUp += UrlTextBox_KeyUp;
|
// UrlTextBox.KeyUp += UrlTextBox_KeyUp;
|
||||||
ReloadButton.Click += (o, args) => ReloadRequested?.Invoke();
|
// ReloadButton.Click += (o, args) => ReloadRequested?.Invoke();
|
||||||
BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke();
|
// BackButton.Click += (o, args) => BackwardNavigationRequested?.Invoke();
|
||||||
ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
|
// ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
|
||||||
|
|
||||||
ApplySettings();
|
// ApplySettings();
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void BrowserWindow_KeyUp(object sender, KeyEventArgs e)
|
//private void BrowserWindow_KeyUp(object sender, KeyEventArgs e)
|
||||||
{
|
//{
|
||||||
if (e.Key == Key.F5)
|
// if (e.Key == Key.F5)
|
||||||
{
|
// {
|
||||||
ReloadRequested?.Invoke();
|
// ReloadRequested?.Invoke();
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void UrlTextBox_KeyUp(object sender, KeyEventArgs e)
|
//private void UrlTextBox_KeyUp(object sender, KeyEventArgs e)
|
||||||
{
|
//{
|
||||||
if (e.Key == Key.Enter)
|
// if (e.Key == Key.Enter)
|
||||||
{
|
// {
|
||||||
AddressChanged?.Invoke(UrlTextBox.Text);
|
// AddressChanged?.Invoke(UrlTextBox.Text);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
private void ApplySettings()
|
//private void ApplySettings()
|
||||||
{
|
//{
|
||||||
if (IsMainWindow && settings.FullScreenMode)
|
// if (IsMainWindow && settings.FullScreenMode)
|
||||||
{
|
// {
|
||||||
MaxHeight = SystemParameters.WorkArea.Height;
|
// MaxHeight = SystemParameters.WorkArea.Height;
|
||||||
ResizeMode = ResizeMode.NoResize;
|
// ResizeMode = ResizeMode.NoResize;
|
||||||
WindowState = WindowState.Maximized;
|
// WindowState = WindowState.Maximized;
|
||||||
WindowStyle = WindowStyle.None;
|
// WindowStyle = WindowStyle.None;
|
||||||
}
|
// }
|
||||||
|
|
||||||
UrlTextBox.IsEnabled = settings.AllowAddressBar;
|
// UrlTextBox.IsEnabled = settings.AllowAddressBar;
|
||||||
|
|
||||||
ReloadButton.IsEnabled = settings.AllowReloading;
|
// ReloadButton.IsEnabled = settings.AllowReloading;
|
||||||
ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
|
// ReloadButton.Visibility = settings.AllowReloading ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
BackButton.IsEnabled = settings.AllowBackwardNavigation;
|
// BackButton.IsEnabled = settings.AllowBackwardNavigation;
|
||||||
BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
// BackButton.Visibility = settings.AllowBackwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
ForwardButton.IsEnabled = settings.AllowForwardNavigation;
|
// ForwardButton.IsEnabled = settings.AllowForwardNavigation;
|
||||||
ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
// ForwardButton.Visibility = settings.AllowForwardNavigation ? Visibility.Visible : Visibility.Collapsed;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ namespace SafeExamBrowser.UserInterface.Windows10
|
||||||
|
|
||||||
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings)
|
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)
|
public IWindow CreateLogWindow(ILogger logger)
|
||||||
|
|
Loading…
Reference in a new issue