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