mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-22 21:16:40 -04:00
add params check and destroy callback for native
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com> Change-Id: I6af9cae2942a262c719a25070bcfcfef2a1bb57d
This commit is contained in:
@@ -44,6 +44,7 @@ namespace OHOS::Ace {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using NotifyNativeWinDestroyFunc = std::function<void(std::string windowName)>;
|
||||
class RSSurfaceNode;
|
||||
class IWindowChangeListener : virtual public RefBase {
|
||||
public:
|
||||
@@ -126,6 +127,7 @@ public:
|
||||
virtual void UnregisterDragListener(const sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0;
|
||||
virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
|
||||
NativeValue* storage, bool isdistributed = false) = 0;
|
||||
virtual std::string GetContentInfo() = 0;
|
||||
|
||||
@@ -203,7 +203,7 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win
|
||||
windowOption->SetWindowType(winType);
|
||||
sptr<Window> window = Window::Create(windowName, windowOption, context->lock());
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window));
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowManager::OnCreateWindow success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
@@ -227,7 +227,7 @@ static void CreateSubWindowTask(std::string parentWinName, std::string windowNam
|
||||
windowOption->SetParentName(parentWinName);
|
||||
sptr<Window> window = Window::Create(windowName, windowOption);
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window));
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, true));
|
||||
WLOGFI("JsWindowManager::OnCreateWindow success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
@@ -242,17 +242,19 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac
|
||||
NativeValue* nativeContext = nullptr;
|
||||
NativeValue* nativeType = nullptr;
|
||||
NativeValue* callback = nullptr;
|
||||
if (info.argc >= ARGC_TWO && info.argv[0]->TypeOf() == NATIVE_STRING) {
|
||||
if (info.argc >= 2 && info.argv[0]->TypeOf() == NATIVE_STRING) { // 2: minimum params num
|
||||
nativeString = info.argv[0];
|
||||
nativeType = info.argv[ARGC_ONE];
|
||||
callback = (info.argc == ARGC_TWO) ? nullptr :
|
||||
(info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
} else if (info.argc >= ARGC_THREE) {
|
||||
nativeType = info.argv[1];
|
||||
// 2: minimum params num
|
||||
callback = (info.argc == 2) ? nullptr :
|
||||
(info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr); // 2: index of callback
|
||||
} else if (info.argc >= 3) { // 3: minimum params num
|
||||
nativeContext = info.argv[0]->TypeOf() == NATIVE_OBJECT ? info.argv[0] : nullptr;
|
||||
nativeString = info.argv[ARGC_ONE];
|
||||
nativeType = info.argv[ARGC_TWO];
|
||||
callback = (info.argc == ARGC_THREE) ? nullptr :
|
||||
(info.argv[INDEX_THREE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_THREE] : nullptr);
|
||||
nativeString = info.argv[1];
|
||||
nativeType = info.argv[2]; // 2: index of type
|
||||
// 3: minimum params num;
|
||||
callback = (info.argc == 3) ? nullptr :
|
||||
(info.argv[3]->TypeOf() == NATIVE_FUNCTION ? info.argv[3] : nullptr); // 3: index of callback
|
||||
}
|
||||
std::string windowName;
|
||||
WMError errCode = WMError::WM_OK;
|
||||
@@ -291,11 +293,15 @@ NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackI
|
||||
WLOGFI("JsWindowManager::JsOnFindWindow is called");
|
||||
std::string windowName;
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
@@ -312,13 +318,14 @@ NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackI
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnFindWindow failed."));
|
||||
} else {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window));
|
||||
AppExecFwk::Ability* ability = nullptr;
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, GetAPI7Ability(engine, ability)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -329,7 +336,7 @@ NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallback
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnMinimizeAll is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < ARGC_ONE) {
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param is too small!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -355,8 +362,8 @@ NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallback
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowManager::OnMinimizeAll success");
|
||||
};
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -366,7 +373,7 @@ NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallback
|
||||
NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback is called");
|
||||
if (info.argc != 2) { // 2 is num of argc
|
||||
if (info.argc != 2) { // 2: params num
|
||||
WLOGFE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -389,7 +396,7 @@ NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engin
|
||||
NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnUnregisterWindowCallback is called");
|
||||
if (info.argc == 0) {
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -447,7 +454,7 @@ static void GetTopWindowTask(void* contextPtr, bool isNewApi, NativeEngine& engi
|
||||
if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
|
||||
task.Resolve(engine, jsWindowObj->Get());
|
||||
} else {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window));
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, isNewApi));
|
||||
}
|
||||
WLOGFI("JsWindowManager::OnGetTopWindow success");
|
||||
return;
|
||||
@@ -456,22 +463,28 @@ static void GetTopWindowTask(void* contextPtr, bool isNewApi, NativeEngine& engi
|
||||
NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnGetTopWindow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
NativeValue* nativeContext = nullptr;
|
||||
NativeValue* nativeCallback = nullptr;
|
||||
bool isNewApi = true;
|
||||
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?)
|
||||
isNewApi = true;
|
||||
nativeContext = info.argv[0];
|
||||
nativeCallback = (info.argc == ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
} else { // (callback?)
|
||||
isNewApi = false;
|
||||
nativeCallback = (info.argc == 0) ? nullptr :
|
||||
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
|
||||
}
|
||||
void* contextPtr = nullptr;
|
||||
WMError errCode = WMError::WM_OK;
|
||||
GetNativeContext(nativeContext, contextPtr, errCode);
|
||||
bool isNewApi = true;
|
||||
if (info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?)
|
||||
isNewApi = true;
|
||||
nativeContext = info.argv[0];
|
||||
nativeCallback = (info.argc == 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
} else { // (callback?)
|
||||
isNewApi = false;
|
||||
nativeCallback = (info.argc == 0) ? nullptr :
|
||||
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
|
||||
}
|
||||
GetNativeContext(nativeContext, contextPtr, errCode);
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
@@ -490,7 +503,7 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnSetWindowLayoutMode is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < ARGC_TWO) {
|
||||
if (info.argc < 2 || info.argc > 3) { // 2: minimum params num; 3: maximum params num
|
||||
WLOGFE("JsWindowManager::OnSetWindowLayoutMode params too small");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -526,8 +539,9 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "do failed"));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc < ARGC_THREE) ? nullptr :
|
||||
(info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
// 2: maximum params num; 2: index of callback
|
||||
NativeValue* lastParam = (info.argc <= 2) ? nullptr :
|
||||
(info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
|
||||
@@ -28,14 +28,26 @@ namespace {
|
||||
|
||||
static std::map<std::string, std::shared_ptr<NativeReference>> g_jsWindowMap;
|
||||
std::recursive_mutex g_mutex;
|
||||
JsWindow::JsWindow(const sptr<Window>& window)
|
||||
: windowToken_(window), registerManager_(std::make_unique<JsWindowRegisterManager>())
|
||||
JsWindow::JsWindow(const sptr<Window>& window, bool isOldApi)
|
||||
: windowToken_(window), registerManager_(std::make_unique<JsWindowRegisterManager>()), isOldApi_(isOldApi)
|
||||
{
|
||||
NotifyNativeWinDestroyFunc func = [](std::string windowName) {
|
||||
WLOGE("NotifyNativeWinDestroyFunc is called %{public}s", windowName.c_str());
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) {
|
||||
WLOGE("windowName not exist %{public}s", windowName.c_str());
|
||||
return;
|
||||
}
|
||||
g_jsWindowMap.erase(windowName);
|
||||
WLOGFI("JsWindow::NotifyNativeWinDestroyFuncwindowName %{public}s is destroyed", windowName.c_str());
|
||||
};
|
||||
windowToken_->RegisterWindowDestroyedListener(func);
|
||||
}
|
||||
|
||||
JsWindow::~JsWindow()
|
||||
{
|
||||
WLOGFI("JsWindow::~JsWindow is called");
|
||||
windowToken_ = nullptr;
|
||||
}
|
||||
|
||||
std::string JsWindow::GetWindowName()
|
||||
@@ -263,14 +275,15 @@ NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnShow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->Show();
|
||||
@@ -294,14 +307,15 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnDestroy is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->Destroy();
|
||||
@@ -309,12 +323,7 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnDestroy failed."));
|
||||
return;
|
||||
}
|
||||
std::string windowName = windowToken_->GetWindowName();
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) {
|
||||
g_jsWindowMap.erase(windowName);
|
||||
WLOGFI("JsWindow::OnDestroy windowName %{public}s is destroyed", windowName.c_str());
|
||||
}
|
||||
windowToken_ = nullptr;
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindow::OnDestroy success");
|
||||
};
|
||||
@@ -331,14 +340,15 @@ NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnHide is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->Hide();
|
||||
@@ -362,8 +372,8 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnMoveTo is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_TWO) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or params not match");
|
||||
if (info.argc < 2 || info.argc > 3) { // 2:minimum param num, 3: maximum param num
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
int32_t x = 0;
|
||||
@@ -373,14 +383,15 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
}
|
||||
|
||||
int32_t y = 0;
|
||||
if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[ARGC_ONE], y)) {
|
||||
if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], y)) {
|
||||
WLOGFE("Failed to convert parameter to y");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->MoveTo(x, y);
|
||||
@@ -391,9 +402,9 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnMoveTo failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_TWO) ? nullptr :
|
||||
(info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
// 2: params num; 2: index of callback
|
||||
NativeValue* lastParam = (info.argc <= 2) ? nullptr :
|
||||
(info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -404,7 +415,7 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnResize is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_TWO) {
|
||||
if (info.argc < 2 || info.argc > 3) { // 2: minimum param num, 3: maximum param num
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -415,14 +426,15 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
}
|
||||
|
||||
uint32_t height = 0;
|
||||
if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[ARGC_ONE], height)) {
|
||||
if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], height)) {
|
||||
WLOGFE("Failed to convert parameter to height");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->Resize(width, height);
|
||||
@@ -432,8 +444,9 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnResize failed."));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc <= ARGC_TWO) ? nullptr :
|
||||
(info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
// 2: params num; 2: index of callback
|
||||
NativeValue* lastParam = (info.argc <= 2) ? nullptr :
|
||||
(info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -444,7 +457,7 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo&
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetWindowType is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
if (info.argc < 1 || info.argc > 2) { // 2 is max num of argc
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -470,8 +483,9 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo&
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->SetWindowType(winType);
|
||||
@@ -484,8 +498,8 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -496,7 +510,7 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo&
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetWindowMode is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
if (info.argc < 1 || info.argc > 2) { // 2 is max num of argc
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -513,8 +527,9 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo&
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
WMError ret = windowToken_->SetWindowMode(winMode);
|
||||
@@ -527,8 +542,8 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc == 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -539,14 +554,15 @@ NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo&
|
||||
{
|
||||
WLOGFI("JsWindow::OnGetProperties is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_);
|
||||
@@ -576,7 +592,7 @@ NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCall
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (info.argc != ARGC_TWO) {
|
||||
if (info.argc != 2) { // 2: params num
|
||||
WLOGFE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -609,7 +625,7 @@ NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCa
|
||||
if (info.argc == 1) {
|
||||
registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, nullptr);
|
||||
} else {
|
||||
NativeValue* value = info.argv[ARGC_ONE];
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsWindow::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
return engine.CreateUndefined();
|
||||
@@ -624,7 +640,7 @@ NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& i
|
||||
{
|
||||
WLOGFI("JsWindow::OnLoadContent is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
if (info.argc < 1 || info.argc > 3) { // 3 maximum param num
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
@@ -635,23 +651,25 @@ NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& i
|
||||
}
|
||||
NativeValue* storage = nullptr;
|
||||
NativeValue* callBack = nullptr;
|
||||
if (info.argc == ARGC_TWO) {
|
||||
NativeValue* value = info.argv[INDEX_ONE];
|
||||
if (info.argc == 2) { // 2: num of params
|
||||
NativeValue* value = info.argv[1];
|
||||
if (value->TypeOf() == NATIVE_FUNCTION) {
|
||||
callBack = info.argv[INDEX_ONE];
|
||||
callBack = info.argv[1];
|
||||
} else {
|
||||
storage = info.argv[INDEX_ONE];
|
||||
storage = info.argv[1];
|
||||
}
|
||||
} else if (info.argc == ARGC_THREE) {
|
||||
storage = info.argv[INDEX_ONE];
|
||||
callBack = (info.argv[INDEX_TWO]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_TWO] : nullptr);
|
||||
} else if (info.argc == 3) { // 3: num of params
|
||||
storage = info.argv[1];
|
||||
// 2: index of callback
|
||||
callBack = (info.argv[2]->TypeOf() == NATIVE_FUNCTION ? info.argv[2] : nullptr);
|
||||
}
|
||||
std::shared_ptr<NativeReference> contentStorage = (storage == nullptr) ? nullptr :
|
||||
std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK || isOldApi_) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param or is old version API");
|
||||
return;
|
||||
}
|
||||
NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get();
|
||||
@@ -674,8 +692,8 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo&
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetFullScreen is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or param is too small!");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("JsWindow param not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
bool isFullScreen = false;
|
||||
@@ -691,7 +709,7 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo&
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
@@ -705,8 +723,8 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -717,8 +735,8 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetLayoutFullScreen is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or param is too small!");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("JsWindow param not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
bool isLayoutFullScreen = false;
|
||||
@@ -733,7 +751,7 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
@@ -746,8 +764,8 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac
|
||||
static_cast<int32_t>(ret), "JsWindow::OnSetLayoutFullScreen failed."));
|
||||
}
|
||||
};
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -758,8 +776,8 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetSystemBarEnable is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or param is too small!");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("JsWindow params not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
std::map<WindowType, SystemBarProperty> systemBarProperties;
|
||||
@@ -768,9 +786,9 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
}
|
||||
WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
|
||||
systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR));
|
||||
@@ -785,8 +803,8 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -797,8 +815,8 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall
|
||||
{
|
||||
WLOGFI("JsWindow::OnSetSystemBarProperties is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < ARGC_ONE) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or param is too small!");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("JsWindow params not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
std::map<WindowType, SystemBarProperty> systemBarProperties;
|
||||
@@ -816,9 +834,9 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
}
|
||||
WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
|
||||
systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR));
|
||||
@@ -833,8 +851,8 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -845,8 +863,8 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo&
|
||||
{
|
||||
WLOGFI("JsWindow::OnGetAvoidArea is called info.argc: %{public}d", info.argc);
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowToken_ == nullptr || info.argc < 1 || info.argc > 2) { // 2 is max num of argv
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or param is too small!");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("JsWindow params not match!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
|
||||
@@ -862,9 +880,9 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
}
|
||||
// getAvoidRect by avoidAreaType
|
||||
AvoidArea avoidArea;
|
||||
@@ -886,8 +904,8 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo&
|
||||
}
|
||||
};
|
||||
WLOGFI("JsWindow::OnGetAvoidArea AsyncTask end");
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -897,12 +915,16 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo&
|
||||
NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnIsShowing is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowToken_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindow::OnIsShowing failed."));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
bool state = windowToken_->GetShowState();
|
||||
@@ -920,12 +942,16 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf
|
||||
NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnIsSupportWideGamut is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowToken_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindow::OnIsSupportWideGamut failed."));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
bool flag = windowToken_->IsSupportWideGamut();
|
||||
@@ -948,8 +974,8 @@ NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallback
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -964,8 +990,8 @@ NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo&
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -980,8 +1006,8 @@ NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo&
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -996,8 +1022,8 @@ NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo&
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1012,8 +1038,8 @@ NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInf
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1028,8 +1054,8 @@ NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbac
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1044,8 +1070,8 @@ NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1060,8 +1086,8 @@ NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo&
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1073,12 +1099,7 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo&
|
||||
WLOGFI("JsWindow::OnSetColorSpace is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
ColorSpace colorSpace = ColorSpace::COLOR_SPACE_DEFAULT;
|
||||
if (windowToken_ == nullptr) {
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (info.argc < 1) {
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
WLOGFE("JsWindow::OnSetColorSpace argc < 1");
|
||||
} else {
|
||||
@@ -1101,7 +1122,7 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo&
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode),
|
||||
"JsWindow::OnSetColorSpace failed."));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or args error");
|
||||
return;
|
||||
@@ -1110,8 +1131,8 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo&
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARGC_ONE) ? nullptr :
|
||||
(info.argv[INDEX_ONE]->TypeOf() == NATIVE_FUNCTION ? info.argv[INDEX_ONE] : nullptr);
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
@@ -1121,12 +1142,16 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo&
|
||||
NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindow::OnGetColorSpace is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("JsWindow params not match");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowToken_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindow::OnGetColorSpace failed."));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr");
|
||||
if (windowToken_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindow windowToken_ is nullptr or invalid param");
|
||||
return;
|
||||
}
|
||||
ColorSpace colorSpace = windowToken_->GetColorSpace();
|
||||
@@ -1151,7 +1176,7 @@ std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName)
|
||||
return g_jsWindowMap[windowName];
|
||||
}
|
||||
|
||||
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
|
||||
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window, bool isOldApi)
|
||||
{
|
||||
WLOGFI("JsWindow::CreateJsWindow is called");
|
||||
std::string windowName = window->GetWindowName();
|
||||
@@ -1164,7 +1189,8 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsWindow> jsWindow = std::make_unique<JsWindow>(window);
|
||||
WLOGFI("JsWindow::CreateJsWindow isOldApi %{public}d", isOldApi);
|
||||
std::unique_ptr<JsWindow> jsWindow = std::make_unique<JsWindow>(window, isOldApi);
|
||||
object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr);
|
||||
|
||||
BindNativeFunction(engine, *object, "show", JsWindow::Show);
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window);
|
||||
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window, bool isOldApi);
|
||||
std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName);
|
||||
class JsWindow final {
|
||||
public:
|
||||
explicit JsWindow(const sptr<Window>& window);
|
||||
JsWindow(const sptr<Window>& window, bool isOldApi);
|
||||
~JsWindow();
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint);
|
||||
static NativeValue* Show(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
@@ -98,6 +98,7 @@ private:
|
||||
|
||||
sptr<Window> windowToken_ = nullptr;
|
||||
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;
|
||||
bool isOldApi_ = false;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -24,12 +24,6 @@
|
||||
#include "wm_common.h"
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t INDEX_TWO = 2;
|
||||
constexpr int32_t INDEX_THREE = 3;
|
||||
constexpr int32_t RGB_LENGTH = 6;
|
||||
constexpr int32_t RGBA_LENGTH = 8;
|
||||
enum class ApiWindowType : uint32_t {
|
||||
|
||||
@@ -102,7 +102,7 @@ NativeValue* JsWindowStage::GetSubWindow(NativeEngine* engine, NativeCallbackInf
|
||||
NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnSetUIContent is called");
|
||||
if (info.argc < 2) { // 2: minimum param nums
|
||||
if (info.argc < 2) { // 2: minimum param num
|
||||
WLOGFE("JsWindowStage::OnSetUIContent Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -134,20 +134,16 @@ NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackI
|
||||
NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetMainWindow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnGetMainWindow windowScene_ is nullptr");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, OHOS::Rosen::CreateJsWindowObject(engine, window));
|
||||
task.Resolve(engine, OHOS::Rosen::CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowStage::OnGetMainWindow success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
@@ -155,8 +151,7 @@ NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallback
|
||||
"JsWindowStage::OnGetMainWindow failed."));
|
||||
}
|
||||
};
|
||||
NativeValue* callback = (info.argc == 0) ? nullptr :
|
||||
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
@@ -198,10 +193,6 @@ NativeValue* JsWindowStage::OffEvent(NativeEngine& engine, NativeCallbackInfo& i
|
||||
WLOGFE("JsWindowStage::OffEvent windowScene_ is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (info.argc < 1 || info.argc > 2) { // 1: minimum param nums, 2: maximum param nums
|
||||
WLOGFE("JsWindowStage::OffEvent wrong input params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// Parse info->argv[0] as string
|
||||
std::string eventString;
|
||||
@@ -236,10 +227,6 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnLoadContent is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc <= 0 || windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage param not match or windowScene_ is nullptr");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
std::string contextUrl;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], contextUrl)) {
|
||||
WLOGFE("Failed to convert parameter to context url");
|
||||
@@ -247,8 +234,8 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
}
|
||||
NativeValue* storage = nullptr;
|
||||
NativeValue* callBack = nullptr;
|
||||
NativeValue* value1 = info.argv[INDEX_ONE];
|
||||
NativeValue* value2 = info.argv[INDEX_TWO];
|
||||
NativeValue* value1 = info.argv[1];
|
||||
NativeValue* value2 = info.argv[2]; // 2: param index
|
||||
if (value1->TypeOf() == NATIVE_FUNCTION) {
|
||||
callBack = value1;
|
||||
} else if (value1->TypeOf() == NATIVE_OBJECT) {
|
||||
@@ -261,8 +248,9 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
std::shared_ptr<NativeReference>(engine.CreateReference(storage, 1));
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
auto win = windowScene_->GetMainWindow();
|
||||
@@ -288,15 +276,11 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetWindowMode is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc > ARGC_ONE || windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnGetWindowMode params not match or windowScene is nullptr!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
@@ -315,8 +299,7 @@ NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallback
|
||||
WLOGFI("JsWindowStage OnGetWindowMode success, but not in apimode");
|
||||
}
|
||||
};
|
||||
NativeValue* callback = (info.argc == 0) ? nullptr :
|
||||
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
@@ -327,10 +310,6 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnCreateSubWindow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < ARGC_ONE || windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnCreateSubWindow params less than 1!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
std::string windowName;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
@@ -338,8 +317,9 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowScene_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr or invaliad params!");
|
||||
return;
|
||||
}
|
||||
sptr<Rosen::WindowOption> windowOption = new Rosen::WindowOption();
|
||||
@@ -352,11 +332,10 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba
|
||||
WLOGFE("JsWindowStage window is nullptr");
|
||||
return;
|
||||
}
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window));
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowStage OnCreateSubWindow success");
|
||||
};
|
||||
NativeValue* callback = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* callback = (info.argv[1]->TypeOf() == NATIVE_FUNCTION) ? info.argv[1] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
@@ -375,7 +354,7 @@ NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine,
|
||||
}
|
||||
uint32_t index = 0;
|
||||
for (size_t i = 0; i < subWinVec.size(); i++) {
|
||||
array->SetElement(index++, CreateJsWindowObject(engine, subWinVec[i]));
|
||||
array->SetElement(index++, CreateJsWindowObject(engine, subWinVec[i], false));
|
||||
}
|
||||
return objValue;
|
||||
}
|
||||
@@ -383,23 +362,18 @@ NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine,
|
||||
NativeValue* JsWindowStage::OnGetSubWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetSubWindow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc > 1 || windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnGetSubWindow params not match or windowScene is nullptr!");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<Window>> subWindowVec = windowScene_->GetSubWindow();
|
||||
task.Resolve(engine, CreateJsSubWindowArrayObject(engine, subWindowVec));
|
||||
WLOGFI("JsWindowStage OnGetSubWindow success");
|
||||
};
|
||||
NativeValue* callback = (info.argc == 0) ? nullptr :
|
||||
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
|
||||
@@ -67,6 +67,10 @@ public:
|
||||
virtual const std::string& GetWindowName() const override;
|
||||
virtual uint32_t GetWindowId() const override;
|
||||
virtual uint32_t GetWindowFlags() const override;
|
||||
inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback()
|
||||
{
|
||||
return notifyNativefunc_;
|
||||
}
|
||||
virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
|
||||
virtual bool IsFullScreen() const override;
|
||||
virtual bool IsLayoutFullScreen() const override;
|
||||
@@ -80,6 +84,10 @@ public:
|
||||
virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
|
||||
virtual WMError SetLayoutFullScreen(bool status) override;
|
||||
virtual WMError SetFullScreen(bool status) override;
|
||||
inline void SetWindowState(WindowState state)
|
||||
{
|
||||
state_ = state;
|
||||
}
|
||||
virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override;
|
||||
|
||||
WMError Create(const std::string& parentName,
|
||||
@@ -110,7 +118,7 @@ public:
|
||||
virtual void UnregisterDragListener(const sptr<IWindowDragListener>& listener) override;
|
||||
virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
|
||||
virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
|
||||
|
||||
virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override;
|
||||
void UpdateRect(const struct Rect& rect, WindowSizeChangeReason reason);
|
||||
void UpdateMode(WindowMode mode);
|
||||
virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override;
|
||||
@@ -135,7 +143,6 @@ public:
|
||||
virtual ColorSpace GetColorSpace() override;
|
||||
|
||||
virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
|
||||
|
||||
private:
|
||||
inline void NotifyAfterForeground() const
|
||||
{
|
||||
@@ -153,19 +160,27 @@ private:
|
||||
{
|
||||
CALL_LIFECYCLE_LISTENER(AfterUnfocused, UnFocus);
|
||||
}
|
||||
inline void NotifyBeforeDestroy() const
|
||||
inline void NotifyBeforeDestroy(std::string windowName) const
|
||||
{
|
||||
if (uiContent_ != nullptr) {
|
||||
uiContent_->Destroy();
|
||||
}
|
||||
if (notifyNativefunc_) {
|
||||
notifyNativefunc_(windowName);
|
||||
}
|
||||
}
|
||||
inline void NotifyBeforeSubWindowDestroy(sptr<Window>& window) const
|
||||
inline void NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window) const
|
||||
{
|
||||
auto uiContent = window->GetUIContent();
|
||||
if (uiContent != nullptr) {
|
||||
uiContent->Destroy();
|
||||
}
|
||||
if (window->GetNativeDestroyCallback()) {
|
||||
window->GetNativeDestroyCallback()(window->GetWindowName());
|
||||
}
|
||||
}
|
||||
void DestroyFloatingWindow();
|
||||
void DestroySubWindow();
|
||||
void SetDefaultOption(); // for api7
|
||||
bool IsWindowValid() const;
|
||||
void OnVsync(int64_t timeStamp);
|
||||
@@ -191,8 +206,8 @@ private:
|
||||
std::shared_ptr<VsyncStation::VsyncCallback> callback_ =
|
||||
std::make_shared<VsyncStation::VsyncCallback>(VsyncStation::VsyncCallback());
|
||||
static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_;
|
||||
static std::map<uint32_t, std::vector<sptr<Window>>> subWindowMap_;
|
||||
static std::map<uint32_t, std::vector<sptr<Window>>> appFloatingWindowMap_;
|
||||
static std::map<uint32_t, std::vector<sptr<WindowImpl>>> subWindowMap_;
|
||||
static std::map<uint32_t, std::vector<sptr<WindowImpl>>> appFloatingWindowMap_;
|
||||
sptr<WindowProperty> property_;
|
||||
WindowState state_ { WindowState::STATE_INITIAL };
|
||||
std::vector<sptr<IWindowLifeCycle>> lifecycleListeners_;
|
||||
@@ -200,6 +215,7 @@ private:
|
||||
std::vector<sptr<IAvoidAreaChangedListener>> avoidAreaChangeListeners_;
|
||||
std::vector<sptr<IWindowDragListener>> windowDragListeners_;
|
||||
std::vector<sptr<IDisplayMoveListener>> displayMoveListeners_;
|
||||
NotifyNativeWinDestroyFunc notifyNativefunc_;
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
std::string name_;
|
||||
std::unique_ptr<Ace::UIContent> uiContent_;
|
||||
|
||||
+66
-33
@@ -39,8 +39,8 @@ const WindowImpl::ColorSpaceConvertMap WindowImpl::colorSpaceConvertMap[] = {
|
||||
};
|
||||
|
||||
std::map<std::string, std::pair<uint32_t, sptr<Window>>> WindowImpl::windowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<Window>>> WindowImpl::subWindowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<Window>>> WindowImpl::appFloatingWindowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::subWindowMap_;
|
||||
std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::appFloatingWindowMap_;
|
||||
|
||||
WindowImpl::WindowImpl(const sptr<WindowOption>& option)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ sptr<Window> WindowImpl::GetTopWindowWithContext(const std::shared_ptr<AbilityRu
|
||||
}
|
||||
}
|
||||
WLOGFI("GetTopWindowfinal MainWinId:%{public}u!", mainWinId);
|
||||
if (!mainWinId) {
|
||||
if (mainWinId == INVALID_WINDOW_ID) {
|
||||
WLOGFE("Cannot find topWindow!");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ std::vector<sptr<Window>> WindowImpl::GetSubWindow(uint32_t parentId)
|
||||
WLOGFE("Cannot parentWindow with id: %{public}d!", parentId);
|
||||
return std::vector<sptr<Window>>();
|
||||
}
|
||||
return subWindowMap_[parentId];
|
||||
return std::vector<sptr<Window>>(subWindowMap_[parentId].begin(), subWindowMap_[parentId].end());
|
||||
}
|
||||
|
||||
std::shared_ptr<RSSurfaceNode> WindowImpl::GetSurfaceNode() const
|
||||
@@ -336,8 +336,7 @@ WMError WindowImpl::SetWindowFlags(uint32_t flags)
|
||||
WMError WindowImpl::SetUIContent(const std::string& contentInfo,
|
||||
NativeEngine* engine, NativeValue* storage, bool isdistributed)
|
||||
{
|
||||
WLOGFI("SetUIContent");
|
||||
WLOGFI("contentInfo: %{public}s, context_:%{public}p", contentInfo.c_str(), context_.get());
|
||||
WLOGFI("SetUIContent contentInfo: %{public}s", contentInfo.c_str());
|
||||
uiContent_ = Ace::UIContent::Create(context_.get(), engine);
|
||||
if (uiContent_ == nullptr) {
|
||||
WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId());
|
||||
@@ -553,7 +552,6 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<
|
||||
return ret;
|
||||
}
|
||||
context_ = context;
|
||||
// FIX ME: use context_
|
||||
abilityContext_ = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
|
||||
if (abilityContext_ != nullptr) {
|
||||
ret = SingletonContainer::Get<WindowAdapter>().SaveAbilityToken(abilityContext_->GetToken(), windowId);
|
||||
@@ -574,6 +572,58 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WindowImpl::DestroyFloatingWindow()
|
||||
{
|
||||
// remove from appFloatingWindowMap_
|
||||
for (auto& floatingWindows: appFloatingWindowMap_) {
|
||||
for (auto iter = floatingWindows.second.begin(); iter != floatingWindows.second.end(); ++iter) {
|
||||
if ((*iter)->GetWindowId() == GetWindowId()) {
|
||||
floatingWindows.second.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy app floating window if exist
|
||||
if (appFloatingWindowMap_.count(GetWindowId()) > 0) {
|
||||
for (auto& floatingWindow : appFloatingWindowMap_.at(GetWindowId())) {
|
||||
NotifyBeforeSubWindowDestroy(floatingWindow);
|
||||
WMError fltRet = SingletonContainer::Get<WindowAdapter>().DestroyWindow(floatingWindow->GetWindowId());
|
||||
if (fltRet == WMError::WM_OK) {
|
||||
WLOGFI("Destroy App %{public}d FltWindow %{}d", GetWindowId(), floatingWindow->GetWindowId());
|
||||
} else {
|
||||
WLOGFE("Floating Window %{public}d Destroy Failed", floatingWindow->GetWindowId());
|
||||
}
|
||||
floatingWindow->SetWindowState(WindowState::STATE_DESTROYED);
|
||||
windowMap_.erase(floatingWindow->GetWindowName());
|
||||
}
|
||||
appFloatingWindowMap_.erase(GetWindowId());
|
||||
}
|
||||
}
|
||||
|
||||
void WindowImpl::DestroySubWindow()
|
||||
{
|
||||
if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_
|
||||
std::vector<sptr<WindowImpl>>& subWindows = subWindowMap_.at(property_->GetParentId());
|
||||
for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) {
|
||||
if ((*iter)->GetWindowId() == GetWindowId()) {
|
||||
subWindows.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (subWindowMap_.count(GetWindowId()) > 0) { // remove from subWindowMap_ and windowMap_
|
||||
std::vector<sptr<WindowImpl>>& subWindows = subWindowMap_.at(GetWindowId());
|
||||
for (auto& subWindow : subWindows) {
|
||||
subWindow->SetWindowState(WindowState::STATE_DESTROYED);
|
||||
windowMap_.erase(subWindow->GetWindowName());
|
||||
}
|
||||
subWindowMap_[GetWindowId()].clear();
|
||||
subWindowMap_.erase(GetWindowId());
|
||||
}
|
||||
}
|
||||
|
||||
WMError WindowImpl::Destroy()
|
||||
{
|
||||
if (!IsWindowValid()) {
|
||||
@@ -582,7 +632,7 @@ WMError WindowImpl::Destroy()
|
||||
|
||||
WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId());
|
||||
|
||||
NotifyBeforeDestroy();
|
||||
NotifyBeforeDestroy(GetWindowName());
|
||||
if (subWindowMap_.count(GetWindowId()) > 0) {
|
||||
for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
|
||||
NotifyBeforeSubWindowDestroy(subWindow);
|
||||
@@ -595,30 +645,8 @@ WMError WindowImpl::Destroy()
|
||||
return ret;
|
||||
}
|
||||
windowMap_.erase(GetWindowName());
|
||||
if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_
|
||||
std::vector<sptr<Window>>& subWindows = subWindowMap_.at(property_->GetParentId());
|
||||
for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) {
|
||||
if ((*iter)->GetWindowId() == GetWindowId()) {
|
||||
subWindows.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
subWindowMap_.erase(GetWindowId());
|
||||
|
||||
// Destroy app floating window if exist
|
||||
if (appFloatingWindowMap_.count(GetWindowId()) > 0) {
|
||||
for (auto& floatingWindow : appFloatingWindowMap_.at(GetWindowId())) {
|
||||
NotifyBeforeSubWindowDestroy(floatingWindow);
|
||||
WMError fltRet = SingletonContainer::Get<WindowAdapter>().DestroyWindow(floatingWindow->GetWindowId());
|
||||
if (fltRet == WMError::WM_OK) {
|
||||
WLOGFI("Destroy App %{public}d FltWindow %{public}d", GetWindowId(), floatingWindow->GetWindowId());
|
||||
} else {
|
||||
WLOGFE("Floating Window %{public}d Destroy Failed", floatingWindow->GetWindowId());
|
||||
}
|
||||
}
|
||||
appFloatingWindowMap_.erase(GetWindowId());
|
||||
}
|
||||
DestroySubWindow();
|
||||
DestroyFloatingWindow();
|
||||
|
||||
state_ = WindowState::STATE_DESTROYED;
|
||||
InputTransferStation::GetInstance().RemoveInputWindow(this);
|
||||
@@ -908,6 +936,12 @@ void WindowImpl::UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& liste
|
||||
displayMoveListeners_.erase(iter);
|
||||
}
|
||||
|
||||
void WindowImpl::RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func)
|
||||
{
|
||||
WLOGFE("JS RegisterWindowDestroyedListener the listener");
|
||||
notifyNativefunc_ = std::move(func);
|
||||
}
|
||||
|
||||
void WindowImpl::UpdateRect(const struct Rect& rect, WindowSizeChangeReason reason)
|
||||
{
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
|
||||
@@ -966,7 +1000,6 @@ void WindowImpl::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent)
|
||||
WLOGI("ConsumeKeyEvent keyEvent is consumed");
|
||||
return;
|
||||
}
|
||||
// FIX ME: use context_
|
||||
if (abilityContext_ != nullptr) {
|
||||
WLOGI("ConsumeKeyEvent ability TerminateSelf");
|
||||
abilityContext_->TerminateSelf();
|
||||
|
||||
Reference in New Issue
Block a user