aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Browser/Views/MainView.xaml.cs
blob: 917d16e492448a07436d2b6c56973802eb2c62e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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();
        }
    }
}