1 /*
2 * Copyright (c) 2023-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
16 #include "accessibility_property.h"
17
18 #include "core/accessibility/accessibility_constants.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/pipeline_ng/pipeline_context.h"
21
22 namespace OHOS::Ace::NG {
23 constexpr uint64_t ACTIONS = std::numeric_limits<uint64_t>::max();
GetSupportAction() const24 std::unordered_set<AceAction> AccessibilityProperty::GetSupportAction() const
25 {
26 static const AceAction allActions[] = {
27 AceAction::ACTION_NONE,
28 AceAction::GLOBAL_ACTION_BACK,
29 AceAction::CUSTOM_ACTION,
30 AceAction::ACTION_CLICK,
31 AceAction::ACTION_LONG_CLICK,
32 AceAction::ACTION_SCROLL_FORWARD,
33 AceAction::ACTION_SCROLL_BACKWARD,
34 AceAction::ACTION_FOCUS,
35 AceAction::ACTION_CLEAR_FOCUS,
36 AceAction::ACTION_ACCESSIBILITY_FOCUS,
37 AceAction::ACTION_CLEAR_ACCESSIBILITY_FOCUS,
38 AceAction::ACTION_NEXT_AT_MOVEMENT_GRANULARITY,
39 AceAction::ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
40 AceAction::ACTION_SET_TEXT,
41 AceAction::ACTION_COPY,
42 AceAction::ACTION_PASTE,
43 AceAction::ACTION_CUT,
44 AceAction::ACTION_SELECT,
45 AceAction::ACTION_SET_SELECTION,
46 AceAction::ACTION_CLEAR_SELECTION,
47 AceAction::ACTION_SET_CURSOR_POSITION,
48 AceAction::ACTION_EXEC_SUB_COMPONENT,
49 };
50
51 std::unordered_set<AceAction> supportActions;
52 if (supportActions_ == 0) {
53 return supportActions;
54 }
55
56 auto finalSupportActions = supportActions_ & ACTIONS;
57 for (auto action : allActions) {
58 if ((finalSupportActions & (1UL << static_cast<uint32_t>(action))) != 0) {
59 supportActions.emplace(action);
60 }
61 }
62 return supportActions;
63 }
64
NotifyComponentChangeEvent(AccessibilityEventType eventType)65 void AccessibilityProperty::NotifyComponentChangeEvent(AccessibilityEventType eventType)
66 {
67 if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled()) {
68 auto frameNode = host_.Upgrade();
69 CHECK_NULL_VOID(frameNode);
70 auto pipeline = frameNode->GetContext();
71 CHECK_NULL_VOID(pipeline);
72 pipeline->AddAccessibilityCallbackEvent(AccessibilityCallbackEventId::ON_SEND_ELEMENT_INFO_CHANGE,
73 frameNode->GetAccessibilityId());
74 }
75 }
76
GetText() const77 std::string AccessibilityProperty::GetText() const
78 {
79 return propText_.value_or("");
80 }
81
GetGroupText(bool forceGetChildren) const82 std::string AccessibilityProperty::GetGroupText(bool forceGetChildren) const
83 {
84 std::string text;
85 GetGroupTextRecursive(forceGetChildren, text, false);
86 return text;
87 }
88
GetGroupPreferAccessibilityText(bool forceGetChildren) const89 std::string AccessibilityProperty::GetGroupPreferAccessibilityText(bool forceGetChildren) const
90 {
91 std::string text;
92 GetGroupTextRecursive(forceGetChildren, text, true);
93 return text;
94 }
95
GetGroupTextRecursive(bool forceGetChildren,std::string & text,bool preferAccessibilityText) const96 void AccessibilityProperty::GetGroupTextRecursive(bool forceGetChildren, std::string& text,
97 bool preferAccessibilityText) const
98 {
99 auto node = host_.Upgrade();
100 CHECK_NULL_VOID(node);
101 if (node->IsInternal()) {
102 return;
103 }
104 auto level = GetAccessibilityLevel();
105 if (level == Level::AUTO || level == Level::YES_STR) {
106 std::string accessibilityText = GetAccessibilityText();
107 auto nodeText = preferAccessibilityText && !accessibilityText.empty() ? accessibilityText : GetText();
108 if (!text.empty() && !nodeText.empty()) {
109 text += ", ";
110 }
111 text += nodeText;
112 } else if (level == Level::NO_HIDE_DESCENDANTS) {
113 return;
114 }
115 // Do not change text if level is no
116
117 if (!(forceGetChildren || IsAccessibilityGroup())) {
118 return;
119 }
120 auto& children = node->GetFrameChildren();
121 for (auto& childWeak : children) {
122 auto child = childWeak.Upgrade();
123 if (child == nullptr) {
124 continue;
125 }
126 child->GetAccessibilityProperty<AccessibilityProperty>()->GetGroupTextRecursive(true, text,
127 preferAccessibilityText);
128 }
129 }
130
GetScrollOffSet() const131 float AccessibilityProperty::GetScrollOffSet() const
132 {
133 return DEFAULT_ACCESSIBILITY_SCROLL_OFFSET;
134 }
135
HoverTest(const PointF & point,const RefPtr<FrameNode> & root,std::unique_ptr<HoverTestDebugTraceInfo> & debugInfo)136 AccessibilityHoverTestPath AccessibilityProperty::HoverTest(
137 const PointF& point,
138 const RefPtr<FrameNode>& root,
139 std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo)
140 {
141 AccessibilityHoverTestPath path;
142 CHECK_NULL_RETURN(root, path);
143 ACE_SCOPED_TRACE("AccessibilityHoverTest");
144 bool ancestorGroupFlag = false;
145 auto accessibilityProperty = root->GetAccessibilityProperty<NG::AccessibilityProperty>();
146 if (accessibilityProperty != nullptr) {
147 ancestorGroupFlag = accessibilityProperty->IsAccessibilityGroup();
148 }
149 AccessibilityProperty::HoverTestRecursive(point, root, path, debugInfo, ancestorGroupFlag);
150 return path;
151 }
152
GetHitTestModeStr(HitTestMode hitTestMode,std::string & testModeStr)153 void GetHitTestModeStr(HitTestMode hitTestMode, std::string& testModeStr)
154 {
155 switch (hitTestMode) {
156 case HitTestMode::HTMDEFAULT:
157 testModeStr = "Default";
158 break;
159 case HitTestMode::HTMBLOCK:
160 testModeStr = "Block";
161 break;
162 case HitTestMode::HTMTRANSPARENT:
163 testModeStr = "Transparent";
164 break;
165 case HitTestMode::HTMNONE:
166 testModeStr = "None";
167 break;
168 default:
169 testModeStr = "Unsupported";
170 }
171 }
172
CreateNodeSearchInfo(const RefPtr<FrameNode> & node,const PointF & parentPoint,bool & ancestorGroupFlag)173 std::unique_ptr<JsonValue> AccessibilityProperty::CreateNodeSearchInfo(const RefPtr<FrameNode>& node,
174 const PointF& parentPoint, bool& ancestorGroupFlag)
175 {
176 auto nodeInfo = JsonUtil::Create();
177 nodeInfo->Put("id", node->GetAccessibilityId());
178 nodeInfo->Put("tag", node->GetTag().c_str());
179 if (!node->IsRootNode()) {
180 if (node->GetParent()) {
181 nodeInfo->Put("parent", node->GetParent()->GetAccessibilityId());
182 } else {
183 nodeInfo->Put("parent", -1);
184 }
185 }
186 nodeInfo->Put("visible", node->IsVisible());
187 auto [shouldSearchSelf, shouldSearchChildren, groupFlag]
188 = AccessibilityProperty::GetSearchStrategy(node, ancestorGroupFlag);
189 nodeInfo->Put("shouldSearchSelf", shouldSearchSelf);
190 nodeInfo->Put("shouldSearchChildren", shouldSearchChildren);
191 nodeInfo->Put("currentGroup", groupFlag);
192
193 auto renderContext = node->GetRenderContext();
194 auto rect = renderContext->GetPaintRectWithoutTransform();
195 PointF selfPoint = parentPoint;
196 renderContext->GetPointWithRevert(selfPoint);
197 bool hitSelf = rect.IsInnerRegion(selfPoint);
198 nodeInfo->Put("hitNode", hitSelf);
199 nodeInfo->Put("rect", rect.ToString().c_str());
200 nodeInfo->Put("hoverPoint", selfPoint.ToString().c_str());
201 nodeInfo->Put("clip", renderContext->GetClipEdge().value_or(false));
202
203 auto eventHub = node->GetEventHub<EventHub>();
204 nodeInfo->Put("enabled", eventHub->IsEnabled());
205
206 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
207 if (accessibilityProperty != nullptr) {
208 nodeInfo->Put("accessibilityLevel", accessibilityProperty->GetAccessibilityLevel().c_str());
209 nodeInfo->Put("accessibilityGroup", accessibilityProperty->IsAccessibilityGroup());
210 nodeInfo->Put("hasVirtualNode", accessibilityProperty->HasAccessibilityVirtualNode());
211 nodeInfo->Put("accessibilityText", accessibilityProperty->GetAccessibilityText().c_str());
212 nodeInfo->Put("accessibilityDescription", accessibilityProperty->GetAccessibilityDescription().c_str());
213 }
214
215 std::string testModeStr = "";
216 GetHitTestModeStr(node->GetHitTestMode(), testModeStr);
217 nodeInfo->Put("hitTestMode", testModeStr.c_str());
218 return nodeInfo;
219 }
220
ProcessHoverTestRecursive(const PointF & noOffsetPoint,const RefPtr<FrameNode> & node,AccessibilityHoverTestPath & path,std::unique_ptr<HoverTestDebugTraceInfo> & debugInfo,RecursiveParam recursiveParam)221 bool AccessibilityProperty::ProcessHoverTestRecursive(const PointF& noOffsetPoint, const RefPtr<FrameNode>& node,
222 AccessibilityHoverTestPath& path, std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo,
223 RecursiveParam recursiveParam)
224 {
225 auto property = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
226 auto virtualNode = property->GetAccessibilityVirtualNode();
227 if (virtualNode != nullptr) {
228 auto frameNode = AceType::DynamicCast<FrameNode>(virtualNode);
229 CHECK_NULL_RETURN(frameNode, false);
230
231 if (AccessibilityProperty::HoverTestRecursive(noOffsetPoint, frameNode, path, debugInfo,
232 recursiveParam.ancestorGroupFlag)) {
233 return true;
234 }
235 } else {
236 auto children = node->GetFrameChildren();
237 for (auto childWeak = children.rbegin(); childWeak != children.rend(); ++childWeak) {
238 auto child = childWeak->Upgrade();
239 if (child == nullptr) {
240 continue;
241 }
242 if (AccessibilityProperty::HoverTestRecursive(noOffsetPoint, child, path, debugInfo,
243 recursiveParam.ancestorGroupFlag)) {
244 return true;
245 }
246 }
247 }
248 return recursiveParam.hitTarget;
249 }
250
IsAccessibilityCompInResponseRegion(const RectF & rect,const RectF & origRect)251 bool AccessibilityProperty::IsAccessibilityCompInResponseRegion(const RectF& rect, const RectF& origRect)
252 {
253 auto rectLeft = rect.Left();
254 auto rectTop = rect.Top();
255 auto rectRight = rect.Right();
256 auto rectBottom = rect.Bottom();
257
258 auto origLeft = origRect.Left();
259 auto origTop = origRect.Top();
260 auto origRight = origRect.Right();
261 auto origBottom = origRect.Bottom();
262 if (LessNotEqual(origLeft, rectLeft) || LessNotEqual(origTop, rectTop) || LessNotEqual(rectRight, origRight) ||
263 LessNotEqual(rectBottom, origBottom)) {
264 return false;
265 }
266 return true;
267 }
268
IsMatchAccessibilityResponseRegion(bool isAccessibilityVirtualNode)269 bool AccessibilityProperty::IsMatchAccessibilityResponseRegion(bool isAccessibilityVirtualNode)
270 {
271 auto host = host_.Upgrade();
272 CHECK_NULL_RETURN(host, false);
273 NG::RectF origRect;
274 if (isAccessibilityVirtualNode) {
275 origRect = host->GetTransformRectRelativeToWindow();
276 } else {
277 RefPtr<NG::RenderContext> renderContext = host->GetRenderContext();
278 CHECK_NULL_RETURN(renderContext, false);
279 origRect = renderContext->GetPaintRectWithoutTransform();
280 }
281 auto responseRegionList = host->GetResponseRegionList(origRect, static_cast<int32_t>(SourceType::TOUCH));
282 if (responseRegionList.size() != 1) {
283 return false;
284 }
285 auto& rect = responseRegionList.back();
286 if (rect == origRect) {
287 return false;
288 }
289 if (!IsAccessibilityCompInResponseRegion(rect, origRect)) {
290 return false;
291 }
292 return true;
293 }
294
GetAccessibilityResponseRegionRect(bool isAccessibilityVirtualNode)295 NG::RectT<int32_t> AccessibilityProperty::GetAccessibilityResponseRegionRect(bool isAccessibilityVirtualNode)
296 {
297 NG::RectF origRect;
298 NG::RectT<int32_t> rectInt;
299 auto host = host_.Upgrade();
300 CHECK_NULL_RETURN(host, rectInt);
301 if (isAccessibilityVirtualNode) {
302 origRect = host->GetTransformRectRelativeToWindow();
303 auto responseRegionList = host->GetResponseRegionList(origRect, static_cast<int32_t>(SourceType::TOUCH));
304 CHECK_EQUAL_RETURN(responseRegionList.size(), 0, rectInt);
305 auto& rect = responseRegionList.back();
306 rectInt = { static_cast<int32_t>(rect.Left()), static_cast<int32_t>(rect.Top()),
307 static_cast<int32_t>(rect.Width()), static_cast<int32_t>(rect.Height()) };
308 } else {
309 RefPtr<NG::RenderContext> renderContext = host->GetRenderContext();
310 CHECK_NULL_RETURN(renderContext, rectInt);
311 origRect = renderContext->GetPaintRectWithoutTransform();
312 auto responseRegionList = host->GetResponseRegionList(origRect, static_cast<int32_t>(SourceType::TOUCH));
313 CHECK_EQUAL_RETURN(responseRegionList.size(), 0, rectInt);
314 auto& rect = responseRegionList.back();
315 rectInt = { static_cast<int32_t>(rect.GetX() - origRect.GetX()),
316 static_cast<int32_t>(rect.GetY() - origRect.GetY()),
317 static_cast<int32_t>(rect.Width()),
318 static_cast<int32_t>(rect.Height()) };
319 }
320 return rectInt;
321 }
322
UpdateHoverTestRect(const RefPtr<FrameNode> & node)323 NG::RectF AccessibilityProperty::UpdateHoverTestRect(const RefPtr<FrameNode>& node)
324 {
325 NG::RectF origRect;
326 CHECK_NULL_RETURN(node, origRect);
327 bool IsAccessibilityVirtualNode = node->IsAccessibilityVirtualNode();
328 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
329 CHECK_NULL_RETURN(accessibilityProperty, origRect);
330 auto renderContext = node->GetRenderContext();
331 CHECK_NULL_RETURN(renderContext, origRect);
332 if (IsAccessibilityVirtualNode) {
333 origRect = node->GetTransformRectRelativeToWindow();
334 } else {
335 origRect = renderContext->GetPaintRectWithoutTransform();
336 }
337 if (accessibilityProperty->IsMatchAccessibilityResponseRegion(IsAccessibilityVirtualNode)) {
338 auto responseRegionList = node->GetResponseRegionList(origRect, static_cast<int32_t>(SourceType::TOUCH));
339 CHECK_EQUAL_RETURN(responseRegionList.size(), 0, origRect);
340 return responseRegionList.back();
341 } else {
342 return origRect;
343 }
344 }
345
HoverTestRecursive(const PointF & parentPoint,const RefPtr<FrameNode> & node,AccessibilityHoverTestPath & path,std::unique_ptr<HoverTestDebugTraceInfo> & debugInfo,bool & ancestorGroupFlag)346 bool AccessibilityProperty::HoverTestRecursive(
347 const PointF& parentPoint,
348 const RefPtr<FrameNode>& node,
349 AccessibilityHoverTestPath& path,
350 std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo,
351 bool& ancestorGroupFlag)
352 {
353 if (!node->IsAccessibilityVirtualNode()) {
354 if (!node->IsActive() || node->IsInternal()) {
355 return false;
356 }
357 }
358 if (debugInfo != nullptr) {
359 auto nodeInfo = CreateNodeSearchInfo(node, parentPoint, ancestorGroupFlag);
360 debugInfo->trace.push_back(std::move(nodeInfo));
361 }
362 bool hitTarget = false;
363 if (!node->IsVisible()) {
364 return false;
365 }
366
367 auto [shouldSearchSelf, shouldSearchChildren, currentGroupFlag]
368 = AccessibilityProperty::GetSearchStrategy(node, ancestorGroupFlag);
369
370 auto renderContext = node->GetRenderContext();
371 CHECK_NULL_RETURN(renderContext, false);
372 auto rect = UpdateHoverTestRect(node);
373 PointF selfPoint = parentPoint;
374 renderContext->GetPointWithRevert(selfPoint);
375 bool hitSelf = rect.IsInnerRegion(selfPoint);
376 // hitTarget true means self hit hover, and will not search brothers
377 if (hitSelf && shouldSearchSelf
378 && CheckHoverConsumeByAccessibility(node)
379 && CheckHoverConsumeByComponent(node, selfPoint)) {
380 hitTarget = true;
381 path.push_back(node);
382 }
383 bool hasClip = renderContext->GetClipEdge().value_or(false);
384 if (hasClip && !hitSelf) {
385 return false;
386 }
387
388 if (shouldSearchChildren) {
389 auto orginRect = renderContext->GetPaintRectWithoutTransform();
390 PointF noOffsetPoint = selfPoint - orginRect.GetOffset();
391 RecursiveParam recursiveParam;
392 recursiveParam.hitTarget = hitTarget;
393 recursiveParam.ancestorGroupFlag = currentGroupFlag;
394 return ProcessHoverTestRecursive(noOffsetPoint, node, path, debugInfo, recursiveParam);
395 }
396 return hitTarget;
397 }
398
UpdateSearchStrategyByHitTestMode(HitTestMode hitTestMode,bool & shouldSearchSelf,bool & shouldSearchChildren)399 void UpdateSearchStrategyByHitTestMode(HitTestMode hitTestMode, bool& shouldSearchSelf, bool& shouldSearchChildren)
400 {
401 switch (hitTestMode) {
402 case HitTestMode::HTMBLOCK:
403 shouldSearchChildren = false;
404 break;
405 case HitTestMode::HTMTRANSPARENT:
406 break;
407 case HitTestMode::HTMNONE:
408 shouldSearchSelf = false;
409 break;
410 default:
411 break;
412 }
413 }
414
415 static const std::set<std::string> TAGS_SUBTREE_COMPONENT = {
416 V2::XCOMPONENT_ETS_TAG,
417 V2::UI_EXTENSION_COMPONENT_ETS_TAG,
418 V2::EMBEDDED_COMPONENT_ETS_TAG,
419 V2::FORM_ETS_TAG,
420 V2::ISOLATED_COMPONENT_ETS_TAG,
421 V2::DYNAMIC_COMPONENT_ETS_TAG,
422 V2::WEB_ETS_TAG,
423 };
424
425 static const std::set<std::string> TAGS_MODAL_DIALOG_COMPONENT = {
426 V2::MENU_WRAPPER_ETS_TAG,
427 V2::SELECT_ETS_TAG,
428 V2::DIALOG_ETS_TAG,
429 V2::SHEET_PAGE_TAG,
430 V2::SHEET_WRAPPER_TAG,
431 };
432
IsTagInSubTreeComponent(const std::string & tag)433 bool AccessibilityProperty::IsTagInSubTreeComponent(const std::string& tag)
434 {
435 if (TAGS_SUBTREE_COMPONENT.find(tag) != TAGS_SUBTREE_COMPONENT.end()) {
436 return true;
437 }
438 return false;
439 }
440
IsTagInModalDialog(const RefPtr<FrameNode> & node)441 bool AccessibilityProperty::IsTagInModalDialog(const RefPtr<FrameNode>& node)
442 {
443 CHECK_NULL_RETURN(node, false);
444 return TAGS_MODAL_DIALOG_COMPONENT.find(node->GetTag()) != TAGS_MODAL_DIALOG_COMPONENT.end();
445 }
446
HitAccessibilityHoverPriority(const RefPtr<FrameNode> & node)447 bool AccessibilityProperty::HitAccessibilityHoverPriority(const RefPtr<FrameNode>& node)
448 {
449 CHECK_NULL_RETURN(node, false);
450 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
451 CHECK_NULL_RETURN(accessibilityProperty, false);
452 return accessibilityProperty->IsAccessibilityHoverPriority();
453 }
454
CheckHoverConsumeByAccessibility(const RefPtr<FrameNode> & node)455 bool AccessibilityProperty::CheckHoverConsumeByAccessibility(const RefPtr<FrameNode>& node)
456 {
457 return (IsAccessibilityFocusable(node) || IsTagInModalDialog(node) || HitAccessibilityHoverPriority(node));
458 }
459
460 // hover hit but need be checked by component,
461 // false means self and descendants no need to be hovered, should search brothers
CheckHoverConsumeByComponent(const RefPtr<FrameNode> & node,const NG::PointF & point)462 bool AccessibilityProperty::CheckHoverConsumeByComponent(const RefPtr<FrameNode>& node, const NG::PointF& point)
463 {
464 CHECK_NULL_RETURN(node, true);
465 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
466 CHECK_NULL_RETURN(accessibilityProperty, true);
467 return accessibilityProperty->IsAccessibilityHoverConsume(point);
468 }
469
GetSearchStrategy(const RefPtr<FrameNode> & node,bool & ancestorGroupFlag)470 std::tuple<bool, bool, bool> AccessibilityProperty::GetSearchStrategy(const RefPtr<FrameNode>& node,
471 bool& ancestorGroupFlag)
472 {
473 bool shouldSearchSelf = true;
474 bool shouldSearchChildren = true;
475 bool currentGroupFlag = false;
476 auto level = AccessibilityProperty::Level::AUTO;
477 do {
478 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
479 if (accessibilityProperty != nullptr) {
480 level = accessibilityProperty->GetAccessibilityLevel();
481 currentGroupFlag = accessibilityProperty->IsAccessibilityGroup();
482 bool hasAccessibilityText = accessibilityProperty->HasAccessibilityTextOrDescription();
483 if (level == AccessibilityProperty::Level::YES_STR) {
484 break;
485 } else if (level == AccessibilityProperty::Level::NO_HIDE_DESCENDANTS) {
486 shouldSearchSelf = false;
487 shouldSearchChildren = false;
488 break;
489 } else {
490 if (level == AccessibilityProperty::Level::NO_STR) {
491 shouldSearchSelf = false;
492 } else {
493 // shouldSearchSelf is true here
494 if (hasAccessibilityText) {
495 break;
496 }
497 }
498 }
499 }
500 auto eventHub = node->GetEventHub<EventHub>();
501 if (!eventHub->IsEnabled()) {
502 shouldSearchChildren = false;
503 // Fall through to update `shouldSearchSelf`
504 }
505 HitTestMode hitTestMode = node->GetHitTestMode();
506 UpdateSearchStrategyByHitTestMode(hitTestMode, shouldSearchSelf, shouldSearchChildren);
507 if (accessibilityProperty != nullptr && accessibilityProperty->HasAccessibilityVirtualNode() &&
508 accessibilityProperty->GetAccessibilityLevel() != AccessibilityProperty::Level::NO_HIDE_DESCENDANTS) {
509 shouldSearchChildren = true;
510 }
511 } while (0);
512 shouldSearchSelf = IsTagInSubTreeComponent(node->GetTag()) ? true : shouldSearchSelf;
513 if (ancestorGroupFlag == true) {
514 if (level != AccessibilityProperty::Level::YES_STR) {
515 shouldSearchSelf = false;
516 }
517 currentGroupFlag = true;
518 }
519
520 return std::make_tuple(shouldSearchSelf, shouldSearchChildren, currentGroupFlag);
521 }
522
523 static const std::set<std::string> TAGS_FOCUSABLE = {
524 V2::CHECKBOX_ETS_TAG,
525 V2::CHECKBOXGROUP_ETS_TAG,
526 V2::GAUGE_ETS_TAG,
527 V2::MARQUEE_ETS_TAG,
528 V2::MENU_ETS_TAG,
529 V2::MENU_ITEM_ETS_TAG,
530 V2::MENU_ITEM_GROUP_ETS_TAG,
531 V2::NAVIGATION_VIEW_ETS_TAG,
532 V2::DATE_PICKER_ETS_TAG,
533 V2::PROGRESS_ETS_TAG,
534 V2::RADIO_ETS_TAG,
535 V2::RATING_ETS_TAG,
536 V2::SCROLL_BAR_ETS_TAG,
537 V2::SELECT_ETS_TAG,
538 V2::SLIDER_ETS_TAG,
539 V2::STEPPER_ETS_TAG,
540 V2::TEXT_ETS_TAG,
541 V2::TEXTCLOCK_ETS_TAG,
542 V2::TEXT_PICKER_ETS_TAG,
543 V2::TEXTTIMER_ETS_TAG,
544 V2::TIME_PICKER_ETS_TAG,
545 V2::TOGGLE_ETS_TAG,
546 V2::WEB_ETS_TAG,
547 V2::XCOMPONENT_ETS_TAG,
548 V2::UI_EXTENSION_COMPONENT_ETS_TAG,
549 V2::EMBEDDED_COMPONENT_ETS_TAG,
550 V2::DYNAMIC_COMPONENT_ETS_TAG,
551 V2::FORM_ETS_TAG
552 };
553
IsAccessibilityFocusableTag(const std::string & tag)554 bool AccessibilityProperty::IsAccessibilityFocusableTag(const std::string &tag)
555 {
556 if (TAGS_FOCUSABLE.find(tag) != TAGS_FOCUSABLE.end()) {
557 return true;
558 }
559 return false;
560 }
561
IsAccessibilityFocusableDebug(const RefPtr<FrameNode> & node,std::unique_ptr<JsonValue> & info)562 bool AccessibilityProperty::IsAccessibilityFocusableDebug(const RefPtr<FrameNode>& node,
563 std::unique_ptr<JsonValue>& info)
564 {
565 bool focusable = IsAccessibilityFocusable(node);
566 info->Put("id", node->GetAccessibilityId());
567 info->Put("tag", node->GetTag().c_str());
568 if (!node->IsRootNode()) {
569 info->Put("parent", node->GetParent()->GetAccessibilityId());
570 }
571 info->Put("selected", focusable);
572
573 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
574 if (accessibilityProperty != nullptr) {
575 info->Put("accessibilityLevel", accessibilityProperty->GetAccessibilityLevel().c_str());
576 info->Put("accessibilityGroup", accessibilityProperty->IsAccessibilityGroup());
577 info->Put("hasVirtualNode", accessibilityProperty->HasAccessibilityVirtualNode());
578 info->Put("accessibilityText", accessibilityProperty->GetAccessibilityText().c_str());
579 info->Put("accessibilityDescription", accessibilityProperty->GetAccessibilityDescription().c_str());
580 info->Put("text", accessibilityProperty->GetText().c_str());
581 info->Put("hasAction", accessibilityProperty->HasAction());
582 }
583
584 auto eventHub = node->GetEventHub<EventHub>();
585 info->Put("enabled", eventHub->IsEnabled());
586 auto gestureEventHub = eventHub->GetGestureEventHub();
587 if (gestureEventHub != nullptr) {
588 info->Put("clickable", gestureEventHub->IsAccessibilityClickable());
589 info->Put("longClickable", gestureEventHub->IsAccessibilityLongClickable());
590 }
591 return focusable;
592 }
593
594
IsAccessibilityFocusable(const RefPtr<FrameNode> & node)595 bool AccessibilityProperty::IsAccessibilityFocusable(const RefPtr<FrameNode>& node)
596 {
597 if (node->IsRootNode()) {
598 return false;
599 }
600 bool focusable = false;
601 do {
602 auto accessibilityProperty = node->GetAccessibilityProperty<NG::AccessibilityProperty>();
603 if (accessibilityProperty != nullptr) {
604 auto level = accessibilityProperty->GetAccessibilityLevel();
605 if (level == AccessibilityProperty::Level::YES_STR) {
606 focusable = true;
607 break;
608 }
609 if (level == AccessibilityProperty::Level::NO_STR) {
610 break;
611 }
612 if (accessibilityProperty->IsAccessibilityGroup() ||
613 accessibilityProperty->HasAccessibilityVirtualNode() ||
614 accessibilityProperty->HasAction() ||
615 accessibilityProperty->HasAccessibilityTextOrDescription() ||
616 !accessibilityProperty->GetText().empty()) {
617 focusable = true;
618 break;
619 }
620 }
621
622 auto eventHub = node->GetEventHub<EventHub>();
623 if (!eventHub->IsEnabled()) {
624 focusable = true;
625 break;
626 }
627 auto gestureEventHub = eventHub->GetGestureEventHub();
628 if (gestureEventHub != nullptr) {
629 if (gestureEventHub->IsAccessibilityClickable() ||
630 gestureEventHub->IsAccessibilityLongClickable()) {
631 focusable = true;
632 break;
633 }
634 }
635
636 if (TAGS_FOCUSABLE.find(node->GetTag()) != TAGS_FOCUSABLE.end()) {
637 focusable = true;
638 break;
639 }
640 } while (0);
641 if (IsTagInSubTreeComponent(node->GetTag())) {
642 focusable = true;
643 }
644 return focusable;
645 }
646
HasAccessibilityTextOrDescription() const647 bool AccessibilityProperty::HasAccessibilityTextOrDescription() const
648 {
649 return !accessibilityText_.value_or("").empty() ||
650 !accessibilityDescription_.value_or("").empty();
651 }
652
HasAction() const653 bool AccessibilityProperty::HasAction() const
654 {
655 return (supportActions_ & ACTIONS) != 0 ||
656 IsCheckable() ||
657 IsScrollable() ||
658 IsEditable() ||
659 IsDeletable();
660 }
661
SetAccessibilityActions(uint32_t actions)662 void AccessibilityProperty::SetAccessibilityActions(uint32_t actions)
663 {
664 accessibilityActions_ = actions;
665 }
666
ResetAccessibilityActions()667 void AccessibilityProperty::ResetAccessibilityActions()
668 {
669 accessibilityActions_ = std::nullopt;
670 }
671
HasAccessibilityActions()672 bool AccessibilityProperty::HasAccessibilityActions()
673 {
674 return accessibilityActions_.has_value();
675 }
676
GetAccessibilityActions() const677 uint32_t AccessibilityProperty::GetAccessibilityActions() const
678 {
679 return accessibilityActions_.value_or(0);
680 }
681
SetAccessibilityRole(const std::string & role)682 void AccessibilityProperty::SetAccessibilityRole(const std::string& role)
683 {
684 accessibilityRole_ = role;
685 }
686
ResetAccessibilityRole()687 void AccessibilityProperty::ResetAccessibilityRole()
688 {
689 accessibilityRole_ = std::nullopt;
690 }
691
HasAccessibilityRole()692 bool AccessibilityProperty::HasAccessibilityRole()
693 {
694 return accessibilityRole_.has_value();
695 }
696
GetAccessibilityRole() const697 std::string AccessibilityProperty::GetAccessibilityRole() const
698 {
699 return accessibilityRole_.value_or("");
700 }
701
SetAccessibilityCustomRole(const std::string & role)702 void AccessibilityProperty::SetAccessibilityCustomRole(const std::string& role)
703 {
704 accessibilityCustomRole_ = role;
705 }
706
ResetAccessibilityCustomRole()707 void AccessibilityProperty::ResetAccessibilityCustomRole()
708 {
709 accessibilityCustomRole_ = "";
710 }
711
HasAccessibilityCustomRole()712 bool AccessibilityProperty::HasAccessibilityCustomRole()
713 {
714 return accessibilityCustomRole_.has_value();
715 }
716
GetAccessibilityCustomRole() const717 std::string AccessibilityProperty::GetAccessibilityCustomRole() const
718 {
719 return accessibilityCustomRole_.value_or("");
720 }
721
SetAccessibilitySamePage(const std::string & pageMode)722 void AccessibilityProperty::SetAccessibilitySamePage(const std::string& pageMode)
723 {
724 accessibilityUseSamePage_ = pageMode;
725 }
726
HasAccessibilitySamePage()727 bool AccessibilityProperty::HasAccessibilitySamePage()
728 {
729 return accessibilityUseSamePage_.has_value();
730 }
731
GetAccessibilitySamePage()732 std::string AccessibilityProperty::GetAccessibilitySamePage()
733 {
734 return accessibilityUseSamePage_.value_or("");
735 }
736
SetActions(const ActionsImpl & actionsImpl)737 void AccessibilityProperty::SetActions(const ActionsImpl& actionsImpl)
738 {
739 actionsImpl_ = actionsImpl;
740 }
741
ActionsDefined(uint32_t action)742 bool AccessibilityProperty::ActionsDefined(uint32_t action)
743 {
744 if (!HasAccessibilityActions()) {
745 return false;
746 }
747 if (!actionsImpl_) {
748 return false;
749 }
750 int result = GetAccessibilityActions() & action;
751 return result != 0;
752 }
753
SetUserDisabled(const bool & isDisabled)754 void AccessibilityProperty::SetUserDisabled(const bool& isDisabled)
755 {
756 isDisabled_ = isDisabled;
757 }
758
HasUserDisabled()759 bool AccessibilityProperty::HasUserDisabled()
760 {
761 return isDisabled_.has_value();
762 }
763
IsUserDisabled()764 bool AccessibilityProperty::IsUserDisabled()
765 {
766 return isDisabled_.value_or(false);
767 }
768
SetUserSelected(const bool & isSelected)769 void AccessibilityProperty::SetUserSelected(const bool& isSelected)
770 {
771 isSelected_ = isSelected;
772 }
773
HasUserSelected()774 bool AccessibilityProperty::HasUserSelected()
775 {
776 return isSelected_.has_value();
777 }
778
IsUserSelected()779 bool AccessibilityProperty::IsUserSelected()
780 {
781 return isSelected_.value_or(false);
782 }
783
ResetUserSelected()784 void AccessibilityProperty::ResetUserSelected()
785 {
786 isSelected_.reset();
787 }
788
SetUserCheckedType(const int32_t & checkedType)789 void AccessibilityProperty::SetUserCheckedType(const int32_t& checkedType)
790 {
791 checkedType_ = checkedType;
792 }
793
HasUserCheckedType()794 bool AccessibilityProperty::HasUserCheckedType()
795 {
796 return checkedType_.has_value();
797 }
798
GetUserCheckedType()799 int32_t AccessibilityProperty::GetUserCheckedType()
800 {
801 return checkedType_.value_or(0);
802 }
803
ResetUserCheckedType()804 void AccessibilityProperty::ResetUserCheckedType()
805 {
806 checkedType_.reset();
807 }
808
SetUserCheckable(const bool & checkable)809 void AccessibilityProperty::SetUserCheckable(const bool& checkable)
810 {
811 isUserCheckable_ = checkable;
812 }
813
HasUserCheckable()814 bool AccessibilityProperty::HasUserCheckable()
815 {
816 return isUserCheckable_.has_value();
817 }
818
IsUserCheckable()819 bool AccessibilityProperty::IsUserCheckable()
820 {
821 return isUserCheckable_.value_or(false);
822 }
823
ResetUserCheckable()824 void AccessibilityProperty::ResetUserCheckable()
825 {
826 isUserCheckable_.reset();
827 }
828
SetUserScrollTriggerable(const bool & triggerable)829 void AccessibilityProperty::SetUserScrollTriggerable(const bool& triggerable)
830 {
831 isUserScrollTriggerable_ = triggerable;
832 }
833
HasUserScrollTriggerable()834 bool AccessibilityProperty::HasUserScrollTriggerable()
835 {
836 return isUserScrollTriggerable_.has_value();
837 }
838
IsUserScrollTriggerable()839 bool AccessibilityProperty::IsUserScrollTriggerable()
840 {
841 return isUserScrollTriggerable_.value_or(true);
842 }
843
ResetUserScrollTriggerable()844 void AccessibilityProperty::ResetUserScrollTriggerable()
845 {
846 isUserScrollTriggerable_ = true;
847 }
848
SetUserMinValue(const int32_t & minValue)849 void AccessibilityProperty::SetUserMinValue(const int32_t& minValue)
850 {
851 minValue_ = minValue;
852 }
853
HasUserMinValue()854 bool AccessibilityProperty::HasUserMinValue()
855 {
856 return minValue_.has_value();
857 }
858
GetUserMinValue()859 int32_t AccessibilityProperty::GetUserMinValue()
860 {
861 return minValue_.value_or(-1);
862 }
863
SetUserMaxValue(const int32_t & maxValue)864 void AccessibilityProperty::SetUserMaxValue(const int32_t& maxValue)
865 {
866 maxValue_ = maxValue;
867 }
868
HasUserMaxValue()869 bool AccessibilityProperty::HasUserMaxValue()
870 {
871 return maxValue_.has_value();
872 }
873
GetUserMaxValue()874 int32_t AccessibilityProperty::GetUserMaxValue()
875 {
876 return maxValue_.value_or(-1);
877 }
878
SetUserCurrentValue(const int32_t & currentValue)879 void AccessibilityProperty::SetUserCurrentValue(const int32_t& currentValue)
880 {
881 currentValue_ = currentValue;
882 }
883
HasUserCurrentValue()884 bool AccessibilityProperty::HasUserCurrentValue()
885 {
886 return currentValue_.has_value();
887 }
888
GetUserCurrentValue()889 int32_t AccessibilityProperty::GetUserCurrentValue()
890 {
891 return currentValue_.value_or(-1);
892 }
893
SetUserRangeMinValue(const int32_t rangeMinValue)894 void AccessibilityProperty::SetUserRangeMinValue(const int32_t rangeMinValue)
895 {
896 rangeMinValue_ = rangeMinValue;
897 }
898
HasUserRangeMinValue() const899 bool AccessibilityProperty::HasUserRangeMinValue() const
900 {
901 return rangeMinValue_.has_value();
902 }
903
GetUserRangeMinValue() const904 int32_t AccessibilityProperty::GetUserRangeMinValue() const
905 {
906 return rangeMinValue_.value_or(-1);
907 }
908
SetUserRangeMaxValue(const int32_t rangeMaxValue)909 void AccessibilityProperty::SetUserRangeMaxValue(const int32_t rangeMaxValue)
910 {
911 rangeMaxValue_ = rangeMaxValue;
912 }
913
HasUserRangeMaxValue() const914 bool AccessibilityProperty::HasUserRangeMaxValue() const
915 {
916 return rangeMaxValue_.has_value();
917 }
918
GetUserRangeMaxValue() const919 int32_t AccessibilityProperty::GetUserRangeMaxValue() const
920 {
921 return rangeMaxValue_.value_or(-1);
922 }
923
SetUserRangeCurrentValue(const int32_t rangeCurrentValue)924 void AccessibilityProperty::SetUserRangeCurrentValue(const int32_t rangeCurrentValue)
925 {
926 rangeCurrentValue_ = rangeCurrentValue;
927 }
928
HasUserRangeCurrentValue() const929 bool AccessibilityProperty::HasUserRangeCurrentValue() const
930 {
931 return rangeCurrentValue_.has_value();
932 }
933
GetUserRangeCurrentValue() const934 int32_t AccessibilityProperty::GetUserRangeCurrentValue() const
935 {
936 return rangeCurrentValue_.value_or(-1);
937 }
938
SetUserTextValue(const std::string & textValue)939 void AccessibilityProperty::SetUserTextValue(const std::string& textValue)
940 {
941 textValue_ = textValue;
942 }
943
HasUserTextValue()944 bool AccessibilityProperty::HasUserTextValue()
945 {
946 return textValue_.has_value();
947 }
948
GetUserTextValue()949 std::string AccessibilityProperty::GetUserTextValue()
950 {
951 return textValue_.value_or("");
952 }
953
GetAccessibilityFocusState() const954 bool AccessibilityProperty::GetAccessibilityFocusState() const
955 {
956 return isAccessibilityFocused_;
957 }
958
SetAccessibilityFocusState(bool state)959 void AccessibilityProperty::SetAccessibilityFocusState(bool state)
960 {
961 isAccessibilityFocused_ = state;
962 }
963
SetAccessibilityGroup(bool accessibilityGroup)964 void AccessibilityProperty::SetAccessibilityGroup(bool accessibilityGroup)
965 {
966 if (accessibilityGroup == accessibilityGroup_) {
967 return;
968 }
969 accessibilityGroup_ = accessibilityGroup;
970 NotifyComponentChangeEvent(AccessibilityEventType::ELEMENT_INFO_CHANGE);
971 }
972
SetAccessibilityTextPreferred(bool accessibilityTextPreferred)973 void AccessibilityProperty::SetAccessibilityTextPreferred(bool accessibilityTextPreferred)
974 {
975 accessibilityTextPreferred_ = accessibilityTextPreferred;
976 }
977
SetChildTreeId(int32_t childTreeId)978 void AccessibilityProperty::SetChildTreeId(int32_t childTreeId)
979 {
980 childTreeId_ = childTreeId;
981 }
982
SetChildWindowId(int32_t childWindowId)983 void AccessibilityProperty::SetChildWindowId(int32_t childWindowId)
984 {
985 childWindowId_ = childWindowId;
986 }
987
SetAccessibilityText(const std::string & text)988 void AccessibilityProperty::SetAccessibilityText(const std::string& text)
989 {
990 if (text == accessibilityText_.value_or("")) {
991 return;
992 }
993 accessibilityText_ = text;
994 NotifyComponentChangeEvent(AccessibilityEventType::TEXT_CHANGE);
995 }
996
SetAccessibilityNextFocusInspectorKey(const std::string & accessibilityNextFocusInspectorKey)997 void AccessibilityProperty::SetAccessibilityNextFocusInspectorKey(const std::string& accessibilityNextFocusInspectorKey)
998 {
999 if (accessibilityNextFocusInspectorKey == accessibilityNextFocusInspectorKey_.value_or("")) {
1000 return;
1001 }
1002 accessibilityNextFocusInspectorKey_ = accessibilityNextFocusInspectorKey;
1003 NotifyComponentChangeEvent(AccessibilityEventType::ELEMENT_INFO_CHANGE);
1004 }
1005
SetAccessibilityTextWithEvent(const std::string & text)1006 void AccessibilityProperty::SetAccessibilityTextWithEvent(const std::string& text)
1007 {
1008 if (text == accessibilityText_.value_or("")) {
1009 return;
1010 }
1011 accessibilityText_ = text;
1012 NotifyComponentChangeEvent(AccessibilityEventType::TEXT_CHANGE);
1013 }
1014
SetAccessibilityTextHint(const std::string & text)1015 void AccessibilityProperty::SetAccessibilityTextHint(const std::string& text)
1016 {
1017 textTypeHint_ = text;
1018 }
1019
SetAccessibilityDescription(const std::string & accessibilityDescription)1020 void AccessibilityProperty::SetAccessibilityDescription(const std::string& accessibilityDescription)
1021 {
1022 if (accessibilityDescription == accessibilityDescription_.value_or("")) {
1023 return;
1024 }
1025 accessibilityDescription_ = accessibilityDescription;
1026 NotifyComponentChangeEvent(AccessibilityEventType::TEXT_CHANGE);
1027 }
1028
SetAccessibilityDescriptionWithEvent(const std::string & accessibilityDescription)1029 void AccessibilityProperty::SetAccessibilityDescriptionWithEvent(const std::string& accessibilityDescription)
1030 {
1031 if (accessibilityDescription == accessibilityDescription_.value_or("")) {
1032 return;
1033 }
1034 accessibilityDescription_ = accessibilityDescription;
1035 NotifyComponentChangeEvent(AccessibilityEventType::TEXT_CHANGE);
1036 }
1037
IsAccessibilityGroup() const1038 bool AccessibilityProperty::IsAccessibilityGroup() const
1039 {
1040 return accessibilityGroup_;
1041 }
1042
IsAccessibilityTextPreferred() const1043 bool AccessibilityProperty::IsAccessibilityTextPreferred() const
1044 {
1045 return accessibilityTextPreferred_;
1046 }
1047
GetChildTreeId() const1048 int32_t AccessibilityProperty::GetChildTreeId() const
1049 {
1050 return childTreeId_;
1051 }
1052
GetChildWindowId() const1053 int32_t AccessibilityProperty::GetChildWindowId() const
1054 {
1055 return childWindowId_;
1056 }
1057
SaveAccessibilityVirtualNode(const RefPtr<UINode> & node)1058 void AccessibilityProperty::SaveAccessibilityVirtualNode(const RefPtr<UINode>& node)
1059 {
1060 accessibilityVirtualNode_ = node;
1061 }
1062
GetAccessibilityVirtualNode() const1063 const RefPtr<UINode>& AccessibilityProperty::GetAccessibilityVirtualNode() const
1064 {
1065 return accessibilityVirtualNode_;
1066 }
1067
HasAccessibilityVirtualNode() const1068 bool AccessibilityProperty::HasAccessibilityVirtualNode() const
1069 {
1070 return accessibilityVirtualNode_ != nullptr;
1071 }
1072
GetAccessibilityDescription() const1073 std::string AccessibilityProperty::GetAccessibilityDescription() const
1074 {
1075 return accessibilityDescription_.value_or("");
1076 }
1077
GetTextType() const1078 std::string AccessibilityProperty::GetTextType() const
1079 {
1080 return textTypeHint_.value_or("");
1081 }
1082
SetAccessibilityLevel(const std::string & accessibilityLevel)1083 void AccessibilityProperty::SetAccessibilityLevel(const std::string& accessibilityLevel)
1084 {
1085 auto backupLevel = accessibilityLevel_.value_or("");
1086
1087 if (accessibilityLevel == Level::YES_STR ||
1088 accessibilityLevel == Level::NO_STR ||
1089 accessibilityLevel == Level::NO_HIDE_DESCENDANTS) {
1090 accessibilityLevel_ = accessibilityLevel;
1091 } else {
1092 accessibilityLevel_ = Level::AUTO;
1093 }
1094
1095 if (backupLevel != accessibilityLevel_.value_or("")) {
1096 NotifyComponentChangeEvent(AccessibilityEventType::ELEMENT_INFO_CHANGE);
1097 }
1098 }
1099
SetRelatedElementInfoCallback(const GetRelatedElementInfoImpl & getRelatedElementInfoImpl)1100 void AccessibilityProperty::SetRelatedElementInfoCallback(const GetRelatedElementInfoImpl& getRelatedElementInfoImpl)
1101 {
1102 getRelatedElementInfoImpl_ = getRelatedElementInfoImpl;
1103 }
1104
GetAllExtraElementInfo(Accessibility::ExtraElementInfo & extraElementInfo)1105 void AccessibilityProperty::GetAllExtraElementInfo(Accessibility::ExtraElementInfo& extraElementInfo)
1106 {
1107 if (getRelatedElementInfoImpl_) {
1108 getRelatedElementInfoImpl_(extraElementInfo);
1109 }
1110 GetExtraElementInfo(extraElementInfo);
1111 }
1112
OnAccessibilityFocusCallback(bool isFocus)1113 void AccessibilityProperty::OnAccessibilityFocusCallback(bool isFocus)
1114 {
1115 if (onAccessibilityFocusCallbackImpl_) {
1116 onAccessibilityFocusCallbackImpl_(isFocus);
1117 }
1118 if (onUserAccessibilityFocusCallbackImpl_) {
1119 onUserAccessibilityFocusCallbackImpl_(isFocus);
1120 }
1121 }
1122
SetGetWindowScenePosition(const GetWindowScenePositionImpl & getWindowScenePositionImpl)1123 void AccessibilityProperty::SetGetWindowScenePosition(const GetWindowScenePositionImpl& getWindowScenePositionImpl)
1124 {
1125 getWindowScenePositionImpl_ = getWindowScenePositionImpl;
1126 }
1127
GetWindowScenePosition(WindowSceneInfo & windowSceneInfo)1128 void AccessibilityProperty::GetWindowScenePosition(WindowSceneInfo& windowSceneInfo)
1129 {
1130 if (getWindowScenePositionImpl_ == nullptr) {
1131 return;
1132 }
1133 getWindowScenePositionImpl_(windowSceneInfo);
1134 }
1135
SetOnAccessibilityFocusCallback(const OnAccessibilityFocusCallbackImpl & onAccessibilityFocusCallbackImpl)1136 void AccessibilityProperty::SetOnAccessibilityFocusCallback(
1137 const OnAccessibilityFocusCallbackImpl& onAccessibilityFocusCallbackImpl)
1138 {
1139 onAccessibilityFocusCallbackImpl_ = onAccessibilityFocusCallbackImpl;
1140 }
1141
SetUserOnAccessibilityFocusCallback(const OnAccessibilityFocusCallbackImpl & onUserAccessibilityFocusCallbackImpl)1142 void AccessibilityProperty::SetUserOnAccessibilityFocusCallback(
1143 const OnAccessibilityFocusCallbackImpl& onUserAccessibilityFocusCallbackImpl)
1144 {
1145 onUserAccessibilityFocusCallbackImpl_ = onUserAccessibilityFocusCallbackImpl;
1146 }
1147
ResetUserOnAccessibilityFocusCallback()1148 void AccessibilityProperty::ResetUserOnAccessibilityFocusCallback()
1149 {
1150 onUserAccessibilityFocusCallbackImpl_ = nullptr;
1151 }
1152
ActActionClearSelection()1153 bool AccessibilityProperty::ActActionClearSelection()
1154 {
1155 if (actionClearSelectionImpl_) {
1156 actionClearSelectionImpl_();
1157 return true;
1158 }
1159 return false;
1160 }
1161
SetActionClearSelection(const ActionClearSelectionImpl & actionClearSelectionImpl)1162 void AccessibilityProperty::SetActionClearSelection(const ActionClearSelectionImpl& actionClearSelectionImpl)
1163 {
1164 actionClearSelectionImpl_ = actionClearSelectionImpl;
1165 }
1166
ActActionSelect()1167 bool AccessibilityProperty::ActActionSelect()
1168 {
1169 if (actionSelectImpl_) {
1170 actionSelectImpl_();
1171 return true;
1172 }
1173 return false;
1174 }
1175
SetActionSelect(const ActionSelectImpl & actionSelectImpl)1176 void AccessibilityProperty::SetActionSelect(const ActionSelectImpl& actionSelectImpl)
1177 {
1178 actionSelectImpl_ = actionSelectImpl;
1179 }
1180
ActActionClick()1181 bool AccessibilityProperty::ActActionClick()
1182 {
1183 if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CLICK))) {
1184 actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CLICK));
1185 return true;
1186 }
1187 if (actionClickImpl_) {
1188 actionClickImpl_();
1189 return true;
1190 }
1191 return false;
1192 }
1193
SetActionClick(const ActionClickImpl & actionClickImpl)1194 void AccessibilityProperty::SetActionClick(const ActionClickImpl& actionClickImpl)
1195 {
1196 actionClickImpl_ = actionClickImpl;
1197 }
1198
ActActionLongClick()1199 bool AccessibilityProperty::ActActionLongClick()
1200 {
1201 if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_LONG_CLICK))) {
1202 actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_LONG_CLICK));
1203 return true;
1204 }
1205 if (actionLongClickImpl_) {
1206 actionLongClickImpl_();
1207 return true;
1208 }
1209 return false;
1210 }
1211
SetActionLongClick(const ActionLongClickImpl & actionLongClickImpl)1212 void AccessibilityProperty::SetActionLongClick(const ActionLongClickImpl& actionLongClickImpl)
1213 {
1214 actionLongClickImpl_ = actionLongClickImpl;
1215 }
1216
ActActionPaste()1217 bool AccessibilityProperty::ActActionPaste()
1218 {
1219 if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_PASTE))) {
1220 actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_PASTE));
1221 return true;
1222 }
1223 if (actionPasteImpl_) {
1224 actionPasteImpl_();
1225 return true;
1226 }
1227 return false;
1228 }
1229
SetActionPaste(const ActionPasteImpl & actionPasteImpl)1230 void AccessibilityProperty::SetActionPaste(const ActionPasteImpl& actionPasteImpl)
1231 {
1232 actionPasteImpl_ = actionPasteImpl;
1233 }
1234
ActActionCut()1235 bool AccessibilityProperty::ActActionCut()
1236 {
1237 if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CUT))) {
1238 actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CUT));
1239 return true;
1240 }
1241 if (actionCutImpl_) {
1242 actionCutImpl_();
1243 return true;
1244 }
1245 return false;
1246 }
1247
SetActionCut(const ActionCutImpl & actionCutImpl)1248 void AccessibilityProperty::SetActionCut(const ActionCutImpl& actionCutImpl)
1249 {
1250 actionCutImpl_ = actionCutImpl;
1251 }
1252
ActActionCopy()1253 bool AccessibilityProperty::ActActionCopy()
1254 {
1255 if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_COPY))) {
1256 actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_COPY));
1257 return true;
1258 }
1259 if (actionCopyImpl_) {
1260 actionCopyImpl_();
1261 return true;
1262 }
1263 return false;
1264 }
1265
IsAccessibilityHoverPriority() const1266 bool AccessibilityProperty::IsAccessibilityHoverPriority() const
1267 {
1268 return accessibilityHoverPriority_;
1269 }
1270
SetAccessibilityHoverPriority(bool hoverPriority)1271 void AccessibilityProperty::SetAccessibilityHoverPriority(bool hoverPriority)
1272 {
1273 // true means node consume barrierfree hover event prior to brothers
1274 accessibilityHoverPriority_ = hoverPriority;
1275 }
1276
SetFocusDrawLevel(int32_t drawLevel)1277 void AccessibilityProperty::SetFocusDrawLevel(int32_t drawLevel)
1278 {
1279 if (static_cast<FocusDrawLevel>(drawLevel) == focusDrawLevel_) {
1280 return;
1281 }
1282 focusDrawLevel_ = static_cast<FocusDrawLevel>(drawLevel);
1283 }
1284
GetFocusDrawLevel()1285 int32_t AccessibilityProperty::GetFocusDrawLevel()
1286 {
1287 return static_cast<int32_t>(focusDrawLevel_);
1288 }
1289
SetAccessibilityZIndex(const int32_t & accessibilityZIndex)1290 void AccessibilityProperty::SetAccessibilityZIndex(const int32_t& accessibilityZIndex)
1291 {
1292 accessibilityZIndex_ = accessibilityZIndex;
1293 }
1294
GetAccessibilityZIndex() const1295 int32_t AccessibilityProperty::GetAccessibilityZIndex() const
1296 {
1297 return accessibilityZIndex_;
1298 }
1299
OnAccessibilityDetachFromMainTree()1300 void AccessibilityProperty::OnAccessibilityDetachFromMainTree()
1301 {
1302 if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled()) {
1303 auto frameNode = host_.Upgrade();
1304 CHECK_NULL_VOID(frameNode);
1305 auto context = frameNode->GetContextRefPtr();
1306 CHECK_NULL_VOID(context);
1307 auto accessibilityManager = context->GetAccessibilityManager();
1308 CHECK_NULL_VOID(accessibilityManager);
1309 accessibilityManager->OnAccessbibilityDetachFromMainTree(frameNode);
1310 }
1311 }
1312 } // namespace OHOS::Ace::NG
1313