-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathultralight_controller.h
More file actions
161 lines (138 loc) · 6.31 KB
/
Copy pathultralight_controller.h
File metadata and controls
161 lines (138 loc) · 6.31 KB
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
152
153
154
155
156
157
158
159
160
161
#pragma once
#include <AppCore/AppCore.h>
#include <Ultralight/ConsoleMessage.h>
#include <Ultralight/Ultralight.h>
#include <d3d11.h>
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <wrl/client.h>
using JSCallbackFunc = std::function<void(const ultralight::JSObject &, const ultralight::JSArgs &)>;
using JSCallbackFuncWithRet =
std::function<ultralight::JSValue(const ultralight::JSObject &, const ultralight::JSArgs &)>;
class UltralightController : public ultralight::ViewListener, public ultralight::LoadListener
{
Microsoft::WRL::ComPtr<ID3D11Device> device_;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context_;
ultralight::RefPtr<ultralight::Renderer> renderer_;
ultralight::RefPtr<ultralight::View> view_;
bool needs_texture_update_ = false;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture_view_ = nullptr;
int width_ = 0;
int height_ = 0;
std::map<std::string, JSCallbackFunc> callbacks_;
std::map<std::string, JSCallbackFuncWithRet> callbacks_with_ret_;
public:
UltralightController(ID3D11Device *device, ID3D11DeviceContext *context);
~UltralightController();
ID3D11ShaderResourceView *getTextureView()
{
return texture_view_.Get();
}
void LoadHTML(const std::string &html_string);
void Resize(int width, int height);
void Update();
void Render();
void AddCallback(const std::string &name, JSCallbackFunc callback);
void AddCallback(const std::string &name, JSCallbackFuncWithRet callback);
ID3D11ShaderResourceView *GetTexture()
{
return texture_view_.Get();
}
int GetWidth() const
{
return width_;
}
int GetHeight() const
{
return height_;
}
bool IsLoaded() const
{
return view_ && !view_->is_loading();
}
bool IsRendererValid() const
{
return renderer_.get() != nullptr;
}
ultralight::View *GetView()
{
return view_.get();
}
void init();
void setCachePath(const std::string &path);
void setResourcePrefix(const std::string &prefix);
void setFaceWinding(ultralight::FaceWinding winding);
void setFontHinting(ultralight::FontHinting hinting);
void setFontGamma(double gamma);
void setUserCSS(const std::string &css);
void forceRepaint(bool force);
void setAnimTimerDelay(double delay);
void setScrollTimerDelay(double delay);
void setRecycleDelay(double delay);
void setMemCacheSize(uint32_t size);
void setPageCacheSize(uint32_t size);
void setRAMOverride(uint32_t size);
void setMinLargeHeap(uint32_t size);
void setMinSmallHeap(uint32_t size);
void setRenderThreads(uint32_t num_threads);
void setMaxUpdateTime(double time);
void setBitmapAlign(uint32_t alignment);
void setEffectQuality(ultralight::EffectQuality quality);
std::optional<std::string> evalScript(const std::string &script);
bool checkScriptSyntax(const std::string &script);
void forceGC();
JSValueRef createJSString(const std::string &str);
JSValueRef createJSNumber(double num);
JSValueRef createJSBoolean(bool val);
JSValueRef createJSNull();
JSValueRef createJSUndefined();
std::string jsValueToCppString(JSValueRef val);
double jsValueToNumber(JSValueRef val, std::string &err);
bool jsValueToBoolean(JSValueRef val);
JSType getJSValueType(JSValueRef val);
bool isValueUndefined(JSValueRef val);
bool isValueNull(JSValueRef val);
bool isValueBoolean(JSValueRef val);
bool isValueNumber(JSValueRef val);
bool isValueString(JSValueRef val);
bool isValueObject(JSValueRef val);
bool hasProperty(JSObjectRef obj, const std::string &propName);
JSValueRef getProperty(JSObjectRef obj, const std::string &propName, std::string &err);
void setProperty(JSObjectRef obj, const std::string &propName, JSValueRef val, std::string &err);
bool deleteProperty(JSObjectRef obj, const std::string &propName, std::string &err);
std::vector<std::string> getPropertyNames(JSObjectRef obj);
JSValueRef callFunction(JSObjectRef func, JSObjectRef thisObj, const std::vector<JSValueRef> &args,
std::string &err);
JSObjectRef createTypedArray(JSTypedArrayType arrayType, size_t length, std::string &err);
JSObjectRef createTypedArrayWithBytes(JSTypedArrayType arrayType, void *bytes, size_t byteLength, std::string &err);
JSObjectRef createArrayBufferWithBytes(void *bytes, size_t byteLength, std::string &err);
void *getTypedArrayBytes(JSObjectRef object, std::string &err);
size_t getTypedArrayLength(JSObjectRef object, std::string &err);
size_t getTypedArrayByteLength(JSObjectRef object, std::string &err);
JSObjectRef getTypedArrayBuffer(JSObjectRef object, std::string &err);
JSContextRef getJSContext();
private:
ultralight::Config config_;
protected:
void BindCallbacks();
void UpdateTexture();
void OnChangeTitle(ultralight::View *caller, const ultralight::String &title) override;
void OnChangeURL(ultralight::View *caller, const ultralight::String &url) override;
void OnChangeTooltip(ultralight::View *caller, const ultralight::String &tooltip) override;
void OnChangeCursor(ultralight::View *caller, ultralight::Cursor cursor) override;
void OnAddConsoleMessage(ultralight::View *caller, const ultralight::ConsoleMessage &message) override;
void OnBeginLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame,
const ultralight::String &url) override;
void OnFinishLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame,
const ultralight::String &url) override;
void OnFailLoading(ultralight::View *caller, uint64_t frame_id, bool is_main_frame, const ultralight::String &url,
const ultralight::String &description, const ultralight::String &error_domain,
int error_code) override;
void OnDOMReady(ultralight::View *caller, uint64_t frame_id, bool is_main_frame,
const ultralight::String &url) override;
std::string jsValueToErrorString(JSValueRef err);
};