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_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H
17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H
18 
19 #include "interfaces/inner_api/ace/ui_content.h"
20 #include "interfaces/inner_api/ace/viewport_config.h"
21 #include "native_engine/native_engine.h"
22 #include "native_engine/native_value.h"
23 #include "previewer/include/window.h"
24 
25 #include "adapter/preview/entrance/ace_run_args.h"
26 #include "adapter/preview/external/ability/context.h"
27 #include "adapter/preview/external/ability/fa/fa_context.h"
28 #include "adapter/preview/external/ability/stage/stage_context.h"
29 
30 namespace OHOS::Ace {
31 class ACE_FORCE_EXPORT UIContentImpl : public UIContent {
32 public:
33     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime);
34     UIContentImpl(OHOS::AppExecFwk::Ability* ability);
35     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime, bool isCard);
~UIContentImpl()36     ~UIContentImpl()
37     {
38         DestroyUIDirector();
39         DestroyCallback();
40     }
41 
42     // UI content lifeCycles
43     UIContentErrorCode Initialize(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override;
Initialize(OHOS::Rosen::Window * window,const std::shared_ptr<std::vector<uint8_t>> & content,napi_value storage)44     UIContentErrorCode Initialize(OHOS::Rosen::Window* window,
45         const std::shared_ptr<std::vector<uint8_t>>& content, napi_value storage) override {
46         return UIContentErrorCode::NO_ERRORS;
47     }
InitializeByName(OHOS::Rosen::Window * window,const std::string & name,napi_value storage)48     UIContentErrorCode InitializeByName(OHOS::Rosen::Window *window, const std::string &name,
49         napi_value storage) override {
50         return UIContentErrorCode::NO_ERRORS;
51     }
InitializeDynamic(const std::string & hapPath,const std::string & abcPath,const std::string & entryPoint,const std::vector<std::string> & registerComponents)52     void InitializeDynamic(const std::string& hapPath, const std::string& abcPath, const std::string& entryPoint,
53         const std::vector<std::string>& registerComponents) override {}
Initialize(OHOS::Rosen::Window * window,const std::string & url,napi_value storage,uint32_t focusWindowId)54     void Initialize(
55         OHOS::Rosen::Window* window, const std::string& url, napi_value storage, uint32_t focusWindowId) override {}
Foreground()56     void Foreground() override {}
Background()57     void Background() override {}
Focus()58     void Focus() override {}
UnFocus()59     void UnFocus() override {}
60     void Destroy() override;
OnNewWant(const OHOS::AAFwk::Want & want)61     void OnNewWant(const OHOS::AAFwk::Want& want) override {}
62 
63     // restore
Restore(OHOS::Rosen::Window * window,const std::string & contentInfo,napi_value storage,ContentInfoType type)64     UIContentErrorCode Restore(OHOS::Rosen::Window* window, const std::string& contentInfo,
65         napi_value storage, ContentInfoType type) override {
66         return UIContentErrorCode::NO_ERRORS;
67     }
68     std::string GetContentInfo(ContentInfoType type) const override;
69     void DestroyUIDirector() override;
70 
71     // UI content event process
72     bool ProcessBackPressed() override;
73     bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
74     bool ProcessPointerEventWithCallback(
75         const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent, const std::function<void()>& callback) override;
76     bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent, bool isPreIme) override;
77     bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
78     bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
SetIsFocusActive(bool isFocusActive)79     void SetIsFocusActive(bool isFocusActive) override {}
80     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
81     void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason,
82         const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr,
83         const std::map<OHOS::Rosen::AvoidAreaType, OHOS::Rosen::AvoidArea>& avoidAreas = {}) override;
84     void UpdateWindowMode(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override {}
85     void UpdateDecorVisible(bool visible, bool hasDeco = true) override {};
HideWindowTitleButton(bool hideSplit,bool hideMaximize,bool hideMinimize,bool hideClose)86     void HideWindowTitleButton(bool hideSplit, bool hideMaximize, bool hideMinimize, bool hideClose) override {}
SetIgnoreViewSafeArea(bool ignoreViewSafeArea)87     void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) override {}
UpdateTitleInTargetPos(bool isShow,int32_t height)88     void UpdateTitleInTargetPos(bool isShow, int32_t height) override {}
89 
90     // Window color
91     uint32_t GetBackgroundColor() override;
92     void SetBackgroundColor(uint32_t color) override;
93 
94     void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
95 
96     // Set UIContent callback for custom window animation
97     void SetNextFrameLayoutCallback(std::function<void()>&& callback) override;
98 
99     // Receive memory level notification
100     void NotifyMemoryLevel(int32_t level) override;
101 
SetAppWindowTitle(const std::string & title)102     void SetAppWindowTitle(const std::string& title) override {}
SetAppWindowIcon(const std::shared_ptr<Media::PixelMap> & pixelMap)103     void SetAppWindowIcon(const std::shared_ptr<Media::PixelMap>& pixelMap) override {}
SetActionEventHandler(std::function<void (const std::string & action)> && actionCallback)104     void SetActionEventHandler(std::function<void(const std::string& action)>&& actionCallback) override {}
SetErrorEventHandler(std::function<void (const std::string &,const std::string &)> && errorCallback)105     void SetErrorEventHandler(std::function<void(const std::string&, const std::string&)>&& errorCallback) override {}
SetFormLinkInfoUpdateHandler(std::function<void (const std::vector<std::string> &)> && callback)106     void SetFormLinkInfoUpdateHandler(std::function<void(const std::vector<std::string>&)>&& callback) override {}
107 
108     // ArkTS Form
PreInitializeForm(OHOS::Rosen::Window * window,const std::string & url,napi_value storage)109     void PreInitializeForm(OHOS::Rosen::Window* window, const std::string& url, napi_value storage) override {}
RunFormPage()110     void RunFormPage() override {}
111     void OnFormSurfaceChange(float width, float height,
112         OHOS::Rosen::WindowSizeChangeReason type = static_cast<OHOS::Rosen::WindowSizeChangeReason>(0),
113         const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr) override {}
UpdateFormData(const std::string & data)114     void UpdateFormData(const std::string& data) override {}
UpdateFormSharedImage(const std::map<std::string,sptr<OHOS::AppExecFwk::FormAshmem>> & imageDataMap)115     void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap) override
116     {}
SetFormWidth(float width)117     void SetFormWidth(float width) override {}
SetFormHeight(float height)118     void SetFormHeight(float height) override {}
GetFormWidth()119     float GetFormWidth() override
120     {
121         return 0.0;
122     }
GetFormHeight()123     float GetFormHeight() override
124     {
125         return 0.0;
126     }
GetFormRootNode()127     std::shared_ptr<Rosen::RSSurfaceNode> GetFormRootNode() override
128     {
129         return nullptr;
130     }
131 
132     int32_t CreateModalUIExtension(const AAFwk::Want& want,
133         const ModalUIExtensionCallbacks& callbacks, const ModalUIExtensionConfig& config) override;
134     void CloseModalUIExtension(int32_t sessionId) override;
135 
SetParentToken(sptr<IRemoteObject> token)136     void SetParentToken(sptr<IRemoteObject> token) override {}
GetParentToken()137     sptr<IRemoteObject> GetParentToken() override
138     {
139         return nullptr;
140     }
141 
GetFormSerializedGesture()142     SerializedGesture GetFormSerializedGesture() override
143     {
144         return SerializedGesture();
145     }
146 
UpdateTransform(const OHOS::Rosen::Transform & transform)147     void UpdateTransform(const OHOS::Rosen::Transform& transform) override {};
148 
SetContentNodeGrayScale(float grayscale)149     void SetContentNodeGrayScale(float grayscale) override {};
150 
PreLayout()151     void PreLayout() override {};
152 
153     void SetStatusBarItemColor(uint32_t color) override;
154 
SetForceSplitEnable(bool isForceSplit,const std::string & homePage)155     void SetForceSplitEnable(bool isForceSplit, const std::string& homePage) override {};
156 
EnableContainerModalGesture(bool isEnable)157     void EnableContainerModalGesture(bool isEnable) override {};
158 
GetContainerFloatingTitleVisible()159     bool GetContainerFloatingTitleVisible() override
160     {
161         return false;
162     }
163 
GetContainerCustomTitleVisible()164     bool GetContainerCustomTitleVisible() override
165     {
166         return false;
167     }
168 
GetContainerControlButtonVisible()169     bool GetContainerControlButtonVisible() override
170     {
171         return false;
172     }
173 
174 private:
175     UIContentErrorCode CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo,
176         napi_value storage);
177     void DestroyCallback() const;
178 
179 private:
180     int32_t instanceId_ = -1;
181     void* runtime_ = nullptr;
182     // All parameters that need to be passed.
183     std::string assetPath_;
184     std::string systemResourcesPath_;
185     std::string appResourcesPath_;
186     std::string containerSdkPath_;
187     std::string language_;
188     std::string region_;
189     std::string script_;
190     uint32_t themeId_ = 0;
191     int32_t deviceWidth_ = 0;
192     int32_t deviceHeight_ = 0;
193     bool isRound_ = false;
194     Platform::SendCurrentRouterCallback onRouterChange_;
195     DeviceConfig deviceConfig_;
196 
197     std::string bundleName_;
198     std::string moduleName_;
199     std::string compileMode_;
200     std::string pageProfile_;
201     int32_t compatibleVersion_ = 0;
202     int32_t targetVersion_ = 0;
203     bool installationFree_ = false;
204     uint32_t labelId_ = 0;
205     bool useNewPipeline_ = true;
206 
207     sptr<OHOS::Rosen::Window> rsWindow_;
208     // ITouchOutsideListener is used for touching out of hot areas of window.
209     OHOS::sptr<OHOS::Rosen::ITouchOutsideListener> touchOutsideListener_ = nullptr;
210     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
211     OHOS::sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_ = nullptr;
212     OHOS::sptr<OHOS::Rosen::IIgnoreViewSafeAreaListener> ignoreViewSafeAreaListener_ = nullptr;
213     // ArkTS Form
214     bool isFormRender_ = false;
215 };
216 } // namespace OHOS::Ace
217 
218 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ENTRANCE_UI_CONTENT_IMPL_H
219