mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 15:00:12 +00:00
新增接口
Signed-off-by: 张有康 <zhangyoukang1@h-partners.com>
This commit is contained in:
parent
56ba08ed04
commit
eceecd2cab
@ -43,8 +43,10 @@ ohos_shared_library("screensessionmanager_napi") {
|
|||||||
]
|
]
|
||||||
|
|
||||||
external_deps = [
|
external_deps = [
|
||||||
|
"ability_runtime:ability_context_native",
|
||||||
"ability_runtime:app_manager",
|
"ability_runtime:app_manager",
|
||||||
"ability_runtime:runtime",
|
"ability_runtime:runtime",
|
||||||
|
"ace_engine:ace_uicontent",
|
||||||
"c_utils:utils",
|
"c_utils:utils",
|
||||||
"eventhandler:libeventhandler",
|
"eventhandler:libeventhandler",
|
||||||
"graphic_2d:librender_service_base",
|
"graphic_2d:librender_service_base",
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <hitrace_meter.h>
|
#include <hitrace_meter.h>
|
||||||
#include <js_runtime_utils.h>
|
#include <js_runtime_utils.h>
|
||||||
|
#include <ui_content.h>
|
||||||
|
|
||||||
#include "interfaces/include/ws_common.h"
|
#include "interfaces/include/ws_common.h"
|
||||||
#include "js_screen_utils.h"
|
#include "js_screen_utils.h"
|
||||||
@ -68,6 +69,8 @@ napi_value JsScreenSession::Create(napi_env env, const sptr<ScreenSession>& scre
|
|||||||
BindNativeFunction(env, objValue, "setTouchEnabled", moduleName,
|
BindNativeFunction(env, objValue, "setTouchEnabled", moduleName,
|
||||||
JsScreenSession::SetTouchEnabled);
|
JsScreenSession::SetTouchEnabled);
|
||||||
BindNativeFunction(env, objValue, "loadContent", moduleName, JsScreenSession::LoadContent);
|
BindNativeFunction(env, objValue, "loadContent", moduleName, JsScreenSession::LoadContent);
|
||||||
|
BindNativeFunction(env, objValue, "getScreenUIContext", moduleName,
|
||||||
|
JsScreenSession::GetScreenUIContext);
|
||||||
return objValue;
|
return objValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +325,45 @@ napi_value JsScreenSession::OnRegisterCallback(napi_env env, napi_callback_info
|
|||||||
return NapiGetUndefined(env);
|
return NapiGetUndefined(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
napi_value JsScreenSession::GetScreenUIContext(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
JsScreenSession* me = CheckParamsAndGetThis<JsScreenSession>(env, info);
|
||||||
|
return (me != nullptr) ? me->OnGetScreenUIContext(env, info) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
napi_value JsScreenSession::OnGetScreenUIContext(napi_env env, napi_callback_info info)
|
||||||
|
{
|
||||||
|
WLOGI("[NAPI]OnGetScreenUIContext");
|
||||||
|
size_t argc = 1;
|
||||||
|
napi_value argv[1] = {nullptr};
|
||||||
|
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
|
||||||
|
if (argc > 0) { // 0: params num
|
||||||
|
WLOGFE("Argc is invalid: %{public}zu", argc);
|
||||||
|
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM)));
|
||||||
|
return NapiGetUndefined(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screenScene_ == nullptr) {
|
||||||
|
WLOGFE("screenScene_ is nullptr");
|
||||||
|
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
|
||||||
|
return NapiGetUndefined(env);
|
||||||
|
}
|
||||||
|
const auto& uiContent = screenScene_->GetUIContent();
|
||||||
|
if (uiContent == nullptr) {
|
||||||
|
WLOGFE("uiContent is nullptr");
|
||||||
|
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
|
||||||
|
return NapiGetUndefined(env);
|
||||||
|
}
|
||||||
|
napi_value uiContext = uiContent->GetUINapiContext();
|
||||||
|
if (uiContext == nullptr) {
|
||||||
|
WLOGFE("uiContext obtained from jsEngine is nullptr");
|
||||||
|
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WmErrorCode::WM_ERROR_STATE_ABNORMALLY)));
|
||||||
|
return NapiGetUndefined(env);
|
||||||
|
}
|
||||||
|
WLOGI("success");
|
||||||
|
return uiContext;
|
||||||
|
}
|
||||||
|
|
||||||
void JsScreenSession::CallJsCallback(const std::string& callbackType)
|
void JsScreenSession::CallJsCallback(const std::string& callbackType)
|
||||||
{
|
{
|
||||||
WLOGI("Call js callback: %{public}s.", callbackType.c_str());
|
WLOGI("Call js callback: %{public}s.", callbackType.c_str());
|
||||||
|
@ -43,6 +43,8 @@ private:
|
|||||||
napi_value OnSetScreenRotationLocked(napi_env env, napi_callback_info info);
|
napi_value OnSetScreenRotationLocked(napi_env env, napi_callback_info info);
|
||||||
static napi_value SetTouchEnabled(napi_env env, napi_callback_info info);
|
static napi_value SetTouchEnabled(napi_env env, napi_callback_info info);
|
||||||
napi_value OnSetTouchEnabled(napi_env env, napi_callback_info info);
|
napi_value OnSetTouchEnabled(napi_env env, napi_callback_info info);
|
||||||
|
static napi_value GetScreenUIContext(napi_env env, napi_callback_info info);
|
||||||
|
napi_value OnGetScreenUIContext(napi_env env, napi_callback_info info);
|
||||||
void CallJsCallback(const std::string& callbackType);
|
void CallJsCallback(const std::string& callbackType);
|
||||||
void RegisterScreenChangeListener();
|
void RegisterScreenChangeListener();
|
||||||
|
|
||||||
|
@ -76,15 +76,11 @@ public:
|
|||||||
return 1; // 1 for root and screen
|
return 1; // 1 for root and screen
|
||||||
}
|
}
|
||||||
|
|
||||||
Ace::UIContent* GetUIContent() const override
|
Ace::UIContent* GetUIContent() const override;
|
||||||
{
|
|
||||||
return uiContent_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
WMError Destroy() override;
|
WMError Destroy() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
std::unique_ptr<Ace::UIContent> uiContent_;
|
std::unique_ptr<Ace::UIContent> uiContent_;
|
||||||
float density_ = 1.0f;
|
float density_ = 1.0f;
|
||||||
int32_t orientation_;
|
int32_t orientation_;
|
||||||
|
@ -201,5 +201,16 @@ void ScreenScene::SetDisplayOrientation(int32_t orientation)
|
|||||||
}
|
}
|
||||||
orientation_ = orientation;
|
orientation_ = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ace::UIContent* ScreenScene::GetUIContent() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
if (uiContent_) {
|
||||||
|
return uiContent_.get();
|
||||||
|
} else {
|
||||||
|
TLOGE(WmsLogTag::DMS, "uiContent_ is nullptr!");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace Rosen
|
} // namespace Rosen
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
Loading…
Reference in New Issue
Block a user