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