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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ACCESSIBILITY_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ACCESSIBILITY_PROPERTY_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <unordered_set>
22 
23 #include "base/memory/ace_type.h"
24 #include "interfaces/native/native_type.h"
25 #include "core/accessibility/accessibility_utils.h"
26 #include "core/components_ng/base/inspector_filter.h"
27 #include "core/components_ng/base/ui_node.h"
28 
29 namespace OHOS::Accessibility {
30 class ExtraElementInfo;
31 }
32 
33 namespace OHOS::Ace::NG {
34 using ActionNoParam = std::function<void()>;
35 using ActionSetTextImpl = std::function<void(const std::string&)>;
36 using ActionScrollForwardImpl = ActionNoParam;
37 using ActionScrollForwardWithParamImpl = std::function<void(AccessibilityScrollType scrollType)>;;
38 using ActionScrollBackwardImpl = ActionNoParam;
39 using ActionScrollBackwardWithParamImpl = std::function<void(AccessibilityScrollType scrollType)>;;
40 using ActionSetSelectionImpl = std::function<void(int32_t start, int32_t end, bool isForward)>;
41 using ActionCopyImpl = ActionNoParam;
42 using ActionCutImpl = ActionNoParam;
43 using ActionPasteImpl = ActionNoParam;
44 using ActionSelectImpl = ActionNoParam;
45 using ActionClearSelectionImpl = ActionNoParam;
46 using ActionMoveTextImpl = std::function<void(int32_t moveUnit, bool forward)>;
47 using ActionSetCursorIndexImpl = std::function<void(int32_t index)>;
48 using ActionExecSubComponentImpl = std::function<bool(int32_t spanId)>;
49 using ActionGetCursorIndexImpl = std::function<int32_t(void)>;
50 using ActionClickImpl = ActionNoParam;
51 using ActionLongClickImpl = ActionNoParam;
52 using ActionsImpl = std::function<void((uint32_t actionType))>;
53 using GetRelatedElementInfoImpl = std::function<void(Accessibility::ExtraElementInfo& extraElementInfo)>;
54 using OnAccessibilityFocusCallbackImpl = std::function<void((bool isFocus))>;
55 
56 class FrameNode;
57 using AccessibilityHoverTestPath = std::vector<RefPtr<FrameNode>>;
58 
59 class ACE_FORCE_EXPORT AccessibilityProperty : public virtual AceType {
60     DECLARE_ACE_TYPE(AccessibilityProperty, AceType);
61 
62 public:
63     AccessibilityProperty() = default;
64 
65     ~AccessibilityProperty() override = default;
66 
67     virtual std::string GetText() const;
68 
69     virtual std::string GetGroupText(bool forceGetChildren = false) const;
70 
71     virtual std::string GetGroupPreferAccessibilityText(bool forceGetChildren = false) const;
72 
SetText(const std::string & text)73     virtual void SetText(const std::string& text)
74     {
75         propText_ = text;
76     }
77 
IsCheckable()78     virtual bool IsCheckable() const
79     {
80         return false;
81     }
82 
IsChecked()83     virtual bool IsChecked() const
84     {
85         return false;
86     }
87 
IsSelected()88     virtual bool IsSelected() const
89     {
90         return false;
91     }
92 
IsPassword()93     virtual bool IsPassword() const
94     {
95         return false;
96     }
97 
IsEditable()98     virtual bool IsEditable() const
99     {
100         return false;
101     }
102 
IsMultiLine()103     virtual bool IsMultiLine() const
104     {
105         return false;
106     }
107 
IsDeletable()108     virtual bool IsDeletable() const
109     {
110         return false;
111     }
112 
IsHint()113     virtual bool IsHint() const
114     {
115         return false;
116     }
117 
IsScrollable()118     virtual bool IsScrollable() const
119     {
120         return false;
121     }
122 
GetCurrentIndex()123     virtual int32_t GetCurrentIndex() const
124     {
125         return -1;
126     }
127 
GetBeginIndex()128     virtual int32_t GetBeginIndex() const
129     {
130         return -1;
131     }
132 
GetEndIndex()133     virtual int32_t GetEndIndex() const
134     {
135         return -1;
136     }
137 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)138     virtual void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const
139     {
140         json->PutFixedAttr("scrollable", IsScrollable(), filter, FIXED_ATTR_SCROLLABLE);
141         json->PutExtAttr("accessibilityLevel", GetAccessibilityLevel().c_str(), filter);
142         json->PutExtAttr("accessibilityGroup", IsAccessibilityGroup(), filter);
143         json->PutExtAttr("accessibilityVirtualNode", HasAccessibilityVirtualNode(), filter);
144         json->PutExtAttr("accessibilityText", GetAccessibilityText().c_str(), filter);
145         json->PutExtAttr("accessibilityTextHint", GetTextType().c_str(), filter);
146         json->PutExtAttr("accessibilityDescription", GetAccessibilityDescription().c_str(), filter);
147     }
148 
FromJson(const std::unique_ptr<JsonValue> & json)149     virtual void FromJson(const std::unique_ptr<JsonValue>& json) {}
150 
HasRange()151     virtual bool HasRange() const
152     {
153         return false;
154     }
155 
HasSubComponent()156     virtual bool HasSubComponent() const
157     {
158         return false;
159     }
160 
GetSubComponentInfo(std::vector<SubComponentInfo> & subComponentInfos)161     virtual void GetSubComponentInfo(std::vector<SubComponentInfo>& subComponentInfos) const {}
162 
GetAccessibilityValue()163     virtual AccessibilityValue GetAccessibilityValue() const
164     {
165         return AccessibilityValue();
166     }
167 
SetHost(const WeakPtr<FrameNode> & host)168     void SetHost(const WeakPtr<FrameNode>& host)
169     {
170         host_ = host;
171     }
172 
GetHintText()173     virtual std::string GetHintText() const
174     {
175         return "";
176     }
177 
GetTextLengthLimit()178     virtual int32_t GetTextLengthLimit() const
179     {
180         return -1;
181     }
182 
GetCollectionInfo()183     virtual AceCollectionInfo GetCollectionInfo() const
184     {
185         return AceCollectionInfo();
186     }
187 
GetCollectionItemInfo()188     virtual AceCollectionItemInfo GetCollectionItemInfo() const
189     {
190         return AceCollectionItemInfo();
191     }
192 
GetErrorText()193     virtual std::string GetErrorText() const
194     {
195         return "";
196     }
197 
GetTextSelectionStart()198     virtual int32_t GetTextSelectionStart() const
199     {
200         return 0;
201     }
202 
GetTextSelectionEnd()203     virtual int32_t GetTextSelectionEnd() const
204     {
205         return 0;
206     }
207 
GetTextInputType()208     virtual AceTextCategory GetTextInputType() const
209     {
210         return AceTextCategory::INPUT_TYPE_DEFAULT;
211     }
212 
GetCollectionItemCounts()213     virtual int32_t GetCollectionItemCounts() const
214     {
215         return 0;
216     }
217 
GetContentInvalid()218     virtual bool GetContentInvalid() const
219     {
220         return true;
221     }
222 
223     virtual float GetScrollOffSet() const;
224 
AddSupportAction(AceAction action)225     void AddSupportAction(AceAction action)
226     {
227         supportActions_ |= (1UL << static_cast<uint32_t>(action));
228     }
229 
230     std::unordered_set<AceAction> GetSupportAction() const;
231 
ResetSupportAction()232     void ResetSupportAction()
233     {
234         supportActions_ = 0;
235         SetSpecificSupportAction();
236     };
237 
SetActionSetText(const ActionSetTextImpl & actionSetTextImpl)238     void SetActionSetText(const ActionSetTextImpl& actionSetTextImpl)
239     {
240         actionSetTextImpl_ = actionSetTextImpl;
241     }
242 
ActActionSetText(const std::string & text)243     bool ActActionSetText(const std::string& text)
244     {
245         if (actionSetTextImpl_) {
246             actionSetTextImpl_(text);
247             return true;
248         }
249         return false;
250     }
251 
SetActionSetSelection(const ActionSetSelectionImpl & actionSetSelection)252     void SetActionSetSelection(const ActionSetSelectionImpl& actionSetSelection)
253     {
254         actionSetSelectionImpl_ = actionSetSelection;
255     }
256 
257     bool ActActionSetSelection(int32_t start, int32_t end, bool isForward = false)
258     {
259         if (actionSetSelectionImpl_) {
260             actionSetSelectionImpl_(start, end, isForward);
261             return true;
262         }
263         return false;
264     }
265 
SetActionSetIndex(const ActionSetCursorIndexImpl & actionSetCursorIndexImpl)266     void SetActionSetIndex(const ActionSetCursorIndexImpl& actionSetCursorIndexImpl)
267     {
268         actionSetCursorIndexImpl_ = actionSetCursorIndexImpl;
269     }
270 
ActActionSetIndex(int32_t index)271     bool ActActionSetIndex(int32_t index)
272     {
273         if (actionSetCursorIndexImpl_) {
274             actionSetCursorIndexImpl_(index);
275             return true;
276         }
277         return false;
278     }
279 
SetActionExecSubComponent(const ActionExecSubComponentImpl & actionExecSubComponentImpl)280     void SetActionExecSubComponent(const ActionExecSubComponentImpl& actionExecSubComponentImpl)
281     {
282         actionExecSubComponentImpl_ = actionExecSubComponentImpl;
283     }
284 
ActActionExecSubComponent(int32_t spanId)285     bool ActActionExecSubComponent(int32_t spanId)
286     {
287         if (actionExecSubComponentImpl_) {
288             return actionExecSubComponentImpl_(spanId);
289         }
290         return false;
291     }
292 
SetActionGetIndex(const ActionGetCursorIndexImpl & actionGetCursorIndexImpl)293     void SetActionGetIndex(const ActionGetCursorIndexImpl& actionGetCursorIndexImpl)
294     {
295         actionGetCursorIndexImpl_ = actionGetCursorIndexImpl;
296     }
297 
ActActionGetIndex()298     int32_t ActActionGetIndex()
299     {
300         if (actionGetCursorIndexImpl_) {
301             return actionGetCursorIndexImpl_();
302         }
303         return -1;
304     }
305 
SetActionMoveText(const ActionMoveTextImpl & actionMoveText)306     void SetActionMoveText(const ActionMoveTextImpl& actionMoveText)
307     {
308         actionMoveTextImpl_ = actionMoveText;
309     }
310 
ActActionMoveText(int32_t moveUnit,bool forward)311     bool ActActionMoveText(int32_t moveUnit, bool forward)
312     {
313         if (actionMoveTextImpl_) {
314             actionMoveTextImpl_(moveUnit, forward);
315             return true;
316         }
317         return false;
318     }
319 
SetActionScrollForward(const ActionScrollForwardImpl & actionScrollForwardImpl)320     void SetActionScrollForward(const ActionScrollForwardImpl& actionScrollForwardImpl)
321     {
322         actionScrollForwardImpl_ = actionScrollForwardImpl;
323     }
324 
SetActionScrollForward(const ActionScrollForwardWithParamImpl & actionScrollForwardImpl)325     void SetActionScrollForward(const ActionScrollForwardWithParamImpl& actionScrollForwardImpl)
326     {
327         actionScrollForwardWithParamImpl_ = actionScrollForwardImpl;
328     }
329 
330     bool ActActionScrollForward(AccessibilityScrollType scrollType = AccessibilityScrollType::SCROLL_DEFAULT)
331     {
332         if (actionScrollForwardWithParamImpl_ == nullptr) {
333             scrollType = AccessibilityScrollType::SCROLL_DEFAULT;
334         }
335 
336         if ((scrollType == AccessibilityScrollType::SCROLL_DEFAULT) && (actionScrollForwardImpl_)) {
337             actionScrollForwardImpl_();
338             return true;
339         }
340 
341         if (actionScrollForwardWithParamImpl_) {
342             actionScrollForwardWithParamImpl_(scrollType);
343             return true;
344         }
345         return false;
346     }
347 
SetActionScrollBackward(const ActionScrollBackwardImpl & actionScrollBackwardImpl)348     void SetActionScrollBackward(const ActionScrollBackwardImpl& actionScrollBackwardImpl)
349     {
350         actionScrollBackwardImpl_ = actionScrollBackwardImpl;
351     }
352 
SetActionScrollBackward(const ActionScrollBackwardWithParamImpl & actionScrollBackwardImpl)353     void SetActionScrollBackward(const ActionScrollBackwardWithParamImpl& actionScrollBackwardImpl)
354     {
355         actionScrollBackwardWithParamImpl_ = actionScrollBackwardImpl;
356     }
357 
358     bool ActActionScrollBackward(AccessibilityScrollType scrollType = AccessibilityScrollType::SCROLL_DEFAULT)
359     {
360         if (actionScrollBackwardWithParamImpl_ == nullptr) {
361             scrollType = AccessibilityScrollType::SCROLL_DEFAULT;
362         }
363 
364         if ((scrollType == AccessibilityScrollType::SCROLL_DEFAULT) && (actionScrollBackwardImpl_)) {
365             actionScrollBackwardImpl_();
366             return true;
367         }
368 
369         if (actionScrollBackwardWithParamImpl_) {
370             actionScrollBackwardWithParamImpl_(scrollType);
371             return true;
372         }
373         return false;
374     }
375 
SetActionCopy(const ActionCopyImpl & actionCopyImpl)376     void SetActionCopy(const ActionCopyImpl& actionCopyImpl)
377     {
378         actionCopyImpl_ = actionCopyImpl;
379     }
380 
ActActionCopy()381     bool ActActionCopy()
382     {
383         if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_COPY))) {
384             actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_COPY));
385             return true;
386         }
387         if (actionCopyImpl_) {
388             actionCopyImpl_();
389             return true;
390         }
391         return false;
392     }
393 
SetActionCut(const ActionCutImpl & actionCutImpl)394     void SetActionCut(const ActionCutImpl& actionCutImpl)
395     {
396         actionCutImpl_ = actionCutImpl;
397     }
398 
ActActionCut()399     bool ActActionCut()
400     {
401         if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CUT))) {
402             actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CUT));
403             return true;
404         }
405         if (actionCutImpl_) {
406             actionCutImpl_();
407             return true;
408         }
409         return false;
410     }
411 
SetActionPaste(const ActionPasteImpl & actionPasteImpl)412     void SetActionPaste(const ActionPasteImpl& actionPasteImpl)
413     {
414         actionPasteImpl_ = actionPasteImpl;
415     }
416 
ActActionPaste()417     bool ActActionPaste()
418     {
419         if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_PASTE))) {
420             actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_PASTE));
421             return true;
422         }
423         if (actionPasteImpl_) {
424             actionPasteImpl_();
425             return true;
426         }
427         return false;
428     }
429 
SetActionLongClick(const ActionLongClickImpl & actionLongClickImpl)430     void SetActionLongClick(const ActionLongClickImpl& actionLongClickImpl)
431     {
432         actionLongClickImpl_ = actionLongClickImpl;
433     }
434 
ActActionLongClick()435     bool ActActionLongClick()
436     {
437         if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_LONG_CLICK))) {
438             actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_LONG_CLICK));
439             return true;
440         }
441         if (actionLongClickImpl_) {
442             actionLongClickImpl_();
443             return true;
444         }
445         return false;
446     }
447 
SetActionClick(const ActionClickImpl & actionClickImpl)448     void SetActionClick(const ActionClickImpl& actionClickImpl)
449     {
450         actionClickImpl_ = actionClickImpl;
451     }
452 
ActActionClick()453     bool ActActionClick()
454     {
455         if (ActionsDefined(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CLICK))) {
456             actionsImpl_(static_cast<uint32_t>(ARKUI_ACCESSIBILITY_ACTION_CLICK));
457             return true;
458         }
459         if (actionClickImpl_) {
460             actionClickImpl_();
461             return true;
462         }
463         return false;
464     }
465 
SetActionSelect(const ActionSelectImpl & actionSelectImpl)466     void SetActionSelect(const ActionSelectImpl& actionSelectImpl)
467     {
468         actionSelectImpl_ = actionSelectImpl;
469     }
470 
ActActionSelect()471     bool ActActionSelect()
472     {
473         if (actionSelectImpl_) {
474             actionSelectImpl_();
475             return true;
476         }
477         return false;
478     }
479 
SetActionClearSelection(const ActionClearSelectionImpl & actionClearSelectionImpl)480     void SetActionClearSelection(const ActionClearSelectionImpl& actionClearSelectionImpl)
481     {
482         actionClearSelectionImpl_ = actionClearSelectionImpl;
483     }
484 
ActActionClearSelection()485     bool ActActionClearSelection()
486     {
487         if (actionClearSelectionImpl_) {
488             actionClearSelectionImpl_();
489             return true;
490         }
491         return false;
492     }
493 
SetOnAccessibilityFocusCallback(const OnAccessibilityFocusCallbackImpl & onAccessibilityFocusCallbackImpl)494     void SetOnAccessibilityFocusCallback(const OnAccessibilityFocusCallbackImpl& onAccessibilityFocusCallbackImpl)
495     {
496         onAccessibilityFocusCallbackImpl_ = onAccessibilityFocusCallbackImpl;
497     }
498 
OnAccessibilityFocusCallback(bool isFocus)499     void OnAccessibilityFocusCallback(bool isFocus)
500     {
501         if (onAccessibilityFocusCallbackImpl_) {
502             onAccessibilityFocusCallbackImpl_(isFocus);
503         }
504     }
505 
GetAccessibilityFocusState()506     bool GetAccessibilityFocusState() const
507     {
508         return isAccessibilityFocused_;
509     }
510 
SetAccessibilityFocusState(bool state)511     void SetAccessibilityFocusState(bool state)
512     {
513         isAccessibilityFocused_ = state;
514     }
515 
516     void SetAccessibilityGroup(bool accessibilityGroup);
517 
SetChildTreeId(int32_t childTreeId)518     void SetChildTreeId(int32_t childTreeId)
519     {
520         childTreeId_ = childTreeId;
521     }
522 
523     void SetAccessibilityTextPreferred(bool accessibilityTextPreferred);
524 
SetChildWindowId(int32_t childWindowId)525     void SetChildWindowId(int32_t childWindowId)
526     {
527         childWindowId_ = childWindowId;
528     }
529 
530     void SetAccessibilityText(const std::string& text);
531 
532     void SetAccessibilityTextWithEvent(const std::string& text);
533 
SetAccessibilityTextHint(const std::string & text)534     void SetAccessibilityTextHint(const std::string& text)
535     {
536         textTypeHint_ = text;
537     }
538 
539     void SetAccessibilityDescription(const std::string& accessibilityDescription);
540 
541     void SetAccessibilityDescriptionWithEvent(const std::string& accessibilityDescription);
542 
IsAccessibilityGroup()543     bool IsAccessibilityGroup() const
544     {
545         return accessibilityGroup_;
546     }
547 
GetChildTreeId()548     int32_t GetChildTreeId() const
549     {
550         return childTreeId_;
551     }
552 
553     bool IsAccessibilityTextPreferred() const;
554 
GetChildWindowId()555     int32_t GetChildWindowId() const
556     {
557         return childWindowId_;
558     }
559 
560     void NotifyComponentChangeEvent(AccessibilityEventType eventType);
561 
SaveAccessibilityVirtualNode(const RefPtr<UINode> & node)562     void SaveAccessibilityVirtualNode(const RefPtr<UINode>& node)
563     {
564         accessibilityVirtualNode_ = node;
565     }
566 
GetAccessibilityVirtualNode()567     RefPtr<UINode> GetAccessibilityVirtualNode()
568     {
569         return accessibilityVirtualNode_;
570     }
571 
GetAccessibilityVirtualNodePtr()572     NG::UINode* GetAccessibilityVirtualNodePtr()
573     {
574         return Referenced::RawPtr(accessibilityVirtualNode_);
575     }
576 
HasAccessibilityVirtualNode()577     bool HasAccessibilityVirtualNode() const
578     {
579         return accessibilityVirtualNode_ != nullptr;
580     }
581 
GetAccessibilityText()582     virtual std::string GetAccessibilityText() const
583     {
584         return accessibilityText_.value_or("");
585     }
586 
GetAccessibilityDescription()587     std::string GetAccessibilityDescription() const
588     {
589         return accessibilityDescription_.value_or("");
590     }
591 
GetTextType()592     std::string GetTextType() const
593     {
594         return textTypeHint_.value_or("");
595     }
596 
597     class Level {
598     public:
599         inline static const std::string AUTO = "auto";
600         inline static const std::string YES_STR = "yes";
601         inline static const std::string NO_STR = "no";
602         inline static const std::string NO_HIDE_DESCENDANTS = "no-hide-descendants";
603     };
604 
GetAccessibilityLevel()605     virtual std::string GetAccessibilityLevel() const
606     {
607         if (!accessibilityLevel_.has_value()) {
608             return Level::AUTO;
609         }
610         return accessibilityLevel_.value();
611     }
612 
613     void SetAccessibilityLevel(const std::string& accessibilityLevel);
614 
615     struct HoverTestDebugTraceInfo {
616         std::vector<std::unique_ptr<JsonValue>> trace;
617     };
618 
619     /*
620     * Get path from root to node which hit the hoverPoint.
621     * return: path contains nodes whose border cover the hoverPoint.
622     */
623     static AccessibilityHoverTestPath HoverTest(
624         const PointF& point,
625         const RefPtr<FrameNode>& root,
626         std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo
627     );
628 
629     /*
630     * Judge whether a node can be accessibility focused.
631     * return: if node is accessibility focusable, return true.
632     * param: {node} should be not-null
633     */
634     static bool IsAccessibilityFocusable(const RefPtr<FrameNode>& node);
635 
636     /*
637     * param: {node}, {info} should be not-null
638     */
639     static bool IsAccessibilityFocusableDebug(const RefPtr<FrameNode>& node, std::unique_ptr<JsonValue>& info);
640 
641     /*
642     * Judge whether a node's tag is default accessibility focusable.
643     * return: if a node's tag is default accessibility focusable, return true.
644     * param: {tag} should be not-null
645     */
646     static bool IsAccessibilityFocusableTag(const std::string &tag);
647 
648     static bool IsTagInCrossProcessComponent(const std::string& tag);
649 
650     static bool IsTagInModalDialog(const RefPtr<FrameNode>& node);
651 
652     static bool HitAccessibilityHoverPriority(const RefPtr<FrameNode>& node);
653 
GetExtraElementInfo(Accessibility::ExtraElementInfo & extraElementInfo)654     virtual void GetExtraElementInfo(Accessibility::ExtraElementInfo& extraElementInfo) {}
655 
SetRelatedElementInfoCallback(const GetRelatedElementInfoImpl & getRelatedElementInfoImpl)656     void SetRelatedElementInfoCallback(const GetRelatedElementInfoImpl& getRelatedElementInfoImpl)
657     {
658         getRelatedElementInfoImpl_ = getRelatedElementInfoImpl;
659     }
660 
GetAllExtraElementInfo(Accessibility::ExtraElementInfo & extraElementInfo)661     void GetAllExtraElementInfo(Accessibility::ExtraElementInfo& extraElementInfo)
662     {
663         if (getRelatedElementInfoImpl_) {
664             getRelatedElementInfoImpl_(extraElementInfo);
665         }
666         GetExtraElementInfo(extraElementInfo);
667     }
668 
669     void SetAccessibilityActions(uint32_t actions);
670     void ResetAccessibilityActions();
671     bool HasAccessibilityActions();
672     uint32_t GetAccessibilityActions() const;
673 
674     void SetAccessibilityRole(const std::string& role);
675     void ResetAccessibilityRole();
676     bool HasAccessibilityRole();
677     std::string GetAccessibilityRole() const;
678 
679     void SetActions(const ActionsImpl& actionsImpl);
680     bool ActionsDefined(uint32_t action);
681 
682     void SetUserDisabled(const bool& isDisabled);
683     bool HasUserDisabled();
684     bool IsUserDisabled();
685 
686     void SetUserSelected(const bool& isSelected);
687     bool HasUserSelected();
688     bool IsUserSelected();
689     void ResetUserSelected();
690 
691     void SetUserCheckedType(const int32_t& checkedType);
692     bool HasUserCheckedType();
693     int32_t GetUserCheckedType();
694     void ResetUserCheckedType();
695 
696     void SetUserMinValue(const int32_t& minValue);
697     bool HasUserMinValue();
698     int32_t GetUserMinValue();
699 
700     void SetUserMaxValue(const int32_t& maxValue);
701     bool HasUserMaxValue();
702     int32_t GetUserMaxValue();
703 
704     void SetUserCurrentValue(const int32_t& currentValue);
705     bool HasUserCurrentValue();
706     int32_t GetUserCurrentValue();
707 
708     void SetUserTextValue(const std::string& textValue);
709     bool HasUserTextValue();
710     std::string GetUserTextValue();
711 
712     void SetUserCheckable(const bool& checkable);
713     bool HasUserCheckable();
714     bool IsUserCheckable();
715     void ResetUserCheckable();
716 
717     virtual bool IsAccessibilityHoverPriority() const;
718     void SetAccessibilityHoverPriority(bool hoverPriority);
719 
720 private:
721     // node should be not-null
722     static bool HoverTestRecursive(
723         const PointF& parentPoint,
724         const RefPtr<FrameNode>& node,
725         AccessibilityHoverTestPath& path,
726         std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo,
727         bool& ancestorGroupFlag
728     );
729 
730     struct RecursiveParam {
731         bool hitTarget;
732         bool ancestorGroupFlag;
733     };
734 
735     static bool ProcessHoverTestRecursive(const PointF& noOffsetPoint, const RefPtr<FrameNode>& node,
736         AccessibilityHoverTestPath& path, std::unique_ptr<HoverTestDebugTraceInfo>& debugInfo,
737         RecursiveParam recursiveParam);
738 
739     static std::unique_ptr<JsonValue> CreateNodeSearchInfo(const RefPtr<FrameNode>& node, const PointF& parentPoint,
740         bool& ancestorGroupFlag);
741 
742     /*
743     * Get whether node and its children should be searched.
744     * return: first: node itself should be searched.
745     *         second: children of node should be searched.
746     * param: {node} should be not-null
747     */
748     static std::tuple<bool, bool, bool> GetSearchStrategy(const RefPtr<FrameNode>& node, bool& ancestorGroupFlag);
749 
750     void GetGroupTextRecursive(bool forceGetChildren, std::string& text, bool preferAccessibilityText) const;
751 
752     bool HasAccessibilityTextOrDescription() const;
753 
754     bool HasAction() const;
755 
756 protected:
SetSpecificSupportAction()757     virtual void SetSpecificSupportAction() {}
758     std::optional<std::string> propText_;
759     WeakPtr<FrameNode> host_;
760     uint64_t supportActions_ = 0;
761     ActionSetTextImpl actionSetTextImpl_;
762     ActionSetSelectionImpl actionSetSelectionImpl_;
763     ActionMoveTextImpl actionMoveTextImpl_;
764     ActionScrollForwardImpl actionScrollForwardImpl_;
765     ActionScrollForwardWithParamImpl actionScrollForwardWithParamImpl_;
766     ActionScrollBackwardImpl actionScrollBackwardImpl_;
767     ActionScrollBackwardWithParamImpl actionScrollBackwardWithParamImpl_;
768     ActionCopyImpl actionCopyImpl_;
769     ActionCutImpl actionCutImpl_;
770     ActionPasteImpl actionPasteImpl_;
771     ActionSelectImpl actionSelectImpl_;
772     ActionClearSelectionImpl actionClearSelectionImpl_;
773     ActionSetCursorIndexImpl actionSetCursorIndexImpl_;
774     ActionExecSubComponentImpl actionExecSubComponentImpl_;
775     ActionGetCursorIndexImpl actionGetCursorIndexImpl_;
776     ActionClickImpl actionClickImpl_;
777     ActionLongClickImpl actionLongClickImpl_;
778     ActionsImpl actionsImpl_;
779     GetRelatedElementInfoImpl getRelatedElementInfoImpl_;
780     OnAccessibilityFocusCallbackImpl onAccessibilityFocusCallbackImpl_;
781     bool isAccessibilityFocused_ = false;
782     bool accessibilityGroup_ = false;
783     bool accessibilityHoverPriority_ = false;
784     bool accessibilityTextPreferred_ = false;
785     int32_t childTreeId_ = -1;
786     int32_t childWindowId_ = 0;
787     RefPtr<UINode> accessibilityVirtualNode_;
788     std::optional<std::string> accessibilityText_;
789     std::optional<std::string> accessibilityDescription_;
790     std::optional<std::string> accessibilityLevel_;
791     std::optional<std::string> textTypeHint_;
792     std::optional<uint32_t> accessibilityActions_;
793     std::optional<std::string> accessibilityRole_;
794     ACE_DISALLOW_COPY_AND_MOVE(AccessibilityProperty);
795 
796     std::optional<bool> isDisabled_;
797     std::optional<bool> isSelected_;
798     std::optional<int32_t> checkedType_;
799     std::optional<bool> isUserCheckable_;
800 
801     std::optional<int32_t> minValue_;
802     std::optional<int32_t> maxValue_;
803     std::optional<int32_t> currentValue_;
804     std::optional<std::string> textValue_;
805 };
806 } // namespace OHOS::Ace::NG
807 
808 #endif
809