• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_DYNAMIC_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_DYNAMIC_PATTERN_H
18 
19 #include "core/common/dynamic_component_renderer.h"
20 #include "core/components_ng/pattern/ui_extension/accessibility_session_adapter_isolated_component.h"
21 #include "core/components_ng/pattern/ui_extension/platform_accessibility_child_tree_callback.h"
22 #include "core/components_ng/pattern/ui_extension/platform_container_handler.h"
23 #include "core/components_ng/pattern/ui_extension/platform_pattern.h"
24 #include "core/components_ng/pattern/ui_extension/surface_proxy_node.h"
25 
26 namespace OHOS::Ace::NG {
27 enum DCResultCode : int32_t {
28     DC_NO_ERRORS = 0,
29     DC_INTERNAL_ERROR = 10011,
30     DC_EXCEED_MAX_NUM_IN_WORKER = 10012,
31     DC_ONLY_RUN_ON_SCB = 10013,
32     DC_PARAM_ERROE = 10014,
33     DC_NOT_SUPPORT_UI_CONTENT_TYPE = 10015,
34     DC_WORKER_EXCEED_MAX_NUM = 10016
35 };
36 
37 struct DynamicDumpInfo {
38     int64_t createLimitedWorkerTime = 0;
39 };
40 
41 class DynamicPattern : public PlatformPattern, public PlatformAccessibilityBase,
42     public SurfaceProxyNode, public PlatformContainerHandler {
43     DECLARE_ACE_TYPE(DynamicPattern, PlatformPattern,
44     PlatformAccessibilityBase, SurfaceProxyNode, PlatformContainerHandler);
45 
46 public:
47     DynamicPattern();
48     ~DynamicPattern() override;
49 
50     void InitializeDynamicComponent(const std::string& hapPath,
51         const std::string& abcPath, const std::string& entryPoint, void* runtime);
52     bool OnDirtyLayoutWrapperSwap(
53         const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
54     void OnDetachFromFrameNode(FrameNode* frameNode) override;
55     int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId) override;
56     RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter() override;
57     void SetAdaptiveWidth(bool state);
58     void SetAdaptiveHeight(bool state);
59     void OnAttachContext(PipelineContext *context) override;
60     void OnDetachContext(PipelineContext *context) override;
61     void DumpDynamicRenderer(int32_t depth, bool hasJson);
62     void SetIsReportFrameEvent(bool isReportFrameEvent);
63 
64     void DumpInfo() override;
65     void DumpInfo(std::unique_ptr<JsonValue>& json) override;
DumpSimplifyInfo(std::shared_ptr<JsonValue> & json)66     void DumpSimplifyInfo(std::shared_ptr<JsonValue>& json) override {}
67     void FireOnErrorCallbackOnUI(
68         int32_t code, const std::string& name, const std::string& msg);
69 
70     void OnAccessibilityChildTreeRegister(uint32_t windowId, int32_t treeId, int64_t accessibilityId) const override;
71     void OnAccessibilityChildTreeDeregister() const override;
72     void OnSetAccessibilityChildTree(int32_t childWindowId, int32_t childTreeId) override;
73     void OnAccessibilityDumpChildInfo(
74         const std::vector<std::string>& params, std::vector<std::string>& info) const override;
75     void TransferAccessibilityRectInfo(bool isForce = false);
76     void OnFrameNodeChanged(FrameNodeChangeInfoFlag flag) override;
77     void OnAccessibilityParentRectInfoUpdate() override;
78 
79     void InitializeAccessibility();
80     void ResetAccessibilityChildTreeCallback();
81 
82     void SetBackgroundTransparent(bool backgroundTransparent);
83 
HasDynamicRenderer()84     bool HasDynamicRenderer() const
85     {
86         return dynamicComponentRenderer_ != nullptr;
87     }
88 
89     void HandleVisibleAreaChange(bool visible, double ratio);
90 
91     bool HandleTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
92 
93 private:
94     void InitializeRender(void* runtime);
95     DCResultCode CheckConstraint();
96     bool CheckDynamicRendererConstraint(void* runtime);
97     void HandleErrorCallback(DCResultCode resultCode);
98 
99     void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
100     void DispatchFocusActiveEvent(bool isFocusActive) override;
101     bool HandleKeyEvent(const KeyEvent& event) override;
102     void HandleFocusEvent() override;
103     void HandleBlurEvent() override;
104     bool IsAncestorNodeGeometryChange(FrameNodeChangeInfoFlag flag);
105     bool IsAncestorNodeTransformChange(FrameNodeChangeInfoFlag flag);
106 
107     void OnAttachToFrameNode() override;
108     void RegisterPipelineEvent(int32_t instanceId);
109     void UnRegisterPipelineEvent(int32_t instanceId);
110 
111     void AddToPageEventController();
112     void ReleasePageEvent() const;
113     AccessibilityParentRectInfo GetAccessibilityRectInfo() const;
114     void RegisterAccessibilitySAObserverCallback(int32_t instanceId);
115     void UnRegisterAccessibilitySAObserverCallback(int32_t instanceId);
116     void RegisterSingleHandTransformChangedCallback(int32_t instanceId);
117     void UnRegisterSingleHandTransformChangedCallback(int32_t instanceId);
118 
119     void RegisterVisibleAreaChange();
120 
121     void HandleMouseEvent(const MouseInfo& info) override;
122 
123     RefPtr<DynamicComponentRenderer> dynamicComponentRenderer_;
124     bool adaptiveWidth_ = false;
125     bool adaptiveHeight_ = false;
126     bool backgroundTransparent_ = true;
127     IsolatedInfo curDynamicInfo_;
128     DynamicDumpInfo dynamicDumpInfo_;
129     int32_t uiExtensionId_ = 0;
130     RefPtr<AccessibilitySessionAdapterIsolatedComponent> accessibilitySessionAdapter_;
131     std::shared_ptr<AccessibilityChildTreeCallback> accessibilityChildTreeCallback_ = nullptr;
132     bool isVisible_ = true;
133     int32_t surfacePositionCallBackId_ = -1;
134     std::shared_ptr<AccessibilitySAObserverCallback> accessibilitySAObserverCallback_;
135 
136     static int32_t dynamicGenerator_; // only run on JS thread, and do not require mutex
137     ACE_DISALLOW_COPY_AND_MOVE(DynamicPattern);
138 };
139 } // namespace OHOS::Ace::NG
140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_DYNAMIC_PATTERN_H
141