1 /* 2 * Copyright (c) 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_BRIDGE_COMMON_ACCESSIBILITY_JS_THIRD_ACCESSIBILITY_HOVER_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_ACCESSIBILITY_JS_THIRD_ACCESSIBILITY_HOVER_NG_H 18 19 #include <vector> 20 21 #include "accessibility_config.h" 22 #include "accessibility_element_operator.h" 23 #include "accessibility_event_info.h" 24 #include "accessibility_state_event.h" 25 #include "base/geometry/ng/point_t.h" 26 #include "base/memory/ace_type.h" 27 #include "base/utils/type_definition.h" 28 #include "core/accessibility/accessibility_manager.h" 29 #include "core/accessibility/accessibility_utils.h" 30 #include "core/event/ace_events.h" 31 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h" 32 33 namespace OHOS::Ace { 34 struct MouseEvent; 35 struct TouchEvent; 36 37 namespace Framework { 38 class JsAccessibilityManager; 39 struct ActionParam; 40 class JsThirdProviderInteractionOperation; 41 42 using namespace OHOS::Accessibility; 43 44 struct AccessibilityHoverForThirdState { 45 SourceType source = SourceType::NONE; 46 std::vector<int64_t> nodesHovering; 47 TimeStamp time; 48 bool idle = true; 49 bool thirdOperationIdle = true; 50 }; 51 52 struct AccessibilityHoverForThirdConfig { 53 int64_t hostElementId = -1; 54 NG::PointF point; 55 SourceType sourceType = SourceType::NONE; 56 NG::AccessibilityHoverEventType eventType = NG::AccessibilityHoverEventType::ENTER; 57 TimeStamp time = std::chrono::high_resolution_clock::now(); 58 RefPtr<NG::PipelineContext> context; 59 }; 60 61 using AccessibilityHoverTestPathForThird = std::vector<int64_t>; 62 63 class AccessibilityHoverManagerForThirdNG : public AceType { 64 DECLARE_ACE_TYPE(AccessibilityHoverManagerForThirdNG, AceType); 65 66 public: 67 void HandleAccessibilityHoverForThird( 68 const AccessibilityHoverForThirdConfig& config); 69 bool GetElementInfoForThird( 70 int64_t elementId, 71 AccessibilityElementInfo& info, 72 int64_t hostElementId); 73 74 bool ActThirdAccessibilityFocus( 75 int64_t elementId, 76 const AccessibilityElementInfo& nodeInfo, 77 const RefPtr<NG::FrameNode>& hostNode, 78 const RefPtr<NG::PipelineContext>& context, 79 bool isNeedClear); 80 void RegisterJsThirdProviderInteractionOperation( 81 int64_t hostElementId, 82 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator); 83 void DeregisterJsThirdProviderInteractionOperation(int64_t hostElementId); GetJsThirdProviderInteractionOperation(int64_t hostElementId)84 std::weak_ptr<JsThirdProviderInteractionOperation> &GetJsThirdProviderInteractionOperation( 85 int64_t hostElementId) 86 { 87 return jsThirdProviderOperator_[hostElementId]; 88 } 89 90 bool OnDumpChildInfoForThirdRecursive( 91 int64_t hostElementId, 92 const std::vector<std::string>& params, 93 std::vector<std::string>& info, 94 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager); 95 bool ClearThirdAccessibilityFocus(const RefPtr<NG::FrameNode>& hostNode); 96 97 private: 98 void HandleAccessibilityHoverForThirdInner( 99 const AccessibilityHoverForThirdConfig& config); 100 void ResetHoverForThirdState(); 101 AccessibilityHoverTestPathForThird HoverPathForThird( 102 const int64_t hostElementId, 103 const NG::PointF& point, 104 AccessibilityElementInfo& rootInfo); 105 bool HoverPathForThirdRecursive( 106 const int64_t hostElementId, 107 const NG::PointF& hoverPoint, 108 const AccessibilityElementInfo& nodeInfo, 109 AccessibilityHoverTestPathForThird& path); 110 std::pair<bool, bool> GetSearchStrategyForThird( 111 const AccessibilityElementInfo& nodeInfo); 112 bool IsAccessibilityFocusable(const AccessibilityElementInfo& nodeInfo); 113 bool HasAccessibilityTextOrDescription(const AccessibilityElementInfo& nodeInfo); 114 void UpdateSearchStrategyByHitTestModeStr( 115 std::string& hitTestMode, 116 bool& shouldSearchSelf, 117 bool& shouldSearchChildren); 118 void DumpPropertyForThird( 119 int64_t elementId, 120 const WeakPtr<JsAccessibilityManager>& jsAccessibilityManager, 121 const std::shared_ptr<JsThirdProviderInteractionOperation>& jsThirdProviderOperator); 122 123 AccessibilityHoverForThirdState hoverForThirdState_; 124 std::unordered_map<int64_t, std::weak_ptr<JsThirdProviderInteractionOperation>> 125 jsThirdProviderOperator_; 126 }; 127 } // namespace NG 128 } // namespace OHOS::Ace 129 130 #endif 131