!8524 画中画typeNode方案中自定义xcomponent_controller回调整改

Merge pull request !8524 from ningyuanfeng/master
This commit is contained in:
openharmony_ci 2024-09-26 01:22:19 +00:00 committed by Gitee
commit 33071d4a89
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 55 additions and 0 deletions

View File

@ -27,6 +27,13 @@ namespace {
constexpr int32_t NUMBER_TWO = 2;
}
napi_valuetype GetType(napi_env env, napi_value value)
{
napi_valuetype res = napi_undefined;
napi_typeof(env, value, &res);
return res;
}
napi_value NapiGetUndefined(napi_env env)
{
napi_value result = nullptr;
@ -179,6 +186,37 @@ napi_value JsPipManager::OnSetTypeNodeEnabled(napi_env env, napi_callback_info i
return NapiGetUndefined(env);
}
napi_value JsPipManager::SetPipNodeType(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnSetPipNodeType(env, info) : nullptr;
}
napi_value JsPipManager::OnSetPipNodeType(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::WMS_PIP, "[NAPI]");
size_t argc = 4; // 4: arg number
napi_value argv[4] = { nullptr };
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc != NUMBER_TWO) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Argc count is invalid: %{public}zu", argc);
return NapiGetUndefined(env);
}
napi_value typeNode = argv[0];
bool markPip = false;
if (!ConvertFromJsValue(env, argv[1], markPip)) {
TLOGW(WmsLogTag::WMS_PIP, "Failed to convert param to bool");
}
if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) {
XComponentControllerErrorCode ret =
XComponentController::SetSurfaceCallbackMode(env, typeNode, markPip ?
SurfaceCallbackMode::PIP : SurfaceCallbackMode::DEFAULT);
TLOGI(WmsLogTag::WMS_PIP, "set surface mode, ret: %{public}u, isPip: %{public}d",
static_cast<uint32_t>(ret), static_cast<uint32_t>(markPip));
}
return NapiGetUndefined(env);
}
napi_value JsPipManager::RegisterCallback(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
@ -250,6 +288,7 @@ napi_value JsPipManagerInit(napi_env env, napi_value exportObj)
BindNativeFunction(env, exportObj, "on", moduleName, JsPipManager::RegisterCallback);
BindNativeFunction(env, exportObj, "off", moduleName, JsPipManager::UnregisterCallback);
BindNativeFunction(env, exportObj, "setTypeNodeEnabled", moduleName, JsPipManager::SetTypeNodeEnabled);
BindNativeFunction(env, exportObj, "setPipNodeType", moduleName, JsPipManager::SetPipNodeType);
return NapiGetUndefined(env);
}
} // namespace Rosen

View File

@ -32,6 +32,7 @@ public:
static napi_value RegisterCallback(napi_env env, napi_callback_info info);
static napi_value UnregisterCallback(napi_env env, napi_callback_info info);
static napi_value SetTypeNodeEnabled(napi_env env, napi_callback_info info);
static napi_value SetPipNodeType(napi_env env, napi_callback_info info);
private:
napi_value OnInitXComponentController(napi_env env, napi_callback_info info);
napi_value OnGetCustomUIController(napi_env env, napi_callback_info info);
@ -39,6 +40,7 @@ private:
napi_value OnRegisterCallback(napi_env env, napi_callback_info info);
napi_value OnUnregisterCallback(napi_env env, napi_callback_info info);
napi_value OnSetTypeNodeEnabled(napi_env env, napi_callback_info info);
napi_value OnSetPipNodeType(napi_env env, napi_callback_info info);
};
} // namespace Rosen
} // namespace OHOS

View File

@ -99,6 +99,13 @@ export class PiPContent extends ViewPU {
return;
}
this.useNode = true;
let parent = this.xComponent.getParent();
if (parent === null || parent === undefined) {
pip.setPipNodeType(this.xComponent, false);
} else {
pip.setPipNodeType(this.xComponent, true);
parent.removeChild(this.xComponent);
}
pip.setTypeNodeEnabled();
this.mXCNodeController = new XCNodeController(this.xComponent);
console.info(TAG, 'use Node Controller');

View File

@ -63,6 +63,13 @@ export struct PiPContent {
return;
}
this.useNode = true;
let parent: FrameNode | null = this.xComponent.getParent();
if (parent === null || parent === undefined) {
pip.setPipNodeType(this.xComponent, false);
} else {
pip.setPipNodeType(this.xComponent, true);
parent.removeChild(this.xComponent);
}
pip.setTypeNodeEnabled();
this.mXCNodeController = new XCNodeController(this.xComponent);
console.info(TAG, 'use Node Controller');