1 /* 2 * Copyright (c) 2021-2022 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_CORE_ACCESSIBILITY_ACCESSIBILITY_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_NODE_H 18 19 #include <functional> 20 #include <list> 21 #include <string> 22 #include <unordered_map> 23 #include <unordered_set> 24 #include <vector> 25 26 #include "base/geometry/axis.h" 27 #include "base/geometry/matrix4.h" 28 #include "base/geometry/rect.h" 29 #include "base/memory/ace_type.h" 30 #include "base/utils/macros.h" 31 #include "core/accessibility/accessibility_utils.h" 32 #include "core/event/ace_event_handler.h" 33 34 namespace OHOS::Ace { 35 36 struct PositionInfo { 37 double width = 0.0; 38 double height = 0.0; 39 double left = 0.0; 40 double top = 0.0; 41 }; 42 43 using ActionClickImpl = std::function<void()>; 44 using ActionLongClickImpl = std::function<void()>; 45 using ActionSetTextImpl = std::function<void(const std::string&)>; 46 using ActionScrollForwardImpl = std::function<bool()>; 47 using ActionScrollBackwardImpl = std::function<bool()>; 48 using ActionFocusImpl = std::function<void()>; 49 using ActionUpdateIdsImpl = std::function<void()>; 50 using FocusChangeCallback = std::function<void(const std::string&)>; 51 using ActionAccessibilityFocusImpl = std::function<void(bool)>; 52 53 using NodeId = int32_t; 54 // If no insertion location is specified, new child will be added to the end of children list by default. 55 constexpr int32_t DEFAULT_INDEX = -1; 56 constexpr uint64_t DEFAULT_ACTIONS = std::numeric_limits<uint64_t>::max(); 57 58 class ACE_EXPORT AccessibilityNode : public AceType { 59 DECLARE_ACE_TYPE(AccessibilityNode, AceType); 60 61 public: 62 using ChartValue = std::unordered_map<std::string, std::vector<std::pair<std::string, double>>>; 63 64 AccessibilityNode(NodeId nodeId, const std::string& nodeName); 65 ~AccessibilityNode() override = default; 66 67 // node event action 68 void SetActionClickImpl(const ActionClickImpl& actionClickImpl); 69 bool ActionClick(); 70 void SetActionLongClickImpl(const ActionLongClickImpl& actionLongClickImpl); 71 bool ActionLongClick(); 72 void SetActionSetTextImpl(const ActionSetTextImpl& actionSetTextImpl); 73 bool ActionSetText(const std::string& text); 74 void SetActionScrollForward(const ActionScrollForwardImpl& actionScrollForwardImpl); 75 bool ActionScrollForward(); 76 void SetActionScrollBackward(const ActionScrollBackwardImpl& actionScrollBackwardImpl); 77 bool ActionScrollBackward(); 78 void SetActionFocusImpl(const ActionFocusImpl& actionFocusImpl); 79 bool ActionFocus(); 80 void SetActionUpdateIdsImpl(const ActionUpdateIdsImpl& actionUpdateIdsImpl); 81 void ActionUpdateIds(); 82 void SetActionAccessibilityFocusImpl(const ActionAccessibilityFocusImpl& actionAccessibilityFocusImpl); 83 bool ActionAccessibilityFocus(bool isFocus); 84 85 // node base 86 void SetAttr(const std::vector<std::pair<std::string, std::string>>& attrs); 87 // used for inspector node in PC preview 88 void SetStyle(const std::vector<std::pair<std::string, std::string>>& styles); 89 void AddEvent(int32_t pageId, const std::vector<std::string>& events); 90 void AddNode(const RefPtr<AccessibilityNode>& node, int32_t slot = DEFAULT_INDEX); 91 void RemoveNode(const RefPtr<AccessibilityNode>& node); 92 void Mount(int32_t slot); 93 void AddOffsetForChildren(const Offset& offset); 94 SetWindowId(uint32_t windowId)95 void SetWindowId(uint32_t windowId) 96 { 97 windowId_ = windowId; 98 } 99 GetWindowId()100 uint32_t GetWindowId() const 101 { 102 return windowId_; 103 } 104 SetIsRootNode(bool isRootNode)105 void SetIsRootNode(bool isRootNode) 106 { 107 isRootNode_ = isRootNode; 108 } 109 IsRootNode()110 bool IsRootNode() const 111 { 112 return isRootNode_; 113 } 114 ResetChildList(std::list<RefPtr<AccessibilityNode>> & children)115 void ResetChildList(std::list<RefPtr<AccessibilityNode>>& children) 116 { 117 children_.clear(); 118 children_.swap(children); 119 } 120 GetChildList()121 const std::list<RefPtr<AccessibilityNode>> GetChildList() const 122 { 123 return children_; 124 } 125 GetParentId()126 NodeId GetParentId() const 127 { 128 auto parentNode = parentNode_.Upgrade(); 129 return parentNode ? parentNode->GetNodeId() : -1; 130 } 131 GetParentNode()132 RefPtr<AccessibilityNode> GetParentNode() const 133 { 134 return parentNode_.Upgrade(); 135 } 136 137 void SetParentNode(const RefPtr<AccessibilityNode>& parentNode); 138 GetTag()139 const std::string& GetTag() const 140 { 141 return tag_; 142 } 143 SetTag(const std::string & tag)144 void SetTag(const std::string& tag) 145 { 146 tag_ = tag; 147 } 148 GetPageId()149 int32_t GetPageId() const 150 { 151 return pageId_; 152 } 153 SetPageId(int32_t pageId)154 void SetPageId(int32_t pageId) 155 { 156 pageId_ = pageId; 157 } 158 159 void SetPositionInfo(const PositionInfo& positionInfo); 160 GetAccessibilityEventMarker()161 const EventMarker& GetAccessibilityEventMarker() const 162 { 163 return onAccessibilityEventId_; 164 } 165 GetClickEventMarker()166 const EventMarker& GetClickEventMarker() const 167 { 168 return onClickId_; 169 } 170 GetLongPressEventMarker()171 const EventMarker& GetLongPressEventMarker() const 172 { 173 return onLongPressId_; 174 } 175 GetSetTextEventMarker()176 const EventMarker& GetSetTextEventMarker() const 177 { 178 return onSetTextId_; 179 } 180 GetFocusEventMarker()181 const EventMarker& GetFocusEventMarker() const 182 { 183 return onFocusId_; 184 } 185 186 void SetFocusChangeEventMarker(const EventMarker& eventId); 187 188 void OnFocusChange(bool isFocus); 189 GetBlurEventMarker()190 const EventMarker& GetBlurEventMarker() const 191 { 192 return onBlurId_; 193 } 194 195 // node attr need to barrierfree GetNodeId()196 NodeId GetNodeId() const 197 { 198 return nodeId_; 199 } 200 GetText()201 const std::string& GetText() const 202 { 203 return text_; 204 } 205 SetText(const std::string & text)206 void SetText(const std::string& text) 207 { 208 text_ = text; 209 } 210 GetHintText()211 const std::string& GetHintText() const 212 { 213 return hintText_; 214 } 215 SetHintText(const std::string & hintText)216 void SetHintText(const std::string& hintText) 217 { 218 hintText_ = hintText; 219 } 220 GetChildIds()221 const std::vector<int32_t>& GetChildIds() const 222 { 223 return childIds_; 224 } 225 SetChildIds(const std::vector<int32_t> & ids)226 void SetChildIds(const std::vector<int32_t>& ids) 227 { 228 childIds_ = ids; 229 } 230 GetWidth()231 double GetWidth() const 232 { 233 return rect_.Width(); 234 } 235 SetWidth(double width)236 void SetWidth(double width) 237 { 238 rect_.SetWidth(width); 239 } 240 GetHeight()241 double GetHeight() const 242 { 243 return rect_.Height(); 244 } 245 SetHeight(double height)246 void SetHeight(double height) 247 { 248 rect_.SetHeight(height); 249 } 250 GetLeft()251 double GetLeft() const 252 { 253 return rect_.Left(); 254 } 255 SetLeft(double left)256 void SetLeft(double left) 257 { 258 return rect_.SetLeft(left); 259 } 260 GetTop()261 double GetTop() const 262 { 263 return rect_.Top(); 264 } 265 SetTop(double top)266 void SetTop(double top) 267 { 268 return rect_.SetTop(top); 269 } 270 GetCheckedState()271 bool GetCheckedState() const 272 { 273 return isChecked_; 274 } 275 SetCheckedState(bool state)276 void SetCheckedState(bool state) 277 { 278 isChecked_ = state; 279 } 280 GetEnabledState()281 bool GetEnabledState() const 282 { 283 return isEnabled_; 284 } 285 SetEnabledState(bool state)286 void SetEnabledState(bool state) 287 { 288 isEnabled_ = state; 289 } 290 GetEditable()291 bool GetEditable() const 292 { 293 return isEditable_; 294 } 295 SetEditable(bool editable)296 void SetEditable(bool editable) 297 { 298 isEditable_ = editable; 299 } 300 GetFocusedState()301 bool GetFocusedState() const 302 { 303 return isFocused_; 304 } 305 SetFocusedState(bool state)306 void SetFocusedState(bool state) 307 { 308 isFocused_ = state; 309 OnFocusChange(isFocused_); 310 } 311 GetAccessibilityFocusedState()312 bool GetAccessibilityFocusedState() const 313 { 314 return isAccessibilityFocused_; 315 } 316 SetAccessibilityFocusedState(bool state)317 void SetAccessibilityFocusedState(bool state) 318 { 319 isAccessibilityFocused_ = state; 320 } 321 GetSelectedState()322 bool GetSelectedState() const 323 { 324 return isSelected_; 325 } 326 SetSelectedState(bool state)327 void SetSelectedState(bool state) 328 { 329 isSelected_ = state; 330 } 331 GetCheckableState()332 bool GetCheckableState() const 333 { 334 return isCheckable_; 335 } 336 SetCheckableState(bool state)337 void SetCheckableState(bool state) 338 { 339 isCheckable_ = state; 340 } 341 GetClickableState()342 bool GetClickableState() const 343 { 344 return isClickable_; 345 } 346 SetClickableState(bool state)347 void SetClickableState(bool state) 348 { 349 isClickable_ = state; 350 SetSupportAction(AceAction::ACTION_CLICK, state); 351 } 352 GetFocusableState()353 bool GetFocusableState() const 354 { 355 return isFocusable_; 356 } 357 SetFocusableState(bool state)358 void SetFocusableState(bool state) 359 { 360 isFocusable_ = state; 361 } 362 GetScrollableState()363 bool GetScrollableState() const 364 { 365 return isScrollable_; 366 } 367 SetScrollableState(bool state)368 void SetScrollableState(bool state) 369 { 370 isScrollable_ = state; 371 } 372 GetLongClickableState()373 bool GetLongClickableState() const 374 { 375 return isLongClickable_; 376 } 377 SetLongClickableState(bool state)378 void SetLongClickableState(bool state) 379 { 380 isLongClickable_ = state; 381 SetSupportAction(AceAction::ACTION_LONG_CLICK, state); 382 } 383 GetIsMultiLine()384 bool GetIsMultiLine() const 385 { 386 return isMultiLine_; 387 } 388 SetIsMultiLine(bool multiLine)389 void SetIsMultiLine(bool multiLine) 390 { 391 isMultiLine_ = multiLine; 392 } 393 GetIsPassword()394 bool GetIsPassword() const 395 { 396 return isPassword_; 397 } 398 SetIsPassword(bool isPassword)399 void SetIsPassword(bool isPassword) 400 { 401 isPassword_ = isPassword; 402 } 403 404 std::unordered_set<AceAction> GetSupportAction(uint64_t enableActions = DEFAULT_ACTIONS) const; 405 AddSupportAction(AceAction action)406 void AddSupportAction(AceAction action) 407 { 408 supportActions_ |= (1UL << static_cast<uint32_t>(action)); 409 } 410 SetSupportAction(AceAction action,bool isEnable)411 void SetSupportAction(AceAction action, bool isEnable) 412 { 413 isEnable ? supportActions_ |= (1UL << static_cast<uint32_t>(action)) 414 : supportActions_ &= (~(0UL)) ^ (1UL << static_cast<uint32_t>(action)); 415 } 416 GetAccessibilityLabel()417 const std::string& GetAccessibilityLabel() const 418 { 419 return accessibilityLabel_; 420 } 421 SetAccessibilityLabel(const std::string & label)422 void SetAccessibilityLabel(const std::string& label) 423 { 424 accessibilityLabel_ = label; 425 } 426 GetAccessibilityHint()427 const std::string& GetAccessibilityHint() const 428 { 429 return accessibilityHint_; 430 } 431 SetAccessibilityHint(const std::string & hint)432 void SetAccessibilityHint(const std::string& hint) 433 { 434 accessibilityHint_ = hint; 435 } 436 GetImportantForAccessibility()437 const std::string& GetImportantForAccessibility() const 438 { 439 return importantForAccessibility_; 440 } 441 SetImportantForAccessibility(const std::string & importance)442 void SetImportantForAccessibility(const std::string& importance) 443 { 444 importantForAccessibility_ = importance; 445 } 446 GetMaxTextLength()447 size_t GetMaxTextLength() const 448 { 449 return maxTextLength_; 450 } 451 SetMaxTextLength(size_t length)452 void SetMaxTextLength(size_t length) 453 { 454 maxTextLength_ = length; 455 } 456 GetTextSelectionStart()457 int32_t GetTextSelectionStart() const 458 { 459 return textSelectionStart_; 460 } 461 SetTextSelectionStart(int32_t start)462 void SetTextSelectionStart(int32_t start) 463 { 464 textSelectionStart_ = start; 465 } 466 GetTextSelectionEnd()467 int32_t GetTextSelectionEnd() const 468 { 469 return textSelectionEnd_; 470 } 471 SetTextSelectionEnd(int32_t end)472 void SetTextSelectionEnd(int32_t end) 473 { 474 textSelectionEnd_ = end; 475 } 476 GetErrorText()477 const std::string& GetErrorText() const 478 { 479 return errorText_; 480 } 481 SetErrorText(const std::string & errorText)482 void SetErrorText(const std::string& errorText) 483 { 484 errorText_ = errorText; 485 } 486 GetJsComponentId()487 const std::string& GetJsComponentId() const 488 { 489 return jsComponentId_; 490 } 491 SetJsComponentId(const std::string & jsComponentId)492 void SetJsComponentId(const std::string& jsComponentId) 493 { 494 jsComponentId_ = jsComponentId; 495 } 496 GetAccessible()497 bool GetAccessible() const 498 { 499 return accessible_; 500 } 501 SetAccessible(bool accessible)502 void SetAccessible(bool accessible) 503 { 504 accessible_ = accessible; 505 } 506 GetAccessibilityValue()507 AccessibilityValue GetAccessibilityValue() const 508 { 509 return accessibilityValue_; 510 } 511 512 void SetAccessibilityValue(double cur, double min = 0.0, double max = 0.0) 513 { 514 accessibilityValue_.current = cur; 515 accessibilityValue_.min = min; 516 accessibilityValue_.max = max; 517 } 518 GetChartValue()519 const std::unique_ptr<ChartValue>& GetChartValue() const 520 { 521 return chartValue_; 522 } 523 PutChartValue(const std::string & groupName,const std::vector<std::pair<std::string,double>> & values)524 void PutChartValue(const std::string& groupName, const std::vector<std::pair<std::string, double>>& values) 525 { 526 if (!chartValue_) { 527 chartValue_ = std::make_unique<ChartValue>(); 528 } 529 530 auto result = chartValue_->try_emplace(groupName, values); 531 if (!result.second) { 532 result.first->second = values; 533 } 534 } 535 GetInputType()536 std::string GetInputType() const 537 { 538 return inputType_; 539 } 540 GetTextInputType()541 AceTextCategory GetTextInputType() const 542 { 543 return textInputType_; 544 } 545 SetTextInputType(AceTextCategory type)546 void SetTextInputType(AceTextCategory type) 547 { 548 textInputType_ = type; 549 } 550 GetCollectionInfo()551 const AceCollectionInfo& GetCollectionInfo() const 552 { 553 return collectionInfo_; 554 } 555 SetCollectionInfo(const AceCollectionInfo & collectionInfo)556 void SetCollectionInfo(const AceCollectionInfo& collectionInfo) 557 { 558 collectionInfo_ = collectionInfo; 559 } 560 GetCollectionItemInfo()561 const AceCollectionItemInfo& GetCollectionItemInfo() const 562 { 563 return collectionItemInfo_; 564 } 565 SetCollectionItemInfo(const AceCollectionItemInfo & collectionItemInfo)566 void SetCollectionItemInfo(const AceCollectionItemInfo& collectionItemInfo) 567 { 568 collectionItemInfo_ = collectionItemInfo; 569 } 570 GetShown()571 bool GetShown() const 572 { 573 return shown_; 574 } 575 GetVisible()576 bool GetVisible() const 577 { 578 return visible_; 579 } 580 SetVisible(bool visible)581 void SetVisible(bool visible) 582 { 583 visible_ = visible; 584 } 585 GetRect()586 const Rect& GetRect() const 587 { 588 return rect_; 589 } 590 SetRect(const Rect & rect)591 void SetRect(const Rect& rect) 592 { 593 isValidRect_ = rect.IsValid(); 594 if (isValidRect_) { 595 rect_ = rect; 596 } 597 } 598 GetGlobalRect()599 const Rect& GetGlobalRect() 600 { 601 return globalRect_; 602 } 603 SetGlobalRect(const Rect & rect)604 void SetGlobalRect(const Rect& rect) 605 { 606 globalRect_ = rect; 607 } 608 ClearRect()609 void ClearRect() 610 { 611 rect_ = Rect(0, 0, 0, 0); 612 } 613 IsValidRect()614 bool IsValidRect() const 615 { 616 return isValidRect_; 617 } 618 GetClicked()619 bool GetClicked() const 620 { 621 return isClicked_; 622 } 623 SetClicked(bool clicked)624 void SetClicked(bool clicked) 625 { 626 isClicked_ = clicked; 627 } 628 SetMarginSize(const Size & marginSize)629 void SetMarginSize(const Size& marginSize) 630 { 631 marginSize_ = marginSize; 632 } 633 GetMarginSize()634 Size GetMarginSize() const 635 { 636 return marginSize_; 637 } 638 GetAttrs()639 const std::vector<std::pair<std::string, std::string>>& GetAttrs() const 640 { 641 return attrs_; 642 } 643 GetStyles()644 const std::vector<std::pair<std::string, std::string>>& GetStyles() const 645 { 646 return styles_; 647 } 648 SetClipFlagToChild(bool clipFlag)649 void SetClipFlagToChild(bool clipFlag) 650 { 651 for (auto& child : children_) { 652 child->SetClipFlagToChild(clipFlag); 653 } 654 clipFlag_ = clipFlag; 655 } 656 GetClipFlag()657 bool GetClipFlag() 658 { 659 return clipFlag_; 660 } 661 GetListBeginIndex()662 size_t GetListBeginIndex() const 663 { 664 return listBeginIndex_; 665 } 666 SetListBeginIndex(const size_t & index)667 void SetListBeginIndex(const size_t& index) 668 { 669 listBeginIndex_ = index; 670 } 671 GetListEndIndex()672 size_t GetListEndIndex() const 673 { 674 return listEndIndex_; 675 } 676 SetListEndIndex(const size_t & index)677 void SetListEndIndex(const size_t& index) 678 { 679 listEndIndex_ = index; 680 } 681 GetListItemCounts()682 size_t GetListItemCounts() const 683 { 684 return listItemCounts_; 685 } 686 SetListItemCounts(const size_t & index)687 void SetListItemCounts(const size_t& index) 688 { 689 listItemCounts_ = index; 690 } 691 SetTransformToChild(Matrix4 matrix4)692 void SetTransformToChild(Matrix4 matrix4) 693 { 694 for (auto& child : children_) { 695 child->SetTransformToChild(matrix4); 696 } 697 matrix4_ = matrix4; 698 } 699 GetMatrix4()700 Matrix4 GetMatrix4() 701 { 702 return matrix4_; 703 } 704 GetRectWithTransform(const Rect & rect,Matrix4 & matrix4)705 Rect GetRectWithTransform(const Rect& rect, Matrix4& matrix4) 706 { 707 Point ltPoint = matrix4 * Point(rect.Left(), rect.Top()); 708 Point rtPoint = matrix4 * Point(rect.Right(), rect.Top()); 709 Point lbPoint = matrix4 * Point(rect.Left(), rect.Bottom()); 710 Point rbPoint = matrix4 * Point(rect.Right(), rect.Bottom()); 711 auto left = std::min(std::min(ltPoint.GetX(), rtPoint.GetX()), std::min(lbPoint.GetX(), rbPoint.GetX())); 712 auto right = std::max(std::max(ltPoint.GetX(), rtPoint.GetX()), std::max(lbPoint.GetX(), rbPoint.GetX())); 713 auto top = std::min(std::min(ltPoint.GetY(), rtPoint.GetY()), std::min(lbPoint.GetY(), rbPoint.GetY())); 714 auto bottom = std::max(std::max(ltPoint.GetY(), rtPoint.GetY()), std::max(lbPoint.GetY(), rbPoint.GetY())); 715 return Rect(left, top, right - left, bottom - top); 716 } 717 GetMatrix4Flag()718 bool GetMatrix4Flag() 719 { 720 if (matrix4_ == Matrix4()) { 721 return false; 722 } 723 return true; 724 } 725 726 #if defined(PREVIEW) 727 // used for inspector node in PC preview GetClearRectInfoFlag()728 bool GetClearRectInfoFlag() const 729 { 730 return isClearRectInfo_; 731 } 732 733 // used for inspector node in PC preview SetClearRectInfoFlag(bool isClearRectInfo)734 void SetClearRectInfoFlag(bool isClearRectInfo) 735 { 736 isClearRectInfo_ = isClearRectInfo; 737 } 738 739 // used for inspector node in PC preview SetScaleToChild(double scale)740 void SetScaleToChild(double scale) 741 { 742 for (auto& child : children_) { 743 child->SetScaleToChild(scale); 744 } 745 SetScale(scale); 746 } 747 748 // used for inspector node in PC preview SetScaleCenterToChild(Offset center)749 void SetScaleCenterToChild(Offset center) 750 { 751 for (auto& child : children_) { 752 child->SetScaleCenterToChild(center); 753 } 754 SetScaleCenter(center); 755 } 756 757 // used for inspector node in PC preview GetScale()758 double GetScale() 759 { 760 return scale_; 761 } 762 763 // used for inspector node in PC preview SetScale(double scale)764 void SetScale(double scale) 765 { 766 scale_ = scale; 767 SetIsAnimationNode(true); 768 } 769 770 // used for inspector node in PC preview SetScaleCenter(Offset center)771 void SetScaleCenter(Offset center) 772 { 773 scaleCenter_ = center; 774 } 775 776 // used for inspector node in PC preview GetScaleCenter()777 Offset GetScaleCenter() 778 { 779 return scaleCenter_; 780 } 781 782 // used for inspector node in PC preview SetTranslateOffsetToChild(const Offset & offset)783 void SetTranslateOffsetToChild(const Offset& offset) 784 { 785 for (auto& child : children_) { 786 child->SetTranslateOffsetToChild(offset); 787 } 788 SetTranslateOffset(offset); 789 } 790 SetTranslateOffset(const Offset & offset)791 void SetTranslateOffset(const Offset& offset) 792 { 793 translateOffset_ = offset; 794 SetIsAnimationNode(true); 795 } 796 GetTranslateOffset()797 Offset GetTranslateOffset() const 798 { 799 return translateOffset_; 800 } 801 802 // used for inspector node in PC preview SetRotateToChild(const double & angle,const RotateAxis & Axis)803 void SetRotateToChild(const double& angle, const RotateAxis& Axis) 804 { 805 for (auto& child : children_) { 806 child->SetRotateToChild(angle, Axis); 807 } 808 SetRotateAngle(angle); 809 SetRotateAxis(Axis); 810 } 811 SetRotateAngle(const double & angle)812 void SetRotateAngle(const double& angle) 813 { 814 rotateAngle_ = angle; 815 SetIsAnimationNode(true); 816 } 817 GetRotateAngle()818 double GetRotateAngle() const 819 { 820 return rotateAngle_; 821 } 822 SetRotateAxis(const RotateAxis & Axis)823 void SetRotateAxis(const RotateAxis& Axis) 824 { 825 rotateAxis_ = Axis; 826 } 827 GetRotateAxis(RotateAxis Axis)828 RotateAxis GetRotateAxis(RotateAxis Axis) const 829 { 830 return rotateAxis_; 831 } 832 IsAnimationNode()833 bool IsAnimationNode() const 834 { 835 return isAnimationNode_; 836 } 837 SetIsAnimationNode(bool IsAnimationNode)838 void SetIsAnimationNode(bool IsAnimationNode) 839 { 840 isAnimationNode_ = IsAnimationNode; 841 } 842 GetZIndex()843 int32_t GetZIndex() 844 { 845 return zIndex_; 846 } 847 SetZIndex(int32_t index)848 void SetZIndex(int32_t index) 849 { 850 zIndex_ = index; 851 } 852 853 // only panel has ZIndex,others components is default value 0 SetZIndexToChild(int32_t index)854 void SetZIndexToChild(int32_t index) 855 { 856 for (auto& child : children_) { 857 child->SetZIndexToChild(index); 858 } 859 SetZIndex(index); 860 } 861 UpdateRectWithChildRect()862 void UpdateRectWithChildRect() 863 { 864 if (children_.empty()) { 865 return; 866 } 867 SetRect(children_.front()->GetRect()); 868 } 869 #endif 870 871 protected: 872 // inner use, don't need to barrierfree 873 NodeId nodeId_ = -1; 874 int32_t pageId_ = -1; 875 uint32_t windowId_ = 0; 876 bool isRootNode_ = false; 877 std::string inputType_; 878 WeakPtr<AccessibilityNode> parentNode_; 879 std::list<RefPtr<AccessibilityNode>> children_; 880 ActionClickImpl actionClickImpl_; 881 ActionLongClickImpl actionLongClickImpl_; 882 ActionScrollForwardImpl actionScrollForwardImpl_; 883 ActionScrollBackwardImpl actionScrollBackwardImpl_; 884 ActionFocusImpl actionFocusImpl_; 885 ActionUpdateIdsImpl actionUpdateIdsImpl_; 886 ActionAccessibilityFocusImpl actionAccessibilityFocusIdsImpl_; 887 ActionSetTextImpl actionSetTextImpl_; 888 EventMarker onAccessibilityEventId_; 889 EventMarker onClickId_; 890 EventMarker onLongPressId_; 891 EventMarker onSetTextId_; 892 EventMarker onFocusId_; 893 EventMarker onBlurId_; 894 FocusChangeCallback focusChangeEventId_; 895 896 private: 897 void SetOperableInfo(); 898 899 // node attr need to barrierfree 900 size_t listBeginIndex_ = -1; 901 size_t listEndIndex_ = -1; 902 size_t listItemCounts_ = 0; 903 size_t maxTextLength_ = 0; 904 int32_t textSelectionStart_ = 0; 905 int32_t textSelectionEnd_ = 0; 906 std::string tag_; 907 std::string text_; 908 std::string hintText_; 909 std::string errorText_; 910 std::string jsComponentId_; 911 std::string accessibilityLabel_; 912 std::string accessibilityHint_; 913 std::string importantForAccessibility_; 914 AceTextCategory textInputType_ { AceTextCategory::INPUT_TYPE_DEFAULT }; 915 std::vector<int32_t> childIds_; 916 uint64_t supportActions_ = 0; 917 std::unique_ptr<ChartValue> chartValue_; 918 919 Rect globalRect_; 920 Rect rect_; 921 Size marginSize_; 922 union { 923 struct { 924 bool isValidRect_ : 1; 925 bool isChecked_ : 1; 926 bool isEditable_ : 1; 927 bool isEnabled_ : 1; 928 bool accessible_ : 1; 929 bool isFocused_ : 1; 930 bool isSelected_ : 1; 931 bool isCheckable_ : 1; 932 bool isClickable_ : 1; 933 bool isFocusable_ : 1; 934 bool isScrollable_ : 1; 935 bool isLongClickable_ : 1; 936 bool isMultiLine_ : 1; 937 bool isPassword_ : 1; 938 bool visible_ : 1; 939 bool shown_ : 1; 940 bool isClicked_ : 1; 941 bool isAccessibilityFocused_ : 1; 942 }; 943 uint64_t bits_ = 0; 944 }; 945 AccessibilityValue accessibilityValue_; 946 AceCollectionInfo collectionInfo_; 947 AceCollectionItemInfo collectionItemInfo_; 948 949 std::vector<std::pair<std::string, std::string>> attrs_; 950 std::vector<std::pair<std::string, std::string>> styles_; 951 bool clipFlag_ = false; 952 Matrix4 matrix4_; 953 #if defined(PREVIEW) 954 // used for inspector node in PC preview 955 bool isClearRectInfo_ = false; 956 // focus scale or translateScale for inspector node in PC preview 957 double scale_ = 1.0; 958 Offset scaleCenter_ { 0.0, 0.0 }; 959 Offset translateOffset_ { 0.0, 0.0 }; 960 double rotateAngle_ = 0.0; 961 RotateAxis rotateAxis_ = RotateAxis::AXIS_Z; 962 bool isAnimationNode_ = false; 963 int32_t zIndex_ = 0; 964 #endif 965 }; 966 967 } // namespace OHOS::Ace 968 969 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ACCESSIBILITY_ACCESSIBILITY_NODE_H 970