aboutsummaryrefslogtreecommitdiffstats
path: root/support/hololens/ServoApp/BrowserPage.h
blob: a5ad43b4286d5250c85a01dddf25644cb69e20d9 (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#pragma once

#include "BrowserPage.g.h"
#include "ConsoleLog.g.h"
#include "ServoControl/ServoControl.h"
#include "Devtools/Client.h"

namespace winrt::ServoApp::implementation {

using namespace winrt::Windows;
using namespace winrt::Windows::Data::Json;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Media;

static const hstring FXR_SCHEME = L"fxr";
static const hstring FXR_SCHEME_SLASH_SLASH = L"fxr://";
static const hstring FXRMIN_SCHEME = L"fxrmin";
static const hstring FXRMIN_SCHEME_SLASH_SLASH = L"fxrmin://";

struct BrowserPage : BrowserPageT<BrowserPage>, public servo::DevtoolsDelegate {
public:
  BrowserPage();

  void OnForwardButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnBackButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnReloadButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnStopButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnHomeButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnDevtoolsButtonClicked(IInspectable const &, RoutedEventArgs const &);
  void OnJSInputEdited(IInspectable const &, Input::KeyRoutedEventArgs const &);
  void OnURLEdited(IInspectable const &, Input::KeyRoutedEventArgs const &);
  void OnURLFocused(IInspectable const &);
  void
  OnURLKeyboardAccelerator(IInspectable const &,
                           Input::KeyboardAcceleratorInvokedEventArgs const &);
  void Shutdown();
  void LoadFXRURI(Uri uri);
  void SetArgs(hstring);
  void OnDismissCrashReport(IInspectable const &, RoutedEventArgs const &);
  void OnSubmitCrashReport(IInspectable const &, RoutedEventArgs const &);
  void OnMediaControlsPlayClicked(IInspectable const &,
                                  RoutedEventArgs const &);
  void OnMediaControlsPauseClicked(IInspectable const &,
                                   RoutedEventArgs const &);
  void OnPrefererenceSearchboxEdited(IInspectable const &,
                                     Input::KeyRoutedEventArgs const &);
  void OnDevtoolsMessage(servo::DevtoolsMessageLevel, hstring, hstring);
  void ClearConsole();
  void OnDevtoolsDetached();
  Collections::IObservableVector<IInspectable> ConsoleLogs() { return mLogs; };

private:
  void SetTransientMode(bool);
  void UpdatePref(ServoApp::Pref, Controls::Control);
  void CheckCrashReport();
  void BindServoEvents();
  void BuildPrefList();
  void ShowToolbox();
  void HideToolbox();
  DevtoolsStatus mDevtoolsStatus = DevtoolsStatus::Stopped;
  unsigned int mDevtoolsPort = 0;
  hstring mDevtoolsToken;
  bool mPanicking = false;
  std::unique_ptr<servo::DevtoolsClient> mDevtoolsClient;
  Collections::IObservableVector<IInspectable> mLogs;
};

struct ConsoleLog : ConsoleLogT<ConsoleLog> {
public:
  ConsoleLog(Windows::UI::Color glyph, hstring g, hstring b, hstring s)
      : mGlyph(g), mSource(s), mBody(b) {
    mGlyphColor = UI::Xaml::Media::SolidColorBrush(glyph);
  };
  SolidColorBrush GlyphColor() { return mGlyphColor; };
  hstring Glyph() { return mGlyph; };
  hstring Source() { return mSource; };
  hstring Body() { return mBody; };

private:
  SolidColorBrush mGlyphColor;
  hstring mGlyph;
  hstring mSource;
  hstring mBody;
};

} // namespace winrt::ServoApp::implementation

namespace winrt::ServoApp::factory_implementation {
struct BrowserPage : BrowserPageT<BrowserPage, implementation::BrowserPage> {};
struct ConsoleLog : ConsoleLogT<ConsoleLog, implementation::ConsoleLog> {};
} // namespace winrt::ServoApp::factory_implementation