From e5d91f2ac1b2dd9516dedb1d298bd890ff4a6361 Mon Sep 17 00:00:00 2001 From: zhanghang Date: Wed, 23 Jul 2025 15:24:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:inspector=E6=94=AF=E6=8C=81=E6=96=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghang --- .../bridge/arkts_frontend/arkts_frontend.h | 35 +++++++++++++++++-- .../arkui-ohos/@ohos.arkui.inspector.ts | 4 +-- .../ets/ani/inspector/src/inspector.cpp | 33 +++++++++++++++-- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/frameworks/bridge/arkts_frontend/arkts_frontend.h b/frameworks/bridge/arkts_frontend/arkts_frontend.h index aa3bfbc5fa7..b75c01d438f 100644 --- a/frameworks/bridge/arkts_frontend/arkts_frontend.h +++ b/frameworks/bridge/arkts_frontend/arkts_frontend.h @@ -255,6 +255,23 @@ public: ); } + void OnDrawChildrenCompleted(const std::string& componentId) override + { + auto iter = drawChildrenCallbacks_.find(componentId); + if (iter == drawChildrenCallbacks_.end()) { + return; + } + if (taskExecutor_ == nullptr) { + return; + } + auto&& observer = iter->second; + taskExecutor_->PostTask( + [observer] { + (*observer)(); + }, TaskExecutor::TaskType::JS, "ArkUIDrawChildrenCompleted" + ); + } + void DumpFrontend() const override {} std::string GetPagePath() const override { @@ -329,6 +346,11 @@ public: drawCallbacks_[componentId] = drawFunc; } + void RegisterDrawChildrenInspectorCallback(const RefPtr& drawFunc, const std::string& componentId) + { + drawChildrenCallbacks_[componentId] = drawFunc; + } + void UnregisterLayoutInspectorCallback(const std::string& componentId) { layoutCallbacks_.erase(componentId); @@ -338,8 +360,16 @@ public: { drawCallbacks_.erase(componentId); } - bool IsDrawChildrenCallbackFuncExist(const std::string& componentId) override { return false; } - void OnDrawChildrenCompleted(const std::string& componentId) override {} + + void UnregisterDrawChildrenInspectorCallback(const std::string& componentId) + { + drawChildrenCallbacks_.erase(componentId); + } + + bool IsDrawChildrenCallbackFuncExist(const std::string& componentId) override + { + return drawChildrenCallbacks_.find(componentId) != drawChildrenCallbacks_.end(); + } virtual void CallbackMediaQuery(const std::string& callbackId, const std::string& args) { @@ -388,6 +418,7 @@ private: std::map> layoutCallbacks_; std::map> drawCallbacks_; + std::map> drawChildrenCallbacks_; MediaQueryCallback mediaQueryCallbacks_; RefPtr mediaQueryInfo_ = AceType::MakeRefPtr(); std::function mediaUpdateCallback_; diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.inspector.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.inspector.ts index 127a678dd5b..4b8af7cb4e4 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.inspector.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/@ohos.arkui.inspector.ts @@ -1,8 +1,8 @@ declare namespace inspector { export interface ComponentObserver { - on(type: 'layout' | 'draw', callback: () => void): void; + on(type: 'layout' | 'draw' | 'drawChildren', callback: () => void): void; - off(type: 'layout' | 'draw', callback?: () => void): void; + off(type: 'layout' | 'draw' | 'drawChildren', callback?: () => void): void; } export function createComponentObserver(id: string): ComponentObserver; } diff --git a/interfaces/ets/ani/inspector/src/inspector.cpp b/interfaces/ets/ani/inspector/src/inspector.cpp index e1cd9e983bf..810ad52fec6 100644 --- a/interfaces/ets/ani/inspector/src/inspector.cpp +++ b/interfaces/ets/ani/inspector/src/inspector.cpp @@ -24,6 +24,7 @@ namespace { const char LAYOUT_TYPE[] = "layout"; const char DRAW_TYPE[] = "draw"; +const char DRAW_CHILDREN_TYPE[] = "drawChildren"; const char ANI_INSPECTOR_NS[] = "L@ohos/arkui/inspector/inspector;"; const char ANI_COMPONENT_OBSERVER_CLS[] = "L@ohos/arkui/inspector/inspector/ComponentObserverImpl;"; const char KOALA_INSPECTOR_CLS[] = "L@koalaui/arkts-arkui/generated/arkts/ohos/arkui/inspector/Inspector;"; @@ -63,6 +64,13 @@ public: env->Reference_StrictEquals(cb, item, &rs); return rs == ANI_TRUE; }); + } else if (strcmp(DRAW_CHILDREN_TYPE, eventType.c_str()) == 0) { + return std::find_if(cbDrawChildrenList_.begin(), cbDrawChildrenList_.end(), + [env, cb](const ani_ref& item) -> bool { + ani_boolean rs; + env->Reference_StrictEquals(cb, item, &rs); + return rs == ANI_TRUE; + }); } else { return std::find_if(cbDrawList_.begin(), cbDrawList_.end(), [env, cb](const ani_ref& item) -> bool { ani_boolean rs; @@ -108,6 +116,8 @@ public: } if (strcmp(LAYOUT_TYPE, eventType.c_str()) == 0) { arkTsFrontend->UnregisterLayoutInspectorCallback(id_); + } else if (strcmp(DRAW_CHILDREN_TYPE, eventType.c_str()) == 0) { + arkTsFrontend->UnregisterDrawChildrenInspectorCallback(id_); } else { arkTsFrontend->UnregisterDrawInspectorCallback(id_); } @@ -129,6 +139,8 @@ public: { if (strcmp(LAYOUT_TYPE, eventType.c_str()) == 0) { return cbLayoutList_; + } else if (strcmp(DRAW_CHILDREN_TYPE, eventType.c_str()) == 0) { + return cbDrawChildrenList_; } return cbDrawList_; } @@ -137,6 +149,8 @@ public: { if (strcmp(LAYOUT_TYPE, eventType.c_str()) == 0) { return layoutEvent_; + } else if (strcmp(DRAW_CHILDREN_TYPE, eventType.c_str()) == 0) { + return drawChildrenEvent_; } return drawEvent_; } @@ -145,6 +159,8 @@ public: { if (strcmp(LAYOUT_TYPE, eventType.c_str()) == 0) { layoutEvent_ = fun; + } else if (strcmp(DRAW_CHILDREN_TYPE, eventType.c_str()) == 0) { + drawChildrenEvent_ = fun; } else { drawEvent_ = fun; } @@ -153,8 +169,10 @@ private: std::string id_; std::list cbLayoutList_; std::list cbDrawList_; + std::list cbDrawChildrenList_; RefPtr layoutEvent_; RefPtr drawEvent_; + RefPtr drawChildrenEvent_; }; static ComponentObserver* Unwrapp(ani_env *env, ani_object object) @@ -198,7 +216,9 @@ static void On(ani_env *env, ani_object object, ani_string type, ani_fn_object f } std::string typeStr; ANIUtils_ANIStringToStdString(env, type, typeStr); - if (strcmp(LAYOUT_TYPE, typeStr.c_str()) != 0 && strcmp(DRAW_TYPE, typeStr.c_str()) != 0) { + if (strcmp(LAYOUT_TYPE, typeStr.c_str()) != 0 && + strcmp(DRAW_TYPE, typeStr.c_str()) != 0 && + strcmp(DRAW_CHILDREN_TYPE, typeStr.c_str()) != 0) { TAG_LOGE(AceLogTag::ACE_LAYOUT_INSPECTOR, "inspector-ani method on not support event type %{public}s", typeStr.c_str()); return; @@ -218,7 +238,9 @@ static void Off(ani_env *env, ani_object object, ani_string type, ani_fn_object { std::string typeStr; ANIUtils_ANIStringToStdString(env, type, typeStr); - if (strcmp(LAYOUT_TYPE, typeStr.c_str()) != 0 && strcmp(DRAW_TYPE, typeStr.c_str()) != 0) { + if (strcmp(LAYOUT_TYPE, typeStr.c_str()) != 0 && + strcmp(DRAW_TYPE, typeStr.c_str()) != 0 && + strcmp(DRAW_CHILDREN_TYPE, typeStr.c_str())) { TAG_LOGE(AceLogTag::ACE_LAYOUT_INSPECTOR, "inspector-ani method on not support event type %{public}s", typeStr.c_str()); return; @@ -343,8 +365,15 @@ static ani_object CreateComponentObserver(ani_env *env, ani_string id, const cha }; observer->SetInspectorFuncByType(DRAW_TYPE, AceType::MakeRefPtr(std::move(drawCallback))); + auto drawChildrenCallback = [observer, env]() -> void { + observer->CallUserFunction(env, observer->GetCbListByType(DRAW_CHILDREN_TYPE)); + }; + observer->SetInspectorFuncByType(DRAW_CHILDREN_TYPE, + AceType::MakeRefPtr(std::move(drawChildrenCallback))); + arkTsFrontend->RegisterLayoutInspectorCallback(observer->GetInspectorFuncByType(LAYOUT_TYPE), key); arkTsFrontend->RegisterDrawInspectorCallback(observer->GetInspectorFuncByType(DRAW_TYPE), key); + arkTsFrontend->RegisterDrawChildrenInspectorCallback(observer->GetInspectorFuncByType(DRAW_CHILDREN_TYPE), key); return context_object; } -- Gitee