diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index e20e0f7b6bfdbd8b4e264ee877bbaaa977b05a2d..1545b0c9163a7fad36983cc31aa557660b3d3ebf 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -40,12 +40,12 @@ class AbilityContext; namespace OHOS { namespace Rosen { -class IWindowChangeListener : public RefBase { +class IWindowChangeListener : virtual public RefBase { public: virtual void OnSizeChange(Rect rect) = 0; }; -class IWindowSystemBarChangeListener : public RefBase { +class IWindowSystemBarChangeListener : virtual public RefBase { public: virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0; }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 388086cd90acf8ed6c32961e4528271049eb94ad..cf8dcaca022c467d612a2d32a4b29bcac07e68ea 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -94,8 +94,8 @@ enum class WindowFlag : uint32_t { }; namespace { - constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; - constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; + constexpr uint32_t SYSTEM_COLOR_WHITE = 0xFFFFFFE5; + constexpr uint32_t SYSTEM_COLOR_BLACK = 0x00000066; } struct SystemBarProperty { 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 b486f75714591151d4ee840e2660e4700ca54d32..8144a7bde6764117cb9c83dd7e602dfefbf38181 100644 --- a/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts +++ b/interfaces/kits/napi/window_runtime/api/@ohos.window.d.ts @@ -76,6 +76,7 @@ declare namespace windowmanager { */ WINDOW_MODE_PIP } + interface WindowManager { /** * Create a sub window with a specific id and type. @@ -107,6 +108,82 @@ declare namespace windowmanager { find(id: string): Promise; } + /** + * Properties of status bar and navigation bar, it couldn't update automatically + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + interface SystemBarProperties { + /** + * the color of the status bar. + * @since 6 + */ + statusBarColor?: string; + + /** + * the light icon of the status bar. + * @since 7 + */ + isStatusBarLightIcon?: boolean; + + /** + * the color of the navigation bar. + * @since 6 + */ + navigationBarColor?: string; + + /** + * the light icon of the navigation bar. + * @since 7 + */ + isNavigationBarLightIcon?: boolean; + } + /** + * system bar tint of region + * @devices tv, phone, tablet, wearable, car + * @SystemAPI + * @since 8 + */ + interface SystemBarRegionTint { + /** + * system bar type + */ + type: WindowType; + /** + * the visibility of system bar + */ + isEnable?: boolean; + /** + * the region of system bar + */ + region?: Rect; + /** + * the background color of the system bar. + */ + backgroundColor?: string; + /** + * the content color of the system bar. + */ + contentColor?: string + + } + + /** + * system bar tint state for systemui + * @devices tv, phone, tablet, wearable, car + * @SystemAPI + * @since 8 + */ + interface SystemBarTintState { + /** + * id of display + */ + displayId: number; + /** + * region tint of systembar + */ + regionTint: Array; + } /** * Rectangle * @devices tv, phone, tablet, wearable, car @@ -227,7 +304,63 @@ declare namespace windowmanager { * @since 6 */ getProperties(): Promise; + /** + * set the flag of the window is shown full screen + * @param isFullScreen the flag of the window is shown full screen + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + setFullScreen(isFullScreen: boolean, callback: AsyncCallback): void; + /** + * set the flag of the window is shown full screen + * @param isFullScreen the flag of the window is shown full screen + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + setFullScreen(isFullScreen: boolean): Promise; + /** + * set the property of the window can layout in full screen + * @param isLayoutFullScreen the window can layout in full screen + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + setLayoutFullScreen(isLayoutFullScreen: boolean, callback: AsyncCallback): void; + /** + * set the property of the window can layout in full screen + * @param isLayoutFullScreen the window can layout in full screen + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + setLayoutFullScreen(isLayoutFullScreen: boolean): Promise; + /** + * set the system bar to have visible. + * @param names the set of system bar + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + setSystemBarEnable(names: Array<'status'|'navigation'>, callback: AsyncCallback): void; + /** + * set the system bar to have visible. + * @param names the set of system bar + * @devices tv, phone, tablet, wearable, car + * @since 7 + */ + setSystemBarEnable(names: Array<'status'|'navigation'>): Promise; + /** + * set the background color of statusbar + * @param color the background color of statusbar + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + setSystemBarProperties(systemBarProperties: SystemBarProperties, callback: AsyncCallback): void; + /** + * set the background color of statusbar + * @param color the background color of statusbar + * @devices tv, phone, tablet, wearable, car + * @since 6 + */ + setSystemBarProperties(systemBarProperties: SystemBarProperties): Promise; /** * register the callback of windowSizeChange * @param type: 'windowSizeChange' @@ -243,6 +376,24 @@ declare namespace windowmanager { * @since 7 */ off(type: 'windowSizeChange', callback?: Callback): void; + + /** + * register the callback of systemBarTintChange + * @param type: 'systemBarTintChange' + * @devices tv, phone, tablet, wearable, car + * @SystemAPI + * @since 8 + */ + on(type: 'systemBarTintChange', callback: Callback): void; + + /** + * unregister the callback of systemBarTintChange + * @param type: 'systemBarTintChange' + * @devices tv, phone, tablet, wearable, car + * @SystemAPI + * @since 8 + */ + off(type: 'systemBarTintChange', callback?: Callback): void; } } diff --git a/interfaces/kits/napi/window_runtime/js_window.cpp b/interfaces/kits/napi/window_runtime/js_window.cpp index 1d9f66cc668a82de51875a2bdecbb6ade56c7a71..30c110f6ec518b1e5cbe4364f9aa0b81b7d8c506 100644 --- a/interfaces/kits/napi/window_runtime/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/js_window.cpp @@ -104,6 +104,34 @@ NativeValue* JsWindow::UnRegisterWindowCallback(NativeEngine* engine, NativeCall return (me != nullptr) ? me->OnUnRegisterWindowCallback(*engine, *info) : nullptr; } +NativeValue* JsWindow::SetFullScreen(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetFullScreen is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetFullScreen(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetLayoutFullScreen is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetLayoutFullScreen(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetSystemBarEnable is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetSystemBarEnable(*engine, *info) : nullptr; +} + +NativeValue* JsWindow::SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info) +{ + WLOGFI("JsWindow::SetBarProperties is called"); + JsWindow* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnSetSystemBarProperties(*engine, *info) : nullptr; +} + NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnShow is called"); @@ -183,8 +211,8 @@ NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnMoveTo is called"); - if (windowToken_ == nullptr) { - WLOGFE("JsWindow windowToken_ is nullptr"); + if (windowToken_ == nullptr || info.argc < ARGC_TWO) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); return engine.CreateUndefined(); } int32_t x; @@ -219,8 +247,8 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnResize is called"); - if (windowToken_ == nullptr) { - WLOGFE("JsWindow windowToken_ is nullptr"); + if (windowToken_ == nullptr || info.argc < ARGC_TWO) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); return engine.CreateUndefined(); } uint32_t width; @@ -253,8 +281,8 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnSetWindowType is called"); - if (windowToken_ == nullptr) { - WLOGFE("JsWindow windowToken_ is nullptr"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); return engine.CreateUndefined(); } NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); @@ -285,8 +313,8 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) { WLOGFI("JsWindow::OnSetWindowMode is called"); - if (windowToken_ == nullptr) { - WLOGFE("JsWindow windowToken_ is nullptr"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); return engine.CreateUndefined(); } NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); @@ -369,7 +397,12 @@ NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCall if (cbType.compare("windowSizeChange") == 0) { sptr thisListener(windowListener_); windowToken_->RegisterWindowChangeListener(thisListener); - WLOGFI("JsWindow::OnRegisterWindowCallback success"); + WLOGFI("JsWindow::OnRegisterWindowCallback windowSizeChange success"); + } + if (cbType.compare("systemUiTintChange") == 0) { + sptr thisListener(windowListener_); + windowToken_->RegisterWindowSystemBarChangeListener(thisListener); + WLOGFI("JsWindow::OnRegisterWindowCallback systemUiTintChange success"); } return engine.CreateUndefined(); } @@ -395,6 +428,161 @@ NativeValue* JsWindow::OnUnRegisterWindowCallback(NativeEngine& engine, NativeCa return engine.CreateUndefined(); } +NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetFullScreen is called"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); + return engine.CreateUndefined(); + } + NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); + if (nativeVal == nullptr) { + WLOGFE("Failed to convert parameter to isFullScreen"); + return engine.CreateUndefined(); + } + // when false, Do nothing + bool isFullScreen = static_cast(*nativeVal); + if (!isFullScreen) { + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + + SystemBarProperty statusProperty = windowToken_->GetSystemBarPropertyByType( + WindowType::WINDOW_TYPE_STATUS_BAR); + SystemBarProperty navProperty = windowToken_->GetSystemBarPropertyByType( + WindowType::WINDOW_TYPE_NAVIGATION_BAR); + statusProperty.enable_ = false; + navProperty.enable_ = false; + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, statusProperty); + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, navProperty); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetFullScreen success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "JsWindow::OnSetFullScreen failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetLayoutFullScreen is called"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); + return engine.CreateUndefined(); + } + NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); + if (nativeVal == nullptr) { + WLOGFE("Failed to convert parameter to isLayoutFullScreen"); + return engine.CreateUndefined(); + } + bool isLayoutFullScreen = static_cast(*nativeVal); + // when false, Do nothing + if (!isLayoutFullScreen) { + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = windowToken_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ret = windowToken_->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetLayoutFullScreen success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "JsWindow::OnSetLayoutFullScreen failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetSystemBarEnable is called"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); + return engine.CreateUndefined(); + } + std::map systemBarProperties; + if (!GetSystemBarStatus(systemBarProperties, engine, info, windowToken_)) { + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, systemBarProperties](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = WMError::WM_OK; + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, + systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)); + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, + systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetSystemBarEnable success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(ret), "JsWindow::OnSetSystemBarEnable failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_TWO) ? info.argv[INDEX_ONE] : nullptr; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + +NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info) +{ + WLOGFI("JsWindow::OnSetSystemBarProperties is called"); + if (windowToken_ == nullptr || info.argc < ARGC_ONE) { + WLOGFE("JsWindow windowToken_ is nullptr or param is too small!"); + return engine.CreateUndefined(); + } + NativeObject* nativeObj = ConvertNativeValueTo(info.argv[0]); + if (nativeObj == nullptr) { + WLOGFE("Failed to convert object to SystemBarProperties"); + return engine.CreateUndefined(); + } + std::map systemBarProperties; + if (!SetSystemBarPropertiesFromJs(engine, nativeObj, systemBarProperties, windowToken_)) { + WLOGFE("Failed to GetSystemBarProperties From Js Object"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [this, systemBarProperties](NativeEngine& engine, AsyncTask& task, int32_t status) { + WMError ret = WMError::WM_OK; + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, + systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)); + ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, + systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); + if (ret == WMError::WM_OK) { + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("JsWindow::OnSetSystemBarProperties success"); + } else { + task.Reject(engine, CreateJsError(engine, + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnSetSystemBarProperties failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) { WLOGFI("JsWindow::CreateJsWindow is called"); @@ -414,6 +602,10 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window) BindNativeFunction(engine, *object, "getProperties", JsWindow::GetProperties); BindNativeFunction(engine, *object, "on", JsWindow::RegisterWindowCallback); BindNativeFunction(engine, *object, "off", JsWindow::UnRegisterWindowCallback); + BindNativeFunction(engine, *object, "setFullScreen", JsWindow::SetFullScreen); + BindNativeFunction(engine, *object, "setLayoutFullScreen", JsWindow::SetLayoutFullScreen); + BindNativeFunction(engine, *object, "setSystemBarEnable", JsWindow::SetSystemBarEnable); + BindNativeFunction(engine, *object, "setSystemBarProperties", JsWindow::SetSystemBarProperties); return objValue; } } // namespace Rosen diff --git a/interfaces/kits/napi/window_runtime/js_window.h b/interfaces/kits/napi/window_runtime/js_window.h index dceeea194a9f5fd47ca8a11d3a71197a30905a07..4e0e8d35cae8951735d52794b1167af1c63ad43e 100644 --- a/interfaces/kits/napi/window_runtime/js_window.h +++ b/interfaces/kits/napi/window_runtime/js_window.h @@ -40,7 +40,10 @@ public: static NativeValue* GetProperties(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info); - + static NativeValue* SetFullScreen(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info); private: NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info); @@ -52,6 +55,10 @@ private: NativeValue* OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info); sptr windowToken_ = nullptr; sptr windowListener_ = nullptr; }; diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/js_window_listener.cpp index 686be374fb75f9bd45b99b02ab234179896f7f1a..263d86f375064dc48ef5b1062876a58d8a6ce98a 100644 --- a/interfaces/kits/napi/window_runtime/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_listener.cpp @@ -44,12 +44,12 @@ bool JsWindowListener::AddJsListenerObject(std::string type, NativeValue* jsList std::unique_ptr callbackRef; callbackRef.reset(engine_->CreateReference(jsListenerObject, 1)); if (IsCallbackExists(type, jsListenerObject)) { - WLOGFI("JsWindowListener::AddJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", + WLOGFI("JsWindowListener::AddJsListenerObject failed jsWinodwListenerObjectMap_ size: %{public}d!", jsWinodwListenerObjectMap_[type].size()); return false; } jsWinodwListenerObjectMap_[type].insert(std::move(callbackRef)); - WLOGFI("JsWindowListener::AddJsListenerObject failed jsWinodwListenerObjectMap_ size: %{public}d!", + WLOGFI("JsWindowListener::AddJsListenerObject success jsWinodwListenerObjectMap_ size: %{public}d!", jsWinodwListenerObjectMap_[type].size()); return true; } @@ -62,9 +62,7 @@ void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsL WLOGFE("methodName %{public}s not exist!", type.c_str()); return; } - if (jsListenerObject == nullptr) { - jsWinodwListenerObjectMap_.erase(type); - } else { + if (jsListenerObject != nullptr) { for (auto iter = jsWinodwListenerObjectMap_[type].begin(); iter != jsWinodwListenerObjectMap_[type].end(); iter++) { if (jsListenerObject->StrictEquals((*iter)->Get())) { @@ -72,6 +70,7 @@ void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsL } } } + jsWinodwListenerObjectMap_.erase(type); WLOGFI("JsWindowListener::RemoveJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!", jsWinodwListenerObjectMap_[type].size()); WLOGFI("JsWindowListener::RemoveJsListenerObject success!"); @@ -80,6 +79,14 @@ void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsL void JsWindowListener::OnSizeChange(Rect rect) { WLOGFI("JsWindowListener::OnSizeChange is called"); + if (jsWinodwListenerObjectMap_.find("windowSizeChange") == jsWinodwListenerObjectMap_.end()) { + WLOGFE("JsWindowListener::OnSizeChange windowSizeChanged not exists!"); + return; + } + if (jsWinodwListenerObjectMap_["windowSizeChange"].empty()) { + WLOGFE("JsWindowListener::OnSizeChange didn't register!"); + return; + } NativeValue* sizeValue = engine_->CreateObject(); NativeObject* object = ConvertNativeValueTo(sizeValue); if (object == nullptr) { @@ -92,6 +99,26 @@ void JsWindowListener::OnSizeChange(Rect rect) CallJsMethod("windowSizeChange", argv, ArraySize(argv)); } +void JsWindowListener::OnSystemBarPropertyChange(uint32_t displayId, + WindowType type, const SystemBarProperty& prop) +{ + WLOGFI("JsWindowListener::OnSystemBarPropertyChange is called"); + if (jsWinodwListenerObjectMap_["systemUiTintChange"].empty()) { + WLOGFE("JsWindowListener::OnSystemBarPropertyChange didn't register!"); + return; + } + NativeValue* propertyValue = engine_->CreateObject(); + NativeObject* object = ConvertNativeValueTo(propertyValue); + if (object == nullptr) { + WLOGFE("Failed to convert prop to jsObject"); + return; + } + object->SetProperty("displayId", CreateJsValue(*engine_, displayId)); + object->SetProperty("regionTint", CreateJsSystemBarRegionTintObject(*engine_, prop, type)); + NativeValue* argv[] = {propertyValue}; + CallJsMethod("systemUiTintChange", argv, ArraySize(argv)); +} + void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc) { WLOGFI("CallJsMethod methodName = %{public}s", methodName); diff --git a/interfaces/kits/napi/window_runtime/js_window_listener.h b/interfaces/kits/napi/window_runtime/js_window_listener.h index 19ba2d834dd2a654aaf2dcdb9d54e2d72f788df7..175789f9f03c16e189ebd791fac3965efa2c453e 100644 --- a/interfaces/kits/napi/window_runtime/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/js_window_listener.h @@ -19,23 +19,28 @@ #include #include #include +#include "js_window_utils.h" #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" namespace OHOS { namespace Rosen { -class JsWindowListener : public IWindowChangeListener { +class JsWindowListener : public IWindowChangeListener, + public IWindowSystemBarChangeListener { public: explicit JsWindowListener(NativeEngine* engine) : engine_(engine) {} virtual ~JsWindowListener() = default; void OnSizeChange(Rect rect) override; + void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, + const SystemBarProperty& prop) override; bool AddJsListenerObject(std::string type, NativeValue* jsListenerObject); void RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject); private: void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); bool IsCallbackExists(std::string type, NativeValue* jsListenerObject); NativeEngine* engine_ = nullptr; - std::map>> jsWinodwListenerObjectMap_; + std::map>> jsWinodwListenerObjectMap_; std::mutex listenerMutex_; }; } // namespace Rosen diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/js_window_utils.cpp index 0dfe19d8a7b7785d5d38de763cc7d905c40af76e..0fe15b8164e95233f49bf58d8e989d909c5baeec 100644 --- a/interfaces/kits/napi/window_runtime/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/js_window_utils.cpp @@ -13,6 +13,9 @@ * limitations under the License. */ #include "js_window_utils.h" +#include +#include +#include #include "js_runtime_utils.h" #include "window_manager_hilog.h" namespace OHOS { @@ -20,6 +23,7 @@ namespace Rosen { using namespace AbilityRuntime; namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"}; + constexpr int RGB_LENGTH = 7; } static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect) @@ -28,7 +32,7 @@ static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { WLOGFE("Failed to convert rect to jsObject"); - return engine.CreateUndefined(); + return nullptr; } object->SetProperty("left", CreateJsValue(engine, rect.posX_)); object->SetProperty("top", CreateJsValue(engine, rect.posY_)); @@ -56,5 +60,133 @@ NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& object->SetProperty("type", CreateJsValue(engine, window->GetType())); return objValue; } + +static std::string GetHexColor(uint32_t color) +{ + std::stringstream ioss; + std::string temp; + ioss << std::setiosflags(std::ios::uppercase) << std::hex << color; + ioss >> temp; + return temp; +} + +NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, + const SystemBarProperty& prop, WindowType type) +{ + WLOGFI("JsWindow::CreateJsSystemBarRegionTintObject is called"); + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert windowProperties to jsObject"); + return nullptr; + } + object->SetProperty("type", CreateJsValue(engine, static_cast(type))); + object->SetProperty("isEnable", CreateJsValue(engine, prop.enable_)); + std::string bkgColor = GetHexColor(prop.backgroundColor_); + object->SetProperty("backgroundColor", CreateJsValue(engine, bkgColor)); + std::string contentColor = GetHexColor(prop.contentColor_); + object->SetProperty("contentColor", CreateJsValue(engine, contentColor)); + return objValue; +} + +bool GetSystemBarStatus(std::map& systemBarProperties, + NativeEngine& engine, NativeCallbackInfo& info, sptr& window) +{ + NativeArray* nativeArray = ConvertNativeValueTo(info.argv[0]); + if (nativeArray == nullptr) { + WLOGFE("Failed to convert parameter to SystemBarArray"); + return false; + } + uint32_t size = nativeArray->GetLength(); + auto statusProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); + auto navProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR); + statusProperty.enable_ = false; + navProperty.enable_ = false; + systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR] = statusProperty; + systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR] = navProperty; + for (uint32_t i = 0; i < size; i++) { + std::string name; + if (!ConvertFromJsValue(engine, nativeArray->GetElement(i), name)) { + WLOGFE("Failed to convert parameter to SystemBarName"); + return false; + } + if (name.compare("status") == 0) { + systemBarProperties[WindowType::WINDOW_TYPE_STATUS_BAR].enable_ = true; + } else if (name.compare("navigation") == 0) { + systemBarProperties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].enable_ = true; + } + } + return true; +} + +static uint32_t GetBkgColorFromJs(NativeEngine& engine, NativeObject* jsObject, + const char* name, SystemBarProperty& property) +{ + NativeValue* jsColor = jsObject->GetProperty(name); + if (jsColor->TypeOf() != NATIVE_UNDEFINED) { + std::string colorStr; + if (!ConvertFromJsValue(engine, jsColor, colorStr)) { + WLOGFE("Failed to convert parameter to color"); + return property.backgroundColor_; + } + std::regex pattern("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"); + if (!std::regex_match(colorStr, pattern)) { + WLOGFE("invalid color input"); + return property.backgroundColor_; + } + if (colorStr.length() == RGB_LENGTH) { + colorStr += "FF"; // RGB + A + } + std::string color = colorStr.substr(1); + std::stringstream ss; + uint32_t hexColor; + ss << std::hex << color; + ss >> hexColor; + WLOGFI("Final Color is %{public}x", hexColor); + return hexColor; + } + return property.backgroundColor_; +} + +bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, + std::map& properties, sptr& window) +{ + auto statusProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR); + auto navProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR); + properties[WindowType::WINDOW_TYPE_STATUS_BAR] = statusProperty; + properties[WindowType::WINDOW_TYPE_NAVIGATION_BAR] = navProperty; + properties[WindowType::WINDOW_TYPE_STATUS_BAR].backgroundColor_ = GetBkgColorFromJs(engine, + jsObject, "statusBarColor", properties[WindowType::WINDOW_TYPE_STATUS_BAR]); + properties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].backgroundColor_ = GetBkgColorFromJs(engine, + jsObject, "navigationBarColor", properties[WindowType::WINDOW_TYPE_NAVIGATION_BAR]); + NativeValue* jsStatusIcon = jsObject->GetProperty("isStatusBarLightIcon"); + if (jsStatusIcon->TypeOf() != NATIVE_UNDEFINED) { + bool isStatusBarLightIcon; + if (!ConvertFromJsValue(engine, jsStatusIcon, isStatusBarLightIcon)) { + WLOGFE("Failed to convert parameter to isStatusBarLightIcon"); + return false; + } + if (isStatusBarLightIcon) { + properties[WindowType::WINDOW_TYPE_STATUS_BAR].contentColor_ = SYSTEM_COLOR_WHITE; + } else { + properties[WindowType::WINDOW_TYPE_STATUS_BAR].contentColor_ = SYSTEM_COLOR_BLACK; + } + } + + NativeValue* jsNavigationIcon = jsObject->GetProperty("isNavigationBarLightIcon"); + if (jsNavigationIcon->TypeOf() != NATIVE_UNDEFINED) { + bool isNavigationBarLightIcon; + if (!ConvertFromJsValue(engine, jsNavigationIcon, isNavigationBarLightIcon)) { + WLOGFE("Failed to convert parameter to isNavigationBarLightIcon"); + return false; + } + if (isNavigationBarLightIcon) { + properties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].contentColor_ = SYSTEM_COLOR_WHITE; + } else { + properties[WindowType::WINDOW_TYPE_NAVIGATION_BAR].contentColor_ = SYSTEM_COLOR_BLACK; + } + } + return true; +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/js_window_utils.h b/interfaces/kits/napi/window_runtime/js_window_utils.h index a00c712ddcebd6a0b2070c41f769aa4768e3a926..7b7680ac095ff783f7ba6f724fbb3a870213bc10 100644 --- a/interfaces/kits/napi/window_runtime/js_window_utils.h +++ b/interfaces/kits/napi/window_runtime/js_window_utils.h @@ -15,6 +15,7 @@ #ifndef OHOS_JS_WINDOW_UTILS_H #define OHOS_JS_WINDOW_UTILS_H +#include #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" @@ -30,6 +31,12 @@ namespace { } NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window); + bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, + std::map& properties, sptr& window); + bool GetSystemBarStatus(std::map& systemBarProperties, + NativeEngine& engine, NativeCallbackInfo& info, sptr& window); + NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, + const SystemBarProperty& prop, WindowType type); } } #endif \ No newline at end of file diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 6dd6f004c48638f1ac258b05fe4b73d99efc66c6..aaf0751a9599142a48c22e741cfc33d87f24349d 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -603,6 +603,10 @@ void WindowImpl::SetDefaultOption() property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); break; } + case WindowType::WINDOW_TYPE_KEYGUARD: { + RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + } case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: { property_->SetWindowFlags(0); break;