• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "adapter/preview/inspector/js_inspector_manager.h"
17 
18 #include <cassert>
19 #include <cmath>
20 #include <fstream>
21 #include <iostream>
22 #include <sstream>
23 
24 #include "adapter/preview/inspector/inspector_client.h"
25 #include "bridge/declarative_frontend/declarative_frontend.h"
26 #include "core/components_ng/base/inspector.h"
27 #include "core/components_ng/base/view_stack_processor.h"
28 #include "core/components_ng/pattern/text/span_node.h"
29 #include "core/components_v2/inspector/shape_composed_element.h"
30 #include "core/pipeline_ng/pipeline_context.h"
31 
32 namespace OHOS::Ace::Framework {
33 namespace {
34 
35 constexpr char INSPECTOR_CURRENT_VERSION[] = "1.0";
36 constexpr char INSPECTOR_DEVICE_TYPE[] = "deviceType";
37 constexpr char INSPECTOR_DEFAULT_VALUE[] = "defaultValue";
38 constexpr char INSPECTOR_TYPE[] = "$type";
39 constexpr char INSPECTOR_ROOT[] = "root";
40 constexpr char INSPECTOR_VERSION[] = "version";
41 constexpr char INSPECTOR_WIDTH[] = "width";
42 constexpr char INSPECTOR_HEIGHT[] = "height";
43 constexpr char INSPECTOR_RESOLUTION[] = "$resolution";
44 constexpr char INSPECTOR_CHILDREN[] = "$children";
45 constexpr char INSPECTOR_ID[] = "$ID";
46 constexpr char INSPECTOR_RECT[] = "$rect";
47 constexpr char INSPECTOR_Z_INDEX[] = "$z-index";
48 constexpr char INSPECTOR_ATTRS[] = "$attrs";
49 constexpr char INSPECTOR_STYLES[] = "$styles";
50 constexpr char INSPECTOR_INNER_DEBUGLINE[] = "debugLine";
51 constexpr char INSPECTOR_DEBUGLINE[] = "$debugLine";
52 constexpr char INSPECTOR_VIEW_ID[] = "$viewID";
53 
54 std::list<std::string> specialComponentNameV1 = { "dialog", "panel" };
55 
56 } // namespace
57 
GetDeviceTypeStr(const DeviceType & deviceType)58 std::string GetDeviceTypeStr(const DeviceType& deviceType)
59 {
60     std::string deviceName = "";
61     if (deviceType == DeviceType::TV) {
62         deviceName = "TV";
63     } else if (deviceType == DeviceType::WATCH) {
64         deviceName = "Watch";
65     } else if (deviceType == DeviceType::CAR) {
66         deviceName = "Car";
67     } else {
68         deviceName = "Phone";
69     }
70     return deviceName;
71 }
72 
InitializeCallback()73 void JsInspectorManager::InitializeCallback()
74 {
75     auto assembleJSONTreeCallback = [weak = WeakClaim(this)](std::string& jsonTreeStr) {
76         auto jsInspectorManager = weak.Upgrade();
77         if (!jsInspectorManager) {
78             return false;
79         }
80         jsInspectorManager->AssembleJSONTree(jsonTreeStr);
81         return true;
82     };
83     InspectorClient::GetInstance().RegisterJSONTreeCallback(assembleJSONTreeCallback);
84     auto assembleDefaultJSONTreeCallback = [weak = WeakClaim(this)](std::string& jsonTreeStr) {
85         auto jsInspectorManager = weak.Upgrade();
86         if (!jsInspectorManager) {
87             return false;
88         }
89         jsInspectorManager->AssembleDefaultJSONTree(jsonTreeStr);
90         return true;
91     };
92     InspectorClient::GetInstance().RegisterDefaultJSONTreeCallback(assembleDefaultJSONTreeCallback);
93     auto operateComponentCallback = [weak = WeakClaim(this)](const std::string& attrsJson) {
94         auto jsInspectorManager = weak.Upgrade();
95         if (!jsInspectorManager) {
96             return false;
97         }
98         return jsInspectorManager->OperateComponent(attrsJson);
99     };
100     InspectorClient::GetInstance().RegisterOperateComponentCallback(operateComponentCallback);
101 }
102 
103 // resourse the child from root node to assemble the JSON tree
AssembleJSONTree(std::string & jsonStr)104 void JsInspectorManager::AssembleJSONTree(std::string& jsonStr)
105 {
106     if (Container::IsCurrentUseNewPipeline()) {
107         jsonStr = NG::Inspector::GetInspector(false);
108         return;
109     }
110     auto jsonNode = JsonUtil::Create(true);
111     jsonNode->Put(INSPECTOR_TYPE, INSPECTOR_ROOT);
112 
113     auto context = GetPipelineContext().Upgrade();
114     if (context) {
115         float scale = context->GetViewScale();
116         double rootHeight = context->GetRootHeight();
117         double rootWidth = context->GetRootWidth();
118         deviceRect_ = Rect(0, 0, rootWidth * scale, rootHeight * scale);
119         jsonNode->Put(INSPECTOR_WIDTH, std::to_string(rootWidth * scale).c_str());
120         jsonNode->Put(INSPECTOR_HEIGHT, std::to_string(rootHeight * scale).c_str());
121     }
122     jsonNode->Put(INSPECTOR_RESOLUTION, std::to_string(SystemProperties::GetResolution()).c_str());
123     auto node = GetAccessibilityNodeFromPage(0);
124     if (!node) {
125         LOGE("get root accessibilityNode failed");
126         return;
127     }
128     jsonNode->Put(INSPECTOR_CHILDREN, GetChildrenJson(node));
129     jsonStr = jsonNode->ToString();
130 }
131 
132 // find children of the current node and combine them with this node to form a JSON array object.
GetChildrenJson(RefPtr<AccessibilityNode> node)133 std::unique_ptr<JsonValue> JsInspectorManager::GetChildrenJson(RefPtr<AccessibilityNode> node)
134 {
135     auto jsonNodeArray = JsonUtil::CreateArray(true);
136     if (!node) {
137         LOGW("GetChildrenJson, AccessibilityNode is nullptr");
138         return jsonNodeArray;
139     }
140     auto child = node->GetChildList();
141     for (auto item = child.begin(); item != child.end(); item++) {
142         jsonNodeArray->Put(GetChildJson(*item));
143     }
144     return jsonNodeArray;
145 }
146 
GetChildJson(RefPtr<AccessibilityNode> node)147 std::unique_ptr<JsonValue> JsInspectorManager::GetChildJson(RefPtr<AccessibilityNode> node)
148 {
149     auto jsonNode = JsonUtil::Create(true);
150     if (!node) {
151         LOGW("GetChildJson, AccessibilityNode is nullptr");
152         return jsonNode;
153     }
154     if (node->GetTag() == "inspectDialog") {
155         RemoveAccessibilityNodes(node);
156         return jsonNode;
157     }
158 
159     jsonNode->Put(INSPECTOR_TYPE, node->GetTag().c_str());
160     jsonNode->Put(INSPECTOR_ID, node->GetNodeId());
161     jsonNode->Put(INSPECTOR_Z_INDEX, node->GetZIndex());
162     if (GetVersion() == AccessibilityVersion::JS_VERSION) {
163         jsonNode->Put(INSPECTOR_RECT, UpdateNodeRectStrInfo(node).c_str());
164         GetAttrsAndStyles(jsonNode, node);
165     } else {
166         jsonNode->Put(INSPECTOR_RECT, UpdateNodeRectStrInfoV2(node).c_str());
167         GetAttrsAndStylesV2(jsonNode, node);
168     }
169     jsonNode->Put(INSPECTOR_CHILDREN, GetChildrenJson(node));
170     return jsonNode;
171 }
172 
173 // assemble the default attrs and styles for all components
AssembleDefaultJSONTree(std::string & jsonStr)174 void JsInspectorManager::AssembleDefaultJSONTree(std::string& jsonStr)
175 {
176     auto jsonNode = JsonUtil::Create(true);
177     std::string deviceName = GetDeviceTypeStr(SystemProperties::GetDeviceType());
178 
179     jsonNode->Put(INSPECTOR_VERSION, INSPECTOR_CURRENT_VERSION);
180     jsonNode->Put(INSPECTOR_DEVICE_TYPE, deviceName.c_str());
181     static const std::vector<std::string> tagNames = { DOM_NODE_TAG_BADGE, DOM_NODE_TAG_BUTTON, DOM_NODE_TAG_CAMERA,
182         DOM_NODE_TAG_CANVAS, DOM_NODE_TAG_CHART, DOM_NODE_TAG_DIALOG, DOM_NODE_TAG_DIV, DOM_NODE_TAG_DIVIDER,
183         DOM_NODE_TAG_FORM, DOM_NODE_TAG_GRID_COLUMN, DOM_NODE_TAG_GRID_CONTAINER, DOM_NODE_TAG_GRID_ROW,
184         DOM_NODE_TAG_IMAGE, DOM_NODE_TAG_IMAGE_ANIMATOR, DOM_NODE_TAG_INPUT, DOM_NODE_TAG_LABEL, DOM_NODE_TAG_LIST,
185         DOM_NODE_TAG_LIST_ITEM, DOM_NODE_TAG_LIST_ITEM_GROUP, DOM_NODE_TAG_MARQUEE, DOM_NODE_TAG_MENU,
186         DOM_NODE_TAG_NAVIGATION_BAR, DOM_NODE_TAG_OPTION, DOM_NODE_TAG_PANEL, DOM_NODE_TAG_PICKER_DIALOG,
187         DOM_NODE_TAG_PICKER_VIEW, DOM_NODE_TAG_PIECE, DOM_NODE_TAG_POPUP, DOM_NODE_TAG_PROGRESS, DOM_NODE_TAG_QRCODE,
188         DOM_NODE_TAG_RATING, DOM_NODE_TAG_REFRESH, DOM_NODE_TAG_SEARCH, DOM_NODE_TAG_SELECT, DOM_NODE_TAG_SLIDER,
189         DOM_NODE_TAG_SPAN, DOM_NODE_TAG_STACK, DOM_NODE_TAG_STEPPER, DOM_NODE_TAG_STEPPER_ITEM, DOM_NODE_TAG_SWIPER,
190         DOM_NODE_TAG_SWITCH, DOM_NODE_TAG_TAB_BAR, DOM_NODE_TAG_TAB_CONTENT, DOM_NODE_TAG_TABS, DOM_NODE_TAG_TEXT,
191         DOM_NODE_TAG_TEXTAREA, DOM_NODE_TAG_TOGGLE, DOM_NODE_TAG_TOOL_BAR, DOM_NODE_TAG_TOOL_BAR_ITEM,
192         DOM_NODE_TAG_VIDEO };
193 
194     auto jsonDefaultValue = JsonUtil::Create(true);
195     for (const auto& tag : tagNames) {
196         auto jsonDefaultAttrs = JsonUtil::Create(true);
197         if (!GetDefaultAttrsByType(tag, jsonDefaultAttrs)) {
198             LOGW("node type %{public}s is invalid", tag.c_str());
199             return;
200         }
201         jsonDefaultValue->Put(tag.c_str(), jsonDefaultAttrs);
202     }
203     jsonNode->Put(INSPECTOR_DEFAULT_VALUE, jsonDefaultValue);
204     jsonStr = jsonNode->ToString();
205 }
206 
OperateComponent(const std::string & jsCode)207 bool JsInspectorManager::OperateComponent(const std::string& jsCode)
208 {
209     auto root = JsonUtil::ParseJsonString(jsCode);
210     auto parentID = root->GetInt("parentID", -1);
211     auto slot = root->GetInt("slot", -1);
212     LOGD("parentID = %{public}d, slot = %{public}d", parentID, slot);
213     if (Container::IsCurrentUseNewPipeline()) {
214         static RefPtr<NG::UINode> parent = nullptr;
215         static int32_t preSlot = -1;
216         auto newChild = GetNewFrameNodeWithJsCode(root);
217         CHECK_NULL_RETURN(newChild, false);
218         NG::Inspector::HideAllMenus();
219         if (!root->Contains("id")) {
220             LOGD("Failed to get the nodeId!");
221             parent = (parentID <= 0) ? GetRootUINode() : ElementRegister::GetInstance()->GetUINodeById(parentID);
222             return OperateGeneralUINode(parent, slot, newChild);
223         }
224         auto nodeId = root->GetInt("id");
225         auto oldChild = ElementRegister::GetInstance()->GetUINodeById(nodeId);
226         if (!oldChild) {
227             return OperateGeneralUINode(parent, preSlot, newChild);
228         }
229         parent = oldChild->GetParent();
230         CHECK_NULL_RETURN(parent, false);
231         slot = parent->GetChildIndex(oldChild);
232         preSlot = slot;
233         return OperateGeneralUINode(parent, slot, newChild);
234     } else {
235         auto operateType = root->GetString("type", "");
236         auto newComponent = GetNewComponentWithJsCode(root);
237         if (parentID <= 0) {
238             return OperateRootComponent(newComponent);
239         } else {
240             return OperateGeneralComponent(parentID, slot, operateType, newComponent);
241         }
242     }
243 }
244 
OperateRootComponent(RefPtr<Component> newComponent)245 bool JsInspectorManager::OperateRootComponent(RefPtr<Component> newComponent)
246 {
247     if (!newComponent) {
248         LOGE("operateType:UpdateComponent, newComponent should not be nullptr");
249         return false;
250     }
251     auto rootElement = GetRootElement().Upgrade();
252     auto child = rootElement->GetChildBySlot(-1); // rootElement only has one child,and use the default slot -1
253 
254     rootElement->UpdateChildWithSlot(child, newComponent, -1, -1);
255     return true;
256 }
257 
OperateGeneralComponent(int32_t parentID,int32_t slot,std::string & operateType,RefPtr<Component> newComponent)258 bool JsInspectorManager::OperateGeneralComponent(
259     int32_t parentID, int32_t slot, std::string& operateType, RefPtr<Component> newComponent)
260 {
261     auto parentElement = GetInspectorElementById(parentID);
262     if (!parentElement) {
263         LOGE("parentElement should not be nullptr or display");
264         return false;
265     }
266 
267     if (operateType == "DeleteComponent") {
268         parentElement->DeleteChildWithSlot(slot);
269         return true;
270     }
271 
272     if (newComponent) {
273         if (operateType == "AddComponent") {
274             parentElement->AddChildWithSlot(slot, newComponent);
275         }
276         if (operateType == "UpdateComponent") {
277             parentElement->UpdateChildWithSlot(slot, newComponent);
278         }
279         return true;
280     }
281     return false;
282 }
283 
OperateGeneralUINode(RefPtr<NG::UINode> parent,int32_t slot,RefPtr<NG::UINode> newChild)284 bool JsInspectorManager::OperateGeneralUINode(RefPtr<NG::UINode> parent, int32_t slot, RefPtr<NG::UINode> newChild)
285 {
286     CHECK_NULL_RETURN(parent, false);
287     parent->FastPreviewUpdateChild(slot, newChild);
288     newChild->FastPreviewUpdateChildDone();
289     newChild->FlushUpdateAndMarkDirty();
290     parent->FlushUpdateAndMarkDirty();
291     return true;
292 }
293 
GetNewComponentWithJsCode(const std::unique_ptr<JsonValue> & root)294 RefPtr<Component> JsInspectorManager::GetNewComponentWithJsCode(const std::unique_ptr<JsonValue>& root)
295 {
296     std::string jsCode = root->GetString("jsCode", "");
297     std::string viewID = root->GetString("viewID", "");
298     if (jsCode.length() == 0) {
299         LOGE("Get jsCode Failed");
300         return nullptr;
301     }
302     auto context = context_.Upgrade();
303     if (!context) {
304         LOGE("Get Context Failed");
305         return nullptr;
306     }
307     auto frontend = context->GetFrontend();
308     if (!frontend) {
309         LOGE("Get frontend Failed");
310         return nullptr;
311     }
312     auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontend>(frontend);
313     if (!declarativeFrontend) {
314         LOGE("Get declarativeFrontend Failed");
315         return nullptr;
316     }
317     auto component = declarativeFrontend->GetNewComponentWithJsCode(jsCode, viewID);
318     return component;
319 }
320 
GetNewFrameNodeWithJsCode(const std::unique_ptr<JsonValue> & root)321 RefPtr<NG::UINode> JsInspectorManager::GetNewFrameNodeWithJsCode(const std::unique_ptr<JsonValue>& root)
322 {
323     std::string jsCode = root->GetString("jsCode", "");
324     std::string viewID = root->GetString("viewID", "");
325     if (jsCode.empty() || viewID.empty()) {
326         LOGE("Get jsCode Failed");
327         return nullptr;
328     }
329     auto pipeline = context_.Upgrade();
330     CHECK_NULL_RETURN(pipeline, nullptr);
331     auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontend>(pipeline->GetFrontend());
332 
333     CHECK_NULL_RETURN(declarativeFrontend, nullptr);
334     auto jsEngine = declarativeFrontend->GetJsEngine();
335     CHECK_NULL_RETURN(jsEngine, nullptr);
336     if (!jsEngine->ExecuteJsForFastPreview(jsCode, viewID)) {
337         return nullptr;
338     }
339     return NG::ViewStackProcessor::GetInstance()->GetNewUINode();
340 }
341 
GetInspectorElementById(NodeId nodeId)342 RefPtr<V2::InspectorComposedElement> JsInspectorManager::GetInspectorElementById(NodeId nodeId)
343 {
344     auto composedElement = GetComposedElementFromPage(nodeId).Upgrade();
345     if (!composedElement) {
346         LOGE("get composedElement failed");
347         return nullptr;
348     }
349     auto inspectorElement = AceType::DynamicCast<V2::InspectorComposedElement>(composedElement);
350     if (!inspectorElement) {
351         LOGE("get inspectorElement failed");
352         return nullptr;
353     }
354     return inspectorElement;
355 }
356 
GetRootElement()357 const WeakPtr<Element>& JsInspectorManager::GetRootElement()
358 {
359     auto node = GetAccessibilityNodeFromPage(0);
360     if (!node) {
361         LOGE("get AccessibilityNode failed");
362         return nullptr;
363     }
364     auto child = node->GetChildList();
365     if (child.empty()) {
366         LOGE("child is null");
367         return nullptr;
368     }
369     auto InspectorComponentElement = GetInspectorElementById(child.front()->GetNodeId());
370     if (!InspectorComponentElement) {
371         return nullptr;
372     }
373     return InspectorComponentElement->GetElementParent();
374 }
375 
GetRootUINode()376 const RefPtr<NG::UINode> JsInspectorManager::GetRootUINode()
377 {
378     auto context = context_.Upgrade();
379     auto ngContext = AceType::DynamicCast<NG::PipelineContext>(context);
380     CHECK_NULL_RETURN(ngContext, nullptr);
381 
382     auto node = ngContext->GetStageManager()->GetLastPage();
383     CHECK_NULL_RETURN(node, nullptr);
384     auto child = node->GetLastChild();
385     return child;
386 }
387 
388 // get attrs and styles from AccessibilityNode to JsonValue
GetAttrsAndStyles(std::unique_ptr<JsonValue> & jsonNode,const RefPtr<AccessibilityNode> & node)389 void JsInspectorManager::GetAttrsAndStyles(std::unique_ptr<JsonValue>& jsonNode, const RefPtr<AccessibilityNode>& node)
390 {
391     auto attrJsonNode = JsonUtil::Create(true);
392     for (auto attr : node->GetAttrs()) {
393         // this attr is wrong in API5,will delete in API7
394         if (attr.first.find("clickEffect") != std::string::npos) {
395             attr.first = ConvertStrToPropertyType(attr.first);
396         }
397         attrJsonNode->Put(attr.first.c_str(), attr.second.c_str());
398     }
399     // change debugLine to $debugLine and move out of attrs
400     std::string debugLine = attrJsonNode->GetString(INSPECTOR_INNER_DEBUGLINE);
401     jsonNode->Put(INSPECTOR_DEBUGLINE, debugLine.c_str());
402     attrJsonNode->Delete(INSPECTOR_INNER_DEBUGLINE);
403     jsonNode->Put(INSPECTOR_ATTRS, attrJsonNode);
404 
405     auto styleJsonNode = JsonUtil::Create(true);
406     for (auto style : node->GetStyles()) {
407         if (!style.second.empty()) {
408             styleJsonNode->Put(ConvertStrToPropertyType(style.first).c_str(), style.second.c_str());
409         }
410     }
411     jsonNode->Put(INSPECTOR_STYLES, styleJsonNode);
412 }
413 
GetAttrsAndStylesV2(std::unique_ptr<JsonValue> & jsonNode,const RefPtr<AccessibilityNode> & node)414 void JsInspectorManager::GetAttrsAndStylesV2(
415     std::unique_ptr<JsonValue>& jsonNode, const RefPtr<AccessibilityNode>& node)
416 {
417     auto weakComposedElement = GetComposedElementFromPage(node->GetNodeId());
418     auto composedElement = DynamicCast<V2::InspectorComposedElement>(weakComposedElement.Upgrade());
419     if (!composedElement) {
420         LOGE("return");
421         return;
422     }
423     std::string debugLine = composedElement->GetDebugLine();
424     std::string viewId = composedElement->GetViewId();
425     jsonNode->Put(INSPECTOR_DEBUGLINE, debugLine.c_str());
426     jsonNode->Put(INSPECTOR_VIEW_ID, viewId.c_str());
427     auto inspectorElement = AceType::DynamicCast<V2::InspectorComposedElement>(composedElement);
428     if (inspectorElement) {
429         auto jsonObject = inspectorElement->ToJsonObject();
430         jsonObject->Put("viewId", viewId.c_str());
431         jsonNode->Put(INSPECTOR_ATTRS, jsonObject);
432     }
433     auto shapeComposedElement = AceType::DynamicCast<V2::ShapeComposedElement>(inspectorElement);
434     if (shapeComposedElement) {
435         jsonNode->Replace(INSPECTOR_TYPE, shapeComposedElement->GetShapeType().c_str());
436     }
437 }
438 
UpdateNodeRectStrInfo(const RefPtr<AccessibilityNode> node)439 std::string JsInspectorManager::UpdateNodeRectStrInfo(const RefPtr<AccessibilityNode> node)
440 {
441     auto it = std::find(specialComponentNameV1.begin(), specialComponentNameV1.end(), node->GetTag());
442     if (it != specialComponentNameV1.end()) {
443         node->UpdateRectWithChildRect();
444     }
445 
446     PositionInfo positionInfo = { 0, 0, 0, 0 };
447     if (node->GetTag() == DOM_NODE_TAG_SPAN) {
448         positionInfo = { node->GetParentNode()->GetWidth(), node->GetParentNode()->GetHeight(),
449             node->GetParentNode()->GetLeft(), node->GetParentNode()->GetTop() };
450     } else {
451         positionInfo = { node->GetWidth(), node->GetHeight(), node->GetLeft(), node->GetTop() };
452     }
453     if (!node->GetVisible()) {
454         positionInfo = { 0, 0, 0, 0 };
455     }
456     // the dialog node is hidden, while the position and size of the node are not cleared.
457     if (node->GetClearRectInfoFlag() == true) {
458         positionInfo = { 0, 0, 0, 0 };
459     }
460     std::string strRec = std::to_string(positionInfo.left)
461                              .append(",")
462                              .append(std::to_string(positionInfo.top))
463                              .append(",")
464                              .append(std::to_string(positionInfo.width))
465                              .append(",")
466                              .append(std::to_string(positionInfo.height));
467     return strRec;
468 }
469 
UpdateNodeRectStrInfoV2(const RefPtr<AccessibilityNode> node)470 std::string JsInspectorManager::UpdateNodeRectStrInfoV2(const RefPtr<AccessibilityNode> node)
471 {
472     std::string strRec;
473     auto weakComposedElement = GetComposedElementFromPage(node->GetNodeId());
474     auto composedElement = weakComposedElement.Upgrade();
475     if (!composedElement) {
476         return strRec;
477     }
478     auto inspectorElement = AceType::DynamicCast<V2::InspectorComposedElement>(composedElement);
479     if (inspectorElement) {
480         auto rect = inspectorElement->GetRenderRect();
481         if (!rect.IsIntersectByCommonSideWith(deviceRect_)) {
482             return "0,0,0,0";
483         }
484         strRec = inspectorElement->GetRect();
485         return strRec;
486     }
487     return strRec;
488 }
489 
ConvertStrToPropertyType(std::string & typeValue)490 std::string JsInspectorManager::ConvertStrToPropertyType(std::string& typeValue)
491 {
492     if (typeValue == "transitionEnterName") {
493         typeValue = "transitionEnter";
494     } else if (typeValue == "transitionExitName") {
495         typeValue = "transitionExit";
496     }
497     std::string dstStr;
498     std::regex regex("([A-Z])");
499     dstStr = regex_replace(typeValue, regex, "-$1");
500     std::transform(dstStr.begin(), dstStr.end(), dstStr.begin(), ::tolower);
501     return dstStr;
502 }
503 
Create()504 RefPtr<AccessibilityNodeManager> AccessibilityNodeManager::Create()
505 {
506     return AceType::MakeRefPtr<JsInspectorManager>();
507 }
508 } // namespace OHOS::Ace::Framework
509