From 864b624bb0c328fa488d5395831897a70be90388 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 01:04:49 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18 --- interfaces/innerkits/wm/window.h | 53 +++++++ .../window_runtime/window_napi/js_window.cpp | 71 +++++++++ .../window_runtime/window_napi/js_window.h | 4 + .../window_napi/js_window_listener.cpp | 19 +++ .../window_napi/js_window_listener.h | 5 +- .../js_window_register_manager.cpp | 19 +++ .../window_napi/js_window_register_manager.h | 3 + utils/include/window_helper.h | 5 + .../common/include/window_session_property.h | 26 +++- .../common/src/window_session_property.cpp | 29 +++- .../interfaces/include/ws_common_inner.h | 3 +- .../js_scene_session.cpp | 80 +++++++++- .../scene_session_manager/js_scene_session.h | 5 + .../include/zidl/session_stage_interface.h | 1 + .../zidl/session_stage_ipc_interface_code.h | 1 + .../include/zidl/session_stage_proxy.h | 1 + .../include/zidl/session_stage_stub.h | 1 + .../src/zidl/session_stage_proxy.cpp | 30 ++++ .../container/src/zidl/session_stage_stub.cpp | 11 ++ .../session/host/include/scene_session.h | 8 + window_scene/session/host/include/session.h | 6 + .../session/host/src/scene_session.cpp | 27 ++++ window_scene/session/host/src/session.cpp | 48 ++++++ .../include/scene_session_manager.h | 8 +- .../src/scene_session_manager.cpp | 105 ++++++++++++- window_scene/test/mock/mock_session_stage.h | 1 + .../unittest/scene_session_manager_test12.cpp | 140 ++++++++++++++++++ .../test/unittest/scene_session_test5.cpp | 70 +++++++++ .../test/unittest/session_stage_stub_test.cpp | 15 ++ window_scene/test/unittest/session_test.cpp | 47 ++++++ wm/include/window_session_impl.h | 15 ++ wm/src/window_session_impl.cpp | 99 +++++++++++++ .../unittest/window_session_impl_test4.cpp | 91 ++++++++++++ 33 files changed, 1033 insertions(+), 14 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 4168ae9d9d..d418e47c1c 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -526,6 +526,21 @@ public: virtual void OnMainWindowClose(bool& terminateCloseProcess) {} }; +/** + * @class IWindowHighlightChangeListener + * + * @brief IWindowHighlightChangeListener is a Listener to observe event when highlight change of window. + */ +class IWindowHighlightChangeListener : virtual public RefBase { +public: + /** + * @brief Notify caller when when highlight status changes. + * + * @param isHighlight Whether the window is highlighted. + */ + virtual void OnWindowHighlightChange(bool isHighlight) {} +}; + /** * @class ISwitchFreeMultiWindowListener * @@ -2979,6 +2994,44 @@ public: { return WMError::WM_OK; } + + /** + * @brief Register window highlight change listener. + * + * @param listener IWindowHighlightChangeListener. + * @return WM_OK means register success, others means register failed. + */ + virtual WMError RegisterWindowHighlightChangeListeners(const sptr& listener) + { + return WMError::WM_OK; + } + + /** + * @brief Unregister window highlight change listener. + * + * @param listener IWindowHighlightChangeListener. + * @return WM_OK means unregister success, others means unregister failed. + */ + virtual WMError UnRegisterWindowHighlightChangeListeners(const sptr& listener) + { + return WMError::WM_OK; + } + + /** + * @brief Set whether to enable exclusively highlight. + * + * @param isExclusivelyHighlighted the value true means to enable exclusively highlight, and false means the opposite. + * @return WM_OK means set success, others means set failed. + */ + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { return WMError::WM_OK; } + + /** + * @brief Get highlight property of window. + * + * @return True means the window is highlighted, false means the window is not highlighted. + */ + virtual bool IsWindowHighlighted() { return false; } + }; } } 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 40525c5764..31e3a8c44d 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -1059,6 +1059,20 @@ napi_value JsWindow::IsSystemAvoidAreaEnabled(napi_env env, napi_callback_info i return (me != nullptr) ? me->OnIsSystemAvoidAreaEnabled(env, info) : nullptr; } +napi_value JsWindow::SetExclusivelyHighlighted(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]"); + JsWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSetExclusivelyHighlighted(env, info) : nullptr; +} + +napi_value JsWindow::IsWindowHighlighted(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]"); + JsWindow* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnIsWindowHighlighted(env, info) : nullptr; +} + static WMError UpdateSystemBarProperties(const std::map& systemBarProperties, const std::map& systemBarPropertyFlags, const sptr& window) { @@ -7473,6 +7487,61 @@ napi_value JsWindow::OnIsSystemAvoidAreaEnabled(napi_env env, napi_callback_info } } +napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_info info) +{ + size_t argc = FOUR_PARAMS_SIZE; + napi_value argv[FOUR_PARAMS_SIZE] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != ARG_COUNT_ONE) { + TLOGE(WmsLogTag::WMS_FOCUS, "argc is invalid: %{public}zu", argc); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + bool exclusivelyHighlighted = true; + if (!ConvertFromJsValue(env, argv[INDEX_ZERO], exclusivelyHighlighted)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to convert parameter to exclusivelyHighlighted"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + } + napi_value result = nullptr; + std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); + auto asyncTask = [weakToken = wptr(windowToken_), exclusivelyHighlighted, env, task = napiAsyncTask, where = __func__] { + auto weakWindow = weakToken.promote(); + if (weakWindow == nullptr) { + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s window is nullptr", where); + task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); + return; + } + WMError ret = weakWindow->SetExclusivelyHighlighted(exclusivelyHighlighted); + if (ret == WMError::WM_OK) { + task->Resolve(env, NapiGetUndefined(env)); + } else { + WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); + task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set exclusively highlighted failed")); + } + TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s end, window [%{public}u, %{public}s]", + where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); + }; + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high + )) { + napiAsyncTask->Reject(env, CreateJsError(env, + static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); + } + return result; +} + +napi_value JsWindow::OnIsWindowHighlighted(napi_env env, napi_callback_info info) +{ + wptr weakToken(windowToken_); + auto window = weakToken.promote(); + if (window == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "window is nullptr"); + return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + + bool isHighlighted = window->IsWindowHighlighted(); + TLOGI(WmsLogTag::WMS_FOCUS, "get window highlight end, isHighlighted = %{public}u", isHighlighted); + return CreateJsValue(env, isHighlighted); +} + void BindFunctions(napi_env env, napi_value object, const char* moduleName) { BindNativeFunction(env, object, "startMoving", moduleName, JsWindow::StartMoving); @@ -7615,6 +7684,8 @@ void BindFunctions(napi_env env, napi_value object, const char* moduleName) BindNativeFunction(env, object, "getWindowDensityInfo", moduleName, JsWindow::GetWindowDensityInfo); BindNativeFunction(env, object, "setSystemAvoidAreaEnabled", moduleName, JsWindow::SetSystemAvoidAreaEnabled); BindNativeFunction(env, object, "isSystemAvoidAreaEnabled", moduleName, JsWindow::IsSystemAvoidAreaEnabled); + BindNativeFunction(env, object, "setExclusivelyHighlighted", moduleName, JsWindow::SetExclusivelyHighlighted); + BindNativeFunction(env, object, "isWindowHighlighted", moduleName, JsWindow::IsWindowHighlighted); } } // namespace Rosen } // namespace OHOS 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 5eec163094..fe34a44c8b 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -118,6 +118,8 @@ public: static napi_value StopMoving(napi_env env, napi_callback_info info); static napi_value GetWindowDensityInfo(napi_env env, napi_callback_info info); static napi_value EnableDrag(napi_env env, napi_callback_info info); + static napi_value SetExclusivelyHighlighted(napi_env env, napi_callback_info info); + static napi_value IsWindowHighlighted(napi_env env, napi_callback_info info); // colorspace, gamut static napi_value IsSupportWideGamut(napi_env env, napi_callback_info info); @@ -264,6 +266,8 @@ private: napi_value OnIsFocused(napi_env env, napi_callback_info info); napi_value OnRequestFocus(napi_env env, napi_callback_info info); napi_value OnGetWindowDensityInfo(napi_env env, napi_callback_info info); + napi_value OnSetExclusivelyHighlighted(napi_env env, napi_callback_info info); + napi_value OnIsWindowHighlighted(napi_env env, napi_callback_info info); // colorspace, gamut napi_value OnIsSupportWideGamut(napi_env env, napi_callback_info info); diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 725b83704f..74e09a9d67 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -629,5 +629,24 @@ void JsWindowListener::OnMainWindowClose(bool& terminateCloseProcess) eventHandler_->PostSyncTask(jsCallback, "wms:JsWindowListener::OnMainWindowClose", AppExecFwk::EventQueue::Priority::IMMEDIATE); } + +void JsWindowListener::OnWindowHighlightChange(bool isHighlight) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "isHighlight: %d", isHighlight); + auto jsCallback = [self = weakRef_, isHighlight, env = env_, where = __func__] { + auto thisListener = self.promote(); + if (thisListener == nullptr || env == nullptr) { + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: this listener or env is nullptr", where); + return; + } + HandleScope handleScope(env); + napi_value argv[] = { CreateJsValue(env, isHighlight) }; + thisListener->CallJsMethod(WINDOW_HIGHLIGHT_CHANGE_CB.c_str(), argv, ArraySize(argv)); + }; + if (napi_status::napi_ok != napi_send_event(env_, jsCallback, napi_eprio_immediate)) { + TLOGE(WmsLogTag::WMS_FOCUS, "failed to send event"); + } +} + } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h index 88926ed566..21184693dc 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.h @@ -53,6 +53,7 @@ const std::string WINDOW_NO_INTERACTION_DETECT_CB = "noInteractionDetected"; const std::string WINDOW_RECT_CHANGE_CB = "windowRectChange"; const std::string SUB_WINDOW_CLOSE_CB = "subWindowClose"; const std::string WINDOW_STAGE_CLOSE_CB = "windowStageClose"; +const std::string WINDOW_HIGHLIGHT_CHANGE_CB = "windowHighlightChange"; class JsWindowListener : public IWindowChangeListener, public ISystemBarChangedListener, @@ -73,7 +74,8 @@ class JsWindowListener : public IWindowChangeListener, public IWindowNoInteractionListener, public IWindowRectChangeListener, public IMainWindowCloseListener, - public ISubWindowCloseListener { + public ISubWindowCloseListener, + public IWindowHighlightChangeListener { public: JsWindowListener(napi_env env, std::shared_ptr callback, CaseType caseType) : env_(env), jsCallBack_(callback), caseType_(caseType), weakRef_(wptr (this)) {} @@ -112,6 +114,7 @@ public: void OnRectChange(Rect rect, WindowSizeChangeReason reason) override; void OnSubWindowClose(bool& terminateCloseProcess) override; void OnMainWindowClose(bool& terminateCloseProcess) override; + void OnWindowHighlightChange(bool isHighlight) override; private: void OnLastStrongRef(const void *) override; diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 354b58086a..a79a103dc0 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -51,6 +51,7 @@ const std::map WINDOW_LISTENER_MAP { {WINDOW_NO_INTERACTION_DETECT_CB, RegisterListenerType::WINDOW_NO_INTERACTION_DETECT_CB}, {WINDOW_RECT_CHANGE_CB, RegisterListenerType::WINDOW_RECT_CHANGE_CB}, {SUB_WINDOW_CLOSE_CB, RegisterListenerType::SUB_WINDOW_CLOSE_CB}, + {WINDOW_HIGHLIGHT_CHANGE_CB, RegisterListenerType::WINDOW_HIGHLIGHT_CHANGE_CB}, }; const std::map WINDOW_STAGE_LISTENER_MAP { // white register list for window stage @@ -481,6 +482,8 @@ WmErrorCode JsWindowRegisterManager::ProcessListener(RegisterListenerType regist return ProcessWindowRectChangeRegister(windowManagerListener, window, isRegister, env, parameter); case static_cast(RegisterListenerType::SUB_WINDOW_CLOSE_CB): return ProcessSubWindowCloseRegister(windowManagerListener, window, isRegister, env, parameter); + case static_cast(RegisterListenerType::WINDOW_HIGHLIGHT_CHANGE_CB): + return ProcessWindowHighlightChangeRegister(windowManagerListener, window, isRegister, env, parameter); default: WLOGFE("RegisterListenerType %{public}u is not supported", static_cast(registerListenerType)); @@ -622,5 +625,21 @@ WmErrorCode JsWindowRegisterManager::ProcessMainWindowCloseRegister(const sptrUnregisterMainWindowCloseListeners(listener)); return ret; } + +WmErrorCode JsWindowRegisterManager::ProcessWindowHighlightChangeRegister(const sptr& listener, + const sptr& window, bool isRegister, napi_env env, napi_value parameter) +{ + if (window == nullptr) { + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + } + sptr thisListener(listener); + WmErrorCode ret = WmErrorCode::WM_OK; + if (isRegister) { + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterWindowHighlightChangeListeners(thisListener)); + } else { + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterWindowHighlightChangeListeners(thisListener)); + } + return ret; +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h index 15f2c30e5a..c2f629a583 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.h @@ -49,6 +49,7 @@ enum class RegisterListenerType : uint32_t { SUB_WINDOW_CLOSE_CB, WINDOW_STAGE_EVENT_CB, WINDOW_STAGE_CLOSE_CB, + WINDOW_HIGHLIGHT_CHANGE_CB, }; class JsWindowRegisterManager { @@ -103,6 +104,8 @@ private: bool isRegister, napi_env env, napi_value parameter = nullptr); WmErrorCode ProcessMainWindowCloseRegister(const sptr& listener, const sptr& window, bool isRegister, napi_env env, napi_value parameter = nullptr); + WmErrorCode ProcessWindowHighlightChangeRegister(const sptr& listener, const sptr& window, + bool isRegister, napi_env env, napi_value parameter = nullptr); WmErrorCode ProcessListener(RegisterListenerType registerListenerType, CaseType caseType, const sptr& windowManagerListener, const sptr& window, bool isRegister, napi_env env, napi_value parameter); diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index 73a5cc8772..1d3415421b 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -64,6 +64,11 @@ public: return IsSubWindow(type) && (windowFlags & static_cast(WindowFlag::WINDOW_FLAG_IS_TOAST)); } + static inline bool IsModalWindow(uint32_t windowFlags) + { + return windowFlags & static_cast(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL); + } + static inline bool IsDialogWindow(WindowType type) { return type == WindowType::WINDOW_TYPE_DIALOG; diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 5554010d67..2571a1daa8 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -117,9 +117,6 @@ public: Rect GetRequestRect() const; RectAnimationConfig GetRectAnimationConfig() const; WindowType GetWindowType() const; - bool GetFocusable() const; - bool GetFocusableOnShow() const; - bool GetTouchable() const; bool GetDragEnabled() const; bool GetHideNonSystemFloatingWindows() const; bool GetForceHide() const; @@ -251,6 +248,15 @@ public: void SetKeyboardViewMode(KeyboardViewMode mode); KeyboardViewMode GetKeyboardViewMode() const; + /* + * Window focus + */ + bool GetFocusable() const; + bool GetFocusableOnShow() const; + bool GetTouchable() const; + bool GetExclusivelyHighlighted() const; + void SetExclusivelyHighlighted(bool isExclusivelyHighlighted); + private: void setTouchHotAreasInner(const std::vector& rects, std::vector& touchHotAreas); bool MarshallingTouchHotAreasInner(const std::vector& touchHotAreas, Parcel& parcel) const; @@ -286,6 +292,7 @@ private: bool WriteActionUpdateWindowModeSupportType(Parcel& parcel); bool WriteActionUpdateAvoidAreaOption(Parcel& parcel); bool WriteActionUpdateBackgroundAlpha(Parcel& parcel); + bool WriteActionUpdateExclusivelyHighlighted(Parcel& parcel); void ReadActionUpdateTurnScreenOn(Parcel& parcel); void ReadActionUpdateKeepScreenOn(Parcel& parcel); void ReadActionUpdateFocusable(Parcel& parcel); @@ -313,6 +320,7 @@ private: void ReadActionUpdateWindowModeSupportType(Parcel& parcel); void ReadActionUpdateAvoidAreaOption(Parcel& parcel); void ReadActionUpdateBackgroundAlpha(Parcel& parcel); + void ReadActionUpdateExclusivelyHighlighted(Parcel& parcel); std::string windowName_; SessionInfo sessionInfo_; mutable std::mutex windowRectMutex_; @@ -322,9 +330,6 @@ private: mutable std::mutex rectAnimationConfigMutex_; RectAnimationConfig rectAnimationConfig_ { 0, 0.0f, 0.0f, 0.0f, 0.0f }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; // type main window - bool focusable_ { true }; - bool focusableOnShow_ { true }; - bool touchable_ { true }; bool dragEnabled_ = { true }; bool raiseEnabled_ = { true }; bool isSystemCalling_ = { false }; @@ -434,6 +439,15 @@ private: * Window Immersive */ uint32_t avoidAreaOption_ = 0; + + /* + * Window Focus + */ + bool focusable_ { true }; + bool focusableOnShow_ { true }; + bool touchable_ { true }; + bool isExclusivelyHighlighted_ { true }; + }; struct FreeMultiWindowConfig : public Parcelable { diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index 6bf3616143..a1c9ba7911 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -89,6 +89,8 @@ const std::map WindowSessionProperty::writeFun &WindowSessionProperty::WriteActionUpdateAvoidAreaOption), std::make_pair(static_cast(WSPropertyChangeAction::ACTION_UPDATE_BACKGROUND_ALPHA), &WindowSessionProperty::WriteActionUpdateBackgroundAlpha), + std::make_pair(static_cast(WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED), + &WindowSessionProperty::WriteActionUpdateExclusivelyHighlighted), }; const std::map WindowSessionProperty::readFuncMap_ { @@ -154,6 +156,8 @@ const std::map WindowSessionProperty::readFuncM &WindowSessionProperty::ReadActionUpdateAvoidAreaOption), std::make_pair(static_cast(WSPropertyChangeAction::ACTION_UPDATE_BACKGROUND_ALPHA), &WindowSessionProperty::ReadActionUpdateBackgroundAlpha), + std::make_pair(static_cast(WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED), + &WindowSessionProperty::ReadActionUpdateExclusivelyHighlighted), }; WindowSessionProperty::WindowSessionProperty(const sptr& property) @@ -1172,7 +1176,8 @@ bool WindowSessionProperty::Marshalling(Parcel& parcel) const parcel.WriteBool(isPcAppInPad_) && parcel.WriteBool(compatibleModeEnableInPad_) && parcel.WriteString(appInstanceKey_) && parcel.WriteBool(isSystemKeyboard_) && parcel.WriteUint32(avoidAreaOption_) && parcel.WriteBool(isWindowDelayRaiseEnabled_) && - parcel.WriteUint8(backgroundAlpha_) && parcel.WriteUint32(static_cast(KeyboardViewMode_)); + parcel.WriteUint8(backgroundAlpha_) && parcel.WriteUint32(static_cast(KeyboardViewMode_)) && + parcel.WriteBool(isExclusivelyHighlighted_); } WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) @@ -1257,6 +1262,7 @@ WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) property->SetWindowDelayRaiseEnabled(parcel.ReadBool()); property->SetBackgroundAlpha(parcel.ReadUint8()); property->SetKeyboardViewMode(static_cast(parcel.ReadUint32())); + property->SetExclusivelyHighlighted(parcel.ReadBool()); return property; } @@ -1343,6 +1349,7 @@ void WindowSessionProperty::CopyFrom(const sptr& property isWindowDelayRaiseEnabled_ = property->isWindowDelayRaiseEnabled_; backgroundAlpha_ = property->backgroundAlpha_; KeyboardViewMode_ = property->KeyboardViewMode_; + isExclusivelyHighlighted_ = property->isExclusivelyHighlighted_; } bool WindowSessionProperty::Write(Parcel& parcel, WSPropertyChangeAction action) @@ -1493,6 +1500,11 @@ bool WindowSessionProperty::WriteActionUpdateBackgroundAlpha(Parcel& parcel) return parcel.WriteUint8(backgroundAlpha_); } +bool WindowSessionProperty::WriteActionUpdateExclusivelyHighlighted(Parcel& parcel) +{ + return parcel.WriteBool(isExclusivelyHighlighted_); +} + void WindowSessionProperty::Read(Parcel& parcel, WSPropertyChangeAction action) { const auto funcIter = readFuncMap_.find(static_cast(action)); @@ -1644,6 +1656,11 @@ void WindowSessionProperty::ReadActionUpdateBackgroundAlpha(Parcel& parcel) SetBackgroundAlpha(parcel.ReadUint8()); } +void WindowSessionProperty::ReadActionUpdateExclusivelyHighlighted(Parcel& parcel) +{ + SetExclusivelyHighlighted(parcel.ReadBool()); +} + void WindowSessionProperty::SetTransform(const Transform& trans) { trans_ = trans; @@ -1858,5 +1875,15 @@ void WindowSessionProperty::SetBackgroundAlpha(uint8_t alpha) { backgroundAlpha_ = alpha; } + +void WindowSessionProperty::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) +{ + isExclusivelyHighlighted_ = isExclusivelyHighlighted; +} + +bool WindowSessionProperty::GetExclusivelyHighlighted() const +{ + return isExclusivelyHighlighted_; +} } // namespace Rosen } // namespace OHOS diff --git a/window_scene/interfaces/include/ws_common_inner.h b/window_scene/interfaces/include/ws_common_inner.h index bdc83ff285..5c51b74f60 100644 --- a/window_scene/interfaces/include/ws_common_inner.h +++ b/window_scene/interfaces/include/ws_common_inner.h @@ -59,7 +59,8 @@ enum class WSPropertyChangeAction : uint64_t { ACTION_UPDATE_AVOID_AREA_OPTION = 1llu << 32, ACTION_UPDATE_KEYBOARD_TOUCH_HOT_AREA = 1llu << 33, ACTION_UPDATE_BACKGROUND_ALPHA = 1llu << 34, - ACTION_UPDATE_END = ACTION_UPDATE_BACKGROUND_ALPHA, + ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED = 1llu << 35, + ACTION_UPDATE_END = ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED, }; enum class AreaType : uint32_t { diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index bbb7975f1c..95c6ee719d 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -88,7 +88,10 @@ const std::string SESSION_LOCK_STATE_CHANGE_CB = "sessionLockStateChange"; const std::string UPDATE_SESSION_LABEL_AND_ICON_CB = "updateSessionLabelAndIcon"; const std::string KEYBOARD_STATE_CHANGE_CB = "keyboardStateChange"; const std::string KEYBOARD_VIEW_MODE_CHANGE_CB = "KeyboardViewModeChange"; +const std::string HIGHLIGHT_CHANGE_CB = "highlightChange"; +constexpr int ARG_COUNT_1 = 1; +constexpr int ARG_COUNT_2 = 2; constexpr int ARG_COUNT_3 = 3; constexpr int ARG_COUNT_4 = 4; constexpr int ARG_INDEX_0 = 0; @@ -160,7 +163,8 @@ const std::map ListenerFuncMap { {SESSION_LOCK_STATE_CHANGE_CB, ListenerFuncType::SESSION_LOCK_STATE_CHANGE_CB}, {UPDATE_SESSION_LABEL_AND_ICON_CB, ListenerFuncType::UPDATE_SESSION_LABEL_AND_ICON_CB}, {KEYBOARD_STATE_CHANGE_CB, ListenerFuncType::KEYBOARD_STATE_CHANGE_CB}, - {KEYBOARD_VIEW_MODE_CHANGE_CB, ListenerFuncType::KEYBOARD_VIEW_MODE_CHANGE_CB}, + {KEYBOARD_VIEW_MODE_CHANGE_CB, ListenerFuncType::KEYBOARD_VIEW_MODE_CHANGE_CB}, + {HIGHLIGHT_CHANGE_CB, ListenerFuncType::HIGHLIGHT_CHANGE_CB}, }; const std::vector g_syncGlobalPositionPermission { @@ -448,6 +452,8 @@ void JsSceneSession::BindNativeMethodForFocus(napi_env env, napi_value objValue, BindNativeFunction(env, objValue, "setSystemFocusable", moduleName, JsSceneSession::SetSystemFocusable); BindNativeFunction(env, objValue, "setSystemSceneBlockingFocus", moduleName, JsSceneSession::SetSystemSceneBlockingFocus); + BindNativeFunction(env, objValue, "setExclusivelyHighlighted", moduleName, + JsSceneSession::SetExclusivelyHighlighted); } void JsSceneSession::BindNativeMethodForWaterfall(napi_env env, napi_value objValue, const char* moduleName) @@ -1916,6 +1922,13 @@ napi_value JsSceneSession::SetSystemSceneBlockingFocus(napi_env env, napi_callba return (me != nullptr) ? me->OnSetSystemSceneBlockingFocus(env, info) : nullptr; } +napi_value JsSceneSession::SetExclusivelyHighlighted(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "[NAPI]"); + JsSceneSession* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnSetExclusivelyHighlighted(env, info) : nullptr; +} + napi_value JsSceneSession::MaskSupportEnterWaterfallMode(napi_env env, napi_callback_info info) { TLOGD(WmsLogTag::WMS_LAYOUT_PC, "[NAPI]"); @@ -2527,6 +2540,9 @@ void JsSceneSession::ProcessRegisterCallback(ListenerFuncType listenerFuncType) case static_cast(ListenerFuncType::KEYBOARD_VIEW_MODE_CHANGE_CB): ProcessKeyboardViewModeChangeRegister(); break; + case static_cast(ListenerFuncType::HIGHLIGHT_CHANGE_CB): + ProcessSetHighlightChangeRegister(); + break; default: break; } @@ -2799,6 +2815,34 @@ napi_value JsSceneSession::OnSetSystemSceneBlockingFocus(napi_env env, napi_call return NapiGetUndefined(env); } +napi_value JsSceneSession::OnSetExclusivelyHighlighted(napi_env env, napi_callback_info info) +{ + size_t argc = ARG_COUNT_4; + napi_value argv[ARG_COUNT_4] = { nullptr }; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != ARG_COUNT_1) { + TLOGE(WmsLogTag::WMS_FOCUS, "Argc is invalid: %{public}zu", argc); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + bool isExclusivelyHighlighted = true; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_0], isExclusivelyHighlighted)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Failed to convert parameter to isExclusivelyHighlighted"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr, id:%{public}d", persistentId_); + return NapiGetUndefined(env); + } + session->SetExclusivelyHighlighted(isExclusivelyHighlighted); + TLOGD(WmsLogTag::WMS_FOCUS, "end"); + return NapiGetUndefined(env); +} + napi_value JsSceneSession::OnMaskSupportEnterWaterfallMode(napi_env env, napi_callback_info info) { auto session = weakSession_.promote(); @@ -5998,4 +6042,38 @@ void JsSceneSession::OnKeyboardViewModeChange(const KeyboardViewMode& mode) }; taskScheduler_->PostMainThreadTask(task, "OnKeyboardViewModeChange"); } + +void JsSceneSession::ProcessSetHighlightChangeRegister() +{ + NotifyHighlightChangeFunc func = [this](bool isHighlight) { + this->NotifyHighlightChange(isHighlight); + }; + auto session = weakSession_.promote(); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr"); + return; + } + session->SetHighlightChangeNotifyFunc(func); +} + +void JsSceneSession::NotifyHighlightChange(bool isHighlight) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "isHighlight:%{public}d, id:%{public}d", isHighlight, persistentId_); + auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_] { + auto jsSceneSession = weakThis.promote(); + if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { + TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id:%{public}d has been destroyed", persistentId); + return; + } + auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); + if (!jsCallBack) { + TLOGNE(WmsLogTag::WMS_FOCUS, "jsCallBack is nullptr"); + return; + } + napi_value jsIsHighlight = CreateJsValue(env, isHighlight); + napi_value argv[] = { jsIsHighlight }; + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); + }; + taskScheduler_->PostMainThreadTask(task, "NotifyHighlightChange"); +} } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index 2136a46f33..e236a4ec7e 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -89,6 +89,7 @@ enum class ListenerFuncType : uint32_t { UPDATE_SESSION_LABEL_AND_ICON_CB, KEYBOARD_STATE_CHANGE_CB, KEYBOARD_VIEW_MODE_CHANGE_CB, + HIGHLIGHT_CHANGE_CB, }; class SceneSession; @@ -202,6 +203,7 @@ private: static napi_value SetBehindWindowFilterEnabled(napi_env env, napi_callback_info info); static napi_value SetFreezeImmediately(napi_env env, napi_callback_info info); static napi_value SendContainerModalEvent(napi_env env, napi_callback_info info); + static napi_value SetExclusivelyHighlighted(napi_env env, napi_callback_info info); napi_value OnRegisterCallback(napi_env env, napi_callback_info info); napi_value OnUpdateNativeVisibility(napi_env env, napi_callback_info info); @@ -270,6 +272,7 @@ private: napi_value OnMaskSupportEnterWaterfallMode(napi_env env, napi_callback_info info); napi_value OnUpdateFullScreenWaterfallMode(napi_env env, napi_callback_info info); napi_value OnSendContainerModalEvent(napi_env env, napi_callback_info info); + napi_value OnSetExclusivelyHighlighted(napi_env env, napi_callback_info info); bool IsCallbackRegistered(napi_env env, const std::string& type, napi_value jsListenerObject); void ProcessChangeSessionVisibilityWithStatusBarRegister(); @@ -322,6 +325,7 @@ private: void ProcessUpdateSessionLabelAndIconRegister(); void ProcessKeyboardStateChangeRegister(); void ProcessKeyboardViewModeChangeRegister(); + void ProcessSetHighlightChangeRegister(); /* * PC Window Layout @@ -382,6 +386,7 @@ private: void UpdateSessionLabelAndIcon(const std::string& label, const std::shared_ptr& icon); void OnKeyboardStateChange(const SessionState& state, const KeyboardViewMode& mode); void OnKeyboardViewModeChange(const KeyboardViewMode& mode); + void NotifyHighlightChange(bool isHighlight); /* * PC Window Layout diff --git a/window_scene/session/container/include/zidl/session_stage_interface.h b/window_scene/session/container/include/zidl/session_stage_interface.h index 764f1211bc..70cb80be6d 100644 --- a/window_scene/session/container/include/zidl/session_stage_interface.h +++ b/window_scene/session/container/include/zidl/session_stage_interface.h @@ -86,6 +86,7 @@ public: */ virtual WSError UpdateFocus(bool isFocused) = 0; virtual WSError NotifyDestroy() = 0; + virtual WSError NotifyHighlightChange(bool isHighlight) = 0; /** * @brief Notify client to close the existing pip window. diff --git a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h index 84e13fc739..78732556ed 100644 --- a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h +++ b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h @@ -70,6 +70,7 @@ enum class SessionStageInterfaceCode { TRANS_ID_SET_FULLSCREEN_WATERFALL_MODE, TRANS_ID_SET_SUPPORT_ENTER_WATERFALL_MODE, TRANS_ID_SEND_CONTAINER_MODAL_EVENT, + TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE, }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/session/container/include/zidl/session_stage_proxy.h b/window_scene/session/container/include/zidl/session_stage_proxy.h index aec3625207..dce61d90a7 100644 --- a/window_scene/session/container/include/zidl/session_stage_proxy.h +++ b/window_scene/session/container/include/zidl/session_stage_proxy.h @@ -83,6 +83,7 @@ public: WSError SetFullScreenWaterfallMode(bool isWaterfallMode) override; WSError SetSupportEnterWaterfallMode(bool isSupportEnter) override; WSError SendContainerModalEvent(const std::string& eventName, const std::string& eventValue) override; + WSError NotifyHighlightChange(bool isHighlight) override; private: static inline BrokerDelegator delegator_; diff --git a/window_scene/session/container/include/zidl/session_stage_stub.h b/window_scene/session/container/include/zidl/session_stage_stub.h index c9a0d55d58..8627087cb9 100644 --- a/window_scene/session/container/include/zidl/session_stage_stub.h +++ b/window_scene/session/container/include/zidl/session_stage_stub.h @@ -81,6 +81,7 @@ private: int HandleSetFullScreenWaterfallMode(MessageParcel& data, MessageParcel& reply); int HandleSetSupportEnterWaterfallMode(MessageParcel& data, MessageParcel& reply); int HandleSendContainerModalEvent(MessageParcel& data, MessageParcel& reply); + int HandleNotifyHighlightChange(MessageParcel& data, MessageParcel& reply); }; } // namespace OHOS::Rosen #endif // OHOS_WINDOW_SCENE_SESSION_STAGE_STUB_H diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index 65fb68e151..7fd995e226 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -478,6 +478,36 @@ WSError SessionStageProxy::UpdateFocus(bool focus) return static_cast(ret); } +WSError SessionStageProxy::NotifyHighlightChange(bool isHighlight) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_FOCUS, "WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (!data.WriteBool(isHighlight)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Write isHighlight failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "remote is null"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (remote->SendRequest(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + WSError SessionStageProxy::NotifyTransferComponentData(const AAFwk::WantParams& wantParams) { MessageParcel data; diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index 1cb64e5178..a4b45b68be 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -188,6 +188,8 @@ int SessionStageStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messag return HandleExtensionHostData(data, reply, option); case static_cast(SessionStageInterfaceCode::TRANS_ID_SEND_CONTAINER_MODAL_EVENT): return HandleSendContainerModalEvent(data, reply); + case static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE): + return HandleNotifyHighlightChange(data, reply); default: WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -327,6 +329,15 @@ int SessionStageStub::HandleNotifyTransferComponentData(MessageParcel& data, Mes return ERR_NONE; } +int SessionStageStub::HandleNotifyHighlightChange(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "called!"); + bool isHighlight = data.ReadBool(); + WSError errCode = NotifyHighlightChange(isHighlight); + reply.WriteUint32(static_cast(errCode)); + return ERR_NONE; +} + int SessionStageStub::HandleNotifyTransferComponentDataSync(MessageParcel& data, MessageParcel& reply) { std::shared_ptr wantParams(data.ReadParcelable()); diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index e943e6edb4..4b4a1de483 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -613,6 +613,12 @@ public: bool IsKeyboardAvoidAreaActive() const; virtual void SetKeyboardViewModeChangeListener(const NotifyKeyboarViewModeChangeFunc& func) {}; + /* + * Window Focus + */ + bool IsRelated(sptr& prevSession); + void SetHighlightChangeNotifyFunc(const NotifyHighlightChangeFunc& func); + protected: void NotifyIsCustomAnimationPlaying(bool isPlaying); void SetMoveDragCallback(); @@ -863,6 +869,8 @@ private: WMError HandleActionUpdateAvoidAreaOption(const sptr& property, WSPropertyChangeAction action); WMError HandleBackgroundAlpha(const sptr& property, WSPropertyChangeAction action); + WMError HandleActionUpdateExclusivelyHighlighted(const sptr& property, + WSPropertyChangeAction action); void HandleSpecificSystemBarProperty(WindowType type, const sptr& property); void SetWindowFlags(const sptr& property); void NotifySessionChangeByActionNotifyManager(const sptr& property, diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index afa3578e5a..b628a0cf08 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -95,6 +95,7 @@ using NotifyWindowMovingFunc = std::function& icon)>; using NotifyKeyboardStateChangeFunc = std::function; +using NotifyHighlightChangeFunc = std::function; class ILifecycleListener { public: @@ -398,6 +399,9 @@ public: void NotifyUIRequestFocus(); virtual void NotifyUILostFocus(); WSError NotifyFocusStatus(bool isFocused); + virtual WSError UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange = true); + WSError NotifyHighlightChange(bool isHighlight); + void SetExclusivelyHighlighted(bool isExclusivelyHighlighted); /* * Multi Window @@ -689,6 +693,7 @@ protected: NotifySystemSessionKeyEventFunc systemSessionKeyEventFunc_; NotifyContextTransparentFunc contextTransparentFunc_; NotifyFrameLayoutFinishFunc frameLayoutFinishFunc_; + NotifyHighlightChangeFunc highlightChangeFunc_; /* * Window LifeCycle @@ -746,6 +751,7 @@ protected: */ bool isFocused_ = false; bool blockingFocus_ {false}; + bool isHighlight_ {false}; uint32_t uiNodeId_ = 0; float aspectRatio_ = 0.0f; diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 0095229030..6efbb9e2b8 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -3668,6 +3668,14 @@ bool SceneSession::IsSystemSessionAboveApp() const return false; } +/** @note @window.focus */ +bool SceneSession::IsRelated(sptr& prevSession) +{ + int32_t currSessionId = GetMainSessionId(); + int32_t prevSessionId = prevSession->GetMainSessionId(); + return currSessionId == prevSessionId && prevSessionId != INVALID_SESSION_ID; +} + void SceneSession::NotifyIsCustomAnimationPlaying(bool isPlaying) { WLOGFI("id %{public}d %{public}u", GetPersistentId(), isPlaying); @@ -4460,6 +4468,8 @@ WMError SceneSession::ProcessUpdatePropertyByAction(const sptr(WSPropertyChangeAction::ACTION_UPDATE_BACKGROUND_ALPHA): return HandleBackgroundAlpha(property, action); + case static_cast(WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED): + return HandleActionUpdateExclusivelyHighlighted(property, action); default: TLOGE(WmsLogTag::DEFAULT, "Failed to find func handler!"); return WMError::WM_DO_NOTHING; @@ -4787,6 +4797,18 @@ WMError SceneSession::HandleBackgroundAlpha(const sptr& p return WMError::WM_OK; } +WMError SceneSession::HandleActionUpdateExclusivelyHighlighted(const sptr& property, + WSPropertyChangeAction action) +{ + auto sessionProperty = GetSessionProperty(); + if (!sessionProperty) { + TLOGE(WmsLogTag::WMS_FOCUS, "property is null"); + return WMError::WM_ERROR_INVALID_PARAM; + } + sessionProperty->SetExclusivelyHighlighted(property->GetExclusivelyHighlighte()); + return WMError::WM_OK; +} + void SceneSession::HandleSpecificSystemBarProperty(WindowType type, const sptr& property) { auto systemBarProperties = property->GetSystemBarProperty(); @@ -5760,6 +5782,11 @@ void SceneSession::SetPrivacyModeChangeNotifyFunc(const NotifyPrivacyModeChangeF privacyModeChangeNotifyFunc_ = func; } +void SceneSession::SetHighlightChangeNotifyFunc(const NotifyHighlightChangeFunc& func) +{ + highlightChangeFunc_ = func; +} + int32_t SceneSession::GetStatusBarHeight() { int32_t height = 0; diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 42c98da815..f2ef5c2d91 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2639,6 +2639,54 @@ WSError Session::RequestFocus(bool isFocused) return WSError::WS_OK; } +void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) +{ + auto property = GetSessionProperty(); + if (property == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "windowId: %{public}d property is nullptr", persistentId_); + return; + } + if(isExclusivelyHighlighted == property->GetExclusivelyHighlighted()){ + return; + } + TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isExclusivelyHighlighted: %{public}d", persistentId_, + isExclusivelyHighlighted); + property->SetExclusivelyHighlighted(isExclusivelyHighlighted); +} + +void Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange) +{ + TLOGI(WmsLogTag::WMS_FOCUS, + "windowId: %{public}d, currHighlight: %{public}d, nextHighlight: %{public}d, isNotify:%{public}d", persistentId_, + isHighlight_, isHighlight, isNotifyHighlightChange); + if (isHighlight_ == isHighlight){ + return WSError::WS_DO_NOTHING; + } + isHighlight_ = isHighlight; + if (isNotifyHighlightChange){ + NotifyHighlightChange(isHighlight); + if (highlightChangeFunc_ != nullptr){ + highlightChangeFunc_(isHighlight); + } + } + return WSError::WS_OK; +} + +WSError Session::NotifyHighlightChange(bool isHighlight) +{ + if (!IsSessionValid()) { + TLOGW(WmsLogTag::WMS_FOCUS, "Session is invalid, id:%{public}d state:%{public}u", + persistentId_, GetSessionState()); + return WSError::WS_ERROR_INVALID_SESSION; + } + if (!sessionStage_) { + TLOGE(WmsLogTag::WMS_FOCUS, "sessionStage is null"); + return WSError::WS_ERROR_NULLPTR; + } + sessionStage_ -> NotifyHighlightChange(isHighlight); + return WSError::WS_OK; +} + WSError Session::SetCompatibleModeInPc(bool enable, bool isSupportDragInPcCompatibleMode) { TLOGI(WmsLogTag::WMS_SCB, "SetCompatibleModeInPc enable: %{public}d, isSupportDragInPcCompatibleMode: %{public}d", diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index b032ecc132..e36bd8cfa9 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -264,6 +264,11 @@ public: void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; WSError GetFocusSessionToken(sptr& token) override; WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; + void UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, bool isProactiveUnfocus); + void SetHighlightSessionIds(sptr& sceneSession); + void AddHighlightSessionIds(sptr& sceneSession); + void RemoveHighlightSessionIds(sptr& sceneSession); + void LogHighLight(); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); @@ -694,7 +699,7 @@ private: sptr GetNextFocusableSession(int32_t persistentId); sptr GetTopNearestBlockingFocusSession(uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT); + WSError ShiftFocus(sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT, bool isProactiveUnfocus = false); void UpdateFocusStatus(sptr& sceneSession, bool isFocused); void NotifyFocusStatus(sptr& sceneSession, bool isFocused); int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, @@ -935,6 +940,7 @@ private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; + std::unordered_set highlightIds_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 3d5758514e..37494371a5 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4968,6 +4968,11 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) } oss << "Focus window: " << GetFocusedSessionId() << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; + oss << "Highlighted windows: "; + for( auto persistentId : highlightIds_) { + oss << persistentId << ","; + } + oss << std::endl; dumpInfo.append(oss.str()); return WSError::WS_OK; } @@ -5462,7 +5467,7 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh return WSError::WS_OK; } - return ShiftFocus(nextSession, reason); + return ShiftFocus(nextSession, reason, true); } WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() @@ -5481,7 +5486,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() needBlockNotifyUnfocusStatus_ = needBlockNotifyFocusStatusUntilForeground_; needBlockNotifyFocusStatusUntilForeground_ = false; - return ShiftFocus(nextSession, FocusChangeReason::WIND); + return ShiftFocus(nextSession, FocusChangeReason::WIND, true); } WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId) @@ -5815,7 +5820,7 @@ void SceneSessionManager::SetAbilityManagerCollaboratorRegisteredFunc( taskScheduler_->PostAsyncTask(task, __func__); } -WSError SceneSessionManager::ShiftFocus(sptr& nextSession, FocusChangeReason reason) +WSError SceneSessionManager::ShiftFocus(sptr& nextSession, FocusChangeReason reason, bool isProactiveUnfocus) { // unfocus int32_t focusedId = focusedSessionId_; @@ -5831,6 +5836,7 @@ WSError SceneSessionManager::ShiftFocus(sptr& nextSession, FocusCh nextId = nextSession->GetPersistentId(); } UpdateFocusStatus(nextSession, true); + UpdateHighlightStatus(focusedSession, nextSession, isProactiveUnfocus); bool scbPrevFocus = focusedSession && focusedSession->GetSessionInfo().isSystem_; bool scbCurrFocus = nextSession && nextSession->GetSessionInfo().isSystem_; if (!scbPrevFocus && scbCurrFocus) { @@ -5875,6 +5881,88 @@ void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bo } } +/** @note @window.focus */ +void SceneSessionManager::UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, bool isProactiveUnfocus) +{ + if (preSceneSession == nullptr || currSceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); + return; + } + if(isProactiveUnfocus){ + TLOGD(WmsLogTag::WMS_FOCUS, "proactiveUnfocus"); + RemoveHighlightSessionIds(preSceneSession); + } + auto sessionProperty = currSceneSession->GetSessionProperty(); + if(sessionProperty->GetExclusivelyHighlighted()) { + TLOGD(WmsLogTag::WMS_FOCUS, "exclusively highlighted"); + SetHighlightSessionIds(currSceneSession); + return; + } + if(currSceneSession->GetSessionInfo().isSystem_) { + TLOGD(WmsLogTag::WMS_FOCUS, "system highlighted"); + AddHighlightSessionIds(currSceneSession); + return; + } + if(currSceneSession->IsRelated(preSceneSession)) { + TLOGD(WmsLogTag::WMS_FOCUS, "related highlighted"); + AddHighlightSessionIds(currSceneSession); + return; + } + TLOGD(WmsLogTag::WMS_FOCUS, "highlighted"); + SetHighlightSessionIds(currSceneSession); +} + +/** @note @window.focus */ +void SceneSessionManager::SetHighlightSessionIds(sptr& sceneSession) +{ + if(sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); + return; + } + for (auto persistentId : highlightIds_) { + auto session = GetSceneSession(persistentId); + if (session == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr"); + continue; + } + if (sceneSession->GetPersistentId() != persistentId) { + session->UpdateHighlightStatus(false); + } + } + sceneSession->UpdateHighlightStatus(true); + highlightIds_.clear(); + highlightIds_.insert(sceneSession->GetPersistentId()); + LogHighLight(); +} + +/** @note @window.focus */ +void SceneSessionManager::AddHighlightSessionIds(sptr& sceneSession) +{ + if(sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); + return; + } + sceneSession->UpdateHighlightStatus(true); + highlightIds_.insert(sceneSession->GetPersistentId()); + LogHighLight(); +} + +/** @note @window.focus */ +void SceneSessionManager::RemoveHighlightSessionIds(sptr& sceneSession) +{ + if(sceneSession == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); + return; + } + if (highlightIds_.find(sceneSession->GetPersistentId()) != highlightIds_.end()) { + sceneSession->UpdateHighlightStatus(false); + highlightIds_.erase(sceneSession->GetPersistentId()); + } else { + TLOGE(WmsLogTag::WMS_FOCUS, "not found scene session with id: %{public}d", sceneSession->GetPersistentId()); + } + LogHighLight(); +} + void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bool isFocused) { if (sceneSession == nullptr) { @@ -12496,4 +12584,15 @@ WSError SceneSessionManager::CloneWindow(int32_t fromPersistentId, int32_t toPer return WSError::WS_OK; }, __func__); } + +void SceneSessionManager::LogHighLight() +{ + std::string str = ""; + for (auto persistentId : highlightIds_) { + str += std::to_string(persistentId); + str += ","; + } + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", str.c_str()); +} + } // namespace OHOS::Rosen diff --git a/window_scene/test/mock/mock_session_stage.h b/window_scene/test/mock/mock_session_stage.h index b1efbac77e..272b74a9ad 100644 --- a/window_scene/test/mock/mock_session_stage.h +++ b/window_scene/test/mock/mock_session_stage.h @@ -73,6 +73,7 @@ public: MOCK_METHOD1(SetSplitButtonVisible, WSError(bool isVisible)); MOCK_METHOD1(SetEnableDragBySystem, WSError(bool enableDrag)); MOCK_METHOD2(SendContainerModalEvent, WSError(const std::string& eventName, const std::string& eventValue)); + MOCK_METHOD1(NotifyHighlightChange, WSError(bool isHighlight)); }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index b495fec78e..c50991cf6c 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -1403,6 +1403,146 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground06, Function | Sm EXPECT_EQ(result, WMError::WM_OK); EXPECT_EQ(hasFloatWindowForeground, false); } + +/** + * @tc.name: UpdateHighlightStatus + * @tc.desc: UpdateHighlightStatus + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, UpdateHighlightStatus, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + sptr property1 = sptr::MakeSptr(); + sptr property2 = sptr::MakeSptr(); + + SessionInfo info1; + info1.abilityName_ = "abilityName_test1"; + info1.bundleName_ = "bundleName_test1"; + + SessionInfo info2; + info2.abilityName_ = "abilityName_test2"; + info2.bundleName_ = "bundleName_test2"; + + sptr preSceneSession = sptr::MakeSptr(info1, nullptr); + sptr currSceneSession = sptr::MakeSptr(info2, nullptr); + + preSceneSession->property_ = property1; + currSceneSession->property_ = property2; + preSceneSession->property_->SetPersistentId(1); + currSceneSession->property_->SetPersistentId(2); + + sptr nullSceneSession1; + sptr nullSceneSession2; + + ssm_->UpdateHighlightStatus(nullSceneSession1, nullSceneSession2, false); + ssm_->UpdateHighlightStatus(preSceneSession, nullSceneSession2, false); + ssm_->UpdateHighlightStatus(preSceneSession, currSceneSession, true); + ssm_->UpdateHighlightStatus(preSceneSession, currSceneSession, false); + currSceneSession->property_->isExclusivelyHighlighted_ = false; + info1.isSystem_ = true; + ssm_->UpdateHighlightStatus(preSceneSession, currSceneSession, false); + info1.isSystem_ = false; + ssm_->UpdateHighlightStatus(preSceneSession, currSceneSession, false); + preSceneSession->property_->SetPersistentId(2); + ssm_->UpdateHighlightStatus(preSceneSession, currSceneSession, false); +} + +/** + * @tc.name: SetHighlightSessionIds + * @tc.desc: SetHighlightSessionIds + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, SetHighlightSessionIds, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + sptr property = sptr::MakeSptr(); + SessionInfo info1; + info1.abilityName_ = "abilityName_test1"; + info1.bundleName_ = "bundleName_test1"; + + sptr currSceneSession = sptr::MakeSptr(info1, nullptr); + currSceneSession->property_ = property; + currSceneSession->property_->SetPersistentId(1); + currSceneSession->persistentId_ = 1; + ssm_->highlightIds_.clear(); + ssm_->SetHighlightSessionIds(currSceneSession); + ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true); +} + +/** + * @tc.name: AddHighlightSessionIds + * @tc.desc: AddHighlightSessionIds + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, AddHighlightSessionIds, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + sptr property1 = sptr::MakeSptr(); + sptr property2 = sptr::MakeSptr(); + + SessionInfo info1; + info1.abilityName_ = "abilityName_test1"; + info1.bundleName_ = "bundleName_test1"; + + SessionInfo info2; + info2.abilityName_ = "abilityName_test2"; + info2.bundleName_ = "bundleName_test2"; + + sptr preSceneSession = sptr::MakeSptr(info1, nullptr); + sptr currSceneSession = sptr::MakeSptr(info2, nullptr); + + preSceneSession->property_->SetPersistentId(1); + currSceneSession->property_->SetPersistentId(2); + preSceneSession->persistentId_ = 1; + currSceneSession->persistentId_ = 2; + preSceneSession->property_ = property1; + currSceneSession->property_ = property2; + ssm_->AddHighlightSessionIds(currSceneSession); + ssm_->AddHighlightSessionIds(preSceneSession); + ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true); + ASSERT_EQ(ssm_->highlightIds_.count(2) == 1, true); +} + +/** + * @tc.name: RemoveHighlightSessionIds + * @tc.desc: RemoveHighlightSessionIds + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerTest12, RemoveHighlightSessionIds, Function | SmallTest | Level3) +{ + ASSERT_NE(ssm_, nullptr); + sptr property1 = sptr::MakeSptr(); + sptr property2 = sptr::MakeSptr(); + + SessionInfo info1; + info1.abilityName_ = "abilityName_test1"; + info1.bundleName_ = "bundleName_test1"; + + SessionInfo info2; + info2.abilityName_ = "abilityName_test2"; + info2.bundleName_ = "bundleName_test2"; + + sptr preSceneSession = sptr::MakeSptr(info1, nullptr); + sptr currSceneSession = sptr::MakeSptr(info2, nullptr); + + preSceneSession->property_->SetPersistentId(1); + currSceneSession->property_->SetPersistentId(2); + + preSceneSession->persistentId_ = 1; + currSceneSession->persistentId_ = 2; + + preSceneSession->property_ = property1; + currSceneSession->property_ = property2; + ssm_->AddHighlightSessionIds(currSceneSession); + ssm_->AddHighlightSessionIds(preSceneSession); + ASSERT_EQ(ssm_->highlightIds_.count(1) == 1, true); + ASSERT_EQ(ssm_->highlightIds_.count(2) == 1, true); + ssm_->RemoveHighlightSessionIds(currSceneSession); + ASSERT_EQ(ssm_->highlightIds_.count(2) == 0, true); + ssm_->RemoveHighlightSessionIds(preSceneSession); + ASSERT_EQ(ssm_->highlightIds_.count(1) == 0, true); +} + } } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 3b107c1245..82363a4771 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -1725,6 +1725,76 @@ HWTEST_F(SceneSessionTest5, ActivateKeyboardAvoidArea01, Function | SmallTest | sceneSession->ActivateKeyboardAvoidArea(true, false); ASSERT_EQ(true, sceneSession->IsKeyboardAvoidAreaActive()); } + +/** + * @tc.name: isRelated + * @tc.desc: test isRelated + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest5, isRelated, Function | SmallTest | Level2) +{ + SessionInfo info1; + info1.abilityName_ = "abilityName_test1"; + info1.bundleName_ = "bundleName_test1"; + SessionInfo info2; + info2.abilityName_ = "abilityName_test2"; + info2.bundleName_ = "bundleName_test2"; + sptr preSceneSession = sptr::MakeSptr(info1, nullptr); + sptr currSceneSession = sptr::MakeSptr(info2, nullptr); + preSceneSession->persistentId_ = 1; + currSceneSession->persistentId_ = 1; + ASSERT_EQ(true, currSceneSession->isRelated(preSceneSession)); + currSceneSession->persistentId_ = 2; + ASSERT_EQ(false, currSceneSession->isRelated(preSceneSession)); + + sptr subSession1 = sptr::MakeSptr(info1, nullptr); + sptr subSession2 = sptr::MakeSptr(info2, nullptr); + subSession1->SetParentSession(preSceneSession); + subSession2->SetParentSession(currSceneSession); + currSceneSession->persistentId_ = 1; + subSession1->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); + subSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); + ASSERT_EQ(true, subSession1->isRelated(subSession1)); + currSceneSession->persistentId_ = 2; + ASSERT_EQ(false, subSession1->isRelated(subSession1)); +} + +/** + * @tc.name: HandleActionUpdateExclusivelyHighlighted + * @tc.desc: test HandleActionUpdateExclusivelyHighlighted + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest5, HandleActionUpdateExclusivelyHighlighted, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "HandleActionUpdateExclusivelyHighlighted"; + info.bundleName_ = "HandleActionUpdateExclusivelyHighlighted"; + info.isSystem_ = true; + sptr session = sptr::MakeSptr(info, nullptr); + ASSERT_NE(nullptr, session); + sptr property = sptr::MakeSptr(); + ASSERT_NE(nullptr, property); + property->SetExclusivelyHighlighted(true); + WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED; + auto res = session->HandleActionUpdateExclusivelyHighlighted(property, action); + EXPECT_EQ(WMError::WM_OK, res); +} + +/** + * @tc.name: SetHighlightChangeNotifyFunc + * @tc.desc: SetHighlightChangeNotifyFunc Test + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest5, SetHighlightChangeNotifyFunc, Function | SmallTest | Level2) +{ + SessionInfo info; + info.abilityName_ = "test"; + info.bundleName_ = "test"; + sptr session = sptr::MakeSptr(info, nullptr); + EXPECT_NE(session, nullptr); + session->SetHighlightChangeNotifyFunc([](int32_t persistentId) {}); + EXPECT_NE(session->highlightChangeFunc_, nullptr); +} } } } \ No newline at end of file diff --git a/window_scene/test/unittest/session_stage_stub_test.cpp b/window_scene/test/unittest/session_stage_stub_test.cpp index 0ef062f9e2..e8ddda94ca 100644 --- a/window_scene/test/unittest/session_stage_stub_test.cpp +++ b/window_scene/test/unittest/session_stage_stub_test.cpp @@ -890,6 +890,21 @@ HWTEST_F(SessionStageStubTest, HandleSendContainerModalEvent, Function | SmallTe data.WriteString("value2"); ASSERT_EQ(0, sessionStageStub_->HandleSendContainerModalEvent(data, reply)); } + +/** + * @tc.name: HandleNotifyHighlightChange + * @tc.desc: test function : HandleNotifyHighlightChange + * @tc.type: FUNC + */ +HWTEST_F(SessionStageStubTest, HandleNotifyHighlightChange, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteBool(false); + ASSERT_TRUE((sessionStageStub_ != nullptr)); + ASSERT_EQ(0, sessionStageStub_->HandleNotifyHighlightChange(data, reply)); +} } } } \ No newline at end of file diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 6959d2ef8b..6a15b5e247 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -1624,6 +1624,53 @@ HWTEST_F(WindowSessionTest, UpdateClientRectPosYAndDisplayId03, Function | Small session_->UpdateClientRectPosYAndDisplayId(rect); EXPECT_EQ(rect.posY_, 1000); } + +/** + * @tc.name: SetExclusivelyHighlighted + * @tc.desc: SetExclusivelyHighlighted Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, SetExclusivelyHighlighted, Function | SmallTest | Level2) +{ + ASSERT_NE(session_, nullptr); + session_->SetExclusivelyHighlighted(false); + bool isExclusivelyHighlighted = session_->GetSessionProperty()->GetExclusivelyHighlighted(); + ASSERT_EQ(isExclusivelyHighlighted, false); + session_->SetExclusivelyHighlighted(true); + isExclusivelyHighlighted = session_->GetSessionProperty()->GetExclusivelyHighlighted(); + ASSERT_EQ(isExclusivelyHighlighted, true); +} + +/** + * @tc.name: UpdateHighlightStatus + * @tc.desc: UpdateHighlightStatus Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, UpdateHighlightStatus, Function | SmallTest | Level2) +{ + ASSERT_NE(session_, nullptr); + EXPECT_EQ(session_->UpdateHighlightStatus(false, false), WSError::WS_DO_NOTHING); + + EXPECT_EQ(session_->UpdateHighlightStatus(true, false), WSError::WS_OK); + session_->isHighlight_ = false; + EXPECT_EQ(session_->UpdateHighlightStatus(true, true), WSError::WS_OK); +} + +/** + * @tc.name: NotifyHighlightChange + * @tc.desc: NotifyHighlightChange Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, NotifyHighlightChange, Function | SmallTest | Level2) +{ + ASSERT_NE(session_, nullptr); + EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_ERROR_INVALID_SESSION); + session_->sessionStage_ = mockSessionStage_; + session_->state_ = SessionState::STATE_CONNECT; + EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_OK); + session_->sessionStage_ = nullptr; + EXPECT_EQ(session_->NotifyHighlightChange(true), WSError::WS_ERROR_NULLPTR); +} } } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 1b001fff02..143534693b 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -343,6 +343,16 @@ public: void RegisterWatchFocusActiveChangeCallback(); void NotifyConsumeResultToFloatWindow(const std::shared_ptr& keyEvent, bool isConsumed); + /* + * HightLight Window + */ + bool GetExclusivelyHighlighted() const; + bool IsWindowHighlighted() const override; + WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) override; + WMError RegisterWindowHighlightChangeListeners(const sptr& listener) override; + WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) override; + WSError NotifyHighlightChange(bool isHighlight) override; + protected: WMError Connect(); bool IsWindowSessionInvalid() const; @@ -435,6 +445,7 @@ protected: bool isIgnoreSafeAreaNeedNotify_ = false; bool isIgnoreSafeArea_ = false; std::atomic_bool isFocused_ = false; + std::atomic_bool isHighLighted_ = false; std::shared_ptr handler_ = nullptr; bool shouldReNotifyFocus_ = false; std::shared_ptr vsyncStation_ = nullptr; @@ -554,6 +565,8 @@ private: EnableIfSame> GetListeners(); template EnableIfSame>> GetListeners(); + template + EnableIfSame> GetListeners(); void NotifyAfterFocused(); void NotifyUIContentFocusStatus(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); @@ -611,6 +624,7 @@ private: static std::mutex subWindowCloseListenersMutex_; static std::mutex mainWindowCloseListenersMutex_; static std::mutex switchFreeMultiWindowListenerMutex_; + static std::mutex highlightChangeListenerMutex_; static std::map>> lifecycleListeners_; static std::map>> displayMoveListeners_; static std::map>> windowChangeListeners_; @@ -633,6 +647,7 @@ private: static std::map> subWindowCloseListeners_; static std::map> mainWindowCloseListeners_; static std::map>> switchFreeMultiWindowListeners_; + static std::map> highlightChangeListeners_; // FA only sptr aceAbilityHandler_; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 9dd407716a..d7086c30f0 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -119,6 +119,7 @@ std::map>> WindowSessionImp std::map> WindowSessionImpl::subWindowCloseListeners_; std::map> WindowSessionImpl::mainWindowCloseListeners_; std::map>> WindowSessionImpl::switchFreeMultiWindowListeners_; +std::map> WindowSessionImpl::highlightChangeListeners_; std::recursive_mutex WindowSessionImpl::lifeCycleListenerMutex_; std::recursive_mutex WindowSessionImpl::windowChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::avoidAreaChangeListenerMutex_; @@ -136,6 +137,7 @@ std::mutex WindowSessionImpl::windowRectChangeListenerMutex_; std::mutex WindowSessionImpl::subWindowCloseListenersMutex_; std::mutex WindowSessionImpl::mainWindowCloseListenersMutex_; std::mutex WindowSessionImpl::switchFreeMultiWindowListenerMutex_; +std::mutex WindowSessionImpl::highlightChangeListenerMutex_; std::map>> WindowSessionImpl::windowSessionMap_; std::shared_mutex WindowSessionImpl::windowSessionMutex_; std::set> WindowSessionImpl::windowExtensionSessionSet_; @@ -1652,6 +1654,63 @@ WindowState WindowSessionImpl::GetRequestWindowState() const return requestState_; } +/** @note @window.focus */ +WMError WindowSessionImpl::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) +{ + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isExclusivelyHighlighted: %{public}d", + property_->GetPersistentId(), isExclusivelyHighlighted); + if (WindowHelper::IsMainWindow(GetType()) || WindowHelper::IsDialogWindow(GetType()) || + WindowHelper::IsModalWindow(property_->GetWindowFlags())) { + TLOGE(WmsLogTag::WMS_FOCUS, "window does not support set exclusivelyHighlighted, type: %{public}u, windowFlags: %{public}u ", + GetType(), property_->GetWindowFlags()); + return WMError::WM_ERROR_INVALID_CALLING; + } + if (property_->GetExclusivelyHighlighted() == isExclusivelyHighlighted) { + TLOGD(WmsLogTag::WMS_FOCUS, "hightlight:no nothing"); + return WMError::WM_OK; + } + property_->SetExclusivelyHighlighted(isExclusivelyHighlighted); + return UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_EXCLUSIVE_HIGHLIGHTED); +} + +/** @note @window.focus */ +bool WindowSessionImpl::GetExclusivelyHighlighted() const +{ + bool isExclusivelyHighlighted = property_->GetExclusivelyHighlighted(); + TLOGD(WmsLogTag::WMS_FOCUS, "WindowID: %{public}d, isExclusivelyHighlighted: %{public}d", + property_->GetPersistentId(), isExclusivelyHighlighted); + return isExclusivelyHighlighted; +} + +/** @note @window.focus */ +WSError WindowSessionImpl::NotifyHighlightChange(bool isHighlight) +{ + TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isHighlight: %{public}u,", GetPersistentId(), isHighlight); + isHighLighted_ = isHighlight; + std::lock_guard lockListener(highlightChangeListenerMutex_); + auto highlightChangeListener = GetListeners(); + if (highlightChangeListener != nullptr) { + highlightChangeListener->OnWindowHighlightChange(isHighlight); + return WSError::WS_OK; + } + return WSError::WS_ERROR_NULLPTR; +} + +/** @note @window.focus */ +bool WindowSessionImpl::IsWindowHighlighted() const +{ + if (IsWindowSessionInvalid()) { + TLOGE(WmsLogTag::WMS_FOCUS, "session is invalid"); + return false; + } + TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isWindowHighlighted: %{public}d", + GetPersistentId(), isHighlight_.load()); + return isHighlighted_; +} + WMError WindowSessionImpl::SetFocusable(bool isFocusable) { if (IsWindowSessionInvalid()) { @@ -2536,6 +2595,42 @@ WMError WindowSessionImpl::UnregisterSubWindowCloseListeners(const sptr +EnableIfSame> WindowSessionImpl::GetListeners() +{ + return highlightChangeListeners_[GetPersistentId()]; +} + +WMError WindowSessionImpl::RegisterWindowHighlightChangeListeners(const sptr& listener) +{ + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + auto persistentId = GetPersistentId(); + TLOGD(WmsLogTag::WMS_FOCUS, "Start, id:%{public}d", persistentId); + if (listener == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "listener is null"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lockListener(highlightChangeListenerMutex_); + highlightChangeListeners_[GetPersistentId()] = listener; + return WMError::WM_OK; +} + +WMError WindowSessionImpl::UnregisterWindowHighlightChangeListeners(const sptr& listener) +{ + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + if (listener == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "listener could not be null"); + return WMError::WM_ERROR_NULLPTR; + } + std::lock_guard lockListener(highlightChangeListenerMutex_); + highlightChangeListeners_[GetPersistentId()] = nullptr; + return WMError::WM_OK; +} + template EnableIfSame> WindowSessionImpl::GetListeners() { @@ -2812,6 +2907,10 @@ void WindowSessionImpl::ClearListenersById(int32_t persistentId) std::lock_guard lockListener(occupiedAreaChangeListenerMutex_); ClearUselessListeners(occupiedAreaChangeListeners_, persistentId); } + { + std::lock_guard lockListener(highlightChangeListenerMutex_); + ClearUselessListeners(highlightChangeListeners_, persistentId); + } ClearSwitchFreeMultiWindowListenersById(persistentId); TLOGI(WmsLogTag::WMS_LIFE, "Clear success, id: %{public}d.", GetPersistentId()); } diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index 8e40b08b4e..277f96b110 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -2389,6 +2389,97 @@ HWTEST_F(WindowSessionImplTest4, GetLayoutTransform, Function | SmallTest | Leve ASSERT_EQ(transform.scaleY_, layoutTransform.scaleY_); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); } + +/** + * @tc.name: SetExclusivelyHighlighted + * @tc.desc: SetExclusivelyHighlighted + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest4, SetExclusivelyHighlighted, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("SetExclusivelyHighlighted"); + sptr window = sptr::MakeSptr(option); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); + window->hostSession_ = session; + window->property_->SetPersistentId(INVALID_SESSION_ID); + ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_WINDOW); + window->property_->SetPersistentId(1); + window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); + ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING); + window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); + ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING); + window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); + window->property_->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL); + ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_ERROR_INVALID_CALLING); + window->property_->flags_ = 0; + ASSERT_EQ(window->SetExclusivelyHighlighted(true), WMError::WM_OK); + ASSERT_EQ(window->SetExclusivelyHighlighted(false), WMError::WM_OK); +} + +/** + * @tc.name: GetExclusivelyHighlighted + * @tc.desc: GetExclusivelyHighlighted + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest4, GetExclusivelyHighlighted, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("GetExclusivelyHighlighted"); + sptr window = sptr::MakeSptr(option); + ASSERT_EQ(window->GetExclusivelyHighlighted(), true); +} + +/** + * @tc.name: NotifyHighlightChange + * @tc.desc: NotifyHighlightChange + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest4, NotifyHighlightChange, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("NotifyHighlightChange01"); + sptr window = sptr::MakeSptr(option); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + window->hostSession_ = session; + window->property_->SetPersistentId(1); + + bool highlight = false; + WSError res = window->NotifyHighlightChange(highlight); + EXPECT_EQ(highlight, false); + EXPECT_EQ(res, WSError::WS_ERROR_NULLPTR); + sptr listener = sptr::MakeSptr(); + window->RegisterWindowHighlightChangeListeners(listener); + res = window->NotifyHighlightChange(highlight); + EXPECT_EQ(highlight, false); + EXPECT_EQ(res, WSError::WS_OK); + window->UnregisterWindowHighlightChangeListeners(listener); +} + +/** + * @tc.name: IsWindowHighlighted + * @tc.desc: IsWindowHighlighted + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest4, IsWindowHighlighted, Function | SmallTest | Level2) +{ + sptr option = sptr::MakeSptr(); + option->SetWindowName("IsWindowHighlighted"); + sptr window = sptr::MakeSptr(option); + SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; + sptr session = sptr::MakeSptr(sessionInfo); + ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); + window->hostSession_ = session; + window->property_->SetPersistentId(INVALID_SESSION_ID); + ASSERT_EQ(window->IsWindowHighlighted(), false); + window->property_->SetPersistentId(1); + window->isHighLighted_ = true; + ASSERT_EQ(window->IsWindowHighlighted(), true); +} + } // namespace } // namespace Rosen } // namespace OHOS -- Gitee From 16c7687aca1e7f4e470aaf3e0fd3e90f80238f26 Mon Sep 17 00:00:00 2001 From: 18 Date: Fri, 17 Jan 2025 18:40:26 +0000 Subject: [PATCH 02/24] update interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp. Signed-off-by: 18 --- .../window_runtime/window_napi/js_window_register_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index a79a103dc0..2deb70e7b6 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -637,7 +637,7 @@ WmErrorCode JsWindowRegisterManager::ProcessWindowHighlightChangeRegister(const if (isRegister) { ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterWindowHighlightChangeListeners(thisListener)); } else { - ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterWindowHighlightChangeListeners(thisListener)); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnRegisterWindowHighlightChangeListeners(thisListener)); } return ret; } -- Gitee From b167cf8ca67970046b06580de023e5994c10ca35 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 11:13:15 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18 --- interfaces/innerkits/wm/window.h | 9 ++++----- .../window_runtime/window_napi/js_window.cpp | 6 +++--- .../js_window_register_manager.cpp | 2 +- .../common/include/window_session_property.h | 1 - .../common/src/window_session_property.cpp | 3 +-- window_scene/session/host/src/session.cpp | 14 +++++++------- .../include/scene_session_manager.h | 8 +++++--- .../src/scene_session_manager.cpp | 19 ++++++++----------- wm/src/window_session_impl.cpp | 7 ++++--- 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index d418e47c1c..092f60d541 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -3005,22 +3005,22 @@ public: { return WMError::WM_OK; } - + /** * @brief Unregister window highlight change listener. * * @param listener IWindowHighlightChangeListener. * @return WM_OK means unregister success, others means unregister failed. */ - virtual WMError UnRegisterWindowHighlightChangeListeners(const sptr& listener) + virtual WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) { return WMError::WM_OK; } /** * @brief Set whether to enable exclusively highlight. - * - * @param isExclusivelyHighlighted the value true means to enable exclusively highlight, and false means the opposite. + * + * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. * @return WM_OK means set success, others means set failed. */ virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { return WMError::WM_OK; } @@ -3031,7 +3031,6 @@ public: * @return True means the window is highlighted, false means the window is not highlighted. */ virtual bool IsWindowHighlighted() { return false; } - }; } } 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 31e3a8c44d..de5d222481 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -7503,7 +7503,8 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf } napi_value result = nullptr; std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); - auto asyncTask = [weakToken = wptr(windowToken_), exclusivelyHighlighted, env, task = napiAsyncTask, where = __func__] { + auto asyncTask = [weakToken = wptr(windowToken_), exclusivelyHighlighted, env, + task = napiAsyncTask, where = __func__] { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s window is nullptr", where); @@ -7520,8 +7521,7 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s end, window [%{public}u, %{public}s]", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high - )) { + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, CreateJsError(env, static_cast(WmErrorCode::WM_ERROR_STATE_ABNORMALLY), "send event failed")); } diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 2deb70e7b6..a79a103dc0 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -637,7 +637,7 @@ WmErrorCode JsWindowRegisterManager::ProcessWindowHighlightChangeRegister(const if (isRegister) { ret = WM_JS_TO_ERROR_CODE_MAP.at(window->RegisterWindowHighlightChangeListeners(thisListener)); } else { - ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnRegisterWindowHighlightChangeListeners(thisListener)); + ret = WM_JS_TO_ERROR_CODE_MAP.at(window->UnregisterWindowHighlightChangeListeners(thisListener)); } return ret; } diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 2571a1daa8..638938fab4 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -447,7 +447,6 @@ private: bool focusableOnShow_ { true }; bool touchable_ { true }; bool isExclusivelyHighlighted_ { true }; - }; struct FreeMultiWindowConfig : public Parcelable { diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index a1c9ba7911..ce9ef28ecd 100755 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -1168,8 +1168,7 @@ bool WindowSessionProperty::Marshalling(Parcel& parcel) const parcel.WriteUint32(static_cast(uiExtensionUsage_)) && parcel.WriteUint32(static_cast(parentWindowType_)) && MarshallingWindowMask(parcel) && - parcel.WriteParcelable(&keyboardLayoutParams_) && - parcel.WriteBool(compatibleModeInPc_) && + parcel.WriteParcelable(&keyboardLayoutParams_) && parcel.WriteBool(compatibleModeInPc_) && parcel.WriteInt32(compatibleInPcPortraitWidth_) && parcel.WriteInt32(compatibleInPcPortraitHeight_) && parcel.WriteInt32(compatibleInPcLandscapeWidth_) && parcel.WriteInt32(compatibleInPcLandscapeHeight_) && parcel.WriteBool(isAppSupportPhoneInPc_) && parcel.WriteBool(isSupportDragInPcCompatibleMode_) && diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index f2ef5c2d91..92fd0ca30e 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2646,7 +2646,7 @@ void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) TLOGE(WmsLogTag::WMS_FOCUS, "windowId: %{public}d property is nullptr", persistentId_); return; } - if(isExclusivelyHighlighted == property->GetExclusivelyHighlighted()){ + if (isExclusivelyHighlighted == property->GetExclusivelyHighlighted()) { return; } TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isExclusivelyHighlighted: %{public}d", persistentId_, @@ -2656,16 +2656,16 @@ void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) void Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange) { - TLOGI(WmsLogTag::WMS_FOCUS, - "windowId: %{public}d, currHighlight: %{public}d, nextHighlight: %{public}d, isNotify:%{public}d", persistentId_, - isHighlight_, isHighlight, isNotifyHighlightChange); - if (isHighlight_ == isHighlight){ + TLOGI(WmsLogTag::WMS_FOCUS, + "windowId: %{public}d, currHighlight: %{public}d, nextHighlight: %{public}d, isNotify:%{public}d", + persistentId_, isHighlight_, isHighlight, isNotifyHighlightChange); + if (isHighlight_ == isHighlight) { return WSError::WS_DO_NOTHING; } isHighlight_ = isHighlight; - if (isNotifyHighlightChange){ + if (isNotifyHighlightChange) { NotifyHighlightChange(isHighlight); - if (highlightChangeFunc_ != nullptr){ + if (highlightChangeFunc_ != nullptr) { highlightChangeFunc_(isHighlight); } } diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index e36bd8cfa9..da6bfe7207 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -264,11 +264,12 @@ public: void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; WSError GetFocusSessionToken(sptr& token) override; WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; - void UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, bool isProactiveUnfocus); + void UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, + bool isProactiveUnfocus); void SetHighlightSessionIds(sptr& sceneSession); void AddHighlightSessionIds(sptr& sceneSession); void RemoveHighlightSessionIds(sptr& sceneSession); - void LogHighLight(); + std::string GetHighlightIds(); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); @@ -699,7 +700,8 @@ private: sptr GetNextFocusableSession(int32_t persistentId); sptr GetTopNearestBlockingFocusSession(uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT, bool isProactiveUnfocus = false); + WSError ShiftFocus(sptr& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT, + bool isProactiveUnfocus = false); void UpdateFocusStatus(sptr& sceneSession, bool isFocused); void NotifyFocusStatus(sptr& sceneSession, bool isFocused); int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 37494371a5..453360d475 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4968,11 +4968,7 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) } oss << "Focus window: " << GetFocusedSessionId() << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; - oss << "Highlighted windows: "; - for( auto persistentId : highlightIds_) { - oss << persistentId << ","; - } - oss << std::endl; + oss << "Highlighted windows: " << GetHighlightIds() << std::endl; dumpInfo.append(oss.str()); return WSError::WS_OK; } @@ -5932,7 +5928,7 @@ void SceneSessionManager::SetHighlightSessionIds(sptr& sceneSessio sceneSession->UpdateHighlightStatus(true); highlightIds_.clear(); highlightIds_.insert(sceneSession->GetPersistentId()); - LogHighLight(); + GetHighlightIds(); } /** @note @window.focus */ @@ -5944,7 +5940,7 @@ void SceneSessionManager::AddHighlightSessionIds(sptr& sceneSessio } sceneSession->UpdateHighlightStatus(true); highlightIds_.insert(sceneSession->GetPersistentId()); - LogHighLight(); + GetHighlightIds(); } /** @note @window.focus */ @@ -5960,7 +5956,7 @@ void SceneSessionManager::RemoveHighlightSessionIds(sptr& sceneSes } else { TLOGE(WmsLogTag::WMS_FOCUS, "not found scene session with id: %{public}d", sceneSession->GetPersistentId()); } - LogHighLight(); + GetHighlightIds(); } void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bool isFocused) @@ -12585,14 +12581,15 @@ WSError SceneSessionManager::CloneWindow(int32_t fromPersistentId, int32_t toPer }, __func__); } -void SceneSessionManager::LogHighLight() +std::string SceneSessionManager::GetHighlightIds() { - std::string str = ""; + std::string highlightIdsStr = ""; for (auto persistentId : highlightIds_) { str += std::to_string(persistentId); str += ","; } - TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", str.c_str()); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", highlightIdsStr.c_str()); + return highlightIdsStr; } } // namespace OHOS::Rosen diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index d7086c30f0..488b0a7021 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1664,7 +1664,7 @@ WMError WindowSessionImpl::SetExclusivelyHighlighted(bool isExclusivelyHighlight property_->GetPersistentId(), isExclusivelyHighlighted); if (WindowHelper::IsMainWindow(GetType()) || WindowHelper::IsDialogWindow(GetType()) || WindowHelper::IsModalWindow(property_->GetWindowFlags())) { - TLOGE(WmsLogTag::WMS_FOCUS, "window does not support set exclusivelyHighlighted, type: %{public}u, windowFlags: %{public}u ", + TLOGE(WmsLogTag::WMS_FOCUS, "unsupport window, type: %{public}u, windowFlags: %{public}u ", GetType(), property_->GetWindowFlags()); return WMError::WM_ERROR_INVALID_CALLING; } @@ -2602,7 +2602,7 @@ EnableIfSame& listener) -{ +{ if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; } @@ -2617,7 +2617,8 @@ WMError WindowSessionImpl::RegisterWindowHighlightChangeListeners(const sptr& listener) +WMError WindowSessionImpl::UnregisterWindowHighlightChangeListeners( + const sptr& listener) { if (IsWindowSessionInvalid()) { return WMError::WM_ERROR_INVALID_WINDOW; -- Gitee From 96c84370ec08061a798fbe10d7962f62c42b2ece Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 11:25:09 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18 --- interfaces/innerkits/wm/window.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 092f60d541..8088e088b9 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -2997,7 +2997,7 @@ public: /** * @brief Register window highlight change listener. - * + * * @param listener IWindowHighlightChangeListener. * @return WM_OK means register success, others means register failed. */ @@ -3008,7 +3008,7 @@ public: /** * @brief Unregister window highlight change listener. - * + * * @param listener IWindowHighlightChangeListener. * @return WM_OK means unregister success, others means unregister failed. */ @@ -3027,7 +3027,7 @@ public: /** * @brief Get highlight property of window. - * + * * @return True means the window is highlighted, false means the window is not highlighted. */ virtual bool IsWindowHighlighted() { return false; } -- Gitee From b439797472fdd582612fc0475ceb2d5be34c1314 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 11:46:02 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 18 --- interfaces/innerkits/wm/window.h | 2 +- window_scene/session/host/src/scene_session.cpp | 2 +- window_scene/session/host/src/session.cpp | 2 +- window_scene/session_manager/src/scene_session_manager.cpp | 4 ++-- wm/src/window_session_impl.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 8088e088b9..be5c1d99d6 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -3030,7 +3030,7 @@ public: * * @return True means the window is highlighted, false means the window is not highlighted. */ - virtual bool IsWindowHighlighted() { return false; } + virtual bool IsWindowHighlighted() const { return false; } }; } } diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 10e994adca..6d9840fff6 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -4813,7 +4813,7 @@ WMError SceneSession::HandleActionUpdateExclusivelyHighlighted(const sptrSetExclusivelyHighlighted(property->GetExclusivelyHighlighte()); + sessionProperty->SetExclusivelyHighlighted(property->GetExclusivelyHighlighted()); return WMError::WM_OK; } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 92fd0ca30e..537e8daaf0 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2654,7 +2654,7 @@ void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) property->SetExclusivelyHighlighted(isExclusivelyHighlighted); } -void Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange) +WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange) { TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, currHighlight: %{public}d, nextHighlight: %{public}d, isNotify:%{public}d", diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 453360d475..7cba65758a 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -12585,8 +12585,8 @@ std::string SceneSessionManager::GetHighlightIds() { std::string highlightIdsStr = ""; for (auto persistentId : highlightIds_) { - str += std::to_string(persistentId); - str += ","; + highlightIdsStr += std::to_string(persistentId); + highlightIdsStr += ","; } TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", highlightIdsStr.c_str()); return highlightIdsStr; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 488b0a7021..25006d4de8 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1707,7 +1707,7 @@ bool WindowSessionImpl::IsWindowHighlighted() const return false; } TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isWindowHighlighted: %{public}d", - GetPersistentId(), isHighlight_.load()); + GetPersistentId(), isHighLighted_.load()); return isHighlighted_; } -- Gitee From 31ada9c486186b8c5caef2325ab4465d4e679ad8 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 12:09:20 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wm/include/window_session_impl.h | 2 +- wm/src/window_session_impl.cpp | 4 ++-- wm/test/unittest/window_session_impl_test4.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 143534693b..7e8f80f573 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -445,7 +445,7 @@ protected: bool isIgnoreSafeAreaNeedNotify_ = false; bool isIgnoreSafeArea_ = false; std::atomic_bool isFocused_ = false; - std::atomic_bool isHighLighted_ = false; + std::atomic_bool isHighlighted_ = false; std::shared_ptr handler_ = nullptr; bool shouldReNotifyFocus_ = false; std::shared_ptr vsyncStation_ = nullptr; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 25006d4de8..f45fddf1cc 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1689,7 +1689,7 @@ bool WindowSessionImpl::GetExclusivelyHighlighted() const WSError WindowSessionImpl::NotifyHighlightChange(bool isHighlight) { TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isHighlight: %{public}u,", GetPersistentId(), isHighlight); - isHighLighted_ = isHighlight; + isHighlighted_ = isHighlight; std::lock_guard lockListener(highlightChangeListenerMutex_); auto highlightChangeListener = GetListeners(); if (highlightChangeListener != nullptr) { @@ -1707,7 +1707,7 @@ bool WindowSessionImpl::IsWindowHighlighted() const return false; } TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isWindowHighlighted: %{public}d", - GetPersistentId(), isHighLighted_.load()); + GetPersistentId(), isHighlighted_.load()); return isHighlighted_; } diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index 277f96b110..0869ada8db 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -2476,7 +2476,7 @@ HWTEST_F(WindowSessionImplTest4, IsWindowHighlighted, Function | SmallTest | Lev window->property_->SetPersistentId(INVALID_SESSION_ID); ASSERT_EQ(window->IsWindowHighlighted(), false); window->property_->SetPersistentId(1); - window->isHighLighted_ = true; + window->isHighlighted_ = true; ASSERT_EQ(window->IsWindowHighlighted(), true); } -- Gitee From 684921b41d35e687a83f7c4b1cf30fe994896cb2 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 13:02:23 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_scene/test/unittest/scene_session_test5.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 82363a4771..eee0e8a0b4 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -1727,11 +1727,11 @@ HWTEST_F(SceneSessionTest5, ActivateKeyboardAvoidArea01, Function | SmallTest | } /** - * @tc.name: isRelated - * @tc.desc: test isRelated + * @tc.name: IsRelated + * @tc.desc: test IsRelated * @tc.type: FUNC */ -HWTEST_F(SceneSessionTest5, isRelated, Function | SmallTest | Level2) +HWTEST_F(SceneSessionTest5, IsRelated, Function | SmallTest | Level2) { SessionInfo info1; info1.abilityName_ = "abilityName_test1"; @@ -1743,9 +1743,9 @@ HWTEST_F(SceneSessionTest5, isRelated, Function | SmallTest | Level2) sptr currSceneSession = sptr::MakeSptr(info2, nullptr); preSceneSession->persistentId_ = 1; currSceneSession->persistentId_ = 1; - ASSERT_EQ(true, currSceneSession->isRelated(preSceneSession)); + ASSERT_EQ(true, currSceneSession->IsRelated(preSceneSession)); currSceneSession->persistentId_ = 2; - ASSERT_EQ(false, currSceneSession->isRelated(preSceneSession)); + ASSERT_EQ(false, currSceneSession->IsRelated(preSceneSession)); sptr subSession1 = sptr::MakeSptr(info1, nullptr); sptr subSession2 = sptr::MakeSptr(info2, nullptr); @@ -1754,9 +1754,9 @@ HWTEST_F(SceneSessionTest5, isRelated, Function | SmallTest | Level2) currSceneSession->persistentId_ = 1; subSession1->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); subSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - ASSERT_EQ(true, subSession1->isRelated(subSession1)); + ASSERT_EQ(true, subSession1->IsRelated(subSession1)); currSceneSession->persistentId_ = 2; - ASSERT_EQ(false, subSession1->isRelated(subSession1)); + ASSERT_EQ(false, subSession1->IsRelated(subSession1)); } /** -- Gitee From e74d0137157fbf925745b256e479a876632bc51e Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 14:15:33 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- previewer/include/window.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/previewer/include/window.h b/previewer/include/window.h index 93e9d2442b..2310a12c45 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -471,6 +471,44 @@ public: * @return True means window delay raise is enabled */ virtual bool IsWindowDelayRaiseEnabled() const { return false; } + + /** + * @brief Register window highlight change listener. + * + * @param listener IWindowHighlightChangeListener. + * @return WM_OK means register success, others means register failed. + */ + virtual WMError RegisterWindowHighlightChangeListeners(const sptr& listener) + { + return WMError::WM_OK; + } + + /** + * @brief Unregister window highlight change listener. + * + * @param listener IWindowHighlightChangeListener. + * @return WM_OK means unregister success, others means unregister failed. + */ + virtual WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) + { + return WMError::WM_OK; + } + + /** + * @brief Set whether to enable exclusively highlight. + * + * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. + * @return WM_OK means set success, others means set failed. + */ + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { return WMError::WM_OK; } + + /** + * @brief Get highlight property of window. + * + * @return True means the window is highlighted, false means the window is not highlighted. + */ + virtual bool IsWindowHighlighted() const { return false; } + }; } } -- Gitee From f982cda49539ea6c45829537b87a78c7351ef741 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 14:46:57 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- previewer/include/window.h | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/previewer/include/window.h b/previewer/include/window.h index 2310a12c45..2291d6a357 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -472,28 +472,6 @@ public: */ virtual bool IsWindowDelayRaiseEnabled() const { return false; } - /** - * @brief Register window highlight change listener. - * - * @param listener IWindowHighlightChangeListener. - * @return WM_OK means register success, others means register failed. - */ - virtual WMError RegisterWindowHighlightChangeListeners(const sptr& listener) - { - return WMError::WM_OK; - } - - /** - * @brief Unregister window highlight change listener. - * - * @param listener IWindowHighlightChangeListener. - * @return WM_OK means unregister success, others means unregister failed. - */ - virtual WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) - { - return WMError::WM_OK; - } - /** * @brief Set whether to enable exclusively highlight. * -- Gitee From ea0d9eb16af414eb42bd3c1ed357bfbc15759760 Mon Sep 17 00:00:00 2001 From: 18 Date: Sat, 18 Jan 2025 15:56:11 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../window_runtime/window_napi/js_window.cpp | 11 ++-- .../js_scene_session.cpp | 15 +++-- .../src/zidl/session_stage_proxy.cpp | 60 +++++++++---------- window_scene/session/host/src/session.cpp | 2 +- .../include/scene_session_manager.h | 2 +- 5 files changed, 46 insertions(+), 44 deletions(-) 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 de5d222481..bd74f98313 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -7518,7 +7518,7 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set exclusively highlighted failed")); } - TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s end, window [%{public}u, %{public}s]", + TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s: end, window [%{public}u, %{public}s]", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { @@ -7530,14 +7530,11 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf napi_value JsWindow::OnIsWindowHighlighted(napi_env env, napi_callback_info info) { - wptr weakToken(windowToken_); - auto window = weakToken.promote(); - if (window == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "window is nullptr"); + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_IMMS, "windowToken is nullptr"); return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - - bool isHighlighted = window->IsWindowHighlighted(); + bool isHighlighted = windowToken_->IsWindowHighlighted(); TLOGI(WmsLogTag::WMS_FOCUS, "get window highlight end, isHighlighted = %{public}u", isHighlighted); return CreateJsValue(env, isHighlighted); } diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 95c6ee719d..32e1383e33 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -2835,7 +2835,7 @@ napi_value JsSceneSession::OnSetExclusivelyHighlighted(napi_env env, napi_callba } auto session = weakSession_.promote(); if (session == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr, id:%{public}d", persistentId_); + TLOGE(WmsLogTag::WMS_FOCUS, "session is nullptr, id: %{public}d", persistentId_); return NapiGetUndefined(env); } session->SetExclusivelyHighlighted(isExclusivelyHighlighted); @@ -6045,8 +6045,13 @@ void JsSceneSession::OnKeyboardViewModeChange(const KeyboardViewMode& mode) void JsSceneSession::ProcessSetHighlightChangeRegister() { - NotifyHighlightChangeFunc func = [this](bool isHighlight) { - this->NotifyHighlightChange(isHighlight); + NotifyHighlightChangeFunc func = [weakThis = wptr(this), where = __func__](bool isHighlight) { + auto jsSceneSession = weakThis.promote(); + if (!jsSceneSession) { + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s jsSceneSession is null", where); + return; + } + jsSceneSession->NotifyHighlightChange(isHighlight); }; auto session = weakSession_.promote(); if (session == nullptr) { @@ -6058,11 +6063,11 @@ void JsSceneSession::ProcessSetHighlightChangeRegister() void JsSceneSession::NotifyHighlightChange(bool isHighlight) { - TLOGI(WmsLogTag::WMS_FOCUS, "isHighlight:%{public}d, id:%{public}d", isHighlight, persistentId_); + TLOGI(WmsLogTag::WMS_FOCUS, "isHighlight: %{public}d, id: %{public}d", isHighlight, persistentId_); auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_] { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { - TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id:%{public}d has been destroyed", persistentId); + TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id: %{public}d has been destroyed", persistentId); return; } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index 7fd995e226..ae42e0d3c6 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -478,36 +478,6 @@ WSError SessionStageProxy::UpdateFocus(bool focus) return static_cast(ret); } -WSError SessionStageProxy::NotifyHighlightChange(bool isHighlight) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!data.WriteInterfaceToken(GetDescriptor())) { - TLOGE(WmsLogTag::WMS_FOCUS, "WriteInterfaceToken failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - - if (!data.WriteBool(isHighlight)) { - TLOGE(WmsLogTag::WMS_FOCUS, "Write isHighlight failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - - sptr remote = Remote(); - if (remote == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "remote is null"); - return WSError::WS_ERROR_IPC_FAILED; - } - - if (remote->SendRequest(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE), - data, reply, option) != ERR_NONE) { - TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - int32_t ret = reply.ReadInt32(); - return static_cast(ret); -} - WSError SessionStageProxy::NotifyTransferComponentData(const AAFwk::WantParams& wantParams) { MessageParcel data; @@ -1501,4 +1471,34 @@ WSError SessionStageProxy::SendContainerModalEvent(const std::string& eventName, } return WSError::WS_OK; } + +WSError SessionStageProxy::NotifyHighlightChange(bool isHighlight) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_FOCUS, "Write interfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (!data.WriteBool(isHighlight)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Write isHighlight failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_FOCUS, "remote is null"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (remote->SendRequest(static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE), + data, reply, option) != ERR_NONE) { + TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 537e8daaf0..5c53af0291 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2675,7 +2675,7 @@ WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightC WSError Session::NotifyHighlightChange(bool isHighlight) { if (!IsSessionValid()) { - TLOGW(WmsLogTag::WMS_FOCUS, "Session is invalid, id:%{public}d state:%{public}u", + TLOGW(WmsLogTag::WMS_FOCUS, "Session is invalid, id: %{public}d state: %{public}u", persistentId_, GetSessionState()); return WSError::WS_ERROR_INVALID_SESSION; } diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index da6bfe7207..1af68ce113 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -677,6 +677,7 @@ private: /* * Window Focus */ + std::unordered_set highlightIds_; std::vector>> GetSceneSessionVector(CmpFunc cmp); void TraverseSessionTree(TraverseFunc func, bool isFromTopToBottom); void TraverseSessionTreeFromTopToBottom(TraverseFunc func); @@ -942,7 +943,6 @@ private: int32_t focusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; - std::unordered_set highlightIds_; int32_t brightnessSessionId_ = INVALID_SESSION_ID; float displayBrightness_ = UNDEFINED_BRIGHTNESS; bool isScreenLocked_ {false}; -- Gitee From 400fcac204b317dcbccf02f007d16a2e218d261d Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 09:20:28 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/wm/window.h | 13 +++-- .../window_runtime/window_napi/js_window.cpp | 9 ++- previewer/include/window.h | 10 ++-- window_scene/session/host/src/session.cpp | 2 +- .../include/scene_session_manager.h | 2 +- .../src/scene_session_manager.cpp | 33 +++++------ wm/include/window_session_impl.h | 6 +- wm/src/window_session_impl.cpp | 55 ++++++++----------- 8 files changed, 66 insertions(+), 64 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 2d66f0dd5c..cb2001e166 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -3029,7 +3029,7 @@ public: */ virtual WMError RegisterWindowHighlightChangeListeners(const sptr& listener) { - return WMError::WM_OK; + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } /** @@ -3040,7 +3040,7 @@ public: */ virtual WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) { - return WMError::WM_OK; + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } /** @@ -3049,14 +3049,17 @@ public: * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { return WMError::WM_OK; } + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } /** * @brief Get highlight property of window. * - * @return True means the window is highlighted, false means the window is not highlighted. + * @param highlighted True means the window is highlighted, and false means the opposite. + * @return WM_OK means get success, others means get failed. */ - virtual bool IsWindowHighlighted() const { return false; } + virtual WMError IsWindowHighlighted(bool& highlighted) const { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } }; } } 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 2a88efa0c6..1170a849c4 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -7768,10 +7768,15 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf napi_value JsWindow::OnIsWindowHighlighted(napi_env env, napi_callback_info info) { if (windowToken_ == nullptr) { - TLOGE(WmsLogTag::WMS_IMMS, "windowToken is nullptr"); + TLOGE(WmsLogTag::WMS_FOCUS, "windowToken is nullptr"); return NapiThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - bool isHighlighted = windowToken_->IsWindowHighlighted(); + bool isHighlighted = false; + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->IsWindowHighlighted(isHighlighted)); + if (ret != WmErrorCode::WM_OK) { + TLOGE(WmsLogTag::WMS_FOCUS, "get window highlight failed, ret %{public}d", ret); + return NapiThrowError(env, ret); + } TLOGI(WmsLogTag::WMS_FOCUS, "get window highlight end, isHighlighted = %{public}u", isHighlighted); return CreateJsValue(env, isHighlighted); } diff --git a/previewer/include/window.h b/previewer/include/window.h index 114b6122ee..a1961e0c7e 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -482,15 +482,17 @@ public: * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { return WMError::WM_OK; } + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } /** * @brief Get highlight property of window. * - * @return True means the window is highlighted, false means the window is not highlighted. + * @param highlighted True means the window is highlighted, and false means the opposite. + * @return WM_OK means get success, others means get failed. */ - virtual bool IsWindowHighlighted() const { return false; } - + virtual WMError IsWindowHighlighted(bool& highlighted) const { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } }; } } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index ae7bdec194..c92d01867f 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2681,7 +2681,7 @@ void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightChange) { - TLOGI(WmsLogTag::WMS_FOCUS, + TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, currHighlight: %{public}d, nextHighlight: %{public}d, isNotify:%{public}d", persistentId_, isHighlight_, isHighlight, isNotifyHighlightChange); if (isHighlight_ == isHighlight) { diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index e7508df923..d0fa47014b 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -275,7 +275,7 @@ public: void SetHighlightSessionIds(sptr& sceneSession); void AddHighlightSessionIds(sptr& sceneSession); void RemoveHighlightSessionIds(sptr& sceneSession); - std::string GetHighlightIds(); + std::string GetHighlightIdsStr(); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 37e1b98cc0..f7a009056f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5033,7 +5033,7 @@ WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) oss << "SingleHand: X[" << singleHandTransform_.posX << "] Y[" << singleHandTransform_.posY << "] scale[" << singleHandTransform_.scaleX << "]" << std::endl; oss << "Total window num: " << sceneSessionMapCopy.size() << std::endl; - oss << "Highlighted windows: " << GetHighlightIds() << std::endl; + oss << "Highlighted windows: " << GetHighlightIdsStr() << std::endl; dumpInfo.append(oss.str()); return WSError::WS_OK; } @@ -5993,7 +5993,7 @@ void SceneSessionManager::SetHighlightSessionIds(sptr& sceneSessio sceneSession->UpdateHighlightStatus(true); highlightIds_.clear(); highlightIds_.insert(sceneSession->GetPersistentId()); - GetHighlightIds(); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); } /** @note @window.focus */ @@ -6005,7 +6005,7 @@ void SceneSessionManager::AddHighlightSessionIds(sptr& sceneSessio } sceneSession->UpdateHighlightStatus(true); highlightIds_.insert(sceneSession->GetPersistentId()); - GetHighlightIds(); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); } /** @note @window.focus */ @@ -6021,7 +6021,20 @@ void SceneSessionManager::RemoveHighlightSessionIds(sptr& sceneSes } else { TLOGE(WmsLogTag::WMS_FOCUS, "not found scene session with id: %{public}d", sceneSession->GetPersistentId()); } - GetHighlightIds(); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); +} + +/** @note @window.focus */ +std::string SceneSessionManager::GetHighlightIdsStr() +{ + std::ostringstream oss; + for(auto it = highlightIds_.begin(); it != highlightIds_.end(); it++){ + oss << *it; + if(std::next(it) != highlightIds_.end()) { + oss << ", "; + } + } + return oss.str(); } void SceneSessionManager::NotifyFocusStatus(sptr& sceneSession, bool isFocused) @@ -12736,16 +12749,4 @@ WSError SceneSessionManager::CloneWindow(int32_t fromPersistentId, int32_t toPer return WSError::WS_OK; }, __func__); } - -std::string SceneSessionManager::GetHighlightIds() -{ - std::string highlightIdsStr = ""; - for (auto persistentId : highlightIds_) { - highlightIdsStr += std::to_string(persistentId); - highlightIdsStr += ","; - } - TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", highlightIdsStr.c_str()); - return highlightIdsStr; -} - } // namespace OHOS::Rosen diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index 4997d6cd77..a8af4549f1 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -349,7 +349,7 @@ public: * HightLight Window */ bool GetExclusivelyHighlighted() const; - bool IsWindowHighlighted() const override; + bool IsWindowHighlighted(bool& highlighted) const override; WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) override; WMError RegisterWindowHighlightChangeListeners(const sptr& listener) override; WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) override; @@ -570,7 +570,7 @@ private: template EnableIfSame>> GetListeners(); template - EnableIfSame> GetListeners(); + EnableIfSame>> GetListeners(); void NotifyAfterFocused(); void NotifyUIContentFocusStatus(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); @@ -651,7 +651,7 @@ private: static std::map> subWindowCloseListeners_; static std::map> mainWindowCloseListeners_; static std::map>> switchFreeMultiWindowListeners_; - static std::map> highlightChangeListeners_; + static std::map>> highlightChangeListeners_; // FA only sptr aceAbilityHandler_; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 80bd98d12e..f4c4be18bc 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -120,7 +120,7 @@ std::map>> WindowSessionImp std::map> WindowSessionImpl::subWindowCloseListeners_; std::map> WindowSessionImpl::mainWindowCloseListeners_; std::map>> WindowSessionImpl::switchFreeMultiWindowListeners_; -std::map> WindowSessionImpl::highlightChangeListeners_; +std::map>> WindowSessionImpl::highlightChangeListeners_; std::recursive_mutex WindowSessionImpl::lifeCycleListenerMutex_; std::recursive_mutex WindowSessionImpl::windowChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::avoidAreaChangeListenerMutex_; @@ -1699,24 +1699,26 @@ WSError WindowSessionImpl::NotifyHighlightChange(bool isHighlight) TLOGI(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isHighlight: %{public}u,", GetPersistentId(), isHighlight); isHighlighted_ = isHighlight; std::lock_guard lockListener(highlightChangeListenerMutex_); - auto highlightChangeListener = GetListeners(); - if (highlightChangeListener != nullptr) { - highlightChangeListener->OnWindowHighlightChange(isHighlight); - return WSError::WS_OK; + auto highlightChangeListeners = GetListeners(); + for (auto& listener : highlightChangeListeners) { + if (listener != nullptr) { + listener->OnWindowHighlightChange(isHighlight); + } } - return WSError::WS_ERROR_NULLPTR; + return WSError::WS_OK; } /** @note @window.focus */ -bool WindowSessionImpl::IsWindowHighlighted() const +WMError WindowSessionImpl::IsWindowHighlighted(bool& highlighted) const { if (IsWindowSessionInvalid()) { TLOGE(WmsLogTag::WMS_FOCUS, "session is invalid"); - return false; + return WMError::WM_ERROR_INVALID_WINDOW; } + highlighted = isHighlighted_.load(); TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isWindowHighlighted: %{public}d", GetPersistentId(), isHighlighted_.load()); - return isHighlighted_; + return WMError::WM_OK; } WMError WindowSessionImpl::SetFocusable(bool isFocusable) @@ -2603,41 +2605,30 @@ WMError WindowSessionImpl::UnregisterSubWindowCloseListeners(const sptr -EnableIfSame> WindowSessionImpl::GetListeners() +template +EnableIfSame>> WindowSessionImpl::GetListeners() { - return highlightChangeListeners_[GetPersistentId()]; + std::vector> highlightChangeListeners; + for (auto& listener : highlightChangeListeners_[GetPersistentId()]) { + highlightChangeListeners.push_back(listener); + } + return highlightChangeListeners; } WMError WindowSessionImpl::RegisterWindowHighlightChangeListeners(const sptr& listener) { - if (IsWindowSessionInvalid()) { - return WMError::WM_ERROR_INVALID_WINDOW; - } - auto persistentId = GetPersistentId(); - TLOGD(WmsLogTag::WMS_FOCUS, "Start, id:%{public}d", persistentId); - if (listener == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "listener is null"); - return WMError::WM_ERROR_NULLPTR; - } + TLOGD(WmsLogTag::WMS_FOCUS, "name=%{public}s, id=%{public}u", GetWindowName().c_str(), GetPersistentId()); std::lock_guard lockListener(highlightChangeListenerMutex_); - highlightChangeListeners_[GetPersistentId()] = listener; - return WMError::WM_OK; + return RegisterListener(highlightChangeListeners_[GetPersistentId()], listener); } WMError WindowSessionImpl::UnregisterWindowHighlightChangeListeners( const sptr& listener) { - if (IsWindowSessionInvalid()) { - return WMError::WM_ERROR_INVALID_WINDOW; - } - if (listener == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "listener could not be null"); - return WMError::WM_ERROR_NULLPTR; - } + TLOGD(WmsLogTag::WMS_FOCUS, "name=%{public}s, id=%{public}u", GetWindowName().c_str(), GetPersistentId()); std::lock_guard lockListener(highlightChangeListenerMutex_); - highlightChangeListeners_[GetPersistentId()] = nullptr; - return WMError::WM_OK; + return UnregisterListener(highlightChangeListeners_[GetPersistentId()], listener); } template -- Gitee From bdf847ac37347fbbdf3da2bf895e7bfecfb80fd5 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 09:45:22 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../napi/window_runtime/window_napi/js_window_listener.cpp | 2 +- .../session/container/src/zidl/session_stage_stub.cpp | 6 +++++- window_scene/session/host/include/scene_session.h | 2 +- window_scene/session/host/src/scene_session.cpp | 2 +- window_scene/session_manager/src/scene_session_manager.cpp | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index 74e09a9d67..9d04e78db0 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -632,7 +632,7 @@ void JsWindowListener::OnMainWindowClose(bool& terminateCloseProcess) void JsWindowListener::OnWindowHighlightChange(bool isHighlight) { - TLOGD(WmsLogTag::WMS_FOCUS, "isHighlight: %d", isHighlight); + TLOGD(WmsLogTag::WMS_FOCUS, "isHighlight: %{public}d", isHighlight); auto jsCallback = [self = weakRef_, isHighlight, env = env_, where = __func__] { auto thisListener = self.promote(); if (thisListener == nullptr || env == nullptr) { diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index 8775bd2176..5756c0f83d 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -336,7 +336,11 @@ int SessionStageStub::HandleNotifyTransferComponentData(MessageParcel& data, Mes int SessionStageStub::HandleNotifyHighlightChange(MessageParcel& data, MessageParcel& reply) { TLOGD(WmsLogTag::WMS_FOCUS, "called!"); - bool isHighlight = data.ReadBool(); + bool isHighlight = false; + if (!data.ReadBool(isHighlight)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Read isHighlight failed."); + return ERR_INVALID_DATA; + } WSError errCode = NotifyHighlightChange(isHighlight); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 0db4107e4e..71caffccc8 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -626,7 +626,7 @@ public: /* * Window Focus */ - bool IsRelated(sptr& prevSession); + bool IsRelated(const sptr& prevSession); void SetHighlightChangeNotifyFunc(const NotifyHighlightChangeFunc& func); /* diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 7890638002..804a96d78c 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -3722,7 +3722,7 @@ bool SceneSession::IsSystemSessionAboveApp() const } /** @note @window.focus */ -bool SceneSession::IsRelated(sptr& prevSession) +bool SceneSession::IsRelated(const sptr& prevSession) { int32_t currSessionId = GetMainSessionId(); int32_t prevSessionId = prevSession->GetMainSessionId(); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index f7a009056f..53beeab57d 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5943,7 +5943,8 @@ void SceneSessionManager::UpdateFocusStatus(sptr& sceneSession, bo } /** @note @window.focus */ -void SceneSessionManager::UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, bool isProactiveUnfocus) +void SceneSessionManager::UpdateHighlightStatus(const sptr& preSceneSession, + const sptr& currSceneSession, bool isProactiveUnfocus) { if (preSceneSession == nullptr || currSceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); -- Gitee From 1fc857212acf2f83cabf705df8c1d834864e905b Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 09:47:05 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_scene/session_manager/include/scene_session_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index d0fa47014b..e5691b9545 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -270,7 +270,7 @@ public: void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; WSError GetFocusSessionToken(sptr& token) override; WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; - void UpdateHighlightStatus(sptr& preSceneSession, sptr& currSceneSession, + void UpdateHighlightStatus(const sptr& preSceneSession, const sptr& currSceneSession, bool isProactiveUnfocus); void SetHighlightSessionIds(sptr& sceneSession); void AddHighlightSessionIds(sptr& sceneSession); -- Gitee From 953bd3aa7b7c6d849372ef6230efcd1ad8010a9c Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 12:04:07 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/wm/window.h | 2 +- .../window_runtime/window_napi/js_window.cpp | 8 ++--- .../common/include/window_session_property.h | 2 +- .../js_scene_session.cpp | 8 ++--- .../scene_session_manager/js_scene_session.h | 2 +- .../zidl/session_stage_ipc_interface_code.h | 2 +- .../container/src/zidl/session_stage_stub.cpp | 30 +++++++++---------- window_scene/session/host/src/session.cpp | 2 +- .../include/scene_session_manager.h | 13 ++++---- .../src/scene_session_manager.cpp | 20 ++++++------- .../test/unittest/session_stage_stub_test.cpp | 2 +- wm/src/window_session_impl.cpp | 4 +-- 12 files changed, 47 insertions(+), 48 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index cb2001e166..95c0f84e17 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -534,7 +534,7 @@ public: class IWindowHighlightChangeListener : virtual public RefBase { public: /** - * @brief Notify caller when when highlight status changes. + * @brief Notify caller when highlight status changes. * * @param isHighlight Whether the window is highlighted. */ 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 1170a849c4..14601fa741 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -7744,7 +7744,7 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf task = napiAsyncTask, where = __func__] { auto weakWindow = weakToken.promote(); if (weakWindow == nullptr) { - TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s window is nullptr", where); + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: window is nullptr", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); return; } @@ -7755,7 +7755,7 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf WmErrorCode wmErrorCode = WM_JS_TO_ERROR_CODE_MAP.at(ret); task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set exclusively highlighted failed")); } - TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s: end, window [%{public}u, %{public}s]", + TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s: end, window: [%{public}u, %{public}s]", where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { @@ -7774,10 +7774,10 @@ napi_value JsWindow::OnIsWindowHighlighted(napi_env env, napi_callback_info info bool isHighlighted = false; WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(windowToken_->IsWindowHighlighted(isHighlighted)); if (ret != WmErrorCode::WM_OK) { - TLOGE(WmsLogTag::WMS_FOCUS, "get window highlight failed, ret %{public}d", ret); + TLOGE(WmsLogTag::WMS_FOCUS, "get window highlight failed, ret: %{public}d", ret); return NapiThrowError(env, ret); } - TLOGI(WmsLogTag::WMS_FOCUS, "get window highlight end, isHighlighted = %{public}u", isHighlighted); + TLOGI(WmsLogTag::WMS_FOCUS, "get window highlight end, isHighlighted: %{public}u", isHighlighted); return CreateJsValue(env, isHighlighted); } diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index c3bf21ed07..6331436885 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -118,6 +118,7 @@ public: RectAnimationConfig GetRectAnimationConfig() const; WindowType GetWindowType() const; bool GetDragEnabled() const; + bool GetTouchable() const; bool GetHideNonSystemFloatingWindows() const; bool GetForceHide() const; bool GetRaiseEnabled() const; @@ -259,7 +260,6 @@ public: */ bool GetFocusable() const; bool GetFocusableOnShow() const; - bool GetTouchable() const; bool GetExclusivelyHighlighted() const; void SetExclusivelyHighlighted(bool isExclusivelyHighlighted); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 18f7739014..edf4d7c314 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -6132,7 +6132,7 @@ void JsSceneSession::ProcessSetHighlightChangeRegister() NotifyHighlightChangeFunc func = [weakThis = wptr(this), where = __func__](bool isHighlight) { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession) { - TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s jsSceneSession is null", where); + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsSceneSession is null", where); return; } jsSceneSession->NotifyHighlightChange(isHighlight); @@ -6148,15 +6148,15 @@ void JsSceneSession::ProcessSetHighlightChangeRegister() void JsSceneSession::NotifyHighlightChange(bool isHighlight) { TLOGI(WmsLogTag::WMS_FOCUS, "isHighlight: %{public}d, id: %{public}d", isHighlight, persistentId_); - auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_] { + auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_, where = __func__] { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { - TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id: %{public}d has been destroyed", persistentId); + TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id: %{public}d has been destroyed", where, persistentId); return; } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); if (!jsCallBack) { - TLOGNE(WmsLogTag::WMS_FOCUS, "jsCallBack is nullptr"); + TLOGNE(WmsLogTag::WMS_FOCUS, "jsCallBack is nullptr", where); return; } napi_value jsIsHighlight = CreateJsValue(env, isHighlight); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index f1d2500056..8c32db2e5f 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -89,8 +89,8 @@ enum class ListenerFuncType : uint32_t { UPDATE_SESSION_LABEL_AND_ICON_CB, KEYBOARD_STATE_CHANGE_CB, KEYBOARD_VIEW_MODE_CHANGE_CB, - HIGHLIGHT_CHANGE_CB, SET_WINDOW_CORNER_RADIUS_CB, + HIGHLIGHT_CHANGE_CB, }; class SceneSession; diff --git a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h index 6f030ae35c..a8a055d3ca 100644 --- a/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h +++ b/window_scene/session/container/include/zidl/session_stage_ipc_interface_code.h @@ -71,8 +71,8 @@ enum class SessionStageInterfaceCode { TRANS_ID_SET_FULLSCREEN_WATERFALL_MODE, TRANS_ID_SET_SUPPORT_ENTER_WATERFALL_MODE, TRANS_ID_SEND_CONTAINER_MODAL_EVENT, - TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE, TRANS_ID_SET_DRAG_ACTIVATED, + TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE, }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index 5756c0f83d..d3c92352e7 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -190,10 +190,10 @@ int SessionStageStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Messag return HandleExtensionHostData(data, reply, option); case static_cast(SessionStageInterfaceCode::TRANS_ID_SEND_CONTAINER_MODAL_EVENT): return HandleSendContainerModalEvent(data, reply); - case static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE): - return HandleNotifyHighlightChange(data, reply); case static_cast(SessionStageInterfaceCode::TRANS_ID_SET_DRAG_ACTIVATED): return HandleSetDragActivated(data, reply); + case static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE): + return HandleNotifyHighlightChange(data, reply); default: WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -333,19 +333,6 @@ int SessionStageStub::HandleNotifyTransferComponentData(MessageParcel& data, Mes return ERR_NONE; } -int SessionStageStub::HandleNotifyHighlightChange(MessageParcel& data, MessageParcel& reply) -{ - TLOGD(WmsLogTag::WMS_FOCUS, "called!"); - bool isHighlight = false; - if (!data.ReadBool(isHighlight)) { - TLOGE(WmsLogTag::WMS_FOCUS, "Read isHighlight failed."); - return ERR_INVALID_DATA; - } - WSError errCode = NotifyHighlightChange(isHighlight); - reply.WriteUint32(static_cast(errCode)); - return ERR_NONE; -} - int SessionStageStub::HandleNotifyTransferComponentDataSync(MessageParcel& data, MessageParcel& reply) { std::shared_ptr wantParams(data.ReadParcelable()); @@ -771,4 +758,17 @@ int SessionStageStub::HandleSendContainerModalEvent(MessageParcel& data, Message SendContainerModalEvent(eventName, eventValue); return ERR_NONE; } + +int SessionStageStub::HandleNotifyHighlightChange(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_FOCUS, "called!"); + bool isHighlight = false; + if (!data.ReadBool(isHighlight)) { + TLOGE(WmsLogTag::WMS_FOCUS, "Read isHighlight failed."); + return ERR_INVALID_DATA; + } + WSError errCode = NotifyHighlightChange(isHighlight); + reply.WriteUint32(static_cast(errCode)); + return ERR_NONE; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index c92d01867f..6472fa74b5 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2668,7 +2668,7 @@ void Session::SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { auto property = GetSessionProperty(); if (property == nullptr) { - TLOGE(WmsLogTag::WMS_FOCUS, "windowId: %{public}d property is nullptr", persistentId_); + TLOGE(WmsLogTag::WMS_FOCUS, "property is nullptr, windowId: %{public}d", persistentId_); return; } if (isExclusivelyHighlighted == property->GetExclusivelyHighlighted()) { diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 5e46919b1f..85fed86391 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -270,13 +270,6 @@ public: void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; WSError GetFocusSessionToken(sptr& token) override; WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; - void UpdateHighlightStatus(const sptr& preSceneSession, const sptr& currSceneSession, - bool isProactiveUnfocus); - void SetHighlightSessionIds(sptr& sceneSession); - void AddHighlightSessionIds(sptr& sceneSession); - void RemoveHighlightSessionIds(sptr& sceneSession); - std::string GetHighlightIdsStr(); - WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); WSError RaiseWindowToTop(int32_t persistentId) override; @@ -738,6 +731,12 @@ private: std::vector> GetSceneSessionVectorByType(WindowType type); void UpdateOccupiedAreaIfNeed(int32_t persistentId); void NotifyMMIWindowPidChange(int32_t windowId, bool startMoving); + void UpdateHighlightStatus(const sptr& preSceneSession, const sptr& currSceneSession, + bool isProactiveUnfocus); + void SetHighlightSessionIds(const sptr& sceneSession); + void AddHighlightSessionIds(const sptr& sceneSession); + void RemoveHighlightSessionIds(const sptr& sceneSession); + std::string GetHighlightIdsStr(); /* * Window Immersive diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 70388e7c4c..650d1ad06f 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5972,9 +5972,9 @@ void SceneSessionManager::UpdateHighlightStatus(const sptr& preSce } /** @note @window.focus */ -void SceneSessionManager::SetHighlightSessionIds(sptr& sceneSession) +void SceneSessionManager::SetHighlightSessionIds(const sptr& sceneSession) { - if(sceneSession == nullptr) { + if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); return; } @@ -5991,25 +5991,25 @@ void SceneSessionManager::SetHighlightSessionIds(sptr& sceneSessio sceneSession->UpdateHighlightStatus(true); highlightIds_.clear(); highlightIds_.insert(sceneSession->GetPersistentId()); - TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds: %{public}s", GetHighlightIdsStr().c_str()); } /** @note @window.focus */ -void SceneSessionManager::AddHighlightSessionIds(sptr& sceneSession) +void SceneSessionManager::AddHighlightSessionIds(const sptr& sceneSession) { - if(sceneSession == nullptr) { + if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); return; } sceneSession->UpdateHighlightStatus(true); highlightIds_.insert(sceneSession->GetPersistentId()); - TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds: %{public}s", GetHighlightIdsStr().c_str()); } /** @note @window.focus */ -void SceneSessionManager::RemoveHighlightSessionIds(sptr& sceneSession) +void SceneSessionManager::RemoveHighlightSessionIds(const sptr& sceneSession) { - if(sceneSession == nullptr) { + if (sceneSession == nullptr) { TLOGE(WmsLogTag::WMS_FOCUS, "sceneSession is nullptr"); return; } @@ -6019,14 +6019,14 @@ void SceneSessionManager::RemoveHighlightSessionIds(sptr& sceneSes } else { TLOGE(WmsLogTag::WMS_FOCUS, "not found scene session with id: %{public}d", sceneSession->GetPersistentId()); } - TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds_: %{public}s", GetHighlightIdsStr().c_str()); + TLOGI(WmsLogTag::WMS_FOCUS, "highlightIds: %{public}s", GetHighlightIdsStr().c_str()); } /** @note @window.focus */ std::string SceneSessionManager::GetHighlightIdsStr() { std::ostringstream oss; - for(auto it = highlightIds_.begin(); it != highlightIds_.end(); it++){ + for (auto it = highlightIds_.begin(); it != highlightIds_.end(); it++) { oss << *it; if(std::next(it) != highlightIds_.end()) { oss << ", "; diff --git a/window_scene/test/unittest/session_stage_stub_test.cpp b/window_scene/test/unittest/session_stage_stub_test.cpp index e8ddda94ca..74141b7a23 100644 --- a/window_scene/test/unittest/session_stage_stub_test.cpp +++ b/window_scene/test/unittest/session_stage_stub_test.cpp @@ -902,7 +902,7 @@ HWTEST_F(SessionStageStubTest, HandleNotifyHighlightChange, Function | SmallTest MessageParcel reply; data.WriteBool(false); - ASSERT_TRUE((sessionStageStub_ != nullptr)); + ASSERT_TRUE(sessionStageStub_ != nullptr); ASSERT_EQ(0, sessionStageStub_->HandleNotifyHighlightChange(data, reply)); } } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 58fd8cc151..5e1ef95cf2 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1678,7 +1678,7 @@ WMError WindowSessionImpl::SetExclusivelyHighlighted(bool isExclusivelyHighlight return WMError::WM_ERROR_INVALID_CALLING; } if (property_->GetExclusivelyHighlighted() == isExclusivelyHighlighted) { - TLOGD(WmsLogTag::WMS_FOCUS, "hightlight:no nothing"); + TLOGD(WmsLogTag::WMS_FOCUS, "already exclusivelyHighlighted"); return WMError::WM_OK; } property_->SetExclusivelyHighlighted(isExclusivelyHighlighted); @@ -1689,7 +1689,7 @@ WMError WindowSessionImpl::SetExclusivelyHighlighted(bool isExclusivelyHighlight bool WindowSessionImpl::GetExclusivelyHighlighted() const { bool isExclusivelyHighlighted = property_->GetExclusivelyHighlighted(); - TLOGD(WmsLogTag::WMS_FOCUS, "WindowID: %{public}d, isExclusivelyHighlighted: %{public}d", + TLOGD(WmsLogTag::WMS_FOCUS, "windowId: %{public}d, isExclusivelyHighlighted: %{public}d", property_->GetPersistentId(), isExclusivelyHighlighted); return isExclusivelyHighlighted; } -- Gitee From 0ebc7e2bda9873329abbbc3b95b81b6d498e0963 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 14:56:02 +0800 Subject: [PATCH 15/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/wm/window.h | 3 ++- previewer/include/window.h | 3 ++- .../kits/napi/scene_session_manager/js_scene_session.cpp | 2 +- window_scene/session_manager/src/scene_session_manager.cpp | 3 +-- wm/include/window_session_impl.h | 2 +- wm/src/window_session_impl.cpp | 5 ++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index 95c0f84e17..b8b305c496 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -3049,7 +3049,8 @@ public: * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) + { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } diff --git a/previewer/include/window.h b/previewer/include/window.h index a1961e0c7e..be5f5fccfd 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -482,7 +482,8 @@ public: * @param isExclusivelyHighlighted the value true means to exclusively highlight, and false means the opposite. * @return WM_OK means set success, others means set failed. */ - virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) { + virtual WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) + { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index edf4d7c314..3984b6d697 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -6151,7 +6151,7 @@ void JsSceneSession::NotifyHighlightChange(bool isHighlight) auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_, where = __func__] { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { - TLOGNE(WmsLogTag::WMS_FOCUS, "jsSceneSession id: %{public}d has been destroyed", where, persistentId); + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsSceneSession id: %{public}d has been destroyed", where, persistentId); return; } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 650d1ad06f..371154f8e6 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -4984,9 +4984,8 @@ void SceneSessionManager::DumpSessionInfo(const sptr& session, std WSError SceneSessionManager::GetAllSessionDumpInfo(std::string& dumpInfo) { - int32_t screenGroupId = 0; std::ostringstream oss; - oss << "-------------------------------------ScreenGroup " << screenGroupId + oss << "-------------------------------------ScreenGroup 0" << "-------------------------------------" << std::endl; oss << "WindowName DisplayId Pid WinId Type Mode Flag ZOrd Orientation [ x y w h ]" << " [ OffsetX OffsetY ] [ ScaleX ScaleY PivotX PivotY ]" << std::endl; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index a8af4549f1..dd06891fd6 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -349,7 +349,7 @@ public: * HightLight Window */ bool GetExclusivelyHighlighted() const; - bool IsWindowHighlighted(bool& highlighted) const override; + WMError IsWindowHighlighted(bool& highlighted) const override; WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) override; WMError RegisterWindowHighlightChangeListeners(const sptr& listener) override; WMError UnregisterWindowHighlightChangeListeners(const sptr& listener) override; diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 5e1ef95cf2..de53b7189c 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -120,7 +120,7 @@ std::map>> WindowSessionImp std::map> WindowSessionImpl::subWindowCloseListeners_; std::map> WindowSessionImpl::mainWindowCloseListeners_; std::map>> WindowSessionImpl::switchFreeMultiWindowListeners_; -std::map>> WindowSessionImpl::highlightChangeListeners_; +std::map>> WindowSessionImpl::highlightChangeListeners_; std::recursive_mutex WindowSessionImpl::lifeCycleListenerMutex_; std::recursive_mutex WindowSessionImpl::windowChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::avoidAreaChangeListenerMutex_; @@ -2607,8 +2607,7 @@ WMError WindowSessionImpl::UnregisterSubWindowCloseListeners(const sptr -EnableIfSame>> WindowSessionImpl::GetListeners() +EnableIfSame>> WindowSessionImpl::GetListeners() { std::vector> highlightChangeListeners; for (auto& listener : highlightChangeListeners_[GetPersistentId()]) { -- Gitee From b94d5f21d95bf12b6dad10736885508aec274670 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 15:21:36 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/napi/scene_session_manager/js_scene_session.cpp | 3 ++- wm/src/window_session_impl.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 3984b6d697..decb8094fb 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -6151,7 +6151,8 @@ void JsSceneSession::NotifyHighlightChange(bool isHighlight) auto task = [weakThis = wptr(this), isHighlight, env = env_, persistentId = persistentId_, where = __func__] { auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { - TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsSceneSession id: %{public}d has been destroyed", where, persistentId); + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsSceneSession id: %{public}d has been destroyed", + where, persistentId); return; } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index de53b7189c..5373b75aa0 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2607,7 +2607,8 @@ WMError WindowSessionImpl::UnregisterSubWindowCloseListeners(const sptr -EnableIfSame>> WindowSessionImpl::GetListeners() +EnableIfSame>> + WindowSessionImpl::GetListeners() { std::vector> highlightChangeListeners; for (auto& listener : highlightChangeListeners_[GetPersistentId()]) { -- Gitee From 15e9a92a16d33d45f78be9dcea5707e65c8b6818 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 15:36:47 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/napi/scene_session_manager/js_scene_session.cpp | 2 +- wm/src/window_session_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index decb8094fb..5aa676cfe3 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -6152,7 +6152,7 @@ void JsSceneSession::NotifyHighlightChange(bool isHighlight) auto jsSceneSession = weakThis.promote(); if (!jsSceneSession || jsSceneSessionMap_.find(persistentId) == jsSceneSessionMap_.end()) { TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsSceneSession id: %{public}d has been destroyed", - where, persistentId); + where, persistentId); return; } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 5373b75aa0..a620e88daa 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -2607,7 +2607,7 @@ WMError WindowSessionImpl::UnregisterSubWindowCloseListeners(const sptr -EnableIfSame>> +EnableIfSame>> WindowSessionImpl::GetListeners() { std::vector> highlightChangeListeners; -- Gitee From 045d0a302a72497ecabdadefb0c2084455082d51 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 16:15:13 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/napi/scene_session_manager/js_scene_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 5aa676cfe3..a352b703fc 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -6157,7 +6157,7 @@ void JsSceneSession::NotifyHighlightChange(bool isHighlight) } auto jsCallBack = jsSceneSession->GetJSCallback(HIGHLIGHT_CHANGE_CB); if (!jsCallBack) { - TLOGNE(WmsLogTag::WMS_FOCUS, "jsCallBack is nullptr", where); + TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: jsCallBack is nullptr", where); return; } napi_value jsIsHighlight = CreateJsValue(env, isHighlight); -- Gitee From 63aa6fd9fd22cf9ddb50798e3c9aa1f06ce04cf5 Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 17:26:35 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wm/test/unittest/window_session_impl_test4.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index 0869ada8db..cfd0aca926 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -2474,10 +2474,13 @@ HWTEST_F(WindowSessionImplTest4, IsWindowHighlighted, Function | SmallTest | Lev ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; window->property_->SetPersistentId(INVALID_SESSION_ID); - ASSERT_EQ(window->IsWindowHighlighted(), false); + bool isHighlighted = false; + window->IsWindowHighlighted(isHighlighted) + ASSERT_EQ(isHighlighted, false); window->property_->SetPersistentId(1); window->isHighlighted_ = true; - ASSERT_EQ(window->IsWindowHighlighted(), true); + window->IsWindowHighlighted(isHighlighted) + ASSERT_EQ(isHighlighted, true); } } // namespace -- Gitee From d935ebedfa63dd29e0465b6dc5df03c7fe18d72a Mon Sep 17 00:00:00 2001 From: 18 Date: Wed, 22 Jan 2025 18:11:55 +0800 Subject: [PATCH 20/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wm/test/unittest/window_session_impl_test4.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wm/test/unittest/window_session_impl_test4.cpp b/wm/test/unittest/window_session_impl_test4.cpp index cfd0aca926..22d5f96c33 100644 --- a/wm/test/unittest/window_session_impl_test4.cpp +++ b/wm/test/unittest/window_session_impl_test4.cpp @@ -2475,11 +2475,11 @@ HWTEST_F(WindowSessionImplTest4, IsWindowHighlighted, Function | SmallTest | Lev window->hostSession_ = session; window->property_->SetPersistentId(INVALID_SESSION_ID); bool isHighlighted = false; - window->IsWindowHighlighted(isHighlighted) + window->IsWindowHighlighted(isHighlighted); ASSERT_EQ(isHighlighted, false); window->property_->SetPersistentId(1); window->isHighlighted_ = true; - window->IsWindowHighlighted(isHighlighted) + window->IsWindowHighlighted(isHighlighted); ASSERT_EQ(isHighlighted, true); } -- Gitee From 35090602a8c3b179154a8f1cc8f5686edc1cff6d Mon Sep 17 00:00:00 2001 From: 18 Date: Thu, 23 Jan 2025 09:58:48 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/wm/window.h | 2 +- window_scene/session/host/src/session.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index b8b305c496..d58b7e933f 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -529,7 +529,7 @@ public: /** * @class IWindowHighlightChangeListener * - * @brief IWindowHighlightChangeListener is a Listener to observe event when highlight change of window. + * @brief IWindowHighlightChangeListener is a listener to observe event when highlight change of window. */ class IWindowHighlightChangeListener : virtual public RefBase { public: diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 808ab9bf87..7210a49d8c 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2689,8 +2689,9 @@ WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightC isHighlight_ = isHighlight; if (isNotifyHighlightChange) { NotifyHighlightChange(isHighlight); - if (highlightChangeFunc_ != nullptr) { - highlightChangeFunc_(isHighlight); + auto func = highlightChangeFunc_; + if (func != nullptr) { + func(isHighlight); } } return WSError::WS_OK; -- Gitee From 193ec9954d45642f0a7fcce23c92fba2c2fc5e5f Mon Sep 17 00:00:00 2001 From: 18 Date: Thu, 23 Jan 2025 16:11:17 +0800 Subject: [PATCH 22/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/napi/window_runtime/window_napi/js_window.cpp | 8 ++++---- window_scene/session/host/src/session.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 60c64a6d61..b3e837a0e2 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -7751,13 +7751,13 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf std::shared_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); auto asyncTask = [weakToken = wptr(windowToken_), exclusivelyHighlighted, env, task = napiAsyncTask, where = __func__] { - auto weakWindow = weakToken.promote(); - if (weakWindow == nullptr) { + auto window = weakToken.promote(); + if (window == nullptr) { TLOGNE(WmsLogTag::WMS_FOCUS, "%{public}s: window is nullptr", where); task->Reject(env, JsErrUtils::CreateJsError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY)); return; } - WMError ret = weakWindow->SetExclusivelyHighlighted(exclusivelyHighlighted); + WMError ret = window->SetExclusivelyHighlighted(exclusivelyHighlighted); if (ret == WMError::WM_OK) { task->Resolve(env, NapiGetUndefined(env)); } else { @@ -7765,7 +7765,7 @@ napi_value JsWindow::OnSetExclusivelyHighlighted(napi_env env, napi_callback_inf task->Reject(env, JsErrUtils::CreateJsError(env, wmErrorCode, "Set exclusively highlighted failed")); } TLOGNI(WmsLogTag::WMS_FOCUS, "%{public}s: end, window: [%{public}u, %{public}s]", - where, weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str()); + where, window->GetWindowId(), window->GetWindowName().c_str()); }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { napiAsyncTask->Reject(env, CreateJsError(env, diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index dab11cb73e..17586da6e5 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2691,7 +2691,7 @@ WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightC WSError Session::NotifyHighlightChange(bool isHighlight) { - if (!IsSessionValid()) { + if (IsSystemSession()) { TLOGW(WmsLogTag::WMS_FOCUS, "Session is invalid, id: %{public}d state: %{public}u", persistentId_, GetSessionState()); return WSError::WS_ERROR_INVALID_SESSION; -- Gitee From d596cbf881f393d68c5edb061be3d3cf8178eb21 Mon Sep 17 00:00:00 2001 From: 18 Date: Thu, 23 Jan 2025 20:46:35 +0800 Subject: [PATCH 23/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/include/window_session_property.h | 2 +- window_scene/session/host/include/scene_session.h | 2 +- window_scene/session/host/include/session.h | 5 +++-- window_scene/session/host/src/scene_session.cpp | 3 ++- window_scene/session/host/src/session.cpp | 8 ++++---- .../include/scene_session_manager.h | 4 ++-- .../session_manager/src/scene_session_manager.cpp | 15 +++++++-------- .../test/unittest/scene_session_manager_test5.cpp | 4 ++-- .../test/unittest/scene_session_manager_test9.cpp | 2 +- .../test/unittest/scene_session_test5.cpp | 14 +++++++------- wm/src/window_session_impl.cpp | 2 +- 11 files changed, 31 insertions(+), 30 deletions(-) diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 6331436885..25d2cbe401 100755 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -336,6 +336,7 @@ private: mutable std::mutex rectAnimationConfigMutex_; RectAnimationConfig rectAnimationConfig_ { 0, 0.0f, 0.0f, 0.0f, 0.0f }; WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; // type main window + bool touchable_ { true }; bool dragEnabled_ = { true }; bool raiseEnabled_ = { true }; bool isSystemCalling_ = { false }; @@ -451,7 +452,6 @@ private: */ bool focusable_ { true }; bool focusableOnShow_ { true }; - bool touchable_ { true }; bool isExclusivelyHighlighted_ { true }; /* diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index e791737c68..d76aa1430a 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -627,7 +627,7 @@ public: /* * Window Focus */ - bool IsRelated(const sptr& prevSession); + bool IsSameMainSession(const sptr& prevSession); void SetHighlightChangeNotifyFunc(const NotifyHighlightChangeFunc& func); /* diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 1878aba3ec..70e3e6c3b3 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -693,6 +693,7 @@ protected: NotifySystemSessionKeyEventFunc systemSessionKeyEventFunc_; NotifyContextTransparentFunc contextTransparentFunc_; NotifyFrameLayoutFinishFunc frameLayoutFinishFunc_; + std::mutex highlightChangeFuncMutex_; NotifyHighlightChangeFunc highlightChangeFunc_; /* @@ -750,8 +751,8 @@ protected: * Window Focus */ bool isFocused_ = false; - bool blockingFocus_ {false}; - bool isHighlight_ {false}; + bool blockingFocus_ { false }; + bool isHighlight_ { false }; uint32_t uiNodeId_ = 0; float aspectRatio_ = 0.0f; diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 6ae458dc6b..2cd19794f6 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -3660,7 +3660,7 @@ bool SceneSession::IsSystemSessionAboveApp() const } /** @note @window.focus */ -bool SceneSession::IsRelated(const sptr& prevSession) +bool SceneSession::IsSameMainSession(const sptr& prevSession) { int32_t currSessionId = GetMainSessionId(); int32_t prevSessionId = prevSession->GetMainSessionId(); @@ -5795,6 +5795,7 @@ void SceneSession::SetPrivacyModeChangeNotifyFunc(const NotifyPrivacyModeChangeF void SceneSession::SetHighlightChangeNotifyFunc(const NotifyHighlightChangeFunc& func) { + std::lock_guard lock(highlightChangeFuncMutex_); highlightChangeFunc_ = func; } diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 17586da6e5..2586238c52 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2681,9 +2681,9 @@ WSError Session::UpdateHighlightStatus(bool isHighlight, bool isNotifyHighlightC isHighlight_ = isHighlight; if (isNotifyHighlightChange) { NotifyHighlightChange(isHighlight); - auto func = highlightChangeFunc_; - if (func != nullptr) { - func(isHighlight); + std::lock_guard lock(highlightChangeFuncMutex_); + if (highlightChangeFunc_ != nullptr) { + highlightChangeFunc_(isHighlight); } } return WSError::WS_OK; @@ -2700,7 +2700,7 @@ WSError Session::NotifyHighlightChange(bool isHighlight) TLOGE(WmsLogTag::WMS_FOCUS, "sessionStage is null"); return WSError::WS_ERROR_NULLPTR; } - sessionStage_ -> NotifyHighlightChange(isHighlight); + sessionStage_->NotifyHighlightChange(isHighlight); return WSError::WS_OK; } diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index b082cc6e52..a65bad5c6f 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -722,8 +722,8 @@ private: sptr GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(DisplayId displayId, const sptr& nextSession, - FocusChangeReason reason = FocusChangeReason::DEFAULT, bool isProactiveUnfocus = false); + WSError ShiftFocus(DisplayId displayId, const sptr& nextSession, bool isProactiveUnfocus + FocusChangeReason reason = FocusChangeReason::DEFAULT); void UpdateFocusStatus(DisplayId displayId, const sptr& sceneSession, bool isFocused); void NotifyFocusStatus(const sptr& sceneSession, bool isFocused, const sptr& focusGroup); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 45d63256b9..d4fe50bf58 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -5477,7 +5477,7 @@ WSError SceneSessionManager::RequestSessionFocusImmediately(int32_t persistentId if (!sceneSession->GetSessionInfo().isSystem_ && !IsSessionVisibleForeground(sceneSession)) { focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(true); } - ShiftFocus(displayId, sceneSession, reason); + ShiftFocus(displayId, sceneSession, false, reason); return WSError::WS_OK; } @@ -5530,7 +5530,7 @@ WSError SceneSessionManager::RequestSessionFocus(int32_t persistentId, bool byFo } focusGroup->SetNeedBlockNotifyUnfocusStatus(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()); focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); - ShiftFocus(displayId, sceneSession, reason); + ShiftFocus(displayId, sceneSession, false, reason); return WSError::WS_OK; } @@ -5577,7 +5577,7 @@ WSError SceneSessionManager::RequestSessionUnfocus(int32_t persistentId, FocusCh return WSError::WS_OK; } - return ShiftFocus(displayId, nextSession, reason, true); + return ShiftFocus(displayId, nextSession, true, reason); } WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() @@ -5601,7 +5601,7 @@ WSError SceneSessionManager::RequestAllAppSessionUnfocusInner() focusGroup->SetNeedBlockNotifyUnfocusStatus(focusGroup->GetNeedBlockNotifyFocusStatusUntilForeground()); focusGroup->SetNeedBlockNotifyFocusStatusUntilForeground(false); - return ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::WIND, true); + return ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, true, FocusChangeReason::WIND); } WSError SceneSessionManager::RequestFocusBasicCheck(int32_t persistentId, const sptr& focusGroup) @@ -5959,7 +5959,7 @@ void SceneSessionManager::SetAbilityManagerCollaboratorRegisteredFunc( } WSError SceneSessionManager::ShiftFocus(DisplayId displayId, const sptr& nextSession, - FocusChangeReason reason, bool isProactiveUnfocus) + bool isProactiveUnfocus, FocusChangeReason reason) { // unfocus auto focusedSessionId = windowFocusController_->GetFocusedSessionId(displayId); @@ -6044,8 +6044,7 @@ void SceneSessionManager::UpdateHighlightStatus(const sptr& preSce TLOGD(WmsLogTag::WMS_FOCUS, "proactiveUnfocus"); RemoveHighlightSessionIds(preSceneSession); } - auto sessionProperty = currSceneSession->GetSessionProperty(); - if(sessionProperty->GetExclusivelyHighlighted()) { + if(currSceneSession->GetSessionProperty()->GetExclusivelyHighlighted()) { TLOGD(WmsLogTag::WMS_FOCUS, "exclusively highlighted"); SetHighlightSessionIds(currSceneSession); return; @@ -6055,7 +6054,7 @@ void SceneSessionManager::UpdateHighlightStatus(const sptr& preSce AddHighlightSessionIds(currSceneSession); return; } - if(currSceneSession->IsRelated(preSceneSession)) { + if(currSceneSession->IsSameMainSession(preSceneSession)) { TLOGD(WmsLogTag::WMS_FOCUS, "related highlighted"); AddHighlightSessionIds(currSceneSession); return; diff --git a/window_scene/test/unittest/scene_session_manager_test5.cpp b/window_scene/test/unittest/scene_session_manager_test5.cpp index 4707dc5abf..04d602d41e 100644 --- a/window_scene/test/unittest/scene_session_manager_test5.cpp +++ b/window_scene/test/unittest/scene_session_manager_test5.cpp @@ -708,7 +708,7 @@ HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | info.bundleName_ = "test2"; FocusChangeReason reason = FocusChangeReason::SPLIT_SCREEN; sptr sceneSession = nullptr; - ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession, reason); + ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession, false, reason); info.isSystem_ = true; sptr property = sptr::MakeSptr(); ASSERT_NE(property, nullptr); @@ -723,7 +723,7 @@ HWTEST_F(SceneSessionManagerTest5, SetShiftFocusListener, Function | SmallTest | ssm_->SetCallingSessionIdSessionListenser(func1); ProcessStartUIAbilityErrorFunc func2; ssm_->SetStartUIAbilityErrorListener(func2); - ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession1, reason); + ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, sceneSession1, false, reason); } /** diff --git a/window_scene/test/unittest/scene_session_manager_test9.cpp b/window_scene/test/unittest/scene_session_manager_test9.cpp index 4cdf582fd2..f74d35f1f4 100644 --- a/window_scene/test/unittest/scene_session_manager_test9.cpp +++ b/window_scene/test/unittest/scene_session_manager_test9.cpp @@ -1099,7 +1099,7 @@ HWTEST_F(SceneSessionManagerTest9, ShiftFocus, Function | SmallTest | Level3) ssm_->sceneSessionMap_.insert({4, nextSession}); auto focusGroup = ssm_->windowFocusController_->GetFocusGroup(DEFAULT_DISPLAY_ID); focusGroup->SetFocusedSessionId(1); - WSError ret = ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, FocusChangeReason::DEFAULT); + WSError ret = ssm_->ShiftFocus(DEFAULT_DISPLAY_ID, nextSession, false, FocusChangeReason::DEFAULT); ASSERT_EQ(ret, WSError::WS_OK); ASSERT_EQ(focusedSession->isFocused_, false); ASSERT_EQ(nextSession->isFocused_, true); diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 0436c772c4..ac8403bfb3 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -1727,11 +1727,11 @@ HWTEST_F(SceneSessionTest5, ActivateKeyboardAvoidArea01, Function | SmallTest | } /** - * @tc.name: IsRelated - * @tc.desc: test IsRelated + * @tc.name: IsSameMainSession + * @tc.desc: test IsSameMainSession * @tc.type: FUNC */ -HWTEST_F(SceneSessionTest5, IsRelated, Function | SmallTest | Level2) +HWTEST_F(SceneSessionTest5, IsSameMainSession, Function | SmallTest | Level2) { SessionInfo info1; info1.abilityName_ = "abilityName_test1"; @@ -1743,9 +1743,9 @@ HWTEST_F(SceneSessionTest5, IsRelated, Function | SmallTest | Level2) sptr currSceneSession = sptr::MakeSptr(info2, nullptr); preSceneSession->persistentId_ = 1; currSceneSession->persistentId_ = 1; - ASSERT_EQ(true, currSceneSession->IsRelated(preSceneSession)); + ASSERT_EQ(true, currSceneSession->IsSameMainSession(preSceneSession)); currSceneSession->persistentId_ = 2; - ASSERT_EQ(false, currSceneSession->IsRelated(preSceneSession)); + ASSERT_EQ(false, currSceneSession->IsSameMainSession(preSceneSession)); sptr subSession1 = sptr::MakeSptr(info1, nullptr); sptr subSession2 = sptr::MakeSptr(info2, nullptr); @@ -1754,9 +1754,9 @@ HWTEST_F(SceneSessionTest5, IsRelated, Function | SmallTest | Level2) currSceneSession->persistentId_ = 1; subSession1->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); subSession2->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); - ASSERT_EQ(true, subSession1->IsRelated(subSession1)); + ASSERT_EQ(true, subSession1->IsSameMainSession(subSession1)); currSceneSession->persistentId_ = 2; - ASSERT_EQ(false, subSession1->IsRelated(subSession1)); + ASSERT_EQ(false, subSession1->IsSameMainSession(subSession1)); } /** diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 4d05707a14..b995834645 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1704,7 +1704,7 @@ WSError WindowSessionImpl::NotifyHighlightChange(bool isHighlight) isHighlighted_ = isHighlight; std::lock_guard lockListener(highlightChangeListenerMutex_); auto highlightChangeListeners = GetListeners(); - for (auto& listener : highlightChangeListeners) { + for (const auto& listener : highlightChangeListeners) { if (listener != nullptr) { listener->OnWindowHighlightChange(isHighlight); } -- Gitee From d3101d4d7164d0a19c40f15a71853010d76932cf Mon Sep 17 00:00:00 2001 From: 18 Date: Thu, 23 Jan 2025 21:08:34 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E6=80=81=20Signed-off-by:=2018=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_scene/session_manager/include/scene_session_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index a65bad5c6f..1604388940 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -722,7 +722,7 @@ private: sptr GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder, bool includingAppSession); sptr GetTopFocusableNonAppSession(); - WSError ShiftFocus(DisplayId displayId, const sptr& nextSession, bool isProactiveUnfocus + WSError ShiftFocus(DisplayId displayId, const sptr& nextSession, bool isProactiveUnfocus, FocusChangeReason reason = FocusChangeReason::DEFAULT); void UpdateFocusStatus(DisplayId displayId, const sptr& sceneSession, bool isFocused); void NotifyFocusStatus(const sptr& sceneSession, bool isFocused, -- Gitee