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/Views | |
| 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/Views')
4 files changed, 144 insertions, 94 deletions
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(); - } - } -} |
