From a2044dcfaaac743c08b1e1696a0b8d7cf201e0cb Mon Sep 17 00:00:00 2001 From: kaicui Date: Fri, 15 Nov 2024 17:13:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E5=81=9A=E5=AF=B9=E5=BA=94=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kaicui --- .../js_extension_window_listener.cpp | 22 +++++++++---------- .../js_extension_window_listener.h | 8 +++---- .../js_extension_window_register_manager.cpp | 4 ++-- .../js_extension_window_register_manager.h | 4 ++-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/interfaces/kits/napi/extension_window/js_extension_window_listener.cpp b/interfaces/kits/napi/extension_window/js_extension_window_listener.cpp index 974c98fccf..e19a148d2c 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window_listener.cpp +++ b/interfaces/kits/napi/extension_window/js_extension_window_listener.cpp @@ -116,30 +116,29 @@ void JsExtensionWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason r currRect_ = rect; } -void JsExtensionWindowListener::OnRectChange(Rect rect, WindowSizeChangeReason reason) +void JsExtensionWindowListener::OnRectChange(const Rect& rect, WindowSizeChangeReason reason) { if (currRect_ == rect && reason == WindowSizeChangeReason::UNDEFINED) { TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]Skip redundant rect update"); return; } - RectChangeReason rectChangReason = RectChangeReason::UNDEFINED; + RectChangeReason rectChangeReason = RectChangeReason::UNDEFINED; if (JS_SIZE_CHANGE_REASON.count(reason) != 0 && !(reason == WindowSizeChangeReason::MAXIMIZE && rect.posX_ != 0)) { - rectChangReason = JS_SIZE_CHANGE_REASON.at(reason); + rectChangeReason = JS_SIZE_CHANGE_REASON.at(reason); } - if (currentReason_ != RectChangeReason::DRAG && rectChangReason == RectChangeReason::DRAG_END) { - rectChangReason = RectChangeReason::MOVE; + if (currentRectChangeReason_ != RectChangeReason::DRAG && rectChangeReason == RectChangeReason::DRAG_END) { + rectChangeReason = RectChangeReason::MOVE; } // js callback should run in js thread - auto jsCallback = [self = weakRef_, rect, rectChangReason, env = env_] () { + auto jsCallback = [self = weakRef_, rect, rectChangeReason, env = env_] { HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsExtensionWindowListener::OnRectChange"); auto thisListener = self.promote(); if (thisListener == nullptr || env == nullptr) { TLOGNE(WmsLogTag::WMS_UIEXT, "[NAPI]This listener or env is nullptr"); return; } - napi_handle_scope scope = nullptr; - napi_open_handle_scope(env, &scope); + HandleScope handleScope(env); napi_value objValue = nullptr; napi_create_object(env, &objValue); if (objValue == nullptr) { @@ -152,10 +151,9 @@ void JsExtensionWindowListener::OnRectChange(Rect rect, WindowSizeChangeReason r return; } napi_set_named_property(env, objValue, "rect", rectObjValue); - napi_set_named_property(env, objValue, "reason", CreateJsValue(env, rectChangReason)); - napi_value argv[] = {objValue}; + napi_set_named_property(env, objValue, "reason", CreateJsValue(env, rectChangeReason)); + napi_value argv[] = { objValue }; thisListener->CallJsMethod(WINDOW_RECT_CHANGE_CB.c_str(), argv, ArraySize(argv)); - napi_close_handle_scope(env, scope); }; if (!eventHandler_) { TLOGE(WmsLogTag::WMS_UIEXT, "Get main event handler failed!"); @@ -164,7 +162,7 @@ void JsExtensionWindowListener::OnRectChange(Rect rect, WindowSizeChangeReason r eventHandler_->PostTask(jsCallback, "wms:JsExtensionWindowListener::OnRectChange", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); currRect_ = rect; - currentReason_ = rectChangReason; + currentRectChangeReason_ = rectChangeReason; } void JsExtensionWindowListener::OnModeChange(WindowMode mode, bool hasDeco) diff --git a/interfaces/kits/napi/extension_window/js_extension_window_listener.h b/interfaces/kits/napi/extension_window/js_extension_window_listener.h index 0affae59d8..65fd5083b5 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window_listener.h +++ b/interfaces/kits/napi/extension_window/js_extension_window_listener.h @@ -26,8 +26,8 @@ #include "window.h" #include "window_manager.h" #include "wm_common.h" -#include "js_window_utils.h" #include "js_extension_window_utils.h" +#include "js_window_utils.h" namespace OHOS { namespace Rosen { @@ -43,7 +43,7 @@ public: ~JsExtensionWindowListener(); void OnSizeChange(Rect rect, WindowSizeChangeReason reason, const std::shared_ptr& rsTransaction = nullptr) override; - void OnRectChange(Rect rect, WindowSizeChangeReason reason) override; + void OnRectChange(const Rect& rect, WindowSizeChangeReason reason) override; void OnModeChange(WindowMode mode, bool hasDeco) override; void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; void AfterForeground() override; @@ -59,8 +59,8 @@ public: void SetMainEventHandler(); private: - Rect currRect_ = {}; - RectChangeReason currentReason_ = RectChangeReason::UNDEFINED; + Rect currRect_; + RectChangeReason currentRectChangeReason_ = RectChangeReason::UNDEFINED; napi_env env_ = nullptr; WindowState state_ {WindowState::STATE_INITIAL}; std::shared_ptr jsCallBack_; diff --git a/interfaces/kits/napi/extension_window/js_extension_window_register_manager.cpp b/interfaces/kits/napi/extension_window/js_extension_window_register_manager.cpp index c0510dd45b..f406003ef8 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window_register_manager.cpp +++ b/interfaces/kits/napi/extension_window/js_extension_window_register_manager.cpp @@ -63,8 +63,8 @@ WmErrorCode JsExtensionWindowRegisterManager::ProcessWindowChangeRegister(sptr listener, - sptr window, bool isRegister) +WmErrorCode JsExtensionWindowRegisterManager::ProcessWindowRectChangeRegister(const sptr& listener, + const sptr& window, bool isRegister) { if (window == nullptr) { TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Window is nullptr"); diff --git a/interfaces/kits/napi/extension_window/js_extension_window_register_manager.h b/interfaces/kits/napi/extension_window/js_extension_window_register_manager.h index 428f4be6ea..dfe442d1b3 100644 --- a/interfaces/kits/napi/extension_window/js_extension_window_register_manager.h +++ b/interfaces/kits/napi/extension_window/js_extension_window_register_manager.h @@ -48,8 +48,8 @@ private: bool IsCallbackRegistered(napi_env env, std::string type, napi_value jsListenerObject); WmErrorCode ProcessWindowChangeRegister(sptr listener, sptr window, bool isRegister); - WmErrorCode ProcessWindowRectChangeRegister(sptr listener, - sptr window, bool isRegister); + WmErrorCode ProcessWindowRectChangeRegister(const sptr& listener, + const sptr& window, bool isRegister); WmErrorCode ProcessAvoidAreaChangeRegister(sptr listener, sptr window, bool isRegister); WmErrorCode ProcessLifeCycleEventRegister(sptr listener,