• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_UI_EXTENSION_UI_EXTENSION_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MANAGER_H
18 
19 #include <bitset>
20 #include <memory>
21 #include <mutex>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "base/want/want_wrap.h"
26 #include "core/common/container.h"
27 #include "core/components_ng/pattern/ui_extension/session_wrapper.h"
28 
29 namespace OHOS {
30 template<typename T>
31 class sptr;
32 namespace Rosen {
33 class AvoidArea;
34 enum class WSError;
35 class OccupiedAreaChangeInfo;
36 } // namespace OHOS::Rosen
37 } // namespace OHOS
38 
39 namespace OHOS::Ace::NG {
40 namespace {
41 constexpr int32_t UI_EXTENSION_UNKNOW_ID = 0;
42 constexpr int32_t UI_EXTENSION_ID_FIRST_MAX = 210;
43 constexpr int32_t UI_EXTENSION_ID_OTHER_MAX = 9;
44 constexpr int64_t UI_EXTENSION_OFFSET_MAX = 10000000000000;
45 constexpr int64_t UI_EXTENSION_OFFSET_MIN = 100000000000;
46 constexpr int32_t UI_EXTENSION_ID_FACTOR = 10;
47 constexpr int32_t UI_EXTENSION_LEVEL_MAX = 3;
48 constexpr int32_t UI_EXTENSION_ROOT_ID = -1;
49 }; // namespace
50 
51 class UIExtensionPattern;
52 class UIExtensionManager : public AceType {
53     DECLARE_ACE_TYPE(UIExtensionManager, AceType);
54 
55 public:
56     UIExtensionManager() = default;
57     ~UIExtensionManager() override = default;
58 
59     void RegisterUIExtensionInFocus(
60         const WeakPtr<UIExtensionPattern>& uiExtensionFocused, const WeakPtr<SessionWrapper>& sessionWrapper);
61     bool OnBackPressed();
62     const RefPtr<FrameNode> GetFocusUiExtensionNode();
63     bool IsWrapExtensionAbilityId(int64_t elementId);
64     bool IsWindowTypeUIExtension(const RefPtr<PipelineBase>& pipeline);
65     bool SendAccessibilityEventInfo(const Accessibility::AccessibilityEventInfo& eventInfo,
66         int64_t uiExtensionOffset, const RefPtr<PipelineBase>& pipeline);
67     std::pair<int64_t, int64_t> UnWrapExtensionAbilityId(int64_t extensionOffset, int64_t elementId);
68     int32_t ApplyExtensionId();
69     void RecycleExtensionId(int32_t id);
70 
71     /**
72      * @brief Create a UIExtensionComponent object on the page and save it in the UIExtension management object
73      *
74      * @param uiExtension The UIExtensionComponent pattern object
75      */
76     void AddAliveUIExtension(int32_t nodeId, const WeakPtr<UIExtensionPattern>& uiExtension);
77 
78     /**
79      * @brief Clear the UIExtensionComponent to be destroyed
80      *
81      * @param nodeId The UIExtensionComponent Id
82      */
83     void RemoveDestroyedUIExtension(int32_t nodeId);
84 
85     /**
86      * @brief Transfer the original avoid area and avoid area type to the UIExtensionAbility
87      *
88      * @param avoidArea The original avoid area
89      * @param type The original aovid areatype
90      */
91     void TransferOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type);
92 
93     bool NotifyOccupiedAreaChangeInfo(const sptr<Rosen::OccupiedAreaChangeInfo>& info);
94 
95 private:
96     class UIExtensionIdUtility {
97     public:
98         UIExtensionIdUtility() = default;
99         ~UIExtensionIdUtility() = default;
100         UIExtensionIdUtility(const UIExtensionIdUtility&) = delete;
101         UIExtensionIdUtility& operator=(const UIExtensionIdUtility&) = delete;
102 
103         int32_t ApplyExtensionId();
104         void RecycleExtensionId(int32_t id);
105 
106     private:
107         static std::bitset<UI_EXTENSION_ID_FIRST_MAX> idPool_;
108         static std::mutex poolMutex_;
109     };
110 
111     WeakPtr<UIExtensionPattern> uiExtensionFocused_;
112     WeakPtr<SessionWrapper> sessionWrapper_;
113     std::map<int32_t, OHOS::Ace::WeakPtr<UIExtensionPattern>> aliveUIExtensions_;
114     std::unique_ptr<UIExtensionIdUtility> extensionIdUtility_ = std::make_unique<UIExtensionIdUtility>();
115 };
116 } // namespace OHOS::Ace::NG
117 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MANAGER_H
118