forked from LeenkxTeam/LNXRNT
192 lines
7.9 KiB
C
192 lines
7.9 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#ifdef WITH_WEBVIEW
|
||
|
|
|
||
|
|
#include <map>
|
||
|
|
#include <memory>
|
||
|
|
#include <string>
|
||
|
|
#include <v8.h>
|
||
|
|
|
||
|
|
struct WebViewInstance {
|
||
|
|
int id;
|
||
|
|
int parentWindow; // -1 means detached as its own OS window, >= 0 = child of Kinc window
|
||
|
|
int x, y;
|
||
|
|
int width, height; // -1 means fill parent window for embedded mode only
|
||
|
|
bool autoResize; // true if width or height was -1 at creation
|
||
|
|
bool transparent;
|
||
|
|
bool clickThrough;
|
||
|
|
bool visible;
|
||
|
|
std::string title;
|
||
|
|
|
||
|
|
void* platformHandle;
|
||
|
|
void* platformWindow;
|
||
|
|
|
||
|
|
v8::Isolate* isolate;
|
||
|
|
v8::Global<v8::Context> context;
|
||
|
|
v8::Global<v8::Function> onMessage;
|
||
|
|
v8::Global<v8::Function> onLoad;
|
||
|
|
v8::Global<v8::Function> onError;
|
||
|
|
v8::Global<v8::Function> onClose;
|
||
|
|
v8::Global<v8::Function> onEvalResult;
|
||
|
|
|
||
|
|
WebViewInstance() : id(-1), parentWindow(-1), x(0), y(0),
|
||
|
|
width(800), height(600), autoResize(false), transparent(true),
|
||
|
|
clickThrough(false), visible(false), platformHandle(nullptr),
|
||
|
|
platformWindow(nullptr), isolate(nullptr) {}
|
||
|
|
};
|
||
|
|
|
||
|
|
class WebViewManager {
|
||
|
|
public:
|
||
|
|
static WebViewManager& instance();
|
||
|
|
|
||
|
|
int create(v8::Isolate* isolate, v8::Local<v8::Context> context,
|
||
|
|
int parentWindow, int x, int y, int width, int height,
|
||
|
|
bool transparent, const std::string& title);
|
||
|
|
void destroy(int id);
|
||
|
|
bool isValid(int id);
|
||
|
|
int count();
|
||
|
|
|
||
|
|
void loadHTML(int id, const std::string& html);
|
||
|
|
void loadURL(int id, const std::string& url);
|
||
|
|
void evalJS(int id, const std::string& js);
|
||
|
|
void evalJSAsync(int id, v8::Isolate* isolate, v8::Local<v8::Function> callback, const std::string& js);
|
||
|
|
|
||
|
|
void setActiveDOM(int id, v8::Isolate* isolate);
|
||
|
|
int getActiveDOM();
|
||
|
|
|
||
|
|
void show(int id);
|
||
|
|
void hide(int id);
|
||
|
|
|
||
|
|
void resize(int id, int width, int height);
|
||
|
|
void move(int id, int x, int y);
|
||
|
|
void setBounds(int id, int x, int y, int width, int height);
|
||
|
|
int getX(int id);
|
||
|
|
int getY(int id);
|
||
|
|
int getWidth(int id);
|
||
|
|
int getHeight(int id);
|
||
|
|
|
||
|
|
void setTransparent(int id, bool transparent);
|
||
|
|
void setClickThrough(int id, bool enabled);
|
||
|
|
void setTitle(int id, const std::string& title);
|
||
|
|
|
||
|
|
void send(int id, const std::string& message);
|
||
|
|
|
||
|
|
void goBack(int id);
|
||
|
|
void goForward(int id);
|
||
|
|
void reload(int id);
|
||
|
|
bool canGoBack(int id);
|
||
|
|
bool canGoForward(int id);
|
||
|
|
std::string getURL(int id);
|
||
|
|
std::string getPageTitle(int id);
|
||
|
|
|
||
|
|
void minimize(int id);
|
||
|
|
void maximize(int id);
|
||
|
|
void restore(int id);
|
||
|
|
void setFullscreen(int id, bool fullscreen);
|
||
|
|
bool isFullscreen(int id);
|
||
|
|
|
||
|
|
void enableDevTools(int id, bool enabled);
|
||
|
|
void setContextMenuEnabled(int id, bool enabled);
|
||
|
|
|
||
|
|
void setOnMessage(int id, v8::Isolate* isolate, v8::Local<v8::Function> cb);
|
||
|
|
void setOnLoad(int id, v8::Isolate* isolate, v8::Local<v8::Function> cb);
|
||
|
|
void setOnError(int id, v8::Isolate* isolate, v8::Local<v8::Function> cb);
|
||
|
|
void setOnClose(int id, v8::Isolate* isolate, v8::Local<v8::Function> cb);
|
||
|
|
|
||
|
|
void dispatchMessage(int id, const std::string& message);
|
||
|
|
void dispatchLoad(int id);
|
||
|
|
void dispatchError(int id, const std::string& error);
|
||
|
|
void dispatchClose(int id);
|
||
|
|
void dispatchEvalResult(int id, const std::string& result);
|
||
|
|
|
||
|
|
void tick();
|
||
|
|
|
||
|
|
void onWindowResize(int windowId, int width, int height);
|
||
|
|
|
||
|
|
private:
|
||
|
|
WebViewManager() = default;
|
||
|
|
~WebViewManager();
|
||
|
|
|
||
|
|
std::map<int, std::unique_ptr<WebViewInstance>> webviews;
|
||
|
|
int nextId = 0;
|
||
|
|
int activeDomId = -1;
|
||
|
|
};
|
||
|
|
|
||
|
|
int platformCreate(WebViewInstance* wv);
|
||
|
|
void platformDestroy(WebViewInstance* wv);
|
||
|
|
void platformLoadHTML(WebViewInstance* wv, const std::string& html);
|
||
|
|
void platformLoadURL(WebViewInstance* wv, const std::string& url);
|
||
|
|
void platformEvalJS(WebViewInstance* wv, const std::string& js);
|
||
|
|
void platformEvalJSAsync(WebViewInstance* wv, const std::string& js);
|
||
|
|
void platformShow(WebViewInstance* wv);
|
||
|
|
void platformHide(WebViewInstance* wv);
|
||
|
|
void platformResize(WebViewInstance* wv, int width, int height);
|
||
|
|
void platformMove(WebViewInstance* wv, int x, int y);
|
||
|
|
void platformSetTransparent(WebViewInstance* wv, bool transparent);
|
||
|
|
void platformSetClickThrough(WebViewInstance* wv, bool enabled);
|
||
|
|
void platformSetTitle(WebViewInstance* wv, const std::string& title);
|
||
|
|
void platformSend(WebViewInstance* wv, const std::string& message);
|
||
|
|
|
||
|
|
void platformGoBack(WebViewInstance* wv);
|
||
|
|
void platformGoForward(WebViewInstance* wv);
|
||
|
|
void platformReload(WebViewInstance* wv);
|
||
|
|
bool platformCanGoBack(WebViewInstance* wv);
|
||
|
|
bool platformCanGoForward(WebViewInstance* wv);
|
||
|
|
std::string platformGetURL(WebViewInstance* wv);
|
||
|
|
std::string platformGetTitle(WebViewInstance* wv);
|
||
|
|
|
||
|
|
void platformMinimize(WebViewInstance* wv);
|
||
|
|
void platformMaximize(WebViewInstance* wv);
|
||
|
|
void platformRestore(WebViewInstance* wv);
|
||
|
|
void platformSetFullscreen(WebViewInstance* wv, bool fullscreen);
|
||
|
|
bool platformIsFullscreen(WebViewInstance* wv);
|
||
|
|
|
||
|
|
void platformEnableDevTools(WebViewInstance* wv, bool enabled);
|
||
|
|
void platformSetContextMenuEnabled(WebViewInstance* wv, bool enabled);
|
||
|
|
|
||
|
|
void platformTick();
|
||
|
|
|
||
|
|
void runt_webview_create(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_load_html(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_load_url(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_eval_js(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_show(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_hide(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_destroy(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_resize(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_move(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_bounds(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_x(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_y(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_width(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_height(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_transparent(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_click_through(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_title(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_send(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_on_message(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_on_load(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_on_error(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_on_close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_count(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_is_valid(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_active_dom(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_active_dom(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_eval_js_async(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_go_back(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_go_forward(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_reload(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_can_go_back(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_can_go_forward(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_url(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_get_page_title(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_minimize(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_maximize(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_restore(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_fullscreen(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_is_fullscreen(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_enable_devtools(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
void runt_webview_set_context_menu(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||
|
|
|
||
|
|
#endif
|