1 /*
2 * Copyright (c) 2022-2024 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 #include "js_third_provider_interaction_operation.h"
16
17 #include "accessibility_system_ability_client.h"
18 #include "frameworks/core/accessibility/hidumper/accessibility_hidumper.h"
19 #include "frameworks/core/components_ng/pattern/web/web_pattern.h"
20 #include "js_third_accessibility_hover_ng.h"
21
22 using namespace OHOS::Accessibility;
23 using namespace OHOS::AccessibilityConfig;
24
25 namespace OHOS::Ace::Framework {
26 constexpr int32_t ACCESSIBILITY_FOCUS_WITHOUT_EVENT = -2100001;
27 constexpr int64_t INVALID_NODE_ID = -1;
28
29 namespace {
IsTouchExplorationEnabled(const RefPtr<NG::PipelineContext> & context)30 bool IsTouchExplorationEnabled(const RefPtr<NG::PipelineContext>& context)
31 {
32 CHECK_NULL_RETURN(context, true);
33 auto jsAccessibilityManager = context->GetAccessibilityManager();
34 CHECK_NULL_RETURN(jsAccessibilityManager, true);
35 auto accessibilityWorkMode = jsAccessibilityManager->GenerateAccessibilityWorkMode();
36 return accessibilityWorkMode.isTouchExplorationEnabled;
37 }
38 } // namespace
39
GetElementInfoForThird(int64_t elementId,AccessibilityElementInfo & info,int64_t hostElementId)40 bool AccessibilityHoverManagerForThirdNG::GetElementInfoForThird(
41 int64_t elementId,
42 AccessibilityElementInfo& info,
43 int64_t hostElementId)
44 {
45 // this function only for third party hover process
46 auto jsThirdProviderOperator =
47 GetJsThirdProviderInteractionOperation(hostElementId).lock();
48 if (jsThirdProviderOperator == nullptr) {
49 TAG_LOGE(AceLogTag::ACE_ACCESSIBILITY,
50 "third jsThirdProviderOperator ptr is null, hostElementId %{public}" PRId64,
51 hostElementId);
52 return false;
53 }
54
55 std::list<Accessibility::AccessibilityElementInfo> infos;
56 bool ret = jsThirdProviderOperator->FindAccessibilityNodeInfosByIdFromProvider(
57 elementId, 0, 0, infos, true); // offset in hover no need fix host offset
58 if ((!ret) || (infos.size() == 0)) {
59 TAG_LOGE(AceLogTag::ACE_ACCESSIBILITY,
60 "cannot get third elementinfo :%{public}" PRId64 ", ret: %{public}d",
61 elementId, ret);
62 return false;
63 }
64 info = infos.front();
65 return true;
66 }
67
UpdateSearchStrategyByHitTestModeStr(std::string & hitTestMode,bool & shouldSearchSelf,bool & shouldSearchChildren)68 void AccessibilityHoverManagerForThirdNG::UpdateSearchStrategyByHitTestModeStr(
69 std::string& hitTestMode,
70 bool& shouldSearchSelf,
71 bool& shouldSearchChildren)
72 {
73 if (hitTestMode == "HitTestMode.Block") {
74 shouldSearchChildren = false;
75 } else if (hitTestMode == "HitTestMode.None") {
76 shouldSearchSelf = false;
77 }
78 }
79
HasAccessibilityTextOrDescription(const AccessibilityElementInfo & nodeInfo)80 bool AccessibilityHoverManagerForThirdNG::HasAccessibilityTextOrDescription(
81 const AccessibilityElementInfo& nodeInfo)
82 {
83 std::optional<std::string> accessibilityText = nodeInfo.GetAccessibilityText();
84 std::optional<std::string> accessibilityDescription = nodeInfo.GetDescriptionInfo();
85 return !accessibilityText.value_or("").empty() ||
86 !accessibilityDescription.value_or("").empty();
87 }
88
IsAccessibilityFocusable(const AccessibilityElementInfo & nodeInfo)89 bool AccessibilityHoverManagerForThirdNG::IsAccessibilityFocusable(
90 const AccessibilityElementInfo& nodeInfo)
91 {
92 auto level = nodeInfo.GetAccessibilityLevel();
93 if (level == NG::AccessibilityProperty::Level::YES_STR) {
94 return true;
95 }
96 if (level == NG::AccessibilityProperty::Level::NO_STR) {
97 return false;
98 }
99 if (nodeInfo.GetAccessibilityGroup() ||
100 !nodeInfo.GetActionList().empty() ||
101 HasAccessibilityTextOrDescription(nodeInfo) ||
102 !nodeInfo.GetContent().empty()) {
103 return true;
104 }
105 // expand to enabled and clickable
106 // default tag
107 if (NG::AccessibilityProperty::IsAccessibilityFocusableTag(
108 nodeInfo.GetComponentType()) == true) {
109 return true;
110 }
111 return false;
112 }
113
GetSearchStrategyForThird(const AccessibilityElementInfo & nodeInfo)114 std::pair<bool, bool> AccessibilityHoverManagerForThirdNG::GetSearchStrategyForThird(
115 const AccessibilityElementInfo& nodeInfo)
116 {
117 bool shouldSearchSelf = true;
118 bool shouldSearchChildren = true;
119 auto level = NG::AccessibilityProperty::Level::AUTO;
120 do {
121 level = nodeInfo.GetAccessibilityLevel();
122 bool hasAccessibilityText = HasAccessibilityTextOrDescription(nodeInfo);
123 if (level == NG::AccessibilityProperty::Level::YES_STR) {
124 break;
125 } else if (level == NG::AccessibilityProperty::Level::NO_HIDE_DESCENDANTS) {
126 shouldSearchSelf = false;
127 shouldSearchChildren = false;
128 break;
129 } else {
130 if (level == NG::AccessibilityProperty::Level::NO_STR) {
131 shouldSearchSelf = false;
132 } else {
133 // shouldSearchSelf is true here
134 if (hasAccessibilityText) {
135 break;
136 }
137 }
138 }
139
140 auto hitTestMode = nodeInfo.GetHitTestBehavior();
141 UpdateSearchStrategyByHitTestModeStr(
142 hitTestMode, shouldSearchSelf, shouldSearchChildren);
143 } while (0);
144
145 if (IsAccessibilityFocusable(nodeInfo) == false) {
146 shouldSearchSelf = false;
147 }
148
149 return std::make_pair(shouldSearchSelf, shouldSearchChildren);
150 }
151
152
HoverPathForThirdRecursive(const int64_t hostElementId,const NG::PointF & hoverPoint,const AccessibilityElementInfo & nodeInfo,AccessibilityHoverTestPathForThird & path)153 bool AccessibilityHoverManagerForThirdNG::HoverPathForThirdRecursive(
154 const int64_t hostElementId,
155 const NG::PointF& hoverPoint,
156 const AccessibilityElementInfo& nodeInfo,
157 AccessibilityHoverTestPathForThird& path)
158 {
159 bool hitTarget = false;
160 auto [shouldSearchSelf, shouldSearchChildren]
161 = GetSearchStrategyForThird(nodeInfo);
162 auto rectInScreen = nodeInfo.GetRectInScreen();
163 auto left = static_cast<float>(rectInScreen.GetLeftTopXScreenPostion());
164 auto right = static_cast<float>(rectInScreen.GetLeftTopYScreenPostion());
165 auto width = static_cast<float>(
166 rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion());
167 auto height = static_cast<float>(
168 rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion());
169 NG::RectF rect { left, right, width, height };
170 bool hitSelf = rect.IsInnerRegion(hoverPoint);
171 if (hitSelf && shouldSearchSelf) {
172 hitTarget = true;
173 path.push_back(nodeInfo.GetAccessibilityId());
174 }
175 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
176 "third hover elementId :%{public}" PRId64\
177 ", shouldSearchSelf: %{public}d shouldSearchChildren: %{public}d hitTarget: %{public}d ",
178 nodeInfo.GetAccessibilityId(), shouldSearchSelf, shouldSearchChildren, hitTarget);
179 if (shouldSearchChildren) {
180 auto childrenIds = nodeInfo.GetChildIds();
181 for (auto childId = childrenIds.rbegin(); childId != childrenIds.rend(); ++childId) {
182 AccessibilityElementInfo childInfo;
183 if (GetElementInfoForThird(*childId, childInfo, hostElementId) == false) {
184 break;
185 }
186 if (HoverPathForThirdRecursive(
187 hostElementId, hoverPoint, childInfo, path)) {
188 return true;
189 }
190 }
191 }
192 return hitTarget;
193 }
194
HoverPathForThird(const int64_t hostElementId,const NG::PointF & point,AccessibilityElementInfo & rootInfo)195 AccessibilityHoverTestPathForThird AccessibilityHoverManagerForThirdNG::HoverPathForThird(
196 const int64_t hostElementId,
197 const NG::PointF& point,
198 AccessibilityElementInfo& rootInfo)
199 {
200 AccessibilityHoverTestPathForThird path;
201 HoverPathForThirdRecursive(
202 hostElementId, point, rootInfo, path);
203 return path;
204 }
205
ResetHoverForThirdState()206 void AccessibilityHoverManagerForThirdNG::ResetHoverForThirdState()
207 {
208 hoverForThirdState_.idle = true;
209 hoverForThirdState_.thirdOperationIdle = true;
210 hoverForThirdState_.nodesHovering.clear();
211 }
212
HandleAccessibilityHoverForThirdInner(const AccessibilityHoverForThirdConfig & config)213 void AccessibilityHoverManagerForThirdNG::HandleAccessibilityHoverForThirdInner(
214 const AccessibilityHoverForThirdConfig& config)
215 {
216 if (config.eventType == NG::AccessibilityHoverEventType::ENTER) {
217 ResetHoverForThirdState();
218 }
219 hoverForThirdState_.thirdOperationIdle = false;
220 std::vector<int64_t> currentNodesHovering;
221 std::vector<int64_t> lastNodesHovering = hoverForThirdState_.nodesHovering;
222 if (config.eventType != NG::AccessibilityHoverEventType::EXIT) {
223 AccessibilityElementInfo rootInfo;
224 if (GetElementInfoForThird(-1, rootInfo, config.hostElementId) == false) {
225 ResetHoverForThirdState();
226 return;
227 }
228 AccessibilityHoverTestPathForThird path =
229 HoverPathForThird(config.hostElementId, config.point, rootInfo);
230 for (const auto& node: path) {
231 currentNodesHovering.push_back(node);
232 }
233 }
234 int64_t lastHoveringId = INVALID_NODE_ID;
235 if (!lastNodesHovering.empty()) {
236 lastHoveringId = lastNodesHovering.back();
237 }
238 int64_t currentHoveringId = INVALID_NODE_ID;
239 if (!currentNodesHovering.empty()) {
240 currentHoveringId = currentNodesHovering.back();
241 }
242 auto jsThirdProviderOperator = GetJsThirdProviderInteractionOperation(
243 config.hostElementId).lock();
244 if (jsThirdProviderOperator == nullptr) {
245 TAG_LOGE(AceLogTag::ACE_ACCESSIBILITY, "jsThirdProviderOperator is null, "
246 "hostElementId %{public}" PRId64, config.hostElementId);
247 ResetHoverForThirdState();
248 return;
249 }
250 if (lastHoveringId != INVALID_NODE_ID && lastHoveringId != currentHoveringId) {
251 jsThirdProviderOperator->SendAccessibilityAsyncEventForThird(lastHoveringId,
252 Accessibility::EventType::TYPE_VIEW_HOVER_EXIT_EVENT);
253 }
254 if ((currentHoveringId != INVALID_NODE_ID) && (currentHoveringId != lastHoveringId)) {
255 jsThirdProviderOperator->SendAccessibilityAsyncEventForThird(currentHoveringId,
256 Accessibility::EventType::TYPE_VIEW_HOVER_ENTER_EVENT);
257 }
258 hoverForThirdState_.nodesHovering = std::move(currentNodesHovering);
259 hoverForThirdState_.time = config.time;
260 hoverForThirdState_.source = config.sourceType;
261 hoverForThirdState_.idle = config.eventType == NG::AccessibilityHoverEventType::EXIT;
262 hoverForThirdState_.thirdOperationIdle = true;
263 }
264
HandleAccessibilityHoverForThird(const AccessibilityHoverForThirdConfig & config)265 void AccessibilityHoverManagerForThirdNG::HandleAccessibilityHoverForThird(
266 const AccessibilityHoverForThirdConfig& config)
267 {
268 if (!hoverForThirdState_.thirdOperationIdle) {
269 return;
270 }
271 CHECK_NULL_VOID(config.context);
272 config.context->GetTaskExecutor()->PostTask(
273 [weak = WeakClaim(this), config] {
274 auto accessibilityHoverManagerForThirdNG = weak.Upgrade();
275 CHECK_NULL_VOID(accessibilityHoverManagerForThirdNG);
276 AccessibilityHoverForThirdConfig asyncConfig = config;
277 accessibilityHoverManagerForThirdNG->HandleAccessibilityHoverForThirdInner(asyncConfig);
278 },
279 TaskExecutor::TaskType::BACKGROUND, "ArkUIHandleAccessibilityHoverForThird");
280 }
281
ClearThirdAccessibilityFocus(const RefPtr<NG::FrameNode> & hostNode)282 bool AccessibilityHoverManagerForThirdNG::ClearThirdAccessibilityFocus(
283 const RefPtr<NG::FrameNode>& hostNode)
284 {
285 CHECK_NULL_RETURN(hostNode, false);
286 RefPtr<NG::RenderContext> renderContext = hostNode->GetRenderContext();
287 CHECK_NULL_RETURN(renderContext, false);
288 renderContext->UpdateAccessibilityFocus(false);
289 return true;
290 }
291
ActThirdAccessibilityFocus(int64_t elementId,const AccessibilityElementInfo & nodeInfo,const RefPtr<NG::FrameNode> & hostNode,const RefPtr<NG::PipelineContext> & context,bool isNeedClear)292 bool AccessibilityHoverManagerForThirdNG::ActThirdAccessibilityFocus(
293 int64_t elementId,
294 const AccessibilityElementInfo& nodeInfo,
295 const RefPtr<NG::FrameNode>& hostNode,
296 const RefPtr<NG::PipelineContext>& context,
297 bool isNeedClear)
298 {
299 if (!isNeedClear && !IsTouchExplorationEnabled(context)) {
300 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "third Accessibility focus or update focus but is not in touch mode");
301 return true;
302 }
303
304 CHECK_NULL_RETURN(hostNode, false);
305 RefPtr<NG::RenderContext> renderContext = nullptr;
306 renderContext = hostNode->GetRenderContext();
307 CHECK_NULL_RETURN(renderContext, false);
308 if (isNeedClear) {
309 renderContext->UpdateAccessibilityFocus(false);
310 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
311 "third act Accessibility element Id %{public}" PRId64 "Focus clear",
312 nodeInfo.GetAccessibilityId());
313 return true;
314 }
315 renderContext->UpdateAccessibilityFocus(false);
316 auto rectInScreen = nodeInfo.GetRectInScreen();
317 auto left = rectInScreen.GetLeftTopXScreenPostion();
318 auto right = rectInScreen.GetLeftTopYScreenPostion();
319 auto width = rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion();
320 auto height = rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion();
321 if ((width == 0) && (height == 0)) {
322 renderContext->UpdateAccessibilityFocus(false);
323 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
324 "third act Accessibility element Id %{public}" PRId64 "Focus clear by null rect",
325 nodeInfo.GetAccessibilityId());
326 return true;
327 }
328
329 NG::RectT<int32_t> rectInt { static_cast<int32_t>(left), static_cast<int32_t>(right),
330 static_cast<int32_t>(width), static_cast<int32_t>(height) };
331
332 renderContext->UpdateAccessibilityFocusRect(rectInt);
333 renderContext->UpdateAccessibilityFocus(true, ACCESSIBILITY_FOCUS_WITHOUT_EVENT);
334 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
335 "third act Accessibility element Id %{public}" PRId64 "Focus",
336 nodeInfo.GetAccessibilityId());
337 return true;
338 }
339
RegisterJsThirdProviderInteractionOperation(int64_t hostElementId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)340 void AccessibilityHoverManagerForThirdNG::RegisterJsThirdProviderInteractionOperation(
341 int64_t hostElementId,
342 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
343 {
344 jsThirdProviderOperator_[hostElementId] = jsThirdProviderOperator;
345 }
346
DeregisterJsThirdProviderInteractionOperation(int64_t hostElementId)347 void AccessibilityHoverManagerForThirdNG::DeregisterJsThirdProviderInteractionOperation(
348 int64_t hostElementId)
349 {
350 jsThirdProviderOperator_.erase(hostElementId);
351 }
352
353 namespace {
354
GetDumpInfoArgument(const std::vector<std::string> & params,DumpInfoArgument & argument)355 bool GetDumpInfoArgument(const std::vector<std::string>& params, DumpInfoArgument& argument)
356 {
357 if (params.empty()) {
358 return false;
359 }
360 argument.isDumpSimplify = params[0].compare("-simplify") == 0;
361 for (auto arg = params.begin() + 1; arg != params.end(); ++arg) {
362 if (*arg == "-w") {
363 argument.useWindowId = true;
364 } else if (*arg == "--root") {
365 ++arg;
366 if (arg == params.end()) {
367 DumpLog::GetInstance().Print(std::string("Error: --root is used to set the root node, ") +
368 "e.g. '--root ${AccessibilityId}'!");
369 return false;
370 }
371 argument.rootId = StringUtils::StringToLongInt(*arg);
372 } else if (*arg == "--hover-test") {
373 argument.mode = DumpMode::HOVER_TEST;
374 static constexpr int32_t NUM_POINT_DIMENSION = 2;
375 if (std::distance(arg, params.end()) <= NUM_POINT_DIMENSION) {
376 DumpLog::GetInstance().Print(std::string("Error: --hover-test is used to get nodes at a point ") +
377 "relative to the root node, e.g. '--hover-test ${x} ${y}'!");
378 return false;
379 }
380 ++arg;
381 argument.pointX = StringUtils::StringToInt(*arg);
382 ++arg;
383 argument.pointY = StringUtils::StringToInt(*arg);
384 } else if (*arg == "-v") {
385 argument.verbose = true;
386 } else if (*arg == "-json") {
387 argument.mode = DumpMode::TREE;
388 } else {
389 if (argument.mode == DumpMode::NODE) {
390 argument.mode = DumpMode::HANDLE_EVENT;
391 argument.action = StringUtils::StringToInt(*arg);
392 break;
393 } else {
394 argument.mode = DumpMode::NODE;
395 argument.nodeId = StringUtils::StringToLongInt(*arg);
396 }
397 }
398 }
399 return true;
400 }
401
DumpTreeNodeInfoForThird(Accessibility::AccessibilityElementInfo & info,int32_t depth)402 void DumpTreeNodeInfoForThird(
403 Accessibility::AccessibilityElementInfo& info, int32_t depth)
404 {
405 DumpLog::GetInstance().AddDesc("ID: " + std::to_string(info.GetAccessibilityId()));
406 DumpLog::GetInstance().AddDesc("compid: " + info.GetInspectorKey());
407 DumpLog::GetInstance().AddDesc("text: " + info.GetContent());
408 DumpLog::GetInstance().AddDesc(
409 "accessibilityText: " + info.GetAccessibilityText());
410 DumpLog::GetInstance().AddDesc("accessibilityGroup: " +
411 std::to_string(info.GetAccessibilityGroup()));
412 DumpLog::GetInstance().AddDesc(
413 "accessibilityLevel: " + info.GetAccessibilityLevel());
414 auto rectInScreen = info.GetRectInScreen();
415 DumpLog::GetInstance().AddDesc("top: " + std::to_string(rectInScreen.GetLeftTopYScreenPostion()));
416 DumpLog::GetInstance().AddDesc("left: " + std::to_string(rectInScreen.GetLeftTopXScreenPostion()));
417 DumpLog::GetInstance().AddDesc("width: " +
418 std::to_string(rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion()));
419 DumpLog::GetInstance().AddDesc("height: " +
420 std::to_string(rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion()));
421 DumpLog::GetInstance().AddDesc("visible: " + std::to_string(info.IsVisible()));
422 DumpLog::GetInstance().AddDesc(
423 "clickable: " + std::to_string(info.IsClickable()));
424 DumpLog::GetInstance().AddDesc("longclickable: " +
425 std::to_string(info.IsLongClickable()));
426 DumpLog::GetInstance().AddDesc(
427 "checkable: " + std::to_string(info.IsCheckable()));
428 DumpLog::GetInstance().AddDesc(
429 "scrollable: " + std::to_string(info.IsScrollable()));
430 DumpLog::GetInstance().AddDesc(
431 "checked: " + std::to_string(info.IsChecked()));
432 DumpLog::GetInstance().AddDesc(
433 "hint: " + info.GetHint());
434 DumpLog::GetInstance().Print(depth, info.GetComponentType(), info.GetChildCount());
435 }
436
DumpTreeForThird(int64_t elementId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator,int32_t depth)437 void DumpTreeForThird(
438 int64_t elementId,
439 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator,
440 int32_t depth)
441 {
442 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
443 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
444 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
445 elementId, splitElementId, splitTreeId);
446 std::list<Accessibility::AccessibilityElementInfo> infos;
447 bool ret = jsThirdProviderOperator->FindAccessibilityNodeInfosByIdFromProvider(
448 splitElementId, 0, 0, infos);
449 if ((!ret) || (infos.size() == 0)) {
450 return;
451 }
452 Accessibility::AccessibilityElementInfo info = infos.front();
453 DumpTreeNodeInfoForThird(info, depth);
454 auto childrenIds = info.GetChildIds();
455 for (auto childId = childrenIds.rbegin(); childId != childrenIds.rend(); ++childId) {
456 DumpTreeForThird(*childId, jsThirdProviderOperator, depth+1);
457 }
458 }
459
IsDumpTreeForThird(int64_t inputRootId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)460 bool IsDumpTreeForThird(
461 int64_t inputRootId,
462 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator
463 )
464 {
465 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
466 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
467 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
468 inputRootId, splitElementId, splitTreeId);
469 if (splitTreeId == jsThirdProviderOperator->GetBelongTreeId()) {
470 return true;
471 }
472 return false;
473 }
474
475 class MockDumpOperatorCallBack : public Accessibility::AccessibilityElementOperatorCallback {
476 public:
477 ~MockDumpOperatorCallBack() = default;
478
SetSearchElementInfoByAccessibilityIdResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)479 void SetSearchElementInfoByAccessibilityIdResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
480 const int32_t requestId) override
481 {
482 }
483
SetSearchElementInfoByTextResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)484 void SetSearchElementInfoByTextResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
485 const int32_t requestId) override
486 {
487 }
488
SetSearchDefaultFocusByWindowIdResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)489 void SetSearchDefaultFocusByWindowIdResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
490 const int32_t requestId) override
491 {
492 }
493
SetFindFocusedElementInfoResult(const Accessibility::AccessibilityElementInfo & info,const int32_t requestId)494 void SetFindFocusedElementInfoResult(
495 const Accessibility::AccessibilityElementInfo &info,
496 const int32_t requestId) override
497 {
498 }
499
SetFocusMoveSearchResult(const Accessibility::AccessibilityElementInfo & info,const int32_t requestId)500 void SetFocusMoveSearchResult(const Accessibility::AccessibilityElementInfo &info, const int32_t requestId) override
501 {
502 }
503
SetExecuteActionResult(const bool succeeded,const int32_t requestId)504 void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override
505 {
506 if (succeeded) {
507 DumpLog::GetInstance().Print("Result: action execute succeeded");
508 } else {
509 DumpLog::GetInstance().Print("Result: action execute fail");
510 }
511 }
512
SetCursorPositionResult(const int32_t cursorPosition,const int32_t requestId)513 void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override
514 {
515 }
516
SetSearchElementInfoBySpecificPropertyResult(const std::list<AccessibilityElementInfo> & infos,const std::list<AccessibilityElementInfo> & treeInfos,const int32_t requestId)517 void SetSearchElementInfoBySpecificPropertyResult(const std::list<AccessibilityElementInfo> &infos,
518 const std::list<AccessibilityElementInfo> &treeInfos, const int32_t requestId) override
519 {
520 }
521 };
522
DumpHandleAction(const std::vector<std::string> & params,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)523 void DumpHandleAction(
524 const std::vector<std::string>& params,
525 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager,
526 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
527 {
528 auto jsAccessibilityManagerTemp = jsAccessibilityManager.Upgrade();
529 CHECK_NULL_VOID(jsAccessibilityManagerTemp);
530 if (!jsAccessibilityManagerTemp->CheckDumpHandleEventParams(params)) {
531 return;
532 }
533
534 ActionType op;
535 int64_t nodeId;
536 if (!jsAccessibilityManagerTemp->CheckGetActionIdAndOp(params, nodeId, op)) {
537 return DumpLog::GetInstance().Print("Error: params is illegal!");
538 }
539
540 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
541 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
542 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(nodeId, splitElementId, splitTreeId);
543 nodeId = splitElementId;
544
545 std::map<std::string, std::string> paramsMap;
546 jsAccessibilityManagerTemp->ProcessParameters(op, params, paramsMap);
547
548 MockDumpOperatorCallBack operatorCallback;
549 jsThirdProviderOperator->ExecuteAction(nodeId, op, paramsMap, 0, operatorCallback);
550 }
551 } // namespace
552
DumpPropertyForThird(int64_t elementId,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)553 void AccessibilityHoverManagerForThirdNG::DumpPropertyForThird(
554 int64_t elementId,
555 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager,
556 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
557 {
558 auto jsAccessibilityManagerTemp = jsAccessibilityManager.Upgrade();
559 CHECK_NULL_VOID(jsAccessibilityManagerTemp);
560 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
561 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
562 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
563 elementId, splitElementId, splitTreeId);
564 std::list<Accessibility::AccessibilityElementInfo> infos;
565 bool ret = jsThirdProviderOperator->FindAccessibilityNodeInfosByIdFromProvider(
566 splitElementId, 0, 0, infos);
567 if ((!ret) || (infos.size() == 0)) {
568 return;
569 }
570
571 Accessibility::AccessibilityElementInfo info = infos.front();
572 jsAccessibilityManagerTemp->DumpCommonPropertyNG(info, splitTreeId);
573 jsAccessibilityManagerTemp->DumpAccessibilityPropertyNG(info);
574 DumpLog::GetInstance().Print(0, info.GetComponentType(), info.GetChildCount());
575 }
576
OnDumpChildInfoForThirdRecursive(int64_t hostElementId,const std::vector<std::string> & params,std::vector<std::string> & info,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager)577 bool AccessibilityHoverManagerForThirdNG::OnDumpChildInfoForThirdRecursive(
578 int64_t hostElementId,
579 const std::vector<std::string>& params,
580 std::vector<std::string>& info,
581 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager)
582 {
583 DumpInfoArgument argument;
584 if (GetDumpInfoArgument(params, argument) == false) {
585 return true;
586 }
587 auto jsThirdProviderOperator =
588 GetJsThirdProviderInteractionOperation(hostElementId).lock();
589 if (jsThirdProviderOperator == nullptr) {
590 DumpLog::GetInstance().Print("Error: need start screenReader first");
591 return true;
592 }
593 switch (argument.mode) {
594 case DumpMode::NODE:
595 DumpPropertyForThird(argument.nodeId, jsAccessibilityManager, jsThirdProviderOperator);
596 break;
597 case DumpMode::TREE:
598 if (!IsDumpTreeForThird(argument.rootId, jsThirdProviderOperator)) {
599 break;
600 }
601 DumpTreeForThird(argument.rootId, jsThirdProviderOperator, 0);
602 break;
603 case DumpMode::HANDLE_EVENT:
604 DumpHandleAction(params, jsAccessibilityManager, jsThirdProviderOperator);
605 break;
606 case DumpMode::HOVER_TEST:
607 default:
608 DumpLog::GetInstance().Print("Error: invalid arguments!");
609 break;
610 }
611 return true;
612 }
613
614
615 } // namespace OHOS::Ace::Framework
616