#pragma once #ifdef WITH_WEBVIEW #include #include #include #include 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 context; v8::Global onMessage; v8::Global onLoad; v8::Global onError; v8::Global onClose; v8::Global 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 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 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 cb); void setOnLoad(int id, v8::Isolate* isolate, v8::Local cb); void setOnError(int id, v8::Isolate* isolate, v8::Local cb); void setOnClose(int id, v8::Isolate* isolate, v8::Local 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> 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& args); void runt_webview_load_html(const v8::FunctionCallbackInfo& args); void runt_webview_load_url(const v8::FunctionCallbackInfo& args); void runt_webview_eval_js(const v8::FunctionCallbackInfo& args); void runt_webview_show(const v8::FunctionCallbackInfo& args); void runt_webview_hide(const v8::FunctionCallbackInfo& args); void runt_webview_destroy(const v8::FunctionCallbackInfo& args); void runt_webview_resize(const v8::FunctionCallbackInfo& args); void runt_webview_move(const v8::FunctionCallbackInfo& args); void runt_webview_set_bounds(const v8::FunctionCallbackInfo& args); void runt_webview_get_x(const v8::FunctionCallbackInfo& args); void runt_webview_get_y(const v8::FunctionCallbackInfo& args); void runt_webview_get_width(const v8::FunctionCallbackInfo& args); void runt_webview_get_height(const v8::FunctionCallbackInfo& args); void runt_webview_set_transparent(const v8::FunctionCallbackInfo& args); void runt_webview_set_click_through(const v8::FunctionCallbackInfo& args); void runt_webview_set_title(const v8::FunctionCallbackInfo& args); void runt_webview_send(const v8::FunctionCallbackInfo& args); void runt_webview_set_on_message(const v8::FunctionCallbackInfo& args); void runt_webview_set_on_load(const v8::FunctionCallbackInfo& args); void runt_webview_set_on_error(const v8::FunctionCallbackInfo& args); void runt_webview_set_on_close(const v8::FunctionCallbackInfo& args); void runt_webview_count(const v8::FunctionCallbackInfo& args); void runt_webview_is_valid(const v8::FunctionCallbackInfo& args); void runt_webview_set_active_dom(const v8::FunctionCallbackInfo& args); void runt_webview_get_active_dom(const v8::FunctionCallbackInfo& args); void runt_webview_eval_js_async(const v8::FunctionCallbackInfo& args); void runt_webview_go_back(const v8::FunctionCallbackInfo& args); void runt_webview_go_forward(const v8::FunctionCallbackInfo& args); void runt_webview_reload(const v8::FunctionCallbackInfo& args); void runt_webview_can_go_back(const v8::FunctionCallbackInfo& args); void runt_webview_can_go_forward(const v8::FunctionCallbackInfo& args); void runt_webview_get_url(const v8::FunctionCallbackInfo& args); void runt_webview_get_page_title(const v8::FunctionCallbackInfo& args); void runt_webview_minimize(const v8::FunctionCallbackInfo& args); void runt_webview_maximize(const v8::FunctionCallbackInfo& args); void runt_webview_restore(const v8::FunctionCallbackInfo& args); void runt_webview_set_fullscreen(const v8::FunctionCallbackInfo& args); void runt_webview_is_fullscreen(const v8::FunctionCallbackInfo& args); void runt_webview_enable_devtools(const v8::FunctionCallbackInfo& args); void runt_webview_set_context_menu(const v8::FunctionCallbackInfo& args); #endif