• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
18 
19 #include "ability_info.h"
20 #include "interfaces/inner_api/ace/ui_content.h"
21 #include "interfaces/inner_api/ace/viewport_config.h"
22 #include "key_event.h"
23 #include "native_engine/native_engine.h"
24 #include "native_engine/native_value.h"
25 #include "wm/window.h"
26 
27 #include "adapter/ohos/entrance/distributed_ui_manager.h"
28 #include "core/common/flutter/flutter_asset_manager.h"
29 
30 namespace OHOS::Ace {
31 
32 class ACE_FORCE_EXPORT UIContentImpl : public UIContent {
33 public:
34     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime);
35     UIContentImpl(OHOS::AppExecFwk::Ability* ability);
36     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard);
~UIContentImpl()37     ~UIContentImpl()
38     {
39         DestroyUIDirector();
40         DestroyCallback();
41     }
42 
43     // UI content lifeCycles
44     void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) override;
45     void Initialize(
46         OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage, uint32_t focusWindowId) override;
47     void Foreground() override;
48     void Background() override;
49     void Focus() override;
50     void UnFocus() override;
51     void Destroy() override;
52     void OnNewWant(const OHOS::AAFwk::Want& want) override;
53 
54     // distribute
55     void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) override;
56     std::string GetContentInfo() const override;
57     void DestroyUIDirector() override;
58 
59     // UI content event process
60     bool ProcessBackPressed() override;
61     bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
62     bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override;
63     bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
64     bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
65     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
66     void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
67         const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override;
68     void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override;
69     void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize) override;
70     void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override;
71 
72     // Window color
73     uint32_t GetBackgroundColor() override;
74     void SetBackgroundColor(uint32_t color) override;
75 
76     void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
77 
78     // Set UIContent callback for custom window animation
79     void SetNextFrameLayoutCallback(std::function<void()>&& callback) override;
80 
81     // Receive memory level notification
82     void NotifyMemoryLevel(int32_t level) override;
83 
84     void SetAppWindowTitle(const std::string& title) override;
85     void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override;
86 
87     // ArkTS Form
88     std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override;
89     void UpdateFormData(const std::string& data) override;
90     void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override;
91     void ReloadForm(const std::string& url) override;
92 
SetFormWidth(float width)93     void SetFormWidth(float width) override
94     {
95         formWidth_ = width;
96     }
SetFormHeight(float height)97     void SetFormHeight(float height) override
98     {
99         formHeight_ = height;
100     }
GetFormWidth()101     float GetFormWidth() override
102     {
103         return formWidth_;
104     }
GetFormHeight()105     float GetFormHeight() override
106     {
107         return formHeight_;
108     }
109 
110     void SetActionEventHandler(std::function<void(const std::string& action)>&& actionCallback) override;
111     void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) override;
112     void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& callback) override;
113 
114     void OnFormSurfaceChange(float width, float height) override;
115 
DumpUITree()116     SerializeableObjectArray DumpUITree() override
117     {
118         return uiManager_->DumpUITree();
119     }
SubscribeUpdate(const std::function<void (int32_t,SerializeableObjectArray &)> & onUpdate)120     void SubscribeUpdate(const std::function<void(int32_t, SerializeableObjectArray&)>& onUpdate) override
121     {
122         return uiManager_->SubscribeUpdate(onUpdate);
123     }
UnSubscribeUpdate()124     void UnSubscribeUpdate() override
125     {
126         uiManager_->UnSubscribeUpdate();
127     }
ProcessSerializeableInputEvent(const SerializeableObjectArray & array)128     void ProcessSerializeableInputEvent(const SerializeableObjectArray& array) override
129     {
130         uiManager_->ProcessSerializeableInputEvent(array);
131     }
RestoreUITree(const SerializeableObjectArray & array)132     void RestoreUITree(const SerializeableObjectArray& array) override
133     {
134         uiManager_->RestoreUITree(array);
135     }
UpdateUITree(const SerializeableObjectArray & array)136     void UpdateUITree(const SerializeableObjectArray& array) override
137     {
138         uiManager_->UpdateUITree(array);
139     }
SubscribeInputEventProcess(const std::function<void (SerializeableObjectArray &)> & onEvent)140     void SubscribeInputEventProcess(const std::function<void(SerializeableObjectArray&)>& onEvent) override
141     {
142         uiManager_->SubscribeInputEventProcess(onEvent);
143     }
UnSubscribeInputEventProcess()144     void UnSubscribeInputEventProcess() override
145     {
146         uiManager_->UnSubscribeInputEventProcess();
147     }
148     void GetResourcePaths(std::vector<std::string>& resourcesPaths, std::string& assetRootPath,
149         std::vector<std::string>& assetBasePaths, std::string& resFolderName) override;
150     void SetResourcePaths(const std::vector<std::string>& resourcesPaths, const std::string& assetRootPath,
151         const std::vector<std::string>& assetBasePaths) override;
152     NativeValue* GetUIContext() override;
153     void SetIsFocusActive(bool isFocusActive) override;
154 
155     int32_t CreateModalUIExtension(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks) override;
156     void CloseModalUIExtension(int32_t sessionId) override;
157 
158 private:
159     void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
160     void CommonInitializeForm(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
161     void InitializeSubWindow(OHOS::Rosen::Window* window, bool isDialog = false);
162     void DestroyCallback() const;
163     void SetConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config);
164 
165     void InitializeSafeArea(const RefPtr<Platform::AceContainer>& container);
166 
167     std::weak_ptr<OHOS::AbilityRuntime::Context> context_;
168     void* runtime_ = nullptr;
169     OHOS::Rosen::Window* window_ = nullptr;
170     std::string startUrl_;
171     int32_t instanceId_ = -1;
172     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
173     OHOS::sptr<OHOS::Rosen::IOccupiedAreaChangeListener> occupiedAreaChangeListener_ = nullptr;
174     OHOS::sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr;
175 
176     // ITouchOutsideListener is used for touching out of hot areas of window.
177     OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr;
178 
179     // ArkTS Form
180     bool isFormRender_ = false;
181     bool isFormRenderInit_ = false;
182     std::string bundleName_;
183     std::string moduleName_;
184     std::string hapPath_;
185     bool isBundle_ = false;
186     int32_t minCompatibleVersionCode_ = 0;
187     float formWidth_ = 0.0;
188     float formHeight_ = 0.0;
189     std::string formData_;
190     std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>> formImageDataMap_;
191     std::unique_ptr<DistributedUIManager> uiManager_;
192 };
193 
194 } // namespace OHOS::Ace
195 
196 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
197