1 /* 2 * Copyright (c) 2022-2023 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_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H 18 19 #include <unordered_map> 20 21 #include "transaction/rs_interfaces.h" 22 23 #include "core/common/container.h" 24 #include "core/common/ace_application_info.h" 25 #include "core/components/form/resource/form_request_data.h" 26 #include "core/components_ng/event/event_hub.h" 27 #include "core/components_ng/pattern/form/accessibility_session_adapter_form.h" 28 #include "core/components_ng/pattern/form/form_event_hub.h" 29 #include "core/components_ng/pattern/form/form_layout_property.h" 30 #include "core/components_ng/pattern/pattern.h" 31 #include "core/components_ng/pattern/form/form_special_style.h" 32 #include "core/components/common/properties/color.h" 33 #include "form_skeleton_params.h" 34 35 namespace OHOS { 36 namespace MMI { 37 class PointerEvent; 38 } // namespace MMI 39 40 namespace Ace { 41 class SubContainer; 42 class FormManagerDelegate; 43 class DrawDelegate; 44 struct SerializedGesture; 45 struct AccessibilityParentRectInfo; 46 47 namespace NG { 48 enum class FormChildNodeType : int32_t { 49 /** 50 * Arkts card node type 51 */ 52 FORM_SURFACE_NODE, 53 54 /** 55 * static form image node type 56 */ 57 FORM_STATIC_IMAGE_NODE, 58 59 /** 60 * form skeleton node type 61 */ 62 FORM_SKELETON_NODE, 63 64 /** 65 * forbidden form root node 66 */ 67 FORM_FORBIDDEN_ROOT_NODE, 68 69 /** 70 * time limit text node 71 */ 72 TIME_LIMIT_TEXT_NODE, 73 74 /** 75 * time limit image node 76 */ 77 TIME_LIMIT_IMAGE_NODE, 78 79 /** 80 * app locked text node 81 */ 82 APP_LOCKED_TEXT_NODE, 83 84 /** 85 * app locked image node 86 */ 87 APP_LOCKED_IMAGE_NODE, 88 }; 89 90 class FormPattern : public Pattern { 91 DECLARE_ACE_TYPE(FormPattern, Pattern); 92 93 public: 94 FormPattern(); 95 ~FormPattern() override; 96 97 void OnActionEvent(const std::string& action); 98 99 void OnLoadEvent(); 100 101 void HandleUnTrustForm(); 102 CreateLayoutProperty()103 RefPtr<LayoutProperty> CreateLayoutProperty() override 104 { 105 return MakeRefPtr<FormLayoutProperty>(); 106 } 107 CreateEventHub()108 RefPtr<EventHub> CreateEventHub() override 109 { 110 return MakeRefPtr<FormEventHub>(); 111 } 112 113 std::unique_ptr<DrawDelegate> GetDrawDelegate(); 114 115 const RefPtr<SubContainer>& GetSubContainer() const; 116 117 void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 118 SerializedGesture& serializedGesture); 119 120 void OnSnapshot(std::shared_ptr<Media::PixelMap> pixelMap); 121 122 void HandleOnSnapshot(std::shared_ptr<Media::PixelMap> pixelMap); 123 GetExternalRenderContext()124 RefPtr<RenderContext> GetExternalRenderContext() 125 { 126 return externalRenderContext_; 127 } 128 GetIsLoaded()129 bool GetIsLoaded() const 130 { 131 return isLoaded_; 132 } 133 SetFormLinkInfos(const std::vector<std::string> & infos)134 void SetFormLinkInfos(const std::vector<std::string>& infos) 135 { 136 formLinkInfos_.clear(); 137 formLinkInfos_ = infos; 138 } 139 140 void GetRectRelativeToWindow(AccessibilityParentRectInfo& parentRectInfo); 141 IsJsCard()142 bool IsJsCard() const 143 { 144 return isJsCard_; 145 } 146 SetObscured(bool isObscured)147 void SetObscured(bool isObscured) 148 { 149 isFormObscured_ = isObscured; 150 } 151 152 RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter() override; 153 154 void OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId); 155 156 void OnAccessibilityChildTreeDeregister(); 157 158 void OnAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info); 159 160 void OnLanguageConfigurationUpdate() override; 161 162 void GetResourceContent(std::string resourceName, std::string &content); 163 164 void UnregisterAccessibility(); 165 166 void DumpInfo() override; 167 void DumpInfo(std::unique_ptr<JsonValue>& json) override; 168 169 private: 170 void OnAttachToFrameNode() override; 171 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 172 void OnRebuildFrame() override; 173 void OnVisibleChange(bool isVisible) override; 174 void OnModifyDone() override; 175 176 void InitFormManagerDelegate(); 177 void CreateCardContainer(); 178 void RemoveSubContainer(); 179 180 void FireOnAcquiredEvent(int64_t id) const; 181 void FireOnRouterEvent(const std::unique_ptr<JsonValue>& action); 182 void FireOnLoadEvent() const; 183 void FireOnErrorEvent(const std::string& code, const std::string& msg) const; 184 void FireOnUninstallEvent(int64_t id) const; 185 void FireFormSurfaceNodeCallback(const std::shared_ptr<Rosen::RSSurfaceNode>& node, const AAFwk::Want& want); 186 void FireFormSurfaceChangeCallback(float width, float height, float borderWidth = 0.0); 187 void FireFormSurfaceDetachCallback(); 188 void FireOnUpdateFormDone(int64_t id) const; 189 void UpdateBackgroundColorWhenUnTrustForm(); 190 191 bool ISAllowUpdate() const; 192 void EnableDrag(); 193 void UpdateConfiguration(); 194 void HandleFormComponent(RequestFormInfo& info); 195 void SetParamForWantTask(const RequestFormInfo& info); 196 void AddFormComponent(const RequestFormInfo& info); 197 void AddFormComponentTask(const RequestFormInfo& info, RefPtr<PipelineContext> pipeline); 198 void AddFormComponentUI(bool isTransparencyEnabled, const RequestFormInfo& info); 199 void UpdateFormComponent(const RequestFormInfo& info); 200 void UpdateFormComponentSize(const RequestFormInfo& info); 201 void UpdateSpecialStyleCfg(); 202 void UpdateForbiddenIcon(FormChildNodeType nodeType); 203 void UpdateForbiddenText(FormChildNodeType nodeType); 204 205 void HandleSnapshot(uint32_t delayTime, const std::string& nodeIdStr); 206 void TakeSurfaceCaptureForUI(); 207 void UpdateStaticCard(); 208 RefPtr<FrameNode> CreateImageNode(); 209 void UpdateImageNode(); 210 void RemoveFrsNode(); 211 void ReleaseRenderer(); 212 void DelayDeleteImageNode(bool needHandleCachedClick); 213 void DelayRemoveFormChildNode(FormChildNodeType formChildNodeType); 214 void SetNonTransparentAfterRecover(); 215 void DeleteImageNodeAfterRecover(bool needHandleCachedClick); 216 void HandleStaticFormEvent(const PointF& touchPoint); 217 void ProcDeleteImageNode(const AAFwk::Want& want); 218 void AttachRSNode(const std::shared_ptr<Rosen::RSSurfaceNode>& node, const AAFwk::Want& want); 219 void AttachJsRSNode(const std::shared_ptr<Rosen::RSNode> &jsNode); 220 void HandleEnableForm(const bool enable); 221 222 void InitClickEvent(); 223 void HandleTouchDownEvent(const TouchEventInfo& event); 224 void HandleTouchUpEvent(const TouchEventInfo& event); 225 226 void LoadFormSkeleton(bool isRefresh = false); 227 bool ShouldLoadFormSkeleton(bool isTransparencyEnabled, const RequestFormInfo &info); 228 void LoadDisableFormStyle(const RequestFormInfo& info, bool isRefresh = false); 229 void RemoveDisableFormStyle(const RequestFormInfo& info); 230 void RemoveFormChildNode(FormChildNodeType formChildNodeType); 231 int32_t GetFormDimensionHeight(int32_t dimension); 232 RefPtr<FrameNode> CreateColumnNode(FormChildNodeType formChildNodeType); 233 RefPtr<FrameNode> CreateRowNode(FormChildNodeType formChildNodeType); 234 RefPtr<FrameNode> CreateTextNode(bool isRowStyle); 235 RefPtr<FrameNode> CreateIconNode(bool isRowStyle); 236 RefPtr<FrameNode> CreateForbiddenImageNode(InternalResource::ResourceId resourceId, bool isRowStyle); 237 RefPtr<FrameNode> CreateForbiddenTextNode(std::string resourceName, bool isRowStyle); 238 RefPtr<FrameNode> CreateRectNode(const RefPtr<FrameNode>& parent, const CalcSize& idealSize, 239 const MarginProperty& margin, uint32_t fillColor, double opacity); 240 void CreateSkeletonView(const RefPtr<FrameNode>& parent, const std::shared_ptr<FormSkeletonParams>& params, 241 int32_t dimensionHeight); 242 void SetTransparencyConfig(bool isTransparencyForm, const RequestFormInfo &info); 243 void SetSkeletonEnableConfig(const RequestFormInfo &info); 244 void SetExternalRenderOpacity(double opacity); 245 bool ShouldDoSkeletonAnimation(); 246 void DoSkeletonAnimation(); 247 void UpdateFormBaseConfig(bool isDynamic); 248 void AddFormChildNode(FormChildNodeType formChildNodeType, const RefPtr<FrameNode> child); 249 RefPtr<FrameNode> GetFormChildNode(FormChildNodeType formChildNodeType) const; 250 double GetTimeLimitFontSize(); 251 bool IsMaskEnableForm(const RequestFormInfo &info); 252 void UpdateChildNodeOpacity(FormChildNodeType formChildNodeType, double opacity); 253 void SnapshotSurfaceNode(); 254 bool CheckFormBundleForbidden(const std::string &bundleName); 255 void DelayResetManuallyClickFlag(); 256 void RemoveDelayResetManuallyClickFlagTask(); 257 258 void InitAddFormUpdateAndErrorCallback(int32_t instanceId); 259 void InitAddUninstallAndSurfaceNodeCallback(int32_t instanceId); 260 void InitAddFormSurfaceChangeAndDetachCallback(int32_t instanceId); 261 void InitAddUnTrustAndSnapshotCallback(int32_t instanceId); 262 void InitOtherCallback(int32_t instanceId); 263 void InitUpdateFormDoneCallback(int32_t instanceID); 264 bool IsFormBundleExempt(int64_t formId) const; 265 bool IsFormBundleProtected(const std::string &bundleName, int64_t formId) const; 266 void HandleLockEvent(bool isLock); 267 void HandleFormStyleOperation(const FormSpecialStyle& formSpecialStyle); 268 void HandleFormStyleOperation(const FormSpecialStyle& formSpecialStyle, const RequestFormInfo& info); 269 void UpdateForbiddenRootNodeStyle(const RefPtr<RenderContext> &renderContext); 270 void ReAddStaticFormSnapshotTimer(); 271 // used by ArkTS Card, for RSSurfaceNode from FRS, 272 void enhancesSubContainer(bool hasContainer); 273 bool GetFormDumpInfo(std::vector<std::string> &dumpInfo); 274 void GetRSUIContext(); 275 276 RefPtr<RenderContext> externalRenderContext_; 277 278 RefPtr<SubContainer> subContainer_; 279 RefPtr<FormManagerDelegate> formManagerBridge_; 280 RefPtr<AccessibilitySessionAdapterForm> accessibilitySessionAdapter_; 281 282 FormSpecialStyle formSpecialStyle_; 283 RequestFormInfo cardInfo_; 284 bool isLoaded_ = false; 285 bool isVisible_ = true; 286 bool isBeenLayout_ = false; 287 bool isUnTrust_ = false; 288 bool isDynamic_ = true; 289 bool isFrsNodeDetached_ = false; 290 bool needSnapshotAgain_ = false; 291 bool isSnapshot_ = false; 292 RefPtr<PixelMap> pixelMap_ = nullptr; 293 int64_t snapshotTimestamp_ = 0; 294 int32_t scopeId_; 295 std::string localeTag_ = AceApplicationInfo::GetInstance().GetLocaleTag(); 296 std::vector<std::string> formLinkInfos_; 297 TimeStamp touchDownTime_; 298 bool shouldResponseClick_ = false; 299 Offset lastTouchLocation_; 300 ColorMode colorMode = ColorMode::LIGHT; 301 int32_t instanceId_ = Container::CurrentId(); 302 303 bool isFormObscured_ = false; 304 bool isJsCard_ = true; 305 bool isTransparencyEnable_ = false; 306 bool isSkeletonAnimEnable_ = false; 307 std::unordered_map<FormChildNodeType, RefPtr<FrameNode>> formChildrenNodeMap_; 308 bool isTibetanLanguage_ = false; 309 bool isManuallyClick_ = false; 310 bool ShouldAddChildAtReuildFrame(); 311 bool isStaticFormSnaping_ = false; 312 int64_t updateFormComponentTimestamp_ = 0; 313 std::shared_ptr<Rosen::RSUIContext> rsUIContext_ = nullptr; 314 }; 315 } // namespace NG 316 } // namespace Ace 317 } // namespace OHOS 318 319 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H 320