diff --git a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts index 83747bb0..17dbf5f6 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -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): void; + /** + * register the callback of keyboardHeightChange + * @param type: 'keyboardHeightChange' + * @systemapi Hide this for inner system use. + * @since 7 + */ + function on(type: 'keyboardHeightChange', callback: AsyncCallback): void; + /** * unregister the callback of systemBarTintChange * @param type: 'systemBarTintChange' @@ -227,6 +240,15 @@ declare namespace window { */ function off(type: 'systemBarTintChange', callback?: Callback): void; + + /** + * unregister the callback of keyboardHeightChange + * @param type: 'keyboardHeightChange' + * @systemapi Hide this for inner system use. + * @since 7 + */ + function off(type: 'keyboardHeightChange', callback: AsyncCallback): 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): void; + + /** + * Sets the background color of window. + * @param color the specified color. + * @since 7 + */ + setBackgroundColor(color: string): Promise; + + /** + * Sets the background color of window. + * @param color the specified color. + * @since 7 + */ + setBackgroundColor(color: string, callback: AsyncCallback): void; + + /** + * Sets the brightness of window. + * @param brightness the specified brightness value. + * @since 7 + */ + setBrightness(brightness: number): Promise; + + /** + * Sets the brightness of window. + * @param brightness the specified brightness value. + * @since 7 + */ + setBrightness(brightness: number, callback: AsyncCallback): void; + + /** + * Sets the dimBehind of window. + * @param dimBehindValue the specified dimBehind. + * @since 7 + */ + setDimBehind(dimBehindValue: number, callback: AsyncCallback): void; + + /** + * Sets the dimBehind of window. + * @param dimBehind the specified dimBehind. + * @since 7 + */ + setDimBehind(dimBehindValue: number): Promise; + + /** + * 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; + + + /** + * 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; + + /** + * Sets whether keep screen on or not. + * @param isKeepScreenOn keep screen on if true, or not if false. + * @since 7 + */ + setKeepScreenOn(isKeepScreenOn: boolean): Promise; + + + /** + * 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; + + + /** + * 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; + + + /** + * 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; + + + /** + * Sets whether is private mode or not. + * @param isPrivacyMode in private mode if true, or not if false. + * @since 7 + */ + setPrivacyMode(isPrivacyMode: boolean): Promise; + + + /** + * 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; + + + /** + * Sets whether is touchable or not. + * @param isTouchable is touchable if true, or not if false. + * @since 7 + */ + setTouchable(isTouchable: boolean): Promise; + + /** + * Sets whether is touchable or not. + * @param isTouchable is touchable if true, or not if false. + * @since 7 + */ + setTouchable(isTouchable: boolean, callback: AsyncCallback): void; } enum WindowStageEventType { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index 1176b971..1078104f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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(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) 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 jsWindowRef; jsWindowRef.reset(engine.CreateReference(objValue, 1)); std::lock_guard lock(g_mutex); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index 5eec62b6..c3f6bb01 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -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 windowToken_ = nullptr; std::unique_ptr registerManager_ = nullptr;