wasm: Use common “qt” prefix for exported functions

Prevent namespace collisions and make sure Qt functions
are grouped together.

Change-Id: I217188ee93e4300e273d10a79d6014179fc5a1ef
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Morten Johan Sørvig 2019-03-15 15:04:59 +01:00
parent 8f1acd29e4
commit f4ac50a838
5 changed files with 38 additions and 38 deletions

View File

@ -227,7 +227,7 @@ std::string EventCallback::contextPropertyName(const std::string &eventName)
return std::string("data-qtEventCallbackContext") + eventName;
}
EMSCRIPTEN_BINDINGS(QtStdwebCalback) {
EMSCRIPTEN_BINDINGS(qtStdwebCalback) {
emscripten::function("qtStdWebEventCallbackActivate", &EventCallback::activate);
}

View File

@ -117,7 +117,7 @@ static void q_loadCallback(val event)
val blob = xhr["response"];
val reader = val::global("FileReader").new_();
reader.set("onload", val::module_property("QNetworkReplyWasmImplPrivate_readBinary"));
reader.set("onload", val::module_property("qt_QNetworkReplyWasmImplPrivate_readBinary"));
reader.set("data-handler", xhr["data-handler"]);
reader.call<void>("readAsArrayBuffer", blob);
@ -174,12 +174,12 @@ static void q_readBinary(val event)
QCoreApplication::processEvents();
}
EMSCRIPTEN_BINDINGS(network_module) {
function("QNetworkReplyWasmImplPrivate_requestErrorCallback", q_requestErrorCallback);
function("QNetworkReplyWasmImplPrivate_progressCallback", q_progressCallback);
function("QNetworkReplyWasmImplPrivate_loadCallback", q_loadCallback);
function("QNetworkReplyWasmImplPrivate_responseHeadersCallback", q_responseHeadersCallback);
function("QNetworkReplyWasmImplPrivate_readBinary", q_readBinary);
EMSCRIPTEN_BINDINGS(qtNetworkModule) {
function("qt_QNetworkReplyWasmImplPrivate_requestErrorCallback", q_requestErrorCallback);
function("qt_QNetworkReplyWasmImplPrivate_progressCallback", q_progressCallback);
function("qt_QNetworkReplyWasmImplPrivate_loadCallback", q_loadCallback);
function("qt_QNetworkReplyWasmImplPrivate_responseHeadersCallback", q_responseHeadersCallback);
function("qt_QNetworkReplyWasmImplPrivate_readBinary", q_readBinary);
}
QNetworkReplyWasmImplPrivate::QNetworkReplyWasmImplPrivate()
@ -332,10 +332,10 @@ void QNetworkReplyWasmImplPrivate::doSendRequest()
m_xhr.call<void>("open", verb, request.url().toString().toStdString());
m_xhr.set("onerror", val::module_property("QNetworkReplyWasmImplPrivate_requestErrorCallback"));
m_xhr.set("onload", val::module_property("QNetworkReplyWasmImplPrivate_loadCallback"));
m_xhr.set("onprogress", val::module_property("QNetworkReplyWasmImplPrivate_progressCallback"));
m_xhr.set("onreadystatechange", val::module_property("QNetworkReplyWasmImplPrivate_responseHeadersCallback"));
m_xhr.set("onerror", val::module_property("qt_QNetworkReplyWasmImplPrivate_requestErrorCallback"));
m_xhr.set("onload", val::module_property("qt_QNetworkReplyWasmImplPrivate_loadCallback"));
m_xhr.set("onprogress", val::module_property("qt_QNetworkReplyWasmImplPrivate_progressCallback"));
m_xhr.set("onreadystatechange", val::module_property("qt_QNetworkReplyWasmImplPrivate_responseHeadersCallback"));
m_xhr.set("data-handler", val(quintptr(reinterpret_cast<void *>(this))));

View File

@ -76,8 +76,8 @@ static void qClipboardCutTo(val event)
}
val module = val::global("Module");
val clipdata = module.call<val>("getClipboardData");
val clipFormat = module.call<val>("getClipboardFormat");
val clipdata = module.call<val>("qtGetClipboardData");
val clipFormat = module.call<val>("qtGetClipboardFormat");
event["clipboardData"].call<void>("setData", clipFormat, clipdata);
event.call<void>("preventDefault");
}
@ -91,8 +91,8 @@ static void qClipboardCopyTo(val event)
}
val module = val::global("Module");
val clipdata = module.call<val>("getClipboardData");
val clipFormat = module.call<val>("getClipboardFormat");
val clipdata = module.call<val>("qtGetClipboardData");
val clipFormat = module.call<val>("qtGetClipboardFormat");
event["clipboardData"].call<void>("setData", clipFormat, clipdata);
event.call<void>("preventDefault");
}
@ -101,7 +101,7 @@ static void qClipboardPasteTo(val event)
{
bool hasClipboardApi = QWasmIntegration::get()->getWasmClipboard()->hasClipboardApi;
val clipdata = hasClipboardApi ?
val::global("Module").call<val>("getClipboardData") :
val::global("Module").call<val>("qtGetClipboardData") :
event["clipboardData"].call<val>("getData", std::string("text"));
const std::string data = clipdata.as<std::string>();
@ -113,14 +113,14 @@ static void qClipboardPasteTo(val event)
}
}
EMSCRIPTEN_BINDINGS(clipboard_module) {
function("getClipboardData", &getClipboardData);
function("getClipboardFormat", &getClipboardFormat);
function("pasteClipboardData", &pasteClipboardData);
function("qClipboardPromiseResolve", &qClipboardPromiseResolve);
function("qClipboardCutTo", &qClipboardCutTo);
function("qClipboardCopyTo", &qClipboardCopyTo);
function("qClipboardPasteTo", &qClipboardPasteTo);
EMSCRIPTEN_BINDINGS(qtClipboardModule) {
function("qtGetClipboardData", &getClipboardData);
function("qtGetClipboardFormat", &getClipboardFormat);
function("qtPasteClipboardData", &pasteClipboardData);
function("qtClipboardPromiseResolve", &qClipboardPromiseResolve);
function("qtClipboardCutTo", &qClipboardCutTo);
function("qtClipboardCopyTo", &qClipboardCopyTo);
function("qtClipboardPasteTo", &qClipboardPasteTo);
}
QWasmClipboard::QWasmClipboard()
@ -200,11 +200,11 @@ void QWasmClipboard::installEventHandlers(const QString &canvasId)
// Fallback path for browsers which do not support direct clipboard access
val canvas = val::global(canvasId.toUtf8().constData());
canvas.call<void>("addEventListener", std::string("cut"),
val::module_property("qClipboardCutTo"));
val::module_property("qtClipboardCutTo"));
canvas.call<void>("addEventListener", std::string("copy"),
val::module_property("qClipboardCopyTo"));
val::module_property("qtClipboardCopyTo"));
canvas.call<void>("addEventListener", std::string("paste"),
val::module_property("qClipboardPasteTo"));
val::module_property("qtClipboardPasteTo"));
}
void QWasmClipboard::readTextFromClipboard()
@ -212,7 +212,7 @@ void QWasmClipboard::readTextFromClipboard()
if (QWasmIntegration::get()->getWasmClipboard()->hasClipboardApi) {
val navigator = val::global("navigator");
val textPromise = navigator["clipboard"].call<val>("readText");
val readTextResolve = val::global("Module")["qClipboardPromiseResolve"];
val readTextResolve = val::global("Module")["qtClipboardPromiseResolve"];
textPromise.call<val>("then", readTextResolve);
}
}
@ -221,8 +221,8 @@ void QWasmClipboard::writeTextToClipboard()
{
if (QWasmIntegration::get()->getWasmClipboard()->hasClipboardApi) {
val module = val::global("Module");
val txt = module.call<val>("getClipboardData");
val format = module.call<val>("getClipboardFormat");
val txt = module.call<val>("qtGetClipboardData");
val format = module.call<val>("qtGetClipboardFormat");
val navigator = val::global("navigator");
navigator["clipboard"].call<void>("writeText", txt.as<std::string>());
}

View File

@ -316,8 +316,8 @@ static void mouseWheelEvent(emscripten::val event) {
}
}
EMSCRIPTEN_BINDINGS(mouse_module) {
function("mouseWheelEvent", &mouseWheelEvent);
EMSCRIPTEN_BINDINGS(qtMouseModule) {
function("qtMouseWheelEvent", &mouseWheelEvent);
}
QWasmEventTranslator::QWasmEventTranslator(QWasmScreen *screen)
@ -358,7 +358,7 @@ void QWasmEventTranslator::initEventHandlers()
emscripten::val::global(canvasId).call<void>("addEventListener",
std::string("wheel"),
val::module_property("mouseWheelEvent"));
val::module_property("qtMouseWheelEvent"));
}
}

View File

@ -56,14 +56,14 @@
using namespace emscripten;
QT_BEGIN_NAMESPACE
void browserBeforeUnload(emscripten::val)
static void browserBeforeUnload(emscripten::val)
{
QWasmIntegration::QWasmBrowserExit();
}
EMSCRIPTEN_BINDINGS(my_module)
EMSCRIPTEN_BINDINGS(qtQWasmIntegraton)
{
function("browserBeforeUnload", &browserBeforeUnload);
function("qtBrowserBeforeUnload", &browserBeforeUnload);
}
QWasmIntegration *QWasmIntegration::s_instance;
@ -92,7 +92,7 @@ QWasmIntegration::QWasmIntegration()
addScreen(canvasId);
}
emscripten::val::global("window").set("onbeforeunload", val::module_property("browserBeforeUnload"));
emscripten::val::global("window").set("onbeforeunload", val::module_property("qtBrowserBeforeUnload"));
}
QWasmIntegration::~QWasmIntegration()