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