/
ServoControl.h
151 lines (126 loc) · 4.82 KB
/
ServoControl.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include "ServoControl.g.h"
#include "OpenGLES.h"
#include "Servo.h"
#include "DefaultUrl.h"
namespace winrt::ServoApp::implementation {
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
ServoControl();
void GoBack();
void GoForward();
void Reload();
void Stop();
void Shutdown();
Windows::Foundation::Uri LoadURIOrSearch(hstring);
void OnLoaded(IInspectable const &,
Windows::UI::Xaml::RoutedEventArgs const &);
winrt::event_token
OnURLChanged(Windows::Foundation::EventHandler<hstring> const &handler) {
return mOnURLChangedEvent.add(handler);
};
void OnURLChanged(winrt::event_token const &token) noexcept {
mOnURLChangedEvent.remove(token);
}
winrt::event_token
OnTitleChanged(Windows::Foundation::EventHandler<hstring> const &handler) {
return mOnTitleChangedEvent.add(handler);
};
void OnTitleChanged(winrt::event_token const &token) noexcept {
mOnTitleChangedEvent.remove(token);
}
winrt::event_token OnHistoryChanged(HistoryChangedDelegate const &handler) {
return mOnHistoryChangedEvent.add(handler);
};
void OnHistoryChanged(winrt::event_token const &token) noexcept {
mOnHistoryChangedEvent.remove(token);
}
winrt::event_token OnLoadStarted(EventDelegate const &handler) {
return mOnLoadStartedEvent.add(handler);
};
void OnLoadStarted(winrt::event_token const &token) noexcept {
mOnLoadStartedEvent.remove(token);
}
winrt::event_token OnLoadEnded(EventDelegate const &handler) {
return mOnLoadEndedEvent.add(handler);
};
void OnLoadEnded(winrt::event_token const &token) noexcept {
mOnLoadEndedEvent.remove(token);
}
winrt::event_token OnCaptureGesturesStarted(EventDelegate const &handler) {
return mOnCaptureGesturesStartedEvent.add(handler);
};
void OnCaptureGesturesStarted(winrt::event_token const &token) noexcept {
mOnCaptureGesturesStartedEvent.remove(token);
}
winrt::event_token OnCaptureGesturesEnded(EventDelegate const &handler) {
return mOnCaptureGesturesEndedEvent.add(handler);
};
void OnCaptureGesturesEnded(winrt::event_token const &token) noexcept {
mOnCaptureGesturesEndedEvent.remove(token);
}
void SetTransientMode(bool transient) { mTransient = transient; }
void SetArgs(hstring args) { mArgs = args; }
virtual void WakeUp();
virtual void OnServoLoadStarted();
virtual void OnServoLoadEnded();
virtual void OnServoHistoryChanged(bool, bool);
virtual void OnServoShutdownComplete();
virtual void OnServoTitleChanged(winrt::hstring);
virtual void OnServoAlert(winrt::hstring);
virtual void OnServoURLChanged(winrt::hstring);
virtual void Flush();
virtual void MakeCurrent();
virtual bool OnServoAllowNavigation(winrt::hstring);
virtual void OnServoAnimatingChanged(bool);
virtual void OnServoIMEStateChanged(bool);
private:
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent;
winrt::event<Windows::Foundation::EventHandler<hstring>> mOnTitleChangedEvent;
winrt::event<HistoryChangedDelegate> mOnHistoryChangedEvent;
winrt::event<EventDelegate> mOnLoadStartedEvent;
winrt::event<EventDelegate> mOnLoadEndedEvent;
winrt::event<EventDelegate> mOnCaptureGesturesStartedEvent;
winrt::event<EventDelegate> mOnCaptureGesturesEndedEvent;
float mDPI = 1;
hstring mInitialURL = DEFAULT_URL;
bool mTransient = false;
Windows::UI::Xaml::Controls::SwapChainPanel ServoControl::Panel();
void CreateRenderSurface();
void DestroyRenderSurface();
void RecoverFromLostDevice();
void StartRenderLoop();
void StopRenderLoop();
void Loop();
std::optional<Windows::Foundation::Uri> TryParseURI(hstring input) {
try {
return Windows::Foundation::Uri(input);
} catch (hresult_invalid_argument const &) {
return {};
}
}
void
OnSurfaceClicked(IInspectable const &,
Windows::UI::Xaml::Input::TappedRoutedEventArgs const &);
void OnSurfaceManipulationDelta(
IInspectable const &,
Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &);
void OnSurfaceResized(IInspectable const &,
Windows::UI::Xaml::SizeChangedEventArgs const &);
template <typename Callable> void RunOnUIThread(Callable);
void RunOnGLThread(std::function<void()>);
std::unique_ptr<servo::Servo> mServo;
EGLSurface mRenderSurface{EGL_NO_SURFACE};
OpenGLES mOpenGLES;
bool mAnimating = false;
bool mLooping = false;
std::vector<std::function<void()>> mTasks;
CRITICAL_SECTION mGLLock;
CONDITION_VARIABLE mGLCondVar;
std::unique_ptr<Concurrency::task<void>> mLoopTask;
hstring mArgs;
};
} // namespace winrt::ServoApp::implementation
namespace winrt::ServoApp::factory_implementation {
struct ServoControl
: ServoControlT<ServoControl, implementation::ServoControl> {};
} // namespace winrt::ServoApp::factory_implementation