axmol/core/ui/UIWebView/UIWebViewImpl-android.cpp

372 lines
12 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2014-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
2021-07-15 23:03:43 +08:00
https://axmol.dev/
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ui/UIWebView/UIWebViewImpl-android.h"
#include <unordered_map>
#include <stdlib.h>
#include <string>
#include "platform/android/jni/JniHelper.h"
#include "ui/UIWebView/UIWebView.h"
#include "platform/GLView.h"
#include "base/Director.h"
#include "platform/FileUtils.h"
2019-11-23 20:27:39 +08:00
#include "ui/UIHelper.h"
2023-06-24 21:18:27 +08:00
#include "yasio/string_view.hpp"
2019-11-23 20:27:39 +08:00
2022-10-01 16:24:52 +08:00
static const char* className = "org.axmol.lib.WebViewHelper";
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "", __VA_ARGS__)
2019-11-23 20:27:39 +08:00
2022-03-24 11:03:17 +08:00
static constexpr std::string_view s_assetsBaseUrl = "file:///android_asset/"sv;
static constexpr std::string_view s_sdRootBaseUrl = "file://"sv;
2019-11-23 20:27:39 +08:00
static std::string getFixedBaseUrl(std::string_view baseUrl)
2019-11-23 20:27:39 +08:00
{
std::string fixedBaseUrl;
if (baseUrl.empty())
{
2022-03-24 11:03:17 +08:00
fixedBaseUrl = s_assetsBaseUrl;
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
else if (baseUrl.find(s_sdRootBaseUrl) != std::string::npos)
2019-11-23 20:27:39 +08:00
{
fixedBaseUrl = baseUrl;
}
else if (baseUrl[0] != '/')
2021-12-25 10:04:45 +08:00
{
using namespace cxx17; // for cxx17::string_view literal
if (cxx20::starts_with(baseUrl, "assets/"_sv))
2021-12-25 10:04:45 +08:00
{
2022-03-24 11:03:17 +08:00
fixedBaseUrl.assign(s_assetsBaseUrl).push_back(baseUrl[7]);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
else
{
2022-03-24 11:03:17 +08:00
fixedBaseUrl.assign(s_assetsBaseUrl).append(baseUrl);
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
else
{
fixedBaseUrl.assign(s_sdRootBaseUrl).append(baseUrl);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
if (fixedBaseUrl.c_str()[fixedBaseUrl.length() - 1] != '/')
{
fixedBaseUrl.push_back('/');
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
return fixedBaseUrl;
}
extern "C" {
2021-12-25 10:04:45 +08:00
/*
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
* Class: org_axmol_lib_WebViewHelper
2021-12-25 10:04:45 +08:00
* Method: shouldStartLoading
* Signature: (ILjava/lang/String;)Z
*/
2022-10-01 16:24:52 +08:00
JNIEXPORT jboolean JNICALL Java_org_axmol_lib_WebViewHelper_shouldStartLoading(JNIEnv* env,
2021-12-25 10:04:45 +08:00
jclass,
jint index,
jstring jurl)
{
auto charUrl = env->GetStringUTFChars(jurl, NULL);
std::string url = charUrl;
env->ReleaseStringUTFChars(jurl, charUrl);
2022-08-08 18:02:17 +08:00
return ax::ui::WebViewImpl::shouldStartLoading(index, url);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/*
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
* Class: org_axmol_lib_WebViewHelper
2021-12-25 10:04:45 +08:00
* Method: didFinishLoading
* Signature: (ILjava/lang/String;)V
*/
2022-10-01 16:24:52 +08:00
JNIEXPORT void JNICALL Java_org_axmol_lib_WebViewHelper_didFinishLoading(JNIEnv* env,
2021-12-25 10:04:45 +08:00
jclass,
jint index,
jstring jurl)
{
// LOGD("didFinishLoading");
auto charUrl = env->GetStringUTFChars(jurl, NULL);
std::string url = charUrl;
env->ReleaseStringUTFChars(jurl, charUrl);
2022-08-08 18:02:17 +08:00
ax::ui::WebViewImpl::didFinishLoading(index, url);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/*
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
* Class: org_axmol_lib_WebViewHelper
2021-12-25 10:04:45 +08:00
* Method: didFailLoading
* Signature: (ILjava/lang/String;)V
*/
2022-10-01 16:24:52 +08:00
JNIEXPORT void JNICALL Java_org_axmol_lib_WebViewHelper_didFailLoading(JNIEnv* env,
2021-12-25 10:04:45 +08:00
jclass,
jint index,
jstring jurl)
{
// LOGD("didFailLoading");
auto charUrl = env->GetStringUTFChars(jurl, NULL);
std::string url = charUrl;
env->ReleaseStringUTFChars(jurl, charUrl);
2022-08-08 18:02:17 +08:00
ax::ui::WebViewImpl::didFailLoading(index, url);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
/*
Release 2.1.5 (#2076) * Fix unexpected libpng used * Fix string format incorrect for tests * Fix #1751, use coroutine control AutoTest flow * Update CHANGELOG.md * Added OpenType font (.otf) to the noCompress list. (#2077) * Update 1k & copyright notice in some sources * Move doctest to axmol 3rdparty * Fix ci * Update 1kdist to v90 * Update 1kiss.ps1 * DrawNodeV2 0.95.1 (#2079) * Rename remaining legacy engine related spells and improve code style * Update 3rdparty README.md * Fix checkReallySupportsASTC does not work on ios device reported by @BIGCATDOG in https://github.com/axmolengine/axmol/issues/2078 * Fix ci * FastRNG: add missing include for AXASSERT (#2081) * Delete unused files * Improve FileUtils - Rename FileUtils::createDirectory to FileUtils::createDirectories - Use splitpath_cb to optimize FileUtils::createDirectories - Rename FileUtils::getFileShortName to FileUtils::getPathBaseName - Rename FileUtils::getFileExtension to FileUtils::getPathExtension - Add FileUtils::getPathDirName - Add FileUtils::getPathBaseNameNoExtension - Mark all renamed FileUtils stubs old name deprecated - Mark all FileUtils offthread APIs deprecated * Update box2d to v2.4.2 * Disable /sdl checks explicitly for winuwp For axmol deprecated policy, we need disable /sdl checks explicitly to avoid compiler traits invoking deprecated functions as error * Update cppwinrt to 2.0.240405.15 * Update simdjson to 3.10.0 * Fix box2d testbed compile error * Improve file path to url * Fix FileUtils::createDirectories unix logic * axmol-cmdline: remove arch suffix for host build output directory * Update CHANGELOG.md * Update lua bindings --------- Co-authored-by: Dani Alias <danielgutierrezalias@gmail.com> Co-authored-by: aismann <icesoft@freenet.de> Co-authored-by: smilediver <smilediver@outlook.com>
2024-08-11 21:11:35 +08:00
* Class: org_axmol_lib_WebViewHelper
2021-12-25 10:04:45 +08:00
* Method: onJsCallback
* Signature: (ILjava/lang/String;)V
*/
2022-10-01 16:24:52 +08:00
JNIEXPORT void JNICALL Java_org_axmol_lib_WebViewHelper_onJsCallback(JNIEnv* env,
2021-12-25 10:04:45 +08:00
jclass,
jint index,
jstring jmessage)
{
// LOGD("jsCallback");
auto charMessage = env->GetStringUTFChars(jmessage, NULL);
std::string message = charMessage;
env->ReleaseStringUTFChars(jmessage, charMessage);
2022-08-08 18:02:17 +08:00
ax::ui::WebViewImpl::onJsCallback(index, message);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
namespace
{
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
int createWebViewJNI()
{
2022-08-08 18:02:17 +08:00
ax::JniMethodInfo t;
if (ax::JniHelper::getStaticMethodInfo(t, className, "createWebView", "()I"))
2021-12-25 10:04:45 +08:00
{
2019-11-23 20:27:39 +08:00
// LOGD("error: %s,%d",__func__,__LINE__);
jint viewTag = t.env->CallStaticIntMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
return viewTag;
}
return -1;
}
std::string getUrlStringByFileName(std::string_view fileName)
2021-12-25 10:04:45 +08:00
{
2019-11-23 20:27:39 +08:00
// LOGD("error: %s,%d",__func__,__LINE__);
2022-08-08 18:02:17 +08:00
std::string urlString = ax::FileUtils::getInstance()->fullPathForFilename(fileName);
2022-03-24 11:03:17 +08:00
if (urlString.empty())
return urlString;
2022-03-24 11:03:17 +08:00
if (urlString[0] == '/')
urlString.insert(urlString.begin(), s_sdRootBaseUrl.begin(), s_sdRootBaseUrl.end());
else if (cxx20::starts_with(cxx17::string_view{urlString}, "assets/"sv))
urlString.replace(0, sizeof("assets/") - 1, s_assetsBaseUrl);
2021-12-25 10:04:45 +08:00
else
2022-03-24 11:03:17 +08:00
urlString.insert(urlString.begin(), s_assetsBaseUrl.begin(), s_assetsBaseUrl.end());
2021-07-15 23:03:43 +08:00
2019-11-23 20:27:39 +08:00
return urlString;
}
2021-12-25 10:04:45 +08:00
} // namespace
2019-11-23 20:27:39 +08:00
namespace ax
{
2021-12-25 10:04:45 +08:00
namespace ui
{
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
static std::unordered_map<int, ax::ui::WebViewImpl*> s_WebViewImpls;
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
WebViewImpl::WebViewImpl(WebView* webView) : _viewTag(-1), _webView(webView)
{
_viewTag = createWebViewJNI();
s_WebViewImpls[_viewTag] = this;
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
WebViewImpl::~WebViewImpl()
{
JniHelper::callStaticVoidMethod(className, "removeWebView", _viewTag);
2021-12-25 10:04:45 +08:00
s_WebViewImpls.erase(_viewTag);
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::loadData(const Data& data,
std::string_view MIMEType,
std::string_view encoding,
std::string_view baseURL)
2021-12-25 10:04:45 +08:00
{
std::string dataString(reinterpret_cast<char*>(data.getBytes()), static_cast<unsigned int>(data.getSize()));
JniHelper::callStaticVoidMethod(className, "loadData", _viewTag, dataString, MIMEType, encoding,
2021-12-29 19:31:28 +08:00
baseURL);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::loadHTMLString(std::string_view string, std::string_view baseURL)
2021-12-25 10:04:45 +08:00
{
JniHelper::callStaticVoidMethod(className, "loadHTMLString", _viewTag, string, getFixedBaseUrl(baseURL));
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::loadURL(std::string_view url)
2021-12-25 10:04:45 +08:00
{
this->loadURL(url, false);
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::loadURL(std::string_view url, bool cleanCachedData)
2021-12-25 10:04:45 +08:00
{
JniHelper::callStaticVoidMethod(className, "loadUrl", _viewTag, url, cleanCachedData);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::loadFile(std::string_view fileName)
2021-12-25 10:04:45 +08:00
{
auto fullPath = getUrlStringByFileName(fileName);
JniHelper::callStaticVoidMethod(className, "loadFile", _viewTag, fullPath);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::stopLoading()
{
JniHelper::callStaticVoidMethod(className, "stopLoading", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::reload()
{
JniHelper::callStaticVoidMethod(className, "reload", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
bool WebViewImpl::canGoBack()
{
return JniHelper::callStaticBooleanMethod(className, "canGoBack", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
bool WebViewImpl::canGoForward()
{
return JniHelper::callStaticBooleanMethod(className, "canGoForward", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::goBack()
{
JniHelper::callStaticVoidMethod(className, "goBack", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::goForward()
{
JniHelper::callStaticVoidMethod(className, "goForward", _viewTag);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::setJavascriptInterfaceScheme(std::string_view scheme)
2021-12-25 10:04:45 +08:00
{
JniHelper::callStaticVoidMethod(className, "setJavascriptInterfaceScheme", _viewTag, scheme);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::evaluateJS(std::string_view js)
2021-12-25 10:04:45 +08:00
{
JniHelper::callStaticVoidMethod(className, "evaluateJS", _viewTag, js);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::setScalesPageToFit(const bool scalesPageToFit)
{
JniHelper::callStaticVoidMethod(className, "setScalesPageToFit", _viewTag, scalesPageToFit);
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
bool WebViewImpl::shouldStartLoading(const int viewTag, std::string_view url)
2021-12-25 10:04:45 +08:00
{
bool allowLoad = true;
auto it = s_WebViewImpls.find(viewTag);
if (it != s_WebViewImpls.end())
{
auto webView = it->second->_webView;
if (webView->_onShouldStartLoading)
{
allowLoad = webView->_onShouldStartLoading(webView, url);
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
return allowLoad;
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::didFinishLoading(const int viewTag, std::string_view url)
2021-12-25 10:04:45 +08:00
{
auto it = s_WebViewImpls.find(viewTag);
if (it != s_WebViewImpls.end())
{
auto webView = it->second->_webView;
if (webView->_onDidFinishLoading)
{
webView->_onDidFinishLoading(webView, url);
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::didFailLoading(const int viewTag, std::string_view url)
2021-12-25 10:04:45 +08:00
{
auto it = s_WebViewImpls.find(viewTag);
if (it != s_WebViewImpls.end())
{
auto webView = it->second->_webView;
if (webView->_onDidFailLoading)
{
webView->_onDidFailLoading(webView, url);
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
void WebViewImpl::onJsCallback(const int viewTag, std::string_view message)
2021-12-25 10:04:45 +08:00
{
auto it = s_WebViewImpls.find(viewTag);
if (it != s_WebViewImpls.end())
{
auto webView = it->second->_webView;
if (webView->_onJSCallback)
{
webView->_onJSCallback(webView, message);
2019-11-23 20:27:39 +08:00
}
}
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2022-08-08 18:02:17 +08:00
void WebViewImpl::draw(ax::Renderer* renderer, ax::Mat4 const& transform, uint32_t flags)
2021-12-25 10:04:45 +08:00
{
2022-08-08 18:02:17 +08:00
if (flags & ax::Node::FLAGS_TRANSFORM_DIRTY)
2021-12-25 10:04:45 +08:00
{
2022-08-08 18:02:17 +08:00
auto uiRect = ax::ui::Helper::convertBoundingBoxToScreen(_webView);
JniHelper::callStaticVoidMethod(className, "setWebViewRect", _viewTag, (int)uiRect.origin.x,
2021-12-25 10:04:45 +08:00
(int)uiRect.origin.y, (int)uiRect.size.width, (int)uiRect.size.height);
2019-11-23 20:27:39 +08:00
}
2021-12-25 10:04:45 +08:00
}
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void WebViewImpl::setVisible(bool visible)
{
JniHelper::callStaticVoidMethod(className, "setVisible", _viewTag, visible);
2021-12-25 10:04:45 +08:00
}
void WebViewImpl::setOpacityWebView(const float opacity)
{
JniHelper::callStaticVoidMethod(className, "setOpacityWebView", _viewTag, opacity);
2021-12-25 10:04:45 +08:00
};
float WebViewImpl::getOpacityWebView() const
{
return JniHelper::callStaticFloatMethod(className, "getOpacityWebView", _viewTag);
2021-12-25 10:04:45 +08:00
};
void WebViewImpl::setBackgroundTransparent()
{
JniHelper::callStaticVoidMethod(className, "setBackgroundTransparent", _viewTag);
2021-12-25 10:04:45 +08:00
};
void WebViewImpl::setBounces(bool bounces)
{
// empty function as this was mainly a fix for iOS
}
} // namespace ui
} // namespace ax