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/ace_application_info.h" 24 #include "core/components/form/resource/form_request_data.h" 25 #include "core/components_ng/event/event_hub.h" 26 #include "core/components_ng/pattern/form/accessibility_session_adapter_form.h" 27 #include "core/components_ng/pattern/form/form_event_hub.h" 28 #include "core/components_ng/pattern/form/form_layout_property.h" 29 #include "core/components_ng/pattern/pattern.h" 30 #include "form_skeleton_params.h" 31 32 namespace OHOS { 33 namespace MMI { 34 class PointerEvent; 35 } // namespace MMI 36 37 namespace Ace { 38 class SubContainer; 39 class FormManagerDelegate; 40 41 namespace NG { 42 enum class FormChildNodeType : int32_t { 43 /** 44 * Arkts card node type 45 */ 46 FORM_SURFACE_NODE, 47 48 /** 49 * static form image node type 50 */ 51 FORM_STATIC_IMAGE_NODE, 52 53 /** 54 * form skeleton node type 55 */ 56 FORM_SKELETON_NODE, 57 58 /** 59 * forbidden form root node 60 */ 61 FORM_FORBIDDEN_ROOT_NODE, 62 63 /** 64 * forbidden form text node 65 */ 66 FORM_FORBIDDEN_TEXT_NODE, 67 }; 68 69 class FormPattern : public Pattern { 70 DECLARE_ACE_TYPE(FormPattern, Pattern); 71 72 public: 73 FormPattern(); 74 ~FormPattern() override; 75 76 void OnActionEvent(const std::string& action); 77 78 void OnLoadEvent(); 79 80 void HandleUnTrustForm(); 81 CreateLayoutProperty()82 RefPtr<LayoutProperty> CreateLayoutProperty() override 83 { 84 return MakeRefPtr<FormLayoutProperty>(); 85 } 86 CreateEventHub()87 RefPtr<EventHub> CreateEventHub() override 88 { 89 return MakeRefPtr<FormEventHub>(); 90 } 91 92 std::unique_ptr<DrawDelegate> GetDrawDelegate(); 93 94 const RefPtr<SubContainer>& GetSubContainer() const; 95 96 void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 97 SerializedGesture& serializedGesture); 98 99 void OnSnapshot(std::shared_ptr<Media::PixelMap> pixelMap); 100 101 void HandleOnSnapshot(std::shared_ptr<Media::PixelMap> pixelMap); 102 GetExternalRenderContext()103 RefPtr<RenderContext> GetExternalRenderContext() 104 { 105 return externalRenderContext_; 106 } 107 GetIsLoaded()108 bool GetIsLoaded() const 109 { 110 return isLoaded_; 111 } 112 SetFormLinkInfos(const std::vector<std::string> & infos)113 void SetFormLinkInfos(const std::vector<std::string>& infos) 114 { 115 formLinkInfos_.clear(); 116 formLinkInfos_ = infos; 117 } 118 119 void GetRectRelativeToWindow(int32_t &top, int32_t &left); 120 IsJsCard()121 bool IsJsCard() const 122 { 123 return isJsCard_; 124 } 125 SetObscured(bool isObscured)126 void SetObscured(bool isObscured) 127 { 128 isFormObscured_ = isObscured; 129 } 130 131 RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter() override; 132 133 void OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId); 134 135 void OnAccessibilityChildTreeDeregister(); 136 137 void OnAccessibilityDumpChildInfo(const std::vector<std::string>& params, std::vector<std::string>& info); 138 139 void OnLanguageConfigurationUpdate() override; 140 141 void GetTimeLimitResource(std::string &content); 142 143 void UnregisterAccessibility(); 144 145 private: 146 void OnAttachToFrameNode() override; 147 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 148 void OnRebuildFrame() override; 149 void OnVisibleChange(bool isVisible) override; 150 void OnModifyDone() override; 151 152 void InitFormManagerDelegate(); 153 void CreateCardContainer(); 154 void RemoveSubContainer(); 155 156 void FireOnAcquiredEvent(int64_t id) const; 157 void FireOnRouterEvent(const std::unique_ptr<JsonValue>& action); 158 void FireOnLoadEvent() const; 159 void FireOnErrorEvent(const std::string& code, const std::string& msg) const; 160 void FireOnUninstallEvent(int64_t id) const; 161 void FireFormSurfaceNodeCallback(const std::shared_ptr<Rosen::RSSurfaceNode>& node, const AAFwk::Want& want); 162 void FireFormSurfaceChangeCallback(float width, float height, float borderWidth = 0.0); 163 void FireFormSurfaceDetachCallback(); 164 void UpdateBackgroundColorWhenUnTrustForm(); 165 166 bool ISAllowUpdate() const; 167 void EnableDrag(); 168 void UpdateConfiguration(); 169 void HandleFormComponent(const RequestFormInfo& info); 170 void AddFormComponent(const RequestFormInfo& info); 171 void UpdateFormComponent(const RequestFormInfo& info); 172 void UpdateFormComponentSize(const RequestFormInfo& info); 173 void UpdateTimeLimitFontCfg(); 174 175 void HandleSnapshot(uint32_t delayTime); 176 void TakeSurfaceCaptureForUI(); 177 void UpdateStaticCard(); 178 RefPtr<FrameNode> CreateImageNode(); 179 void UpdateImageNode(); 180 void RemoveFrsNode(); 181 void ReleaseRenderer(); 182 void DelayDeleteImageNode(bool needHandleCachedClick); 183 void SetNonTransparentAfterRecover(); 184 void DeleteImageNodeAfterRecover(bool needHandleCachedClick); 185 void HandleStaticFormEvent(const PointF& touchPoint); 186 void ProcDeleteImageNode(const AAFwk::Want& want); 187 void AttachRSNode(const std::shared_ptr<Rosen::RSSurfaceNode>& node, const AAFwk::Want& want); 188 void AttachJsRSNode(const std::shared_ptr<Rosen::RSNode> &jsNode); 189 void HandleEnableForm(const bool enable); 190 191 void InitClickEvent(); 192 void HandleTouchDownEvent(const TouchEventInfo& event); 193 void HandleTouchUpEvent(const TouchEventInfo& event); 194 195 void LoadFormSkeleton(bool isRefresh = false); 196 bool ShouldLoadFormSkeleton(bool isTransparencyEnabled, const RequestFormInfo &info); 197 void LoadDisableFormStyle(const RequestFormInfo& info, bool isRefresh = false); 198 void RemoveDisableFormStyle(const RequestFormInfo& info); 199 void RemoveFormChildNode(FormChildNodeType formChildNodeType); 200 int32_t GetFormDimensionHeight(int32_t dimension); 201 RefPtr<FrameNode> CreateColumnNode(FormChildNodeType formChildNodeType); 202 RefPtr<FrameNode> CreateTimeLimitNode(); 203 RefPtr<FrameNode> CreateRectNode(const RefPtr<FrameNode>& parent, const CalcSize& idealSize, 204 const MarginProperty& margin, uint32_t fillColor, double opacity); 205 void CreateSkeletonView(const RefPtr<FrameNode>& parent, const std::shared_ptr<FormSkeletonParams>& params, 206 int32_t dimensionHeight); 207 void AddFormChildNode(FormChildNodeType formChildNodeType, const RefPtr<FrameNode> child); 208 RefPtr<FrameNode> GetFormChildNode(FormChildNodeType formChildNodeType) const; 209 double GetTimeLimitFontSize(); 210 bool IsMaskEnableForm(const RequestFormInfo &info); 211 void UpdateChildNodeOpacity(FormChildNodeType formChildNodeType, double opacity); 212 void SnapshotSurfaceNode(); 213 bool CheckFormBundleForbidden(const std::string &bundleName); 214 void DelayResetManuallyClickFlag(); 215 void RemoveDelayResetManuallyClickFlagTask(); 216 // used by ArkTS Card, for RSSurfaceNode from FRS, 217 RefPtr<RenderContext> externalRenderContext_; 218 219 RefPtr<SubContainer> subContainer_; 220 RefPtr<FormManagerDelegate> formManagerBridge_; 221 RefPtr<AccessibilitySessionAdapterForm> accessibilitySessionAdapter_; 222 223 RequestFormInfo cardInfo_; 224 bool isLoaded_ = false; 225 bool isVisible_ = true; 226 bool isBeenLayout_ = false; 227 bool isUnTrust_ = false; 228 bool isDynamic_ = true; 229 bool isFrsNodeDetached_ = false; 230 bool needSnapshotAgain_ = false; 231 bool isSnapshot_ = false; 232 RefPtr<PixelMap> pixelMap_ = nullptr; 233 int64_t snapshotTimestamp_ = 0; 234 int32_t scopeId_; 235 std::string localeTag_ = AceApplicationInfo::GetInstance().GetLocaleTag(); 236 std::vector<std::string> formLinkInfos_; 237 TimeStamp touchDownTime_; 238 bool shouldResponseClick_ = false; 239 Offset lastTouchLocation_; 240 ColorMode colorMode = ColorMode::LIGHT; 241 242 bool isFormObscured_ = false; 243 bool isJsCard_ = true; 244 std::unordered_map<FormChildNodeType, RefPtr<FrameNode>> formChildrenNodeMap_; 245 bool isTibetanLanguage_ = false; 246 bool isManuallyClick_ = false; 247 }; 248 } // namespace NG 249 } // namespace Ace 250 } // namespace OHOS 251 252 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_PATTERN_H 253