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/components_ng/pattern/web/web_pattern.h"
19 #include "js_third_accessibility_hover_ng.h"
20
21 using namespace OHOS::Accessibility;
22 using namespace OHOS::AccessibilityConfig;
23 using namespace std;
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 = rectInScreen.GetLeftTopXScreenPostion();
164 auto right = rectInScreen.GetLeftTopYScreenPostion();
165 auto width = rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion();
166 auto height = rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion();
167 NG::RectF rect { left, right, width, height };
168 bool hitSelf = rect.IsInnerRegion(hoverPoint);
169 if (hitSelf && shouldSearchSelf) {
170 hitTarget = true;
171 path.push_back(nodeInfo.GetAccessibilityId());
172 }
173 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
174 "third hover elementId :%{public}" PRId64\
175 ", shouldSearchSelf: %{public}d shouldSearchChildren: %{public}d hitTarget: %{public}d ",
176 nodeInfo.GetAccessibilityId(), shouldSearchSelf, shouldSearchChildren, hitTarget);
177 if (shouldSearchChildren) {
178 auto childrenIds = nodeInfo.GetChildIds();
179 for (auto childId = childrenIds.rbegin(); childId != childrenIds.rend(); ++childId) {
180 AccessibilityElementInfo childInfo;
181 if (GetElementInfoForThird(*childId, childInfo, hostElementId) == false) {
182 break;
183 }
184 if (HoverPathForThirdRecursive(
185 hostElementId, hoverPoint, childInfo, path)) {
186 return true;
187 }
188 }
189 }
190 return hitTarget;
191 }
192
HoverPathForThird(const int64_t hostElementId,const NG::PointF & point,AccessibilityElementInfo & rootInfo)193 AccessibilityHoverTestPathForThird AccessibilityHoverManagerForThirdNG::HoverPathForThird(
194 const int64_t hostElementId,
195 const NG::PointF& point,
196 AccessibilityElementInfo& rootInfo)
197 {
198 AccessibilityHoverTestPathForThird path;
199 HoverPathForThirdRecursive(
200 hostElementId, point, rootInfo, path);
201 return path;
202 }
203
ResetHoverForThirdState()204 void AccessibilityHoverManagerForThirdNG::ResetHoverForThirdState()
205 {
206 hoverForThirdState_.idle = true;
207 hoverForThirdState_.thirdOperationIdle = true;
208 hoverForThirdState_.nodesHovering.clear();
209 }
210
HandleAccessibilityHoverForThirdInner(const AccessibilityHoverForThirdConfig & config)211 void AccessibilityHoverManagerForThirdNG::HandleAccessibilityHoverForThirdInner(
212 const AccessibilityHoverForThirdConfig& config)
213 {
214 if (config.eventType == NG::AccessibilityHoverEventType::ENTER) {
215 ResetHoverForThirdState();
216 }
217 hoverForThirdState_.thirdOperationIdle = false;
218 std::vector<int64_t> currentNodesHovering;
219 std::vector<int64_t> lastNodesHovering = hoverForThirdState_.nodesHovering;
220 if (config.eventType != NG::AccessibilityHoverEventType::EXIT) {
221 AccessibilityElementInfo rootInfo;
222 if (GetElementInfoForThird(-1, rootInfo, config.hostElementId) == false) {
223 ResetHoverForThirdState();
224 return;
225 }
226 AccessibilityHoverTestPathForThird path =
227 HoverPathForThird(config.hostElementId, config.point, rootInfo);
228 for (const auto& node: path) {
229 currentNodesHovering.push_back(node);
230 }
231 }
232 int64_t lastHoveringId = INVALID_NODE_ID;
233 if (!lastNodesHovering.empty()) {
234 lastHoveringId = lastNodesHovering.back();
235 }
236 int64_t currentHoveringId = INVALID_NODE_ID;
237 if (!currentNodesHovering.empty()) {
238 currentHoveringId = currentNodesHovering.back();
239 }
240 auto jsThirdProviderOperator = GetJsThirdProviderInteractionOperation(
241 config.hostElementId).lock();
242 if (jsThirdProviderOperator == nullptr) {
243 TAG_LOGE(AceLogTag::ACE_ACCESSIBILITY, "jsThirdProviderOperator is null, "
244 "hostElementId %{public}" PRId64, config.hostElementId);
245 ResetHoverForThirdState();
246 return;
247 }
248 if (lastHoveringId != INVALID_NODE_ID && lastHoveringId != currentHoveringId) {
249 jsThirdProviderOperator->SendAccessibilityAsyncEventForThird(lastHoveringId,
250 Accessibility::EventType::TYPE_VIEW_HOVER_EXIT_EVENT);
251 }
252 if ((currentHoveringId != INVALID_NODE_ID) && (currentHoveringId != lastHoveringId)) {
253 jsThirdProviderOperator->SendAccessibilityAsyncEventForThird(currentHoveringId,
254 Accessibility::EventType::TYPE_VIEW_HOVER_ENTER_EVENT);
255 }
256 hoverForThirdState_.nodesHovering = std::move(currentNodesHovering);
257 hoverForThirdState_.time = config.time;
258 hoverForThirdState_.source = config.sourceType;
259 hoverForThirdState_.idle = config.eventType == NG::AccessibilityHoverEventType::EXIT;
260 hoverForThirdState_.thirdOperationIdle = true;
261 }
262
HandleAccessibilityHoverForThird(const AccessibilityHoverForThirdConfig & config)263 void AccessibilityHoverManagerForThirdNG::HandleAccessibilityHoverForThird(
264 const AccessibilityHoverForThirdConfig& config)
265 {
266 if (!hoverForThirdState_.thirdOperationIdle) {
267 return;
268 }
269 CHECK_NULL_VOID(config.context);
270 config.context->GetTaskExecutor()->PostTask(
271 [weak = WeakClaim(this), config] {
272 auto accessibilityHoverManagerForThirdNG = weak.Upgrade();
273 CHECK_NULL_VOID(accessibilityHoverManagerForThirdNG);
274 AccessibilityHoverForThirdConfig asyncConfig = config;
275 accessibilityHoverManagerForThirdNG->HandleAccessibilityHoverForThirdInner(asyncConfig);
276 },
277 TaskExecutor::TaskType::BACKGROUND, "ArkUIHandleAccessibilityHoverForThird");
278 }
279
ClearThirdAccessibilityFocus(const RefPtr<NG::FrameNode> & hostNode)280 bool AccessibilityHoverManagerForThirdNG::ClearThirdAccessibilityFocus(
281 const RefPtr<NG::FrameNode>& hostNode)
282 {
283 CHECK_NULL_RETURN(hostNode, false);
284 RefPtr<NG::RenderContext> renderContext = hostNode->GetRenderContext();
285 CHECK_NULL_RETURN(renderContext, false);
286 renderContext->UpdateAccessibilityFocus(false);
287 return true;
288 }
289
ActThirdAccessibilityFocus(int64_t elementId,const AccessibilityElementInfo & nodeInfo,const RefPtr<NG::FrameNode> & hostNode,const RefPtr<NG::PipelineContext> & context,bool isNeedClear)290 bool AccessibilityHoverManagerForThirdNG::ActThirdAccessibilityFocus(
291 int64_t elementId,
292 const AccessibilityElementInfo& nodeInfo,
293 const RefPtr<NG::FrameNode>& hostNode,
294 const RefPtr<NG::PipelineContext>& context,
295 bool isNeedClear)
296 {
297 if (!isNeedClear && !IsTouchExplorationEnabled(context)) {
298 TAG_LOGI(AceLogTag::ACE_ACCESSIBILITY, "third Accessibility focus or update focus but is not in touch mode");
299 return true;
300 }
301
302 CHECK_NULL_RETURN(hostNode, false);
303 RefPtr<NG::RenderContext> renderContext = nullptr;
304 renderContext = hostNode->GetRenderContext();
305 CHECK_NULL_RETURN(renderContext, false);
306 if (isNeedClear) {
307 renderContext->UpdateAccessibilityFocus(false);
308 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
309 "third act Accessibility element Id %{public}" PRId64 "Focus clear",
310 nodeInfo.GetAccessibilityId());
311 return true;
312 }
313 renderContext->UpdateAccessibilityFocus(false);
314 auto rectInScreen = nodeInfo.GetRectInScreen();
315 auto left = rectInScreen.GetLeftTopXScreenPostion();
316 auto right = rectInScreen.GetLeftTopYScreenPostion();
317 auto width = rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion();
318 auto height = rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion();
319 if ((width == 0) && (height == 0)) {
320 renderContext->UpdateAccessibilityFocus(false);
321 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
322 "third act Accessibility element Id %{public}" PRId64 "Focus clear by null rect",
323 nodeInfo.GetAccessibilityId());
324 return true;
325 }
326
327 NG::RectT<int32_t> rectInt { static_cast<int32_t>(left), static_cast<int32_t>(right),
328 static_cast<int32_t>(width), static_cast<int32_t>(height) };
329
330 renderContext->UpdateAccessibilityFocusRect(rectInt);
331 renderContext->UpdateAccessibilityFocus(true, ACCESSIBILITY_FOCUS_WITHOUT_EVENT);
332 TAG_LOGD(AceLogTag::ACE_ACCESSIBILITY,
333 "third act Accessibility element Id %{public}" PRId64 "Focus",
334 nodeInfo.GetAccessibilityId());
335 return true;
336 }
337
RegisterJsThirdProviderInteractionOperation(int64_t hostElementId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)338 void AccessibilityHoverManagerForThirdNG::RegisterJsThirdProviderInteractionOperation(
339 int64_t hostElementId,
340 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
341 {
342 jsThirdProviderOperator_[hostElementId] = jsThirdProviderOperator;
343 }
344
DeregisterJsThirdProviderInteractionOperation(int64_t hostElementId)345 void AccessibilityHoverManagerForThirdNG::DeregisterJsThirdProviderInteractionOperation(
346 int64_t hostElementId)
347 {
348 jsThirdProviderOperator_.erase(hostElementId);
349 }
350
351 namespace {
352
GetDumpInfoArgument(const std::vector<std::string> & params,DumpInfoArgument & argument)353 bool GetDumpInfoArgument(const std::vector<std::string>& params, DumpInfoArgument& argument)
354 {
355 if (params.empty()) {
356 return false;
357 }
358 argument.isDumpSimplify = params[0].compare("-simplify") == 0;
359 for (auto arg = params.begin() + 1; arg != params.end(); ++arg) {
360 if (*arg == "-w") {
361 argument.useWindowId = true;
362 } else if (*arg == "--root") {
363 ++arg;
364 if (arg == params.end()) {
365 DumpLog::GetInstance().Print(std::string("Error: --root is used to set the root node, ") +
366 "e.g. '--root ${AccessibilityId}'!");
367 return false;
368 }
369 argument.rootId = StringUtils::StringToLongInt(*arg);
370 } else if (*arg == "--hover-test") {
371 argument.mode = DumpMode::HOVER_TEST;
372 static constexpr int32_t NUM_POINT_DIMENSION = 2;
373 if (std::distance(arg, params.end()) <= NUM_POINT_DIMENSION) {
374 DumpLog::GetInstance().Print(std::string("Error: --hover-test is used to get nodes at a point ") +
375 "relative to the root node, e.g. '--hover-test ${x} ${y}'!");
376 return false;
377 }
378 ++arg;
379 argument.pointX = StringUtils::StringToInt(*arg);
380 ++arg;
381 argument.pointY = StringUtils::StringToInt(*arg);
382 } else if (*arg == "-v") {
383 argument.verbose = true;
384 } else if (*arg == "-json") {
385 argument.mode = DumpMode::TREE;
386 } else {
387 if (argument.mode == DumpMode::NODE) {
388 argument.mode = DumpMode::HANDLE_EVENT;
389 argument.action = StringUtils::StringToInt(*arg);
390 break;
391 } else {
392 argument.mode = DumpMode::NODE;
393 argument.nodeId = StringUtils::StringToLongInt(*arg);
394 }
395 }
396 }
397 return true;
398 }
399
DumpTreeNodeInfoForThird(Accessibility::AccessibilityElementInfo & info,int32_t depth)400 void DumpTreeNodeInfoForThird(
401 Accessibility::AccessibilityElementInfo& info, int32_t depth)
402 {
403 DumpLog::GetInstance().AddDesc("ID: " + std::to_string(info.GetAccessibilityId()));
404 DumpLog::GetInstance().AddDesc("compid: " + info.GetInspectorKey());
405 DumpLog::GetInstance().AddDesc("text: " + info.GetContent());
406 DumpLog::GetInstance().AddDesc(
407 "accessibilityText: " + info.GetAccessibilityText());
408 DumpLog::GetInstance().AddDesc("accessibilityGroup: " +
409 std::to_string(info.GetAccessibilityGroup()));
410 DumpLog::GetInstance().AddDesc(
411 "accessibilityLevel: " + info.GetAccessibilityLevel());
412 auto rectInScreen = info.GetRectInScreen();
413 DumpLog::GetInstance().AddDesc("top: " + std::to_string(rectInScreen.GetLeftTopYScreenPostion()));
414 DumpLog::GetInstance().AddDesc("left: " + std::to_string(rectInScreen.GetLeftTopXScreenPostion()));
415 DumpLog::GetInstance().AddDesc("width: " +
416 std::to_string(rectInScreen.GetRightBottomXScreenPostion() - rectInScreen.GetLeftTopXScreenPostion()));
417 DumpLog::GetInstance().AddDesc("height: " +
418 std::to_string(rectInScreen.GetRightBottomYScreenPostion() - rectInScreen.GetLeftTopYScreenPostion()));
419 DumpLog::GetInstance().AddDesc("visible: " + std::to_string(info.IsVisible()));
420 DumpLog::GetInstance().AddDesc(
421 "clickable: " + std::to_string(info.IsClickable()));
422 DumpLog::GetInstance().AddDesc("longclickable: " +
423 std::to_string(info.IsLongClickable()));
424 DumpLog::GetInstance().AddDesc(
425 "checkable: " + std::to_string(info.IsCheckable()));
426 DumpLog::GetInstance().AddDesc(
427 "scrollable: " + std::to_string(info.IsScrollable()));
428 DumpLog::GetInstance().AddDesc(
429 "checked: " + std::to_string(info.IsChecked()));
430 DumpLog::GetInstance().AddDesc(
431 "hint: " + info.GetHint());
432 DumpLog::GetInstance().Print(depth, info.GetComponentType(), info.GetChildCount());
433 }
434
DumpTreeForThird(int64_t elementId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator,int32_t depth)435 void DumpTreeForThird(
436 int64_t elementId,
437 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator,
438 int32_t depth)
439 {
440 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
441 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
442 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
443 elementId, splitElementId, splitTreeId);
444 std::list<Accessibility::AccessibilityElementInfo> infos;
445 bool ret = jsThirdProviderOperator->FindAccessibilityNodeInfosByIdFromProvider(
446 splitElementId, 0, 0, infos);
447 if ((!ret) || (infos.size() == 0)) {
448 return;
449 }
450 Accessibility::AccessibilityElementInfo info = infos.front();
451 DumpTreeNodeInfoForThird(info, depth);
452 auto childrenIds = info.GetChildIds();
453 for (auto childId = childrenIds.rbegin(); childId != childrenIds.rend(); ++childId) {
454 DumpTreeForThird(*childId, jsThirdProviderOperator, depth+1);
455 }
456 }
457
IsDumpTreeForThird(int64_t inputRootId,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)458 bool IsDumpTreeForThird(
459 int64_t inputRootId,
460 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator
461 )
462 {
463 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
464 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
465 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
466 inputRootId, splitElementId, splitTreeId);
467 if (splitTreeId == jsThirdProviderOperator->GetBelongTreeId()) {
468 return true;
469 }
470 return false;
471 }
472
473 class MockDumpOperatorCallBack : public Accessibility::AccessibilityElementOperatorCallback {
474 public:
475 ~MockDumpOperatorCallBack() = default;
476
SetSearchElementInfoByAccessibilityIdResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)477 void SetSearchElementInfoByAccessibilityIdResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
478 const int32_t requestId) override
479 {
480 }
481
SetSearchElementInfoByTextResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)482 void SetSearchElementInfoByTextResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
483 const int32_t requestId) override
484 {
485 }
486
SetSearchDefaultFocusByWindowIdResult(const std::list<Accessibility::AccessibilityElementInfo> & infos,const int32_t requestId)487 void SetSearchDefaultFocusByWindowIdResult(const std::list<Accessibility::AccessibilityElementInfo> &infos,
488 const int32_t requestId) override
489 {
490 }
491
SetFindFocusedElementInfoResult(const Accessibility::AccessibilityElementInfo & info,const int32_t requestId)492 void SetFindFocusedElementInfoResult(
493 const Accessibility::AccessibilityElementInfo &info,
494 const int32_t requestId) override
495 {
496 }
497
SetFocusMoveSearchResult(const Accessibility::AccessibilityElementInfo & info,const int32_t requestId)498 void SetFocusMoveSearchResult(const Accessibility::AccessibilityElementInfo &info, const int32_t requestId) override
499 {
500 }
501
SetExecuteActionResult(const bool succeeded,const int32_t requestId)502 void SetExecuteActionResult(const bool succeeded, const int32_t requestId) override
503 {
504 if (succeeded) {
505 DumpLog::GetInstance().Print("Result: action execute succeeded");
506 } else {
507 DumpLog::GetInstance().Print("Result: action execute fail");
508 }
509 }
510
SetCursorPositionResult(const int32_t cursorPosition,const int32_t requestId)511 void SetCursorPositionResult(const int32_t cursorPosition, const int32_t requestId) override
512 {
513 }
514 };
515
DumpHandleAction(const std::vector<std::string> & params,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)516 void DumpHandleAction(
517 const std::vector<std::string>& params,
518 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager,
519 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
520 {
521 auto jsAccessibilityManagerTemp = jsAccessibilityManager.Upgrade();
522 CHECK_NULL_VOID(jsAccessibilityManagerTemp);
523 if (!jsAccessibilityManagerTemp->CheckDumpHandleEventParams(params)) {
524 return;
525 }
526
527 ActionType op;
528 int64_t nodeId;
529 if (!jsAccessibilityManagerTemp->CheckGetActionIdAndOp(params, nodeId, op)) {
530 return DumpLog::GetInstance().Print("Error: params is illegal!");
531 }
532
533 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
534 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
535 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(nodeId, splitElementId, splitTreeId);
536 nodeId = splitElementId;
537
538 std::map<std::string, std::string> paramsMap;
539 jsAccessibilityManagerTemp->ProcessParameters(op, params, paramsMap);
540
541 MockDumpOperatorCallBack operatorCallback;
542 jsThirdProviderOperator->ExecuteAction(nodeId, op, paramsMap, 0, operatorCallback);
543 }
544 } // namespace
545
DumpPropertyForThird(int64_t elementId,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager,const std::shared_ptr<JsThirdProviderInteractionOperation> & jsThirdProviderOperator)546 void AccessibilityHoverManagerForThirdNG::DumpPropertyForThird(
547 int64_t elementId,
548 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager,
549 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator)
550 {
551 auto jsAccessibilityManagerTemp = jsAccessibilityManager.Upgrade();
552 CHECK_NULL_VOID(jsAccessibilityManagerTemp);
553 int64_t splitElementId = AccessibilityElementInfo::UNDEFINED_ACCESSIBILITY_ID;
554 int32_t splitTreeId = AccessibilityElementInfo::UNDEFINED_TREE_ID;
555 AccessibilitySystemAbilityClient::GetTreeIdAndElementIdBySplitElementId(
556 elementId, splitElementId, splitTreeId);
557 std::list<Accessibility::AccessibilityElementInfo> infos;
558 bool ret = jsThirdProviderOperator->FindAccessibilityNodeInfosByIdFromProvider(
559 splitElementId, 0, 0, infos);
560 if ((!ret) || (infos.size() == 0)) {
561 return;
562 }
563
564 Accessibility::AccessibilityElementInfo info = infos.front();
565 jsAccessibilityManagerTemp->DumpCommonPropertyNG(info, splitTreeId);
566 jsAccessibilityManagerTemp->DumpAccessibilityPropertyNG(info);
567 DumpLog::GetInstance().Print(0, info.GetComponentType(), info.GetChildCount());
568 }
569
OnDumpChildInfoForThirdRecursive(int64_t hostElementId,const std::vector<std::string> & params,std::vector<std::string> & info,const WeakPtr<JsAccessibilityManager> & jsAccessibilityManager)570 bool AccessibilityHoverManagerForThirdNG::OnDumpChildInfoForThirdRecursive(
571 int64_t hostElementId,
572 const std::vector<std::string>& params,
573 std::vector<std::string>& info,
574 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager)
575 {
576 DumpInfoArgument argument;
577 if (GetDumpInfoArgument(params, argument) == false) {
578 return true;
579 }
580 auto jsThirdProviderOperator =
581 GetJsThirdProviderInteractionOperation(hostElementId).lock();
582 if (jsThirdProviderOperator == nullptr) {
583 DumpLog::GetInstance().Print("Error: need start screenReader first");
584 return true;
585 }
586 switch (argument.mode) {
587 case DumpMode::NODE:
588 DumpPropertyForThird(argument.nodeId, jsAccessibilityManager, jsThirdProviderOperator);
589 break;
590 case DumpMode::TREE:
591 if (!IsDumpTreeForThird(argument.rootId, jsThirdProviderOperator)) {
592 break;
593 }
594 DumpTreeForThird(argument.rootId, jsThirdProviderOperator, 0);
595 break;
596 case DumpMode::HANDLE_EVENT:
597 DumpHandleAction(params, jsAccessibilityManager, jsThirdProviderOperator);
598 break;
599 case DumpMode::HOVER_TEST:
600 default:
601 DumpLog::GetInstance().Print("Error: invalid arguments!");
602 break;
603 }
604 return true;
605 }
606
607
608 } // namespace OHOS::Ace::Framework
609