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_ISOLATED_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_ISOLATED_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_pattern.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 struct IsolatedDumpInfo {
26     int64_t createLimitedWorkerTime = 0;
27 };
28 
29 class IsolatedPattern : public PlatformPattern {
30     DECLARE_ACE_TYPE(IsolatedPattern, PlatformPattern);
31 
32 public:
33     IsolatedPattern();
34     ~IsolatedPattern() override;
35 
36     void InitializeDynamicComponent(const std::string& hapPath,
37         const std::string& abcPath, const std::string& entryPoint, void* runtime);
38     void InitializeIsolatedComponent(
39         const RefPtr<OHOS::Ace::WantWrap>& wantWrap, void* runtime);
40     bool OnDirtyLayoutWrapperSwap(
41         const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
42     void OnDetachFromFrameNode(FrameNode* frameNode) override;
43     int32_t GetUiExtensionId() override;
44     int64_t WrapExtensionAbilityId(int64_t extensionOffset, int64_t abilityId) override;
45     RefPtr<AccessibilitySessionAdapter> GetAccessibilitySessionAdapter() override;
46     void SetAdaptiveWidth(bool state);
47     void SetAdaptiveHeight(bool state);
48 
49     virtual void SearchExtensionElementInfoByAccessibilityId(int64_t elementId, int32_t mode, int64_t baseParent,
50         std::list<Accessibility::AccessibilityElementInfo>& output) override;
51     virtual void SearchElementInfosByText(int64_t elementId, const std::string& text, int64_t baseParent,
52         std::list<Accessibility::AccessibilityElementInfo>& output) override;
53     virtual void FindFocusedElementInfo(int64_t elementId, int32_t focusType, int64_t baseParent,
54         Accessibility::AccessibilityElementInfo& output) override;
55     virtual void FocusMoveSearch(int64_t elementId, int32_t direction, int64_t baseParent,
56         Accessibility::AccessibilityElementInfo& output) override;
57     virtual bool TransferExecuteAction(int64_t elementId, const std::map<std::string, std::string>& actionArguments,
58         int32_t action, int64_t offset) override;
59 
60     void DumpInfo() override;
61     void FireOnErrorCallbackOnUI(
62         int32_t code, const std::string& name, const std::string& msg);
63 
64 private:
65     void InitializeRender(void* runtime);
66 
67     void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
68     void DispatchFocusActiveEvent(bool isFocusActive) override;
69     bool HandleKeyEvent(const KeyEvent& event) override;
70     void HandleFocusEvent() override;
71     void HandleBlurEvent() override;
72 
73     void OnAttachToFrameNode() override;
74 
75     RefPtr<DynamicComponentRenderer> dynamicComponentRenderer_;
76     bool adaptiveWidth_ = true;
77     bool adaptiveHeight_ = true;
78     IsolatedInfo curIsolatedInfo_;
79     IsolatedDumpInfo isolatedDumpInfo_;
80     int32_t uiExtensionId_ = 0;
81     RefPtr<AccessibilitySessionAdapterIsolatedComponent> accessibilitySessionAdapter_;
82 
83     static int32_t isolatedIdGenerator_; // only run on JS thread, and do not require mutex
84     ACE_DISALLOW_COPY_AND_MOVE(IsolatedPattern);
85 };
86 } // namespace OHOS::Ace::NG
87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_ISOLATED_PATTERN_H
88