diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-12 13:00:45 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-12-12 13:00:45 +0200 |
| commit | 5fdb4170c92072fa5a3ee32a779bea2ed83b8ef0 (patch) | |
| tree | 231e9b316e3b1f30c815d9bcec5d8b7815625201 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser | |
| parent | 217fcb79fa32f858a06d8200697ddee7c5da625a (diff) | |
| download | Tango-5fdb4170c92072fa5a3ee32a779bea2ed83b8ef0.tar.gz Tango-5fdb4170c92072fa5a3ee32a779bea2ed83b8ef0.zip | |
Added more functionality to browser module.
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser')
15 files changed, 493 insertions, 168 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs new file mode 100644 index 000000000..b4e822f1e --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Attributes/BoundObjectAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Browser.Attributes +{ + public class BoundObjectAttribute : Attribute + { + public String Name { get; set; } + public String ScriptFile { get; set; } + + public BoundObjectAttribute(String name,String scriptFile) + { + Name = name; + ScriptFile = scriptFile; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs index 8743fa054..50df8ae0c 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/MainBound.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BoundsObjects/KeyboardHandler.cs @@ -5,11 +5,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using Tango.PPC.Browser.Attributes; +using Tango.PPC.Common.Helpers; using Tango.Touch.Keyboard; namespace Tango.PPC.Browser.BoundsObjects { - public class MainBound + [BoundObject("keyboard", "keyboard.js")] + public class KeyboardHandler { public void openKeyboard(String inputType) { @@ -18,13 +21,12 @@ namespace Tango.PPC.Browser.BoundsObjects switch (inputType) { case "search": - KeyboardView.Keyboard.ActionKeyMode = KeyboardActionKeyMode.Go; + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); break; default: - KeyboardView.Keyboard.ActionKeyMode = KeyboardActionKeyMode.Next; + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Next); break; } - KeyboardView.Default.IsOpened = true; })); } @@ -32,7 +34,7 @@ namespace Tango.PPC.Browser.BoundsObjects { Application.Current.Dispatcher.BeginInvoke(new Action(() => { - KeyboardView.Default.IsOpened = false; + KeyboardHelper.CloseKeyboard(); })); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs index 51384ae54..a73700fef 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/BrowserModule.cs @@ -66,7 +66,7 @@ namespace Tango.PPC.Browser { get { - return typeof(MainView); + return typeof(BrowserView); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs new file mode 100644 index 000000000..fe68ee848 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Helpers/BoundObjectsHelper.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using Tango.PPC.Browser.Attributes; +using CefSharp; +using CefSharp.Wpf; +using Tango.Core.Helpers; +using System.Windows.Threading; + +namespace Tango.PPC.Browser.Helpers +{ + public static class BoundObjectsHelper + { + private static DispatcherTimer _timer; + private static Dispatcher _dispatcher; + private static ChromiumWebBrowser _browser; + + private static List<String> _scripts = new List<string>(); + + public static void RegisterAllBoundObjects(ChromiumWebBrowser browser, Dispatcher dispatcher) + { + _dispatcher = dispatcher; + _browser = browser; + + _timer = new DispatcherTimer(DispatcherPriority.Background, dispatcher); + _timer.Tick += _timer_Tick; + _timer.Interval = TimeSpan.FromSeconds(2); + _timer.Stop(); + + foreach (var type in typeof(BoundObjectsHelper).Assembly.GetTypes().Where(x => x.GetCustomAttribute<BoundObjectAttribute>() != null)) + { + var att = type.GetCustomAttribute<BoundObjectAttribute>(); + + var script = EmbeddedResourceHelper.GetEmbeddedResourceText($"Tango.PPC.Browser.Scripts.{att.ScriptFile}"); + _scripts.Add(script); + + browser.JavascriptObjectRepository.Register(att.Name, Activator.CreateInstance(type), true); + + browser.FrameLoadEnd += Browser_FrameLoadEnd; + } + } + + private static void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) + { + _timer.Stop(); + _timer.Start(); + } + + private static void _timer_Tick(object sender, EventArgs e) + { + try + { + _timer.Stop(); + + _dispatcher.BeginInvoke(new Action(() => + { + foreach (var script in _scripts) + { + _browser.GetMainFrame().ExecuteJavaScriptAsync(script); + } + })); + } + catch + { + _timer.Start(); + } + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs new file mode 100644 index 000000000..fc6cb119c --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/RequestHandlers/ChromiumRequestHandler.cs @@ -0,0 +1,114 @@ +using CefSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Browser.RequestHandlers +{ + public class ChromiumRequestHandler : IRequestHandler + { + public event EventHandler<String> AddressChanged; + + public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) + { + return false; + } + + public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect) + { + // You can check the Request object for the URL Here + return false; + } + + public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback) + { + // You can also check the URL here + callback.Dispose(); + return CefReturnValue.Continue; + } + + public bool OnCertificateError(IWebBrowser browserControl, IBrowser browser, CefErrorCode errorCode, string requestUrl, ISslInfo sslInfo, IRequestCallback callback) + { + callback.Dispose(); + return false; + } + + public bool OnOpenUrlFromTab(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, WindowOpenDisposition targetDisposition, bool userGesture) + { + return false; + } + + public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath) + { + } + + public bool OnProtocolExecution(IWebBrowser browserControl, IBrowser browser, string url) + { + return false; + } + + public bool OnQuotaRequest(IWebBrowser browserControl, IBrowser browser, string originUrl, long newSize, IRequestCallback callback) + { + callback.Dispose(); + return false; + } + + public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status) + { + } + + public void OnRenderViewReady(IWebBrowser browserControl, IBrowser browser) + { + } + + public void OnResourceLoadComplete(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength) + { + // You can also check the request URL here + } + + public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, ref string newUrl) + { + } + + public bool OnResourceResponse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + { + return false; + } + + + public IResponseFilter GetResourceResponseFilter(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response) + { + return null; + } + + + public void OnResourceRedirect(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IResponse response, ref string newUrl) + { + } + + public bool OnSelectClientCertificate(IWebBrowser browserControl, IBrowser browser, bool isProxy, string host, int port, System.Security.Cryptography.X509Certificates.X509Certificate2Collection certificates, ISelectClientCertificateCallback callback) + { + callback.Dispose(); + return false; + } + + public bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) + { + AddressChanged?.Invoke(this, request.Url); + return false; + } + + public IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling) + { + return null; + } + + public bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback) + { + callback.Dispose(); + return false; + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js index c43e0e272..21771eb8e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/main.js +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Scripts/keyboard.js @@ -1,5 +1,5 @@ (async function () { - await CefSharp.BindObjectAsync("boundAsync", "bound"); + await CefSharp.BindObjectAsync("keyboard", "bound"); var inputs = document.getElementsByTagName('input'); var i = 0; @@ -10,10 +10,10 @@ if (type == 'text' || type == 'email' || type == 'password' || type == 'search' || type == 'date' || type == 'url' || type == 'time' || type == 'tel' || type == 'number') { inputs[i].onfocus = function () { - boundAsync.openKeyboard(type); + keyboard.openKeyboard(type); } inputs[i].onblur = function () { - boundAsync.closeKeyboard(); + keyboard.closeKeyboard(); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj index eb85fefa5..c799887a2 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Tango.PPC.Browser.csproj @@ -76,7 +76,7 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> - <Page Include="Views\MainView.xaml"> + <Page Include="Views\BrowserView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> @@ -85,8 +85,10 @@ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> - <Compile Include="BoundsObjects\MainBound.cs" /> + <Compile Include="Attributes\BoundObjectAttribute.cs" /> + <Compile Include="BoundsObjects\KeyboardHandler.cs" /> <Compile Include="BrowserModule.cs" /> + <Compile Include="Helpers\BoundObjectsHelper.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> @@ -100,10 +102,12 @@ <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> + <Compile Include="RequestHandlers\ChromiumRequestHandler.cs" /> + <Compile Include="ViewContracts\IBrowserView.cs" /> <Compile Include="ViewModelLocator.cs" /> - <Compile Include="ViewModels\MainViewVM.cs" /> - <Compile Include="Views\MainView.xaml.cs"> - <DependentUpon>MainView.xaml</DependentUpon> + <Compile Include="ViewModels\BrowserViewVM.cs" /> + <Compile Include="Views\BrowserView.xaml.cs"> + <DependentUpon>BrowserView.xaml</DependentUpon> </Compile> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> @@ -163,7 +167,7 @@ <Resource Include="Images\browser.png" /> </ItemGroup> <ItemGroup> - <EmbeddedResource Include="Scripts\main.js" /> + <EmbeddedResource Include="Scripts\keyboard.js" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs new file mode 100644 index 000000000..8369209a3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewContracts/IBrowserView.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; +using Tango.SharedUI; + +namespace Tango.PPC.Browser.ViewContracts +{ + public interface IBrowserView : IPPCView + { + event EventHandler<String> AddressChanged; + bool CanGoBack(); + void NavigateTo(String address); + void GoBack(); + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs index 30f936433..054310e99 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModelLocator.cs @@ -15,17 +15,17 @@ namespace Tango.PPC.Browser /// </summary> static ViewModelLocator() { - TangoIOC.Default.Register<MainViewVM>(); + TangoIOC.Default.Register<BrowserViewVM>(); } /// <summary> /// Gets the main view VM. /// </summary> - public static MainViewVM MainViewVM + public static BrowserViewVM BrowserViewVM { get { - return TangoIOC.Default.GetInstance<MainViewVM>(); + return TangoIOC.Default.GetInstance<BrowserViewVM>(); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs new file mode 100644 index 000000000..f24301257 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/BrowserViewVM.cs @@ -0,0 +1,101 @@ +using CefSharp; +using CefSharp.Wpf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.PPC.Browser.ViewContracts; +using Tango.PPC.Common; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Browser.ViewModels +{ + /// <summary> + /// Represents the main view VM and entry point for <see cref="Synchronization.MyModule"/>. + /// </summary> + /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> + public class BrowserViewVM : PPCViewModel<IBrowserView> + { + private String _address; + public String Address + { + get { return _address; } + set { _address = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand GoCommand { get; set; } + + public BrowserViewVM() + { + if (!DesignMode) + { + try + { + var settings = new CefSettings(); + settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; + settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; + + Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); + } + catch (Exception ex) + { + //Log Here Not Throw! + throw; + } + } + + GoCommand = new RelayCommand(Go); + } + + public override void OnViewAttached() + { + base.OnViewAttached(); + View.AddressChanged += View_AddressChanged; + } + + private void View_AddressChanged(object sender, string address) + { + Address = address; + } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; + } + + public override void OnNavigatedFrom() + { + base.OnNavigatedFrom(); + KeyboardView.Default.OutputMode = KeyboardOutputMode.Wpf; + } + + public override Task<bool> OnNavigateBackRequest() + { + if (View.CanGoBack()) + { + View.GoBack(); + return Task.FromResult(false); + } + else + { + return Task.FromResult(true); + } + } + + /// <summary> + /// Called when the application has been started + /// </summary> + public override void OnApplicationStarted() + { + + } + + private void Go() + { + View.NavigateTo(Address); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs deleted file mode 100644 index afea97f73..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/ViewModels/MainViewVM.cs +++ /dev/null @@ -1,56 +0,0 @@ -using CefSharp; -using CefSharp.Wpf; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common; -using Tango.Touch.Keyboard; - -namespace Tango.PPC.Browser.ViewModels -{ - /// <summary> - /// Represents the main view VM and entry point for <see cref="Synchronization.MyModule"/>. - /// </summary> - /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> - public class MainViewVM : PPCViewModel - { - public MainViewVM() - { - try - { - var settings = new CefSettings(); - settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"; - settings.UserAgent = "Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; - - Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null); - } - catch (Exception ex) - { - //Log Here Not Throw! - throw; - } - } - - public override void OnNavigatedTo() - { - base.OnNavigatedTo(); - KeyboardView.Default.OutputMode = KeyboardOutputMode.Windows; - } - - public override void OnNavigatedFrom() - { - base.OnNavigatedFrom(); - KeyboardView.Default.OutputMode = KeyboardOutputMode.Wpf; - } - - /// <summary> - /// Called when the application has been started - /// </summary> - public override void OnApplicationStarted() - { - - } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml new file mode 100644 index 000000000..7b5854101 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml @@ -0,0 +1,29 @@ +<UserControl x:Class="Tango.PPC.Browser.Views.BrowserView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:vm="clr-namespace:Tango.PPC.Browser.ViewModels" + xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" + xmlns:global="clr-namespace:Tango.PPC.Browser" + xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" + xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" + xmlns:local="clr-namespace:Tango.PPC.Browser.Views" + mc:Ignorable="d" + d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:BrowserViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.BrowserViewVM}" Background="{StaticResource TangoPrimaryBackgroundBrush}"> + <Grid> + <DockPanel> + <Border DockPanel.Dock="Top" Padding="10" BorderBrush="{StaticResource TangoGrayBrush}" BorderThickness="0 0 0 1"> + <DockPanel> + <touch:TouchButton Command="{Binding GoCommand}" DockPanel.Dock="Right" Padding="10" Width="150" CornerRadius="20" Margin="20 0 0 0"> + <touch:TouchIcon Icon="ArrowRightBold" Height="20" /> + </touch:TouchButton> + <Border Background="{StaticResource TangoMidBackgroundBrush}" Padding="2" BorderBrush="{StaticResource TangoLightBorderBrush}" BorderThickness="1" CornerRadius="15"> + <TextBox x:Name="txtAddress" GotFocus="TxtAddress_GotFocus" PreviewMouseUp="TxtAddress_MouseUp" LostFocus="TxtAddress_LostFocus" KeyDown="TxtAddress_KeyDown" VerticalContentAlignment="Center" Text="{Binding Address,UpdateSourceTrigger=PropertyChanged}" BorderThickness="0" FontSize="{StaticResource TangoDefaultFontSize}" Padding="5" Background="Transparent"></TextBox> + </Border> + </DockPanel> + </Border> + <wpf:ChromiumWebBrowser x:Name="Browser" Address="http://www.google.com" /> + </DockPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs new file mode 100644 index 000000000..2717c77d3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/BrowserView.xaml.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using CefSharp; +using CefSharp.Wpf; +using Tango.Core.DI; +using Tango.Core.Helpers; +using Tango.PPC.Browser.BoundsObjects; +using Tango.PPC.Browser.ViewContracts; +using Tango.PPC.Common.Helpers; +using Tango.Touch.Keyboard; + +namespace Tango.PPC.Browser.Views +{ + /// <summary> + /// Interaction logic for MainView.xaml + /// </summary> + public partial class BrowserView : UserControl, IBrowserView + { + public event EventHandler<string> AddressChanged; + + public BrowserView() + { + InitializeComponent(); + + TangoIOC.Default.Register<IBrowserView>(this); + + Helpers.BoundObjectsHelper.RegisterAllBoundObjects(Browser, Dispatcher); + + KeyboardView.Default.KeyboardOpened += Default_KeyboardOpened; + KeyboardView.Default.KeyboardClosed += Default_KeyboardClosed; + + var handler = new RequestHandlers.ChromiumRequestHandler(); + handler.AddressChanged += Handler_AddressChanged; + Browser.RequestHandler = handler; + } + + private void Handler_AddressChanged(object sender, string e) + { + Dispatcher.BeginInvoke(new Action(() => + { + AddressChanged?.Invoke(this, Browser.Address); + })); + } + + private void Default_KeyboardClosed(object sender, EventArgs e) + { + Browser.VerticalAlignment = VerticalAlignment.Stretch; + Browser.Height = double.NaN; + } + + private void Default_KeyboardOpened(object sender, EventArgs e) + { + Browser.VerticalAlignment = VerticalAlignment.Top; + Browser.Height = 780; + } + + public bool CanGoBack() + { + return Browser.CanGoBack; + } + + public void NavigateTo(string address) + { + Browser.Address = address; + } + + public void GoBack() + { + if (Browser.CanGoBack) + { + Browser.Back(); + } + } + + private async void TxtAddress_GotFocus(object sender, RoutedEventArgs e) + { + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + await Task.Delay(100); + txtAddress.SelectAll(); + } + + private void TxtAddress_LostFocus(object sender, RoutedEventArgs e) + { + KeyboardHelper.CloseKeyboard(); + } + + private void TxtAddress_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Return) + { + KeyboardHelper.CloseKeyboard(); + NavigateTo(txtAddress.Text); + } + } + + private void TxtAddress_MouseUp(object sender, MouseButtonEventArgs e) + { + KeyboardHelper.OpenKeyboard(KeyboardActionKeyMode.Go); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml deleted file mode 100644 index 903e21cce..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml +++ /dev/null @@ -1,15 +0,0 @@ -<UserControl x:Class="Tango.PPC.Browser.Views.MainView" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:vm="clr-namespace:Tango.PPC.Browser.ViewModels" - xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" - xmlns:global="clr-namespace:Tango.PPC.Browser" - xmlns:local="clr-namespace:Tango.PPC.Browser.Views" - mc:Ignorable="d" - d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}"> - <Grid> - <wpf:ChromiumWebBrowser x:Name="Browser" Address="http://www.google.com" /> - </Grid> -</UserControl> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs deleted file mode 100644 index 917d16e49..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Windows.Threading; -using CefSharp; -using CefSharp.Wpf; -using Tango.Core.Helpers; -using Tango.PPC.Browser.BoundsObjects; -using Tango.Touch.Keyboard; - -namespace Tango.PPC.Browser.Views -{ - /// <summary> - /// Interaction logic for MainView.xaml - /// </summary> - public partial class MainView : UserControl - { - private DispatcherTimer _timer; - - public MainView() - { - InitializeComponent(); - - _timer = new DispatcherTimer(); - _timer.Tick += _timer_Tick; - _timer.Interval = TimeSpan.FromSeconds(2); - _timer.Stop(); - - Browser.JavascriptObjectRepository.Register("boundAsync", new MainBound(), true); - Browser.FrameLoadEnd += Browser_FrameLoadEnd; - - KeyboardView.Default.KeyboardOpened += Default_KeyboardOpened; - KeyboardView.Default.KeyboardClosed += Default_KeyboardClosed; - } - - private void Default_KeyboardClosed(object sender, EventArgs e) - { - Debug.WriteLine("Closed"); - Browser.VerticalAlignment = VerticalAlignment.Stretch; - Browser.Height = double.NaN; - } - - private void Default_KeyboardOpened(object sender, EventArgs e) - { - Debug.WriteLine("Opened"); - Browser.VerticalAlignment = VerticalAlignment.Top; - Browser.Height = 780; - } - - private void _timer_Tick(object sender, EventArgs e) - { - _timer.Stop(); - - Dispatcher.BeginInvoke(new Action(() => - { - var script = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.PPC.Browser.Scripts.main.js"); - Browser.ExecuteScriptAsync(script); - })); - } - - private void Browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) - { - _timer.Stop(); - _timer.Start(); - } - } -} |
