1 /* 2 * Copyright (c) 2025 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_FUNCTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ACCESSIBILITY_PROPERTY_FUNCTION_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/accessibility/accessibility_utils.h" 21 22 namespace OHOS::Accessibility { 23 } 24 25 namespace OHOS::Ace { 26 class TouchEventInfo; 27 28 namespace NG { 29 class FrameNode; 30 31 struct SecCompEnhanceEvent { 32 std::vector<uint8_t> dataBuffer; 33 TimeStamp time; 34 }; 35 36 #define DEFINE_ACTION_FUNCTIONS(TYPE) \ 37 public: \ 38 void Set##TYPE(const Action##TYPE& action##TYPE) \ 39 { \ 40 action##TYPE##_ = action##TYPE; \ 41 } \ 42 bool CheckRegister##TYPE() const \ 43 { \ 44 return action##TYPE##_ == nullptr; \ 45 } \ 46 Action##TYPE Get##TYPE##Func() const \ 47 { \ 48 return action##TYPE##_; \ 49 } \ 50 protected: \ 51 Action##TYPE action##TYPE##_; 52 53 using ActionNotifyChildAction = std::function<AccessibilityActionResult(const RefPtr<FrameNode>& node, 54 NotifyChildActionType childActionType)>; 55 56 using ActionAccessibilityActionIntercept = 57 std::function<AccessibilityActionInterceptResult(AccessibilityInterfaceAction action)>; 58 59 using ActionAccessibilityTransparentCallback = std::function<void(TouchEventInfo& eventInfo)>; 60 61 using ActionSpecificSupportActionCallback = std::function<void()>; 62 63 using ActionSecurityClickAction = std::function<void(const SecCompEnhanceEvent& event)>; 64 65 /** 66 * @brief maintaining the callbacks for components 67 * @details maintaining the callbacks for components inner handle in accessibility action or hover 68 * @note 69 * @attention 70 * @since 71 */ 72 class ACE_FORCE_EXPORT AccessibilityPropertyInnerFunction { 73 /** 74 * @brief bubble up the action to ancestor after descendants handled accessibility action 75 * 76 * @details callback function prototype: ActionNotifyChildAction 77 * register function: SetNotifyChildAction(const RefPtr<FrameNode>& node, 78 * const ActionNotifyChildAction& actionNotifyChildAction) 79 * use register function to register callback. 80 * when descendants handled accessibility action, will bubble up to the ancestor component, notifying the 81 * ancestor that accessibility action has occurred. The ancestor component can decide on subsequent 82 * processing and whether to continue bubbling up 83 * @param [in] NotifyChildActionType the accessibility action type that handled by descendants 84 * 85 * @return AccessibilityActionResult: the result of ancestor handle or continuing to bubble up 86 * 87 * @attention it will be executed on the UI thread, so be aware of thread safety. 88 */ 89 DEFINE_ACTION_FUNCTIONS(NotifyChildAction); 90 91 /** 92 * @brief set the target's specificSupportActionCallback by other component, will update target's support action 93 * 94 * @details callback function prototype: ActionSpecificSupportActionCallback 95 * register function: SetSpecificSupportActionCallback() 96 * use register function to register callback. 97 * when one component want influence another target component's support action, set target's callback 98 * @param [in] void 99 * 100 * @return void 101 * 102 * @attention it will be executed on the UI thread, so be aware of thread safety. 103 */ 104 DEFINE_ACTION_FUNCTIONS(SpecificSupportActionCallback); 105 106 /** 107 * @brief the click action will by handle in this callback with sec enhance data 108 * 109 * @details callback function prototype: ActionSecurityClickAction 110 * register function: SetSecurityClickAction(const SecCompEnhanceEvent& event) 111 * use register function to register callback. 112 * when sec comp want to handle accessibility click with data. 113 * @param [in] SecCompEnhanceEvent the enhance data from accessibility 114 * 115 * @return void 116 * 117 * @attention it will be executed on the UI thread, so be aware of thread safety. 118 */ 119 DEFINE_ACTION_FUNCTIONS(SecurityClickAction); 120 public: 121 AccessibilityPropertyInnerFunction() = default; 122 123 virtual ~AccessibilityPropertyInnerFunction() = default; 124 }; 125 126 /** 127 * @brief maintaining the callbacks for interfaces of accessibility property of callback 128 * @details maintaining the callbacks for interfaces of accessibility property of callback 129 * @note 130 * @attention 131 * @since 132 */ 133 class ACE_FORCE_EXPORT AccessibilityPropertyInterfaceFunction { 134 /** 135 * @brief when register interface of onAccessibilityActionIntercept, 136 * saving the callback and processing before accessibility click 137 * 138 * @details callback function prototype: ActionNAccessibilityActionIntercept 139 * register function: 140 * SetAccessibilityActionIntercept( 141 * const ActionNAccessibilityActionIntercept& actionNAccessibilityActionIntercept) 142 * use register function to register callback. 143 * when the result is ACTION_INTERCEPT, will intercept click action 144 * when the result is ACTION_CONTINUE, will continue process click action 145 * when the result is ACTION_RISE, 146 * will bubble up to the ancestor component to check and process AccessibilityActionIntercept 147 * @param [in] AccessibilityInterfaceAction the accessibility action type that handled by registered component 148 * 149 * @return ActionAccessibilityActionIntercept: the result of intercept or continue handle or continuing to bubble up 150 * 151 * @attention it will be executed on the UI thread, so be aware of thread safety. 152 */ 153 DEFINE_ACTION_FUNCTIONS(AccessibilityActionIntercept) 154 155 /** 156 * @brief when register interface of onAccessibilityHoverTransparent, 157 * saving the callback and processing after hover 158 * 159 * @details callback function prototype: ActionAccessibilityTransparentCallback 160 * register function: 161 * SetAccessibilityTransparentCallback( 162 * const ActionAccessibilityTransparentCallback& actionAccessibilityTransparentCallback) 163 * use register function to register callback. 164 * @param [in] TouchEventInfo the original touch event needed return to developer 165 */ 166 DEFINE_ACTION_FUNCTIONS(AccessibilityTransparentCallback) 167 public: 168 AccessibilityPropertyInterfaceFunction() = default; 169 170 virtual ~AccessibilityPropertyInterfaceFunction() = default; 171 }; 172 } // namespace NG 173 } // namespace OHOS::Ace::NG 174 175 #endif // FOUNDATION_ACE_FRAMEWORKS_COMPONENTS_NG_PROPERTIES_ACCESSIBILITY_PROPERTY_FUNCTION_H 176