add window js interfaces

Signed-off-by: zengqingyu <zengqingyu3@huawei.com>
Change-Id: I8e447d69d1e5bf4b32ba4a0f87ed6cbdd6fbbdd2
This commit is contained in:
zengqingyu
2022-03-08 16:54:25 +08:00
parent 662e52c5f7
commit f35cda2cbf
3 changed files with 386 additions and 0 deletions
@@ -57,6 +57,11 @@ declare namespace window {
* Navigation bar.
*/
TYPE_NAVIGATION_BAR,
/**
* System gesture.
*/
TYPE_SYSTEM_GESTURE,
}
/**
@@ -219,6 +224,14 @@ declare namespace window {
*/
function on(type: 'systemBarTintChange', callback: Callback<SystemBarTintState>): void;
/**
* register the callback of keyboardHeightChange
* @param type: 'keyboardHeightChange'
* @systemapi Hide this for inner system use.
* @since 7
*/
function on(type: 'keyboardHeightChange', callback: AsyncCallback<number>): void;
/**
* unregister the callback of systemBarTintChange
* @param type: 'systemBarTintChange'
@@ -227,6 +240,15 @@ declare namespace window {
*/
function off(type: 'systemBarTintChange', callback?: Callback<SystemBarTintState>): void;
/**
* unregister the callback of keyboardHeightChange
* @param type: 'keyboardHeightChange'
* @systemapi Hide this for inner system use.
* @since 7
*/
function off(type: 'keyboardHeightChange', callback: AsyncCallback<number>): void;
/**
* Properties of status bar and navigation bar, it couldn't update automatically
* @syscap SystemCapability.WindowManager.WindowManager.Core
@@ -426,6 +448,43 @@ declare namespace window {
* @since 6
*/
touchable: boolean
/**
* Brightness value of window.
* @since 7
*/
brightness: number
/**
* The dimbehind value of window.
* @since 7
*/
dimBehindValue: number
/**
* Whether keep screen on.
* @since 7
*/
isKeepScreenOn: boolean
/**
* Whether make window in privacy mode or not.
* @since 7
*/
isPrivacyMode: boolean
/**
* Whether is round corner or not.
* @since 7
*/
isRoundCorner: boolean
/**
* Whether is transparent or not.
* @since 7
*/
isTransparent: boolean
}
/**
@@ -720,6 +779,125 @@ declare namespace window {
* @since 8
*/
getColorSpace(callback: AsyncCallback<ColorSpace>): void;
/**
* Sets the background color of window.
* @param color the specified color.
* @since 7
*/
setBackgroundColor(color: string): Promise<void>;
/**
* Sets the background color of window.
* @param color the specified color.
* @since 7
*/
setBackgroundColor(color: string, callback: AsyncCallback<void>): void;
/**
* Sets the brightness of window.
* @param brightness the specified brightness value.
* @since 7
*/
setBrightness(brightness: number): Promise<void>;
/**
* Sets the brightness of window.
* @param brightness the specified brightness value.
* @since 7
*/
setBrightness(brightness: number, callback: AsyncCallback<void>): void;
/**
* Sets the dimBehind of window.
* @param dimBehindValue the specified dimBehind.
* @since 7
*/
setDimBehind(dimBehindValue: number, callback: AsyncCallback<void>): void;
/**
* Sets the dimBehind of window.
* @param dimBehind the specified dimBehind.
* @since 7
*/
setDimBehind(dimBehindValue: number): Promise<void>;
/**
* Sets whether focusable or not.
* @param isFocusable can be focus if true, or can not be focus if false.
* @since 7
*/
setFocusable(isFocusable: boolean): Promise<void>;
/**
* Sets whether focusable or not.
* @param isFocusable can be focus if true, or can not be focus if false.
* @since 7
*/
setFocusable(isFocusable: boolean, callback: AsyncCallback<void>): void;
/**
* Sets whether keep screen on or not.
* @param isKeepScreenOn keep screen on if true, or not if false.
* @since 7
*/
setKeepScreenOn(isKeepScreenOn: boolean): Promise<void>;
/**
* Sets whether keep screen on or not.
* @param isKeepScreenOn keep screen on if true, or not if false.
* @since 7
*/
setKeepScreenOn(isKeepScreenOn: boolean, callback: AsyncCallback<void>): void;
/**
* Sets whether outside can be touch or not.
* @param touchable outside can be touch if true, or not if false.
* @since 7
*/
setOutsideTouchable(touchable: boolean): Promise<void>;
/**
* Sets whether outside can be touch or not.
* @param touchable outside can be touch if true, or not if false.
* @since 7
*/
setOutsideTouchable(touchable: boolean, callback: AsyncCallback<void>): void;
/**
* Sets whether is private mode or not.
* @param isPrivacyMode in private mode if true, or not if false.
* @since 7
*/
setPrivacyMode(isPrivacyMode: boolean): Promise<void>;
/**
* Sets whether is private mode or not.
* @param isPrivacyMode in private mode if true, or not if false.
* @since 7
*/
setPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void;
/**
* Sets whether is touchable or not.
* @param isTouchable is touchable if true, or not if false.
* @since 7
*/
setTouchable(isTouchable: boolean): Promise<void>;
/**
* Sets whether is touchable or not.
* @param isTouchable is touchable if true, or not if false.
* @since 7
*/
setTouchable(isTouchable: boolean, callback: AsyncCallback<void>): void;
}
enum WindowStageEventType {
@@ -189,6 +189,62 @@ NativeValue* JsWindow::IsSupportWideGamut(NativeEngine* engine, NativeCallbackIn
return (me != nullptr) ? me->OnIsSupportWideGamut(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetBackgroundColor(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetBackgroundColor is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetBackgroundColor(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetBrightness(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetBrightness is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetBrightness(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetDimBehind(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetDimBehind is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetDimBehind(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetFocusable(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetFocusable is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetFocusable(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetKeepScreenOn(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetkeepScreenOn is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetKeepScreenOn(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetOutsideTouchable(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetOutsideTouchable is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetOutsideTouchable(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetPrivacyMode(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetPrivacyMode is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetPrivacyMode(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetTouchable(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetTouchable is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetTouchable(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetColorSpace is called");
@@ -884,6 +940,134 @@ NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallback
return result;
}
NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetBackgroundColor is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetBrightness is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetDimBehind is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetFocusable is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetKeepScreenOn is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetOutsideTouchable is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetPrivacyMode is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetTouchable is called");
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
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* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetColorSpace is called");
@@ -1003,6 +1187,14 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
BindNativeFunction(engine, *object, "isSupportWideGamut", JsWindow::IsSupportWideGamut);
BindNativeFunction(engine, *object, "setColorSpace", JsWindow::SetColorSpace);
BindNativeFunction(engine, *object, "getColorSpace", JsWindow::GetColorSpace);
BindNativeFunction(engine, *object, "setBackgroundColor", JsWindow::SetBackgroundColor);
BindNativeFunction(engine, *object, "setBrightness", JsWindow::SetBrightness);
BindNativeFunction(engine, *object, "setDimBehind", JsWindow::SetDimBehind);
BindNativeFunction(engine, *object, "setFocusable", JsWindow::SetFocusable);
BindNativeFunction(engine, *object, "setKeepScreenOn", JsWindow::SetKeepScreenOn);
BindNativeFunction(engine, *object, "setOutsideTouchable", JsWindow::SetOutsideTouchable);
BindNativeFunction(engine, *object, "setPrivacyMode", JsWindow::SetPrivacyMode);
BindNativeFunction(engine, *object, "setTouchable", JsWindow::SetTouchable);
std::shared_ptr<NativeReference> jsWindowRef;
jsWindowRef.reset(engine.CreateReference(objValue, 1));
std::lock_guard<std::recursive_mutex> lock(g_mutex);
@@ -49,6 +49,14 @@ public:
static NativeValue* SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* IsShowing(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetBackgroundColor(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetBrightness(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetDimBehind(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetFocusable(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetKeepScreenOn(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetOutsideTouchable(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetPrivacyMode(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetTouchable(NativeEngine* engine, NativeCallbackInfo* info);
// colorspace, gamut
static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info);
@@ -79,6 +87,14 @@ private:
NativeValue* OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetBackgroundColor(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetOutsideTouchable(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& info);
sptr<Window> windowToken_ = nullptr;
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;