根据检视意见做对应修改

Signed-off-by: kaicui <cuikai34@huawei.com>
This commit is contained in:
kaicui 2024-11-15 17:13:56 +08:00
parent 41205d6b5c
commit a2044dcfaa
4 changed files with 18 additions and 20 deletions

View File

@ -116,30 +116,29 @@ void JsExtensionWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason r
currRect_ = rect; currRect_ = rect;
} }
void JsExtensionWindowListener::OnRectChange(Rect rect, WindowSizeChangeReason reason) void JsExtensionWindowListener::OnRectChange(const Rect& rect, WindowSizeChangeReason reason)
{ {
if (currRect_ == rect && reason == WindowSizeChangeReason::UNDEFINED) { if (currRect_ == rect && reason == WindowSizeChangeReason::UNDEFINED) {
TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]Skip redundant rect update"); TLOGD(WmsLogTag::WMS_UIEXT, "[NAPI]Skip redundant rect update");
return; return;
} }
RectChangeReason rectChangReason = RectChangeReason::UNDEFINED; RectChangeReason rectChangeReason = RectChangeReason::UNDEFINED;
if (JS_SIZE_CHANGE_REASON.count(reason) != 0 && if (JS_SIZE_CHANGE_REASON.count(reason) != 0 &&
!(reason == WindowSizeChangeReason::MAXIMIZE && rect.posX_ != 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) { if (currentRectChangeReason_ != RectChangeReason::DRAG && rectChangeReason == RectChangeReason::DRAG_END) {
rectChangReason = RectChangeReason::MOVE; rectChangeReason = RectChangeReason::MOVE;
} }
// js callback should run in js thread // 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"); HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "JsExtensionWindowListener::OnRectChange");
auto thisListener = self.promote(); auto thisListener = self.promote();
if (thisListener == nullptr || env == nullptr) { if (thisListener == nullptr || env == nullptr) {
TLOGNE(WmsLogTag::WMS_UIEXT, "[NAPI]This listener or env is nullptr"); TLOGNE(WmsLogTag::WMS_UIEXT, "[NAPI]This listener or env is nullptr");
return; return;
} }
napi_handle_scope scope = nullptr; HandleScope handleScope(env);
napi_open_handle_scope(env, &scope);
napi_value objValue = nullptr; napi_value objValue = nullptr;
napi_create_object(env, &objValue); napi_create_object(env, &objValue);
if (objValue == nullptr) { if (objValue == nullptr) {
@ -152,10 +151,9 @@ void JsExtensionWindowListener::OnRectChange(Rect rect, WindowSizeChangeReason r
return; return;
} }
napi_set_named_property(env, objValue, "rect", rectObjValue); napi_set_named_property(env, objValue, "rect", rectObjValue);
napi_set_named_property(env, objValue, "reason", CreateJsValue(env, rectChangReason)); napi_set_named_property(env, objValue, "reason", CreateJsValue(env, rectChangeReason));
napi_value argv[] = {objValue}; napi_value argv[] = { objValue };
thisListener->CallJsMethod(WINDOW_RECT_CHANGE_CB.c_str(), argv, ArraySize(argv)); thisListener->CallJsMethod(WINDOW_RECT_CHANGE_CB.c_str(), argv, ArraySize(argv));
napi_close_handle_scope(env, scope);
}; };
if (!eventHandler_) { if (!eventHandler_) {
TLOGE(WmsLogTag::WMS_UIEXT, "Get main event handler failed!"); 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, eventHandler_->PostTask(jsCallback, "wms:JsExtensionWindowListener::OnRectChange", 0,
AppExecFwk::EventQueue::Priority::IMMEDIATE); AppExecFwk::EventQueue::Priority::IMMEDIATE);
currRect_ = rect; currRect_ = rect;
currentReason_ = rectChangReason; currentRectChangeReason_ = rectChangeReason;
} }
void JsExtensionWindowListener::OnModeChange(WindowMode mode, bool hasDeco) void JsExtensionWindowListener::OnModeChange(WindowMode mode, bool hasDeco)

View File

@ -26,8 +26,8 @@
#include "window.h" #include "window.h"
#include "window_manager.h" #include "window_manager.h"
#include "wm_common.h" #include "wm_common.h"
#include "js_window_utils.h"
#include "js_extension_window_utils.h" #include "js_extension_window_utils.h"
#include "js_window_utils.h"
namespace OHOS { namespace OHOS {
namespace Rosen { namespace Rosen {
@ -43,7 +43,7 @@ public:
~JsExtensionWindowListener(); ~JsExtensionWindowListener();
void OnSizeChange(Rect rect, WindowSizeChangeReason reason, void OnSizeChange(Rect rect, WindowSizeChangeReason reason,
const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override; const std::shared_ptr<RSTransaction>& 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 OnModeChange(WindowMode mode, bool hasDeco) override;
void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override;
void AfterForeground() override; void AfterForeground() override;
@ -59,8 +59,8 @@ public:
void SetMainEventHandler(); void SetMainEventHandler();
private: private:
Rect currRect_ = {}; Rect currRect_;
RectChangeReason currentReason_ = RectChangeReason::UNDEFINED; RectChangeReason currentRectChangeReason_ = RectChangeReason::UNDEFINED;
napi_env env_ = nullptr; napi_env env_ = nullptr;
WindowState state_ {WindowState::STATE_INITIAL}; WindowState state_ {WindowState::STATE_INITIAL};
std::shared_ptr<NativeReference> jsCallBack_; std::shared_ptr<NativeReference> jsCallBack_;

View File

@ -63,8 +63,8 @@ WmErrorCode JsExtensionWindowRegisterManager::ProcessWindowChangeRegister(sptr<J
return ret; return ret;
} }
WmErrorCode JsExtensionWindowRegisterManager::ProcessWindowRectChangeRegister(sptr<JsExtensionWindowListener> listener, WmErrorCode JsExtensionWindowRegisterManager::ProcessWindowRectChangeRegister(const sptr<JsExtensionWindowListener>& listener,
sptr<Window> window, bool isRegister) const sptr<Window>& window, bool isRegister)
{ {
if (window == nullptr) { if (window == nullptr) {
TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Window is nullptr"); TLOGE(WmsLogTag::WMS_UIEXT, "[NAPI]Window is nullptr");

View File

@ -48,8 +48,8 @@ private:
bool IsCallbackRegistered(napi_env env, std::string type, napi_value jsListenerObject); bool IsCallbackRegistered(napi_env env, std::string type, napi_value jsListenerObject);
WmErrorCode ProcessWindowChangeRegister(sptr<JsExtensionWindowListener> listener, WmErrorCode ProcessWindowChangeRegister(sptr<JsExtensionWindowListener> listener,
sptr<Window> window, bool isRegister); sptr<Window> window, bool isRegister);
WmErrorCode ProcessWindowRectChangeRegister(sptr<JsExtensionWindowListener> listener, WmErrorCode ProcessWindowRectChangeRegister(const sptr<JsExtensionWindowListener>& listener,
sptr<Window> window, bool isRegister); const sptr<Window>& window, bool isRegister);
WmErrorCode ProcessAvoidAreaChangeRegister(sptr<JsExtensionWindowListener> listener, WmErrorCode ProcessAvoidAreaChangeRegister(sptr<JsExtensionWindowListener> listener,
sptr<Window> window, bool isRegister); sptr<Window> window, bool isRegister);
WmErrorCode ProcessLifeCycleEventRegister(sptr<JsExtensionWindowListener> listener, WmErrorCode ProcessLifeCycleEventRegister(sptr<JsExtensionWindowListener> listener,